1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Authors: Martin Trapp, Christian Schaefer
16 # include "entity_t.h"
18 # include "typegmod_t.h"
20 /* All this is needed to build the constant node for methods: */
24 /*******************************************************************/
26 /*******************************************************************/
33 /*******************************************************************/
35 /*******************************************************************/
37 inline void insert_entity_in_owner (entity *ent) {
38 type *owner = ent->owner;
39 switch (get_type_tpop_code(owner)) {
41 add_class_member (owner, ent);
44 add_struct_member (owner, ent);
47 add_union_member (owner, ent);
50 set_array_element_entity(owner, ent);
57 new_entity (type *owner, ident *name, type *type)
62 res = (entity *) malloc (sizeof (entity));
64 assert_legal_owner_of_ent(owner);
68 if (get_type_tpop(type) == type_method)
69 res->allocation = static_allocated;
71 res->allocation = automatic_allocated;
72 res->visibility = local;
74 if (is_method_type(type)) {
75 res->variability = constant;
76 rem = current_ir_graph;
77 current_ir_graph = get_const_code_irg();
78 res->value = new_Const(mode_p, tarval_p_from_entity(res));
79 current_ir_graph = rem;
81 res->variability = uninitialized;
83 res->peculiarity = existent;
84 res->volatility = non_volatile;
86 res->overwrites = NEW_ARR_F(entity *, 1);
87 res->overwrittenby = NEW_ARR_F(entity *, 1);
93 /* Remember entity in it's owner. */
94 insert_entity_in_owner (res);
97 inline void free_entity_attrs(entity *ent) {
99 DEL_ARR_F(ent->overwrites);
100 DEL_ARR_F(ent->overwrittenby);
104 copy_entity_own (entity *old, type *new_owner) {
107 assert_legal_owner_of_ent(new_owner);
108 if (old->owner == new_owner) return old;
109 new = (entity *) malloc (sizeof (entity));
110 memcpy (new, old, sizeof (entity));
111 new->owner = new_owner;
112 new->overwrites = DUP_ARR_F(entity *, old->overwrites);
113 new->overwrittenby = DUP_ARR_F(entity *, old->overwrittenby);
115 insert_entity_in_owner (new);
121 copy_entity_name (entity *old, ident *new_name) {
124 if (old->name == new_name) return old;
125 new = (entity *) malloc (sizeof (entity));
126 memcpy (new, old, sizeof (entity));
127 new->name = new_name;
129 new->overwrites = DUP_ARR_F(entity *, old->overwrites);
130 new->overwrittenby = DUP_ARR_F(entity *, old->overwrittenby);
132 insert_entity_in_owner (new);
138 get_entity_name (entity *ent) {
140 return id_to_str(get_entity_ident(ent));
144 get_entity_ident (entity *ent) {
150 void set_entity_ld_name (entity *, char *ld_name);
151 void set_entity_ld_ident (entity *, ident *ld_ident);
155 get_entity_owner (entity *ent) {
156 return ent->owner = skip_tid(ent->owner);
160 set_entity_owner (entity *ent, type *owner) {
161 assert_legal_owner_of_ent(owner);
165 inline void /* should this go into type.c? */
166 assert_legal_owner_of_ent(type *owner) {
167 assert (get_type_tpop_code(owner) == tpo_class ||
168 get_type_tpop_code(owner) == tpo_union ||
169 get_type_tpop_code(owner) == tpo_struct ||
170 get_type_tpop_code(owner) == tpo_array); /* Yes, array has an entity
171 -- to select fields! */
175 get_entity_ld_ident (entity *ent)
177 if (ent->ld_name == NULL)
178 ent->ld_name = mangle_entity (ent);
183 set_entity_ld_ident (entity *ent, ident *ld_ident) {
184 ent->ld_name = ld_ident;
188 get_entity_ld_name (entity *ent) {
189 return id_to_str(get_entity_ld_ident(ent));
193 char *get_entity_ld_name (entity *);
194 void set_entity_ld_name (entity *, char *ld_name);
198 get_entity_type (entity *ent) {
199 return ent->type = skip_tid(ent->type);
203 set_entity_type (entity *ent, type *type) {
208 inline ent_allocation
209 get_entity_allocation (entity *ent) {
210 return ent->allocation;
214 set_entity_allocation (entity *ent, ent_allocation al) {
215 ent->allocation = al;
219 inline ent_visibility
220 get_entity_visibility (entity *ent) {
221 return ent->visibility;
225 set_entity_visibility (entity *ent, ent_visibility vis) {
226 if (vis != local) assert(ent->allocation == static_allocated);
227 ent->visibility = vis;
230 inline ent_variability
231 get_entity_variability (entity *ent) {
232 return ent->variability;
236 set_entity_variability (entity *ent, ent_variability var){
237 if (var == part_constant)
238 assert(is_class_type(ent->type) || is_struct_type(ent->type));
239 if ((is_compound_type(ent->type)) &&
240 (ent->variability == uninitialized) && (var != uninitialized)) {
241 /* Allocate datastructures for constant values */
242 ent->values = NEW_ARR_F(ir_node *, 1);
243 ent->val_ents = NEW_ARR_F(entity *, 1);
245 if ((is_compound_type(ent->type)) &&
246 (var == uninitialized) && (ent->variability != uninitialized)) {
247 /* Free datastructures for constant values */
248 DEL_ARR_F(ent->values);
249 DEL_ARR_F(ent->val_ents);
251 ent->variability = var;
255 inline ent_volatility
256 get_entity_volatility (entity *ent) {
257 return ent->volatility;
261 set_entity_volatility (entity *ent, ent_volatility vol) {
262 ent->volatility = vol;
266 get_entity_peculiarity (entity *ent) {
268 assert (is_method_type(ent->type));
269 return ent->peculiarity;
273 set_entity_peculiarity (entity *ent, peculiarity pec) {
275 assert (is_method_type(ent->type));
276 ent->peculiarity = pec;
279 /* Set has no effect for entities of type method. */
281 get_atomic_ent_value(entity *ent) {
282 assert(ent); assert(is_atomic_entity(ent)); assert((ent->variability != uninitialized));
287 set_atomic_ent_value(entity *ent, ir_node *val) {
288 assert(ent && is_atomic_entity(ent) && (ent->variability != uninitialized));
289 if (is_method_type(ent->type)) return;
293 ir_node *copy_value(ir_node *n) {
298 switch(get_irn_opcode(n)) {
300 nn = new_Const(m, get_Const_tarval(n)); break;
302 nn = new_SymConst(get_SymConst_type_or_id(n), get_SymConst_kind(n)); break;
304 nn = new_Add(copy_value(get_Add_left(n)), copy_value(get_Add_right(n)), m); break;
306 assert(0 && "opdope invalid or not implemented"); break;
311 /* Copies the value represented by the entity to current_block
312 in current_ir_graph. */
313 ir_node *copy_atomic_ent_value(entity *ent) {
314 assert(ent && is_atomic_entity(ent) && (ent->variability != uninitialized));
315 return copy_value(ent->value);
318 /* A value of a compound entity is a pair of value and the corresponding member of
321 add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
322 assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
323 ARR_APP1 (ir_node *, ent->values, val);
324 ARR_APP1 (entity *, ent->val_ents, member);
328 get_compound_ent_n_values(entity *ent) {
329 assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
330 return (ARR_LEN (ent->values))-1;
334 get_compound_ent_value(entity *ent, int pos) {
335 assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
336 return ent->values[pos+1];
339 /* Copies the value i of the entity to current_block in current_ir_graph. */
340 ir_node *copy_compound_ent_value(entity *ent, int pos) {
341 assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
342 return copy_value(ent->values[pos+1]);
346 get_compound_ent_value_member(entity *ent, int pos) {
347 assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
348 return ent->val_ents[pos+1];
352 set_compound_ent_value(entity *ent, ir_node *val, entity *member, int pos) {
353 assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
354 ent->values[pos+1] = val;
355 ent->val_ents[pos+1] = member;
359 get_entity_offset (entity *ent) {
364 set_entity_offset (entity *ent, int offset) {
365 ent->offset = offset;
369 add_entity_overwrites (entity *ent, entity *overwritten) {
371 assert(is_class_type(get_entity_owner(ent)));
372 ARR_APP1 (entity *, ent->overwrites, overwritten);
373 ARR_APP1 (entity *, overwritten->overwrittenby, ent);
377 get_entity_n_overwrites (entity *ent) {
379 assert(is_class_type(get_entity_owner(ent)));
380 return (ARR_LEN (ent->overwrites))-1;
384 get_entity_overwrites (entity *ent, int pos) {
386 assert(is_class_type(get_entity_owner(ent)));
387 assert(pos < get_entity_n_overwrites(ent));
388 return ent->overwrites[pos+1];
392 set_entity_overwrites (entity *ent, int pos, entity *overwritten) {
394 assert(is_class_type(get_entity_owner(ent)));
395 assert(pos < get_entity_n_overwrites(ent));
396 ent->overwrites[pos+1] = overwritten;
400 add_entity_overwrittenby (entity *ent, entity *overwrites) {
402 assert(is_class_type(get_entity_owner(ent)));
403 add_entity_overwrites(overwrites, ent);
407 get_entity_n_overwrittenby (entity *ent) {
409 assert(is_class_type(get_entity_owner(ent)));
410 return (ARR_LEN (ent->overwrittenby))-1;
414 get_entity_overwrittenby (entity *ent, int pos) {
416 assert(is_class_type(get_entity_owner(ent)));
417 assert(pos < get_entity_n_overwrittenby(ent));
418 return ent->overwrittenby[pos+1];
422 set_entity_overwrittenby (entity *ent, int pos, entity *overwrites) {
424 assert(is_class_type(get_entity_owner(ent)));
425 assert(pos < get_entity_n_overwrittenby(ent));
426 ent->overwrittenby[pos+1] = overwrites;
429 /* A link to store intermediate information */
431 get_entity_link(entity *ent) {
437 set_entity_link(entity *ent, void *l) {
443 get_entity_irg(entity *ent) {
445 assert (is_method_type(ent->type));
450 set_entity_irg(entity *ent, ir_graph *irg) {
451 assert (ent && ent->type);
453 assert (is_method_type(ent->type));
454 assert (ent->peculiarity == existent);
458 int is_atomic_entity(entity *ent) {
459 type* t = get_entity_type(ent);
460 return (is_primitive_type(t) || is_pointer_type(t) ||
461 is_enumeration_type(t) || is_method_type(t));
464 int is_compound_entity(entity *ent) {
465 type* t = get_entity_type(ent);
466 return (is_class_type(t) || is_struct_type(t) ||
467 is_array_type(t) || is_union_type(t));