3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 Institut f. Computersprachen, TU Wien
5 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser, M. Probst,
6 S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich,
9 This file is part of CACAO.
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2, or (at
14 your option) any later version.
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 Contact: cacao@complang.tuwien.ac.at
28 Authors: Carolyn Oates
30 $Id: sets.c 557 2003-11-02 22:51:59Z twisti $
42 * set.c - functions to manipulate ptr sets.
46 /*------------------------------------------------------------*/
47 /*-- fieldinfo call set fns */
48 /*------------------------------------------------------------*/
49 fldSetNode *inFldSet(fldSetNode *s, fieldinfo *f)
52 for (i=s; i != NULL; i = i->nextfldRef) {
54 return i; /* true = found */
61 /*------------------------------------------------------------*/
63 fldSetNode *addFldRef(fldSetNode *s, fieldinfo *f)
67 s1 = (fldSetNode *)malloc(sizeof(fldSetNode));
72 s1->lastptrPUT = NULL;
73 s1->lastptrGET = NULL;
78 s1->index = s->index+1;
84 /*------------------------------------------------------------*/
85 fldSet *add2FldSet(fldSet *sf, fieldinfo *f, bool wput, bool rget)
96 s1 = (fldSetNode *)malloc(sizeof(fldSetNode));
97 if (sf->head == NULL) {
103 sf->tail->nextfldRef = s1;
105 s1->index = sf->length;
107 s1->nextfldRef = NULL;
111 s1->lastptrPUT = NULL;
112 s1->lastptrGET = NULL;
116 if ((s1->writePUT == false) && (wput))
118 if ((s1->readGET == false) && (rget))
125 /*------------------------------------------------------------*/
126 fldSet *createFldSet( )
129 s = (fldSet *)malloc(sizeof(fldSet));
138 /*------------------------------------------------------------*/
139 /*-- methodinfo call set fns */
140 /*------------------------------------------------------------*/
141 int inMethSet (methSetNode *s, methodinfo *m)
144 for (i=s; i != NULL; i = i->nextmethRef) {
145 if (i->methRef == m) {
146 return (int)1; /* true = found */
153 /*------------------------------------------------------------*/
154 methSetNode *addMethRef(methSetNode *s, methodinfo *m)
157 if (!inMethSet(s,m)) {
158 s1 = (methSetNode *)malloc(sizeof(methSetNode));
161 s1->lastptrIntoClassSet2 = NULL;
165 s1->index = s->index+1;
173 /*------------------------------------------------------------*/
174 methSet *add2MethSet(methSet *sm, methodinfo *m)
180 sm = createMethSet();
183 if (!inMethSet(s,m)) {
184 s1 = (methSetNode *)malloc(sizeof(methSetNode));
185 if (sm->head == NULL) {
191 sm->tail->nextmethRef = s1;
193 s1->index = sm->length;
196 s1->nextmethRef= NULL;
198 s1->lastptrIntoClassSet2 = NULL;
205 /*------------------------------------------------------------*/
206 methSet *createMethSet( )
209 s = (methSet *)malloc(sizeof(methSet));
218 /*------------------------------------------------------------*/
219 /*-- classinfo XTA set fns */
220 /*------------------------------------------------------------*/
221 int inSet (classSetNode *s, classinfo *c)
224 for (i=s; i != NULL; i = i->nextClass) {
225 if (i->classType == c) {
226 return ((i->index)+1); /* true = found */
233 /*------------------------------------------------------------*/
234 classSetNode *addElement(classSetNode *s, classinfo *c)
236 classSetNode *s1 = s;
238 s1 = (classSetNode *)malloc(sizeof(classSetNode));
244 s1->index = s->index+1;
250 /*------------------------------------------------------------*/
251 classSet *add2ClassSet(classSet *sc, classinfo *c)
257 sc = createClassSet();
262 s1 = (classSetNode *)malloc(sizeof(classSetNode));
263 if (sc->head == NULL) {
269 sc->tail->nextClass = s1;
271 s1->index = sc->length;
281 /*------------------------------------------------------------*/
282 classSet *createClassSet( )
285 s = (classSet *)malloc(sizeof(classSet));
294 /*------------------------------------------------------------*/
296 /* -1 c is a subclass of an existing set element */
297 /* 0 c class type cone does not overlap any set element */
298 /* 1 c is a superclass of an existing set element */
300 int inRange (classSetNode *s, classinfo *c)
305 for (i=s; i != NULL; i = i->nextClass) {
306 classinfo *cs = i->classType;
307 if (cs->vftbl->baseval <= c->vftbl->baseval) {
308 if (c->vftbl->baseval <= (cs->vftbl->baseval+cs->vftbl->diffval)) {
309 rc = -1; /* subtype */
313 if (cs->vftbl->baseval < (c->vftbl->baseval+c->vftbl->diffval)) {
314 i->classType = c; /* replace element with its new super */
323 /*------------------------------------------------------------*/
324 /* adds class if not subtype of an existing set element */
325 /* if "new" class is super class of an existing element */
326 /* then replace the existing element with the "new" class */
328 classSetNode *addClassCone(classSetNode *s, classinfo *c)
330 classSetNode *s1 = s;
332 if (inRange(s,c) == 0) {
333 /* not in set nor cone of an existing element so add */
334 s1 = (classSetNode *)malloc(sizeof(classSetNode));
340 s1->index = s->index+1;
346 /*------------------------------------------------------------*/
347 classSetNode * intersectSubtypesWithSet(classinfo *t, classSetNode *s) {
348 classSetNode *s1 = NULL;
351 /* for each s class */
352 for (c=s; c != NULL; c = c->nextClass) {
353 vftbl *t_cl_vt = t->vftbl;
354 vftbl *c_cl_vt = c->classType->vftbl;
356 /* if s class is in the t Class range */
357 if ( (t_cl_vt->baseval <= c_cl_vt->baseval)
358 && (c_cl_vt->baseval <= (t_cl_vt->baseval+t_cl_vt->diffval)) ) {
360 /* add s class to return class set */
361 s1 = addElement(s1,c->classType);
368 /*------------------------------------------------------------*/
369 int sizeOfSet(classSetNode *s) {
370 /*** need to update */
373 for (i=s; i != NULL; i = i->nextClass) cnt++;
378 /*------------------------------------------------------------*/
379 int printSet(classSetNode *s)
385 printf("Set of types: <");
386 printf("\t\tEmpty Set\n");
389 printf("<%i>Set of types: ",s->index);
390 for (i=s; i != NULL; i = i->nextClass) {
391 printf("\t#%i: ",cnt);
392 if (i->classType == NULL) {
393 printf("NULL CLASS");
397 utf_display(i->classType->name);
399 printf("<b%i/d%i> ",i->classType->vftbl->baseval,i->classType->vftbl->diffval);
410 /*------------------------------------------------------------*/
411 int printClassSet(classSet *sc) {
413 printf("Class Set not yet created\n");
417 return (printSet(sc->head));
421 /*------------------------------------------------------------*/
422 int printMethSet(methSetNode *s)
428 printf("Set of Methods: "); fflush(stdout);
429 printf("\t\tEmpty Set\n"); fflush(stdout);
432 printf("<%i>Set of Methods: ",s->index);fflush(stdout);
433 for (i=s; i != NULL; i = i->nextmethRef) {
434 printf("\t#%i: ",cnt);
437 utf_display(i->methRef->class->name);
439 method_display(i->methRef);
441 /* lastptr <class> */
443 if (i->lastptrIntoClassSet2 != NULL)
444 utf_display(i->lastptrIntoClassSet2->classType->name);
455 /*------------------------------------------------------------*/
456 int printMethodSet(methSet *sm) {
458 printf("Method Set not yet created\n");
462 return (printMethSet(sm->head));
466 /*------------------------------------------------------------*/
467 int printFldSet(fldSetNode *s)
473 printf("Set of Fields: ");
474 printf("\tEmpty Set\n");
477 printf("<%i>Set of Fields: ",s->index);
478 for (i=s; i != NULL; i = i->nextfldRef) {
479 printf("\t#%i: ",cnt);
480 printf("(%ir/%iw)",i->writePUT,i->readGET);
481 field_display(i->fldRef);
490 /*------------------------------------------------------------*/
491 int printFieldSet(fldSet *sf) {
493 printf("Field Set not yet created\n");
497 return (printFldSet(sf->head));
499 /*------------------------------------------------------------*/
500 /*void destroy_set */
504 * These are local overrides for various environment variables in Emacs.
505 * Please do not remove this and leave it at the end of the file, where
506 * Emacs will automagically detect them.
507 * ---------------------------------------------------------------------
510 * indent-tabs-mode: t