From e683a3e23ede57c176578db22c4a72050f101369 Mon Sep 17 00:00:00 2001 From: =?utf8?q?G=C3=B6tz=20Lindenmaier?= Date: Thu, 22 Aug 2002 10:29:32 +0000 Subject: [PATCH] Add access functions to entity visited flag, fix remove_member functions in type.c [r461] --- ir/tr/entity.c | 38 +++++++++++++++++++++++++++++++++----- ir/tr/entity.h | 29 +++++++++++++++++++++++++++++ ir/tr/type.c | 30 +++++++++++++++--------------- ir/tr/type.h | 17 +++++++---------- 4 files changed, 84 insertions(+), 30 deletions(-) diff --git a/ir/tr/entity.c b/ir/tr/entity.c index ef73a5478..14c895ad3 100644 --- a/ir/tr/entity.c +++ b/ir/tr/entity.c @@ -27,6 +27,8 @@ /** general **/ /*******************************************************************/ +unsigned long entity_visited; + void init_entity (void) { @@ -96,10 +98,13 @@ new_entity (type *owner, ident *name, type *type) insert_entity_in_owner (res); return res; } + INLINE void free_entity_attrs(entity *ent) { assert(ent); - DEL_ARR_F(ent->overwrites); - DEL_ARR_F(ent->overwrittenby); + if (get_type_tpop(get_entity_owner(ent)) == type_class) { + DEL_ARR_F(ent->overwrites); + DEL_ARR_F(ent->overwrittenby); + } } entity * @@ -111,8 +116,15 @@ copy_entity_own (entity *old, type *new_owner) { new = (entity *) malloc (sizeof (entity)); memcpy (new, old, sizeof (entity)); new->owner = new_owner; - new->overwrites = DUP_ARR_F(entity *, old->overwrites); - new->overwrittenby = DUP_ARR_F(entity *, old->overwrittenby); + if ((get_type_tpop(get_entity_owner(old)) == type_class) && + (get_type_tpop(new_owner) == type_class)) { + new->overwrites = DUP_ARR_F(entity *, old->overwrites); + new->overwrittenby = DUP_ARR_F(entity *, old->overwrittenby); + } else if ((get_type_tpop(get_entity_owner(old)) != type_class) && + (get_type_tpop(new_owner) == type_class)) { + new->overwrites = NEW_ARR_F(entity *, 1); + new->overwrittenby = NEW_ARR_F(entity *, 1); + } insert_entity_in_owner (new); @@ -138,7 +150,8 @@ copy_entity_name (entity *old, ident *new_name) { void free_entity (entity *ent) { - /* @@@ */ + free_entity_attrs(ent); + free(ent); } INLINE const char * @@ -515,3 +528,18 @@ int is_compound_entity(entity *ent) { bool equal_entity(entity *ent1, entity *ent2) { return true; } + + +unsigned long get_entity_visited(entity *entity) { + assert (entity); + return entity->visit; +} +void set_entity_visited(entity *entity, unsigned long num) { + assert (entity); + entity->visit = num; +} +/* Sets visited field in entity to entity_visited. */ +void mark_entity_visited(entity *entity) { + assert (entity); + entity->visit = entity_visited; +} diff --git a/ir/tr/entity.h b/ir/tr/entity.h index f084074d0..e70924cf1 100644 --- a/ir/tr/entity.h +++ b/ir/tr/entity.h @@ -103,6 +103,7 @@ typedef struct ir_graph ir_graph; * In that case there nowhere exists code for this entity and this entity * is never dynamically used in the code. * Values: description, existent. Default: existent. + * visited visited flag. Master flag is entity_visited. * * These fields can only be accessed via access functions. * @@ -117,6 +118,7 @@ typedef struct ir_graph ir_graph; typedef struct entity entity; #endif + /* Creates a new entity. Automatically inserts the entity as a member of owner. Entity is automatic_allocated and uninitialize except if the type @@ -283,9 +285,36 @@ int is_compound_entity(entity *ent); /* Returns true if ent1 and ent2 have are equal except for their owner. Two entities are equal if - they have the same type (the same C-struct) + - ...? */ bool equal_entity(entity *ent1, entity *ent2); + +unsigned long get_entity_visited(entity *entity); +void set_entity_visited(entity *entity, unsigned long num); +/* Sets visited field in entity to entity_visited. */ +void mark_entity_visited(entity *entity); + + /*****/ + +/****v* entity/visited + * + * NAME + * entity_visited - visited flag to traverse the entity information + * PURPOSE + * Increase this flag by one before traversing the entity information. + * Mark entity nodes as visited by set_entity_visited(entity, value) or + * mark_entity_visited. + * Check whether node was already visited by comparing get_entity_visited(entity) + * and entity_visited. + * Or use the function to walk all entities. + * SEE ALSO + * SOURCE + */ +extern unsigned long entity_visited; +/*****/ + + # endif /* _ENTITY_H_ */ diff --git a/ir/tr/type.c b/ir/tr/type.c index b536ea2a7..19f460001 100644 --- a/ir/tr/type.c +++ b/ir/tr/type.c @@ -563,9 +563,9 @@ void set_class_members (type *clss, entity **members, int arity) { void remove_class_member(type *clss, entity *member) { int i; assert(clss && (clss->type_op == type_class)); - for (i = 1; i < (ARR_LEN (clss->attr.ca.members))-1; i++) - if (clss->attr.ca.members[i+1] == member) { - for(i++; i < (ARR_LEN (clss->attr.ca.members)) - 1; i++) + for (i = 1; i < (ARR_LEN (clss->attr.ca.members)); i++) + if (clss->attr.ca.members[i] == member) { + for(; i < (ARR_LEN (clss->attr.ca.members)) - 1; i++) clss->attr.ca.members[i] = clss->attr.ca.members[i + 1]; ARR_SETLEN(entity*, clss->attr.ca.members, ARR_LEN(clss->attr.ca.members) - 1); break; @@ -599,9 +599,9 @@ void set_class_subtype (type *clss, type *subtype, int pos) { void remove_class_subtype(type *clss, type *subtype) { int i; assert(clss && (clss->type_op == type_class)); - for (i = 1; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++) - if (clss->attr.ca.subtypes[i+1] == subtype) { - for(i++; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++) + for (i = 1; i < (ARR_LEN (clss->attr.ca.subtypes)); i++) + if (clss->attr.ca.subtypes[i] == subtype) { + for(; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++) clss->attr.ca.subtypes[i] = clss->attr.ca.subtypes[i+1]; ARR_SETLEN(entity*, clss->attr.ca.subtypes, ARR_LEN(clss->attr.ca.subtypes) - 1); break; @@ -636,9 +636,9 @@ void set_class_supertype (type *clss, type *supertype, int pos) { void remove_class_supertype(type *clss, type *supertype) { int i; assert(clss && (clss->type_op == type_class)); - for (i = 1; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++) - if (clss->attr.ca.supertypes[i+1] == supertype) { - for(i++; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++) + for (i = 1; i < (ARR_LEN (clss->attr.ca.supertypes)); i++) + if (clss->attr.ca.supertypes[i] == supertype) { + for(; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++) clss->attr.ca.supertypes[i] = clss->attr.ca.supertypes[i+1]; ARR_SETLEN(entity*, clss->attr.ca.supertypes, ARR_LEN(clss->attr.ca.supertypes) - 1); break; @@ -726,9 +726,9 @@ void set_struct_member (type *strct, int pos, entity *member) { void remove_struct_member(type *strct, entity *member) { int i; assert(strct && (strct->type_op == type_struct)); - for (i = 1; i < (ARR_LEN (strct->attr.sa.members))-1; i++) - if (strct->attr.sa.members[i+1] == member) { - for(i++; i < (ARR_LEN (strct->attr.sa.members))-1; i++) + for (i = 1; i < (ARR_LEN (strct->attr.sa.members)); i++) + if (strct->attr.sa.members[i] == member) { + for(; i < (ARR_LEN (strct->attr.sa.members))-1; i++) strct->attr.sa.members[i] = strct->attr.sa.members[i+1]; ARR_SETLEN(entity*, strct->attr.sa.members, ARR_LEN(strct->attr.sa.members) - 1); break; @@ -871,9 +871,9 @@ void set_union_member (type *uni, int pos, entity *member) { void remove_union_member(type *uni, entity *member) { int i; assert(uni && (uni->type_op == type_union)); - for (i = 1; i < (ARR_LEN (uni->attr.ua.members))-1; i++) - if (uni->attr.ua.members[i+1] == member) { - for(i++; i < (ARR_LEN (uni->attr.ua.members))-1; i++) + for (i = 1; i < (ARR_LEN (uni->attr.ua.members)); i++) + if (uni->attr.ua.members[i] == member) { + for(; i < (ARR_LEN (uni->attr.ua.members))-1; i++) uni->attr.ua.members[i] = uni->attr.ua.members[i+1]; ARR_SETLEN(entity*, uni->attr.ua.members, ARR_LEN(uni->attr.ua.members) - 1); break; diff --git a/ir/tr/type.h b/ir/tr/type.h index 252bb806f..2b5ba80c9 100644 --- a/ir/tr/type.h +++ b/ir/tr/type.h @@ -320,8 +320,9 @@ void set_class_member (type *clss, entity *member, int pos); members is an array of entities, num the size of this array. Sets all owners of the members passed to clss. */ void set_class_members (type *clss, entity **members, int arity); -/* Finds member in the list of members and overwrites it with NULL - @@@ Doesn't work properly. */ +/* Finds member in the list of members and removes it. + Shrinks the member list, so iterate from the end!!! + Does not deallocate the entity. */ void remove_class_member(type *clss, entity *member); @@ -337,8 +338,7 @@ type *get_class_subtype (type *clss, int pos); set the corresponding supertype relation for subtype: this might be a different position! */ void set_class_subtype (type *clss, type *subtype, int pos); -/* Finds subtype in the list of subtypes and overwrites it with NULL - @@@ Doesn't work properly. */ +/* Finds subtype in the list of subtypes and removes it */ void remove_class_subtype(type *clss, type *subtype); @@ -354,8 +354,7 @@ type *get_class_supertype (type *clss, int pos); set the corresponding subtype relation for supertype: this might be a different position! */ void set_class_supertype (type *clss, type *supertype, int pos); -/* Finds supertype in the list of supertypes and overwrites it with NULL - @@@ Doesn't work properly. */ +/* Finds supertype in the list of supertypes and removes it */ void remove_class_supertype(type *clss, type *supertype); /* This enumeration flags the peculiarity of entities and types. */ @@ -411,8 +410,7 @@ void add_struct_member (type *strct, entity *member); int get_struct_n_members (type *strct); entity *get_struct_member (type *strct, int pos); void set_struct_member (type *strct, int pos, entity *member); -/* Finds member in the list of memberss and overwrites it with NULL - @@@ Doesn't work properly. */ +/* Finds member in the list of memberss and removees it */ void remove_struct_member (type *strct, entity *member); /* typecheck */ @@ -486,8 +484,7 @@ int get_union_n_members (type *uni); void add_union_member (type *uni, entity *member); entity *get_union_member (type *uni, int pos); void set_union_member (type *uni, int pos, entity *member); -/* Finds member in the list of members and overwrites it with NULL - @@@ Doesn't work properly. */ +/* Finds member in the list of members and removes it. */ void remove_union_member (type *uni, entity *member); /* typecheck */ -- 2.20.1