10 * set.c - functions to manipulate ptr sets.
13 /*------------------------------------------------------------*/
14 /*-- fieldinfo call set fns */
15 /*------------------------------------------------------------*/
16 fldSetNode *inFldSet (fldSetNode *s, fieldinfo *f)
19 for (i=s; i != NULL; i = i->nextfldRef) {
21 return i; /* true = found */
27 /*------------------------------------------------------------*/
29 fldSetNode *addFldRef(fldSetNode *s, fieldinfo *f)
33 s1 = (fldSetNode *)malloc(sizeof(fldSetNode));
38 s1->lastptrPUT = NULL;
39 s1->lastptrGET = NULL;
44 s1->index = s->index+1;
49 /*------------------------------------------------------------*/
50 fldSet *add2FldSet(fldSet *sf, fieldinfo *f, bool wput, bool rget)
61 s1 = (fldSetNode *)malloc(sizeof(fldSetNode));
62 if (sf->head == NULL) {
68 sf->tail->nextfldRef = s1;
70 s1->index = sf->length;
72 s1->nextfldRef = NULL;
76 s1->lastptrPUT = NULL;
77 s1->lastptrGET = NULL;
81 if ((s1->writePUT == false) && (wput))
83 if ((s1->readGET == false) && (rget))
89 /*------------------------------------------------------------*/
90 fldSet *createFldSet( )
93 s = (fldSet *)malloc(sizeof(fldSet));
101 /*------------------------------------------------------------*/
102 /*-- methodinfo call set fns */
103 /*------------------------------------------------------------*/
104 int inMethSet (methSetNode *s, methodinfo *m)
107 for (i=s; i != NULL; i = i->nextmethRef) {
108 if (i->methRef == m) {
109 return (int)1; /* true = found */
115 /*------------------------------------------------------------*/
116 methSetNode *addMethRef(methSetNode *s, methodinfo *m)
119 if (!inMethSet(s,m)) {
120 s1 = (methSetNode *)malloc(sizeof(methSetNode));
123 s1->lastptrIntoClassSet2 = NULL;
127 s1->index = s->index+1;
134 /*------------------------------------------------------------*/
135 methSet *add2MethSet(methSet *sm, methodinfo *m)
141 sm = createMethSet();
144 if (!inMethSet(s,m)) {
145 s1 = (methSetNode *)malloc(sizeof(methSetNode));
146 if (sm->head == NULL) {
152 sm->tail->nextmethRef = s1;
154 s1->index = sm->length;
157 s1->nextmethRef= NULL;
159 s1->lastptrIntoClassSet2 = NULL;
165 /*------------------------------------------------------------*/
166 methSet *createMethSet( )
169 s = (methSet *)malloc(sizeof(methSet));
177 /*------------------------------------------------------------*/
178 /*-- classinfo XTA set fns */
179 /*------------------------------------------------------------*/
180 int inSet (classSetNode *s, classinfo *c)
183 for (i=s; i != NULL; i = i->nextClass) {
184 if (i->classType == c) {
185 return ((i->index)+1); /* true = found */
191 /*------------------------------------------------------------*/
192 classSetNode *addElement(classSetNode *s, classinfo *c)
194 classSetNode *s1 = s;
196 s1 = (classSetNode *)malloc(sizeof(classSetNode));
202 s1->index = s->index+1;
207 /*------------------------------------------------------------*/
208 classSet *add2ClassSet(classSet *sc, classinfo *c)
214 sc = createClassSet();
219 s1 = (classSetNode *)malloc(sizeof(classSetNode));
220 if (sc->head == NULL) {
226 sc->tail->nextClass = s1;
228 s1->index = sc->length;
237 /*------------------------------------------------------------*/
238 classSet *createClassSet( )
241 s = (classSet *)malloc(sizeof(classSet));
249 /*------------------------------------------------------------*/
251 /* -1 c is a subclass of an existing set element */
252 /* 0 c class type cone does not overlap any set element */
253 /* 1 c is a superclass of an existing set element */
255 int inRange (classSetNode *s, classinfo *c)
260 for (i=s; i != NULL; i = i->nextClass) {
261 classinfo *cs = i->classType;
262 if (cs->vftbl->baseval <= c->vftbl->baseval) {
263 if (c->vftbl->baseval <= (cs->vftbl->baseval+cs->vftbl->diffval)) {
264 rc = -1; /* subtype */
268 if (cs->vftbl->baseval < (c->vftbl->baseval+c->vftbl->diffval)) {
269 i->classType = c; /* replace element with its new super */
277 /*------------------------------------------------------------*/
278 /* adds class if not subtype of an existing set element */
279 /* if "new" class is super class of an existing element */
280 /* then replace the existing element with the "new" class */
282 classSetNode *addClassCone(classSetNode *s, classinfo *c)
284 classSetNode *s1 = s;
286 if (inRange(s,c) == 0) {
287 /* not in set nor cone of an existing element so add */
288 s1 = (classSetNode *)malloc(sizeof(classSetNode));
294 s1->index = s->index+1;
299 /*------------------------------------------------------------*/
300 classSetNode * intersectSubtypesWithSet(classinfo *t, classSetNode *s) {
301 classSetNode *s1 = NULL;
304 /* for each s class */
305 for (c=s; c != NULL; c = c->nextClass) {
306 vftbl *t_cl_vt = t->vftbl;
307 vftbl *c_cl_vt = c->classType->vftbl;
309 /* if s class is in the t Class range */
310 if ( (t_cl_vt->baseval <= c_cl_vt->baseval)
311 && (c_cl_vt->baseval <= (t_cl_vt->baseval+t_cl_vt->diffval)) ) {
313 /* add s class to return class set */
314 s1 = addElement(s1,c->classType);
320 /*------------------------------------------------------------*/
321 int sizeOfSet(classSetNode *s) {
322 /*** need to update */
325 for (i=s; i != NULL; i = i->nextClass) cnt++;
329 /*------------------------------------------------------------*/
330 int printSet(classSetNode *s)
336 printf("Set of types: <");
337 printf("\t\tEmpty Set\n");
340 printf("<%i>Set of types: ",s->index);
341 for (i=s; i != NULL; i = i->nextClass) {
342 printf("\t#%i: ",cnt);
343 if (i->classType == NULL) {
344 printf("NULL CLASS");
348 utf_display(i->classType->name);
350 printf("<b%i/d%i> ",i->classType->vftbl->baseval,i->classType->vftbl->diffval);
359 /*------------------------------------------------------------*/
360 int printClassSet(classSet *sc) {
362 printf("Class Set not yet created\n");
366 return (printSet(sc->head));
369 /*------------------------------------------------------------*/
370 int printMethSet(methSetNode *s)
376 printf("Set of Methods: "); fflush(stdout);
377 printf("\t\tEmpty Set\n"); fflush(stdout);
380 printf("<%i>Set of Methods: ",s->index);fflush(stdout);
381 for (i=s; i != NULL; i = i->nextmethRef) {
382 printf("\t#%i: ",cnt);
385 utf_display(i->methRef->class->name);
387 method_display(i->methRef);
389 /* lastptr <class> */
391 if (i->lastptrIntoClassSet2 != NULL)
392 utf_display(i->lastptrIntoClassSet2->classType->name);
401 /*------------------------------------------------------------*/
402 int printMethodSet(methSet *sm) {
404 printf("Method Set not yet created\n");
408 return (printMethSet(sm->head));
410 /*------------------------------------------------------------*/
411 int printFldSet(fldSetNode *s)
417 printf("Set of Fields: ");
418 printf("\tEmpty Set\n");
421 printf("<%i>Set of Fields: ",s->index);
422 for (i=s; i != NULL; i = i->nextfldRef) {
423 printf("\t#%i: ",cnt);
424 printf("(%ir/%iw)",i->writePUT,i->readGET);
425 field_display(i->fldRef);
433 /*------------------------------------------------------------*/
434 int printFieldSet(fldSet *sf) {
436 printf("Field Set not yet created\n");
440 return (printFldSet(sf->head));
442 /*------------------------------------------------------------*/
443 /*void destroy_set */