Commit 2e3dc475 authored by Götz Lindenmaier's avatar Götz Lindenmaier
Browse files

Added walker to walk entities within a type

Added access and removal routines for entities

[r466]
parent 5470b27c
......@@ -388,6 +388,23 @@ set_compound_ent_value(entity *ent, ir_node *val, entity *member, int pos) {
ent->val_ents[pos+1] = member;
}
void
remove_compound_ent_value(entity *ent, entity *value_ent) {
int i;
assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
for (i = 1; i < (ARR_LEN (ent->val_ents)); i++) {
if (ent->val_ents[i] == value_ent) {
for(; i < (ARR_LEN (ent->val_ents))-1; i++) {
ent->val_ents[i] = ent->val_ents[i+1];
ent->values[i] = ent->values[i+1];
}
ARR_SETLEN(entity*, ent->val_ents, ARR_LEN(ent->val_ents) - 1);
ARR_SETLEN(ir_node*, ent->values, ARR_LEN(ent->values) - 1);
break;
}
}
}
void
set_array_entity_values(entity *ent, tarval **values, int num_vals) {
int i;
......
......@@ -151,7 +151,8 @@ void set_entity_ld_ident (entity *ent, ident *ld_ident);
const char *get_entity_ld_name (entity *end);
type *get_entity_owner (entity *ent);
/* Sets the owner field in entity to owner. */
/* Sets the owner field in entity to owner. Don't forget to add
ent to owner!! */
void set_entity_owner (entity *ent, type *owner);
INLINE void assert_legal_owner_of_ent(type *owner);
......@@ -247,6 +248,7 @@ int get_compound_ent_n_values(entity *ent);
ir_node *get_compound_ent_value(entity *ent, int pos);
entity *get_compound_ent_value_member(entity *ent, int pos);
void set_compound_ent_value(entity *ent, ir_node *val, entity *member, int pos);
void remove_compound_ent_value(entity *ent, entity *value_ent);
/* Inits the entity ent witch must be of a one dimensional
array type with the values given in the values array.
The array must have a lower and an upper bound. Keeps the
......
......@@ -564,13 +564,14 @@ 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)); 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;
}
}
}
void add_class_subtype (type *clss, type *subtype) {
......
......@@ -182,6 +182,7 @@ void type_walk(void (pre)(type_or_ent*, void*),
for (i = 0; i < get_irp_n_types(); i++) {
type_walk_2((type_or_ent *)get_irp_type(i), pre, post, env);
}
type_walk_2((type_or_ent *)get_glob_type(), pre, post, env);
}
void type_walk_irg (ir_graph *irg,
......@@ -458,3 +459,35 @@ void class_walk_super2sub(void (pre)(type*, void*),
}
}
}
/* Walks over all entities in the type */
void walk_types_entities(type *tp,
void (doit)(entity*, void*),
void *env) {
int i;
switch(get_type_tpop_code(tp)) {
case tpo_class: {
for (i=0; i<get_class_n_members(tp); i++)
doit(get_class_member(tp, i), env);
} break;
case tpo_struct: {
for (i=0; i<get_struct_n_members(tp); i++)
doit(get_struct_member(tp, i), env);
} break;
case tpo_union: {
for (i = 0; i < get_union_n_members(tp); i++)
doit(get_union_member(tp, i), env);
} break;
case tpo_array: {
doit(get_array_element_entity(tp), env);
} break;
case tpo_method:
case tpo_enumeration:
case tpo_pointer:
case tpo_primitive:
case tpo_id:
default:
break;
}
}
......@@ -67,4 +67,10 @@ void type_walk_super(void (pre)(type_or_ent*, void*),
void class_walk_super2sub(void (pre)(type*, void*),
void (post)(type*, void*),
void *env);
/* Walks over all entities in the type */
void walk_types_entities(type *tp,
void (doit)(entity*, void*),
void *env);
#endif /* _TYPEWALK_H_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment