3 * File name: ir/tr/entity.c
4 * Purpose: Representation of all program known entities.
5 * Author: Martin Trapp, Christian Schaefer
6 * Modified by: Goetz Lindenmaier
9 * Copyright: (c) 1998-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
21 # include "entity_t.h"
23 # include "typegmod.h"
25 /* All this is needed to build the constant node for methods: */
26 # include "irprog_t.h"
30 /*******************************************************************/
32 /*******************************************************************/
39 /*-----------------------------------------------------------------*/
41 /*-----------------------------------------------------------------*/
43 static void insert_entity_in_owner (entity *ent) {
44 type *owner = ent->owner;
45 switch (get_type_tpop_code(owner)) {
47 add_class_member (owner, ent);
50 add_struct_member (owner, ent);
53 add_union_member (owner, ent);
56 set_array_element_entity(owner, ent);
63 new_entity (type *owner, ident *name, type *type)
68 assert(!id_contains_char(name, ' ') && "entity name should not contain spaces");
70 res = (entity *) xmalloc (sizeof (entity));
72 assert_legal_owner_of_ent(owner);
77 if (get_type_tpop(type) == type_method)
78 res->allocation = allocation_static;
80 res->allocation = allocation_automatic;
82 res->visibility = visibility_local;
84 if (is_method_type(type)) {
85 res->variability = variability_constant;
86 rem = current_ir_graph;
87 current_ir_graph = get_const_code_irg();
88 res->value = new_Const(mode_P_mach, new_tarval_from_entity(res, mode_P_mach));
89 current_ir_graph = rem;
91 res->variability = variability_uninitialized;
94 res->val_paths = NULL;
96 res->peculiarity = peculiarity_existent;
97 res->volatility = volatility_non_volatile;
99 if (is_class_type(owner)) {
100 res->overwrites = NEW_ARR_F(entity *, 0);
101 res->overwrittenby = NEW_ARR_F(entity *, 0);
103 res->overwrites = NULL;
104 res->overwrittenby = NULL;
109 res->nr = get_irp_new_node_nr();
114 /* Remember entity in it's owner. */
115 insert_entity_in_owner (res);
119 new_d_entity (type *owner, ident *name, type *type, dbg_info *db) {
120 entity *res = new_entity(owner, name, type);
121 set_entity_dbg_info(res, db);
125 void free_compound_graph_path (compound_graph_path *gr);
126 int is_compound_graph_path(void *thing);
127 int get_compound_graph_path_length(compound_graph_path *gr);
128 entity *get_compound_graph_path_node(compound_graph_path *gr, int pos);
129 int get_compound_ent_n_values(entity *ent);
131 static void free_entity_attrs(entity *ent) {
133 if (get_type_tpop(get_entity_owner(ent)) == type_class) {
134 DEL_ARR_F(ent->overwrites); ent->overwrites = NULL;
135 DEL_ARR_F(ent->overwrittenby); ent->overwrittenby = NULL;
137 assert(ent->overwrites == NULL);
138 assert(ent->overwrittenby == NULL);
140 /* if (ent->values) DEL_ARR_F(ent->values); *//* @@@ warum nich? */
141 if (ent->val_paths) {
142 if (is_compound_entity(ent))
143 for (i = 0; i < get_compound_ent_n_values(ent); i++)
144 if (ent->val_paths[i]) ;
145 /* free_compound_graph_path(ent->val_paths[i]) ; * @@@ warum nich? */
146 /* Geht nich: wird mehrfach verwendet!!! ==> mehrfach frei gegeben. */
147 /* DEL_ARR_F(ent->val_paths); */
149 ent->val_paths = NULL;
154 copy_entity_own (entity *old, type *new_owner) {
156 assert(old && old->kind == k_entity);
157 assert_legal_owner_of_ent(new_owner);
159 if (old->owner == new_owner) return old;
160 new = (entity *) xmalloc (sizeof (entity));
161 memcpy (new, old, sizeof (entity));
162 new->owner = new_owner;
163 if (is_class_type(new_owner)) {
164 new->overwrites = NEW_ARR_F(entity *, 0);
165 new->overwrittenby = NEW_ARR_F(entity *, 0);
168 new->nr = get_irp_new_node_nr();
171 insert_entity_in_owner (new);
177 copy_entity_name (entity *old, ident *new_name) {
179 assert(old && old->kind == k_entity);
181 if (old->name == new_name) return old;
182 new = (entity *) xmalloc (sizeof (entity));
183 memcpy (new, old, sizeof (entity));
184 new->name = new_name;
186 if (is_class_type(new->owner)) {
187 new->overwrites = DUP_ARR_F(entity *, old->overwrites);
188 new->overwrittenby = DUP_ARR_F(entity *, old->overwrittenby);
191 new->nr = get_irp_new_node_nr();
194 insert_entity_in_owner (new);
201 free_entity (entity *ent) {
202 assert(ent && ent->kind == k_entity);
203 free_tarval_entity(ent);
204 free_entity_attrs(ent);
209 /* Outputs a unique number for this node */
211 get_entity_nr(entity *ent) {
212 assert(ent && ent->kind == k_entity);
221 get_entity_name (entity *ent) {
222 assert(ent && ent->kind == k_entity);
223 return get_id_str(get_entity_ident(ent));
227 get_entity_ident (entity *ent) {
228 assert(ent && ent->kind == k_entity);
233 void set_entitye_ld_name (entity *, char *ld_name);
234 void set_entity_ld_ident (entity *, ident *ld_ident);
238 get_entity_owner (entity *ent) {
239 assert(ent && ent->kind == k_entity);
240 return ent->owner = skip_tid(ent->owner);
244 set_entity_owner (entity *ent, type *owner) {
245 assert(ent && ent->kind == k_entity);
246 assert_legal_owner_of_ent(owner);
250 void /* should this go into type.c? */
251 assert_legal_owner_of_ent(type *owner) {
252 assert(get_type_tpop_code(owner) == tpo_class ||
253 get_type_tpop_code(owner) == tpo_union ||
254 get_type_tpop_code(owner) == tpo_struct ||
255 get_type_tpop_code(owner) == tpo_array); /* Yes, array has an entity
256 -- to select fields! */
260 get_entity_ld_ident (entity *ent)
262 assert(ent && ent->kind == k_entity);
263 if (ent->ld_name == NULL)
264 ent->ld_name = mangle_entity (ent);
269 set_entity_ld_ident (entity *ent, ident *ld_ident) {
270 assert(ent && ent->kind == k_entity);
271 ent->ld_name = ld_ident;
275 get_entity_ld_name (entity *ent) {
276 assert(ent && ent->kind == k_entity);
277 return get_id_str(get_entity_ld_ident(ent));
281 char *get_entity_ld_name (entity *);
282 void set_entity_ld_name (entity *, char *ld_name);
286 get_entity_type (entity *ent) {
287 assert(ent && ent->kind == k_entity);
288 return ent->type = skip_tid(ent->type);
292 set_entity_type (entity *ent, type *type) {
293 assert(ent && ent->kind == k_entity);
299 get_entity_allocation (entity *ent) {
300 assert(ent && ent->kind == k_entity);
301 return ent->allocation;
305 set_entity_allocation (entity *ent, ent_allocation al) {
306 assert(ent && ent->kind == k_entity);
307 ent->allocation = al;
310 /* return the name of the visibility */
311 const char *get_allocation_name(ent_allocation all)
313 #define X(a) case a: return #a
315 X(allocation_automatic);
316 X(allocation_parameter);
317 X(allocation_dynamic);
318 X(allocation_static);
319 default: return "BAD VALUE";
326 get_entity_visibility (entity *ent) {
327 assert(ent && ent->kind == k_entity);
328 return ent->visibility;
332 set_entity_visibility (entity *ent, ent_visibility vis) {
333 assert(ent && ent->kind == k_entity);
334 if (vis != visibility_local)
335 assert((ent->allocation == allocation_static) ||
336 (ent->allocation == allocation_automatic));
337 /* @@@ Test that the owner type is not local, but how??
338 && get_class_visibility(get_entity_owner(ent)) != local));*/
339 ent->visibility = vis;
342 /* return the name of the visibility */
343 const char *get_visibility_name(ent_visibility vis)
345 #define X(a) case a: return #a
348 X(visibility_external_visible);
349 X(visibility_external_allocated);
350 default: return "BAD VALUE";
356 get_entity_variability (entity *ent) {
357 assert(ent && ent->kind == k_entity);
358 return ent->variability;
362 set_entity_variability (entity *ent, ent_variability var)
364 assert(ent && ent->kind == k_entity);
365 if (var == variability_part_constant)
366 assert(is_class_type(ent->type) || is_struct_type(ent->type));
368 if ((is_compound_type(ent->type)) &&
369 (ent->variability == variability_uninitialized) && (var != variability_uninitialized)) {
370 /* Allocate datastructures for constant values */
371 ent->values = NEW_ARR_F(ir_node *, 0);
372 ent->val_paths = NEW_ARR_F(compound_graph_path *, 0);
375 if ((is_compound_type(ent->type)) &&
376 (var == variability_uninitialized) && (ent->variability != variability_uninitialized)) {
377 /* Free datastructures for constant values */
378 DEL_ARR_F(ent->values); ent->values = NULL;
379 DEL_ARR_F(ent->val_paths); ent->val_paths = NULL;
381 ent->variability = var;
384 /* return the name of the variablity */
385 const char *get_variability_name(ent_variability var)
387 #define X(a) case a: return #a
389 X(variability_uninitialized);
390 X(variability_initialized);
391 X(variability_part_constant);
392 X(variability_constant);
393 default: return "BAD VALUE";
399 get_entity_volatility (entity *ent) {
400 assert(ent && ent->kind == k_entity);
401 return ent->volatility;
405 set_entity_volatility (entity *ent, ent_volatility vol) {
406 assert(ent && ent->kind == k_entity);
407 ent->volatility = vol;
410 /* return the name of the volatility */
411 const char *get_volatility_name(ent_volatility var)
413 #define X(a) case a: return #a
415 X(volatility_non_volatile);
416 X(volatility_is_volatile);
417 default: return "BAD VALUE";
423 get_entity_peculiarity (entity *ent) {
424 assert(ent && ent->kind == k_entity);
425 return ent->peculiarity;
429 set_entity_peculiarity (entity *ent, peculiarity pec) {
430 assert(ent && ent->kind == k_entity);
431 /* @@@ why peculiarity only for methods? */
432 assert(is_method_type(ent->type));
433 ent->peculiarity = pec;
436 /* return the name of the peculiarity */
437 const char *get_peculiarity_name(peculiarity var)
439 #define X(a) case a: return #a
441 X(peculiarity_description);
442 X(peculiarity_inherited);
443 X(peculiarity_existent);
444 default: return "BAD VALUE";
449 /* Set has no effect for existent entities of type method. */
451 get_atomic_ent_value(entity *ent)
453 assert(ent && is_atomic_entity(ent));
454 assert(ent->variability != variability_uninitialized);
459 set_atomic_ent_value(entity *ent, ir_node *val) {
460 assert(is_atomic_entity(ent) && (ent->variability != variability_uninitialized));
461 if (is_method_type(ent->type) && (ent->peculiarity == peculiarity_existent))
466 /* Returns true if the the node is representable as code on
468 int is_irn_const_expression(ir_node *n) {
472 switch(get_irn_opcode(n)) {
478 if (is_irn_const_expression(get_Add_left(n)))
479 return is_irn_const_expression(get_Add_right(n));
482 return is_irn_const_expression(get_irn_n(n, 0));
491 ir_node *copy_const_value(ir_node *n) {
496 switch(get_irn_opcode(n)) {
498 nn = new_Const(m, get_Const_tarval(n)); break;
500 nn = new_SymConst(get_SymConst_type_or_id(n), get_SymConst_kind(n)); break;
502 nn = new_Add(copy_const_value(get_Add_left(n)),
503 copy_const_value(get_Add_right(n)), m); break;
505 nn = new_Cast(copy_const_value(get_Cast_op(n)), get_Cast_type(n)); break;
507 nn = new_Conv(copy_const_value(get_Conv_op(n)), m); break;
509 nn = new_Unknown(m); break;
512 assert(0 && "opdope invalid or not implemented");
519 compound_graph_path *
520 new_compound_graph_path(type *tp, int length) {
521 compound_graph_path *res;
522 assert(is_type(tp) && is_compound_type(tp));
525 res = (compound_graph_path *) malloc (sizeof(compound_graph_path) + (length-1) * sizeof(entity *));
526 res->kind = k_ir_compound_graph_path;
529 memset(res->nodes, 0, sizeof(entity *) * length);
534 free_compound_graph_path (compound_graph_path *gr) {
535 assert(gr && is_compound_graph_path(gr));
541 is_compound_graph_path(void *thing) {
542 return (get_kind(thing) == k_ir_compound_graph_path);
545 /* checks whether nodes 0..pos are correct (all lie on a path.) */
546 /* @@@ not implemented */
547 int is_proper_compound_graph_path(compound_graph_path *gr, int pos) {
550 type *owner = gr->tp;
551 for (i = 0; i <= pos; i++) {
552 node = get_compound_graph_path_node(gr, i);
553 if (get_entity_owner(node) != owner) return false;
554 owner = get_entity_type(node);
556 if (pos == get_compound_graph_path_length(gr))
557 if (!is_atomic_type(owner)) return false;
562 get_compound_graph_path_length(compound_graph_path *gr) {
563 assert(gr && is_compound_graph_path(gr));
568 get_compound_graph_path_node(compound_graph_path *gr, int pos) {
569 assert(gr && is_compound_graph_path(gr));
570 assert(pos >= 0 && pos < gr->len);
571 return gr->nodes[pos];
575 set_compound_graph_path_node(compound_graph_path *gr, int pos, entity *node) {
576 assert(gr && is_compound_graph_path(gr));
577 assert(pos >= 0 && pos < gr->len);
578 assert(is_entity(node));
579 gr->nodes[pos] = node;
580 assert(is_proper_compound_graph_path(gr, pos));
583 /* A value of a compound entity is a pair of value and the corresponding path to a member of
586 add_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path) {
587 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
588 ARR_APP1 (ir_node *, ent->values, val);
589 ARR_APP1 (compound_graph_path *, ent->val_paths, path);
593 set_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path, int pos) {
594 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
595 ent->values[pos] = val;
596 ent->val_paths[pos] = path;
600 get_compound_ent_n_values(entity *ent) {
601 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
602 return (ARR_LEN (ent->values));
606 get_compound_ent_value(entity *ent, int pos) {
607 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
608 return ent->values[pos];
611 compound_graph_path *
612 get_compound_ent_value_path(entity *ent, int pos) {
613 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
614 return ent->val_paths[pos];
618 remove_compound_ent_value(entity *ent, entity *value_ent) {
620 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
621 for (i = 0; i < (ARR_LEN (ent->val_paths)); i++) {
622 compound_graph_path *path = ent->val_paths[i];
623 if (path->nodes[path->len-1] == value_ent) {
624 for(; i < (ARR_LEN (ent->val_paths))-1; i++) {
625 ent->val_paths[i] = ent->val_paths[i+1];
626 ent->values[i] = ent->values[i+1];
628 ARR_SETLEN(entity*, ent->val_paths, ARR_LEN(ent->val_paths) - 1);
629 ARR_SETLEN(ir_node*, ent->values, ARR_LEN(ent->values) - 1);
636 add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
637 compound_graph_path *path;
638 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
639 path = new_compound_graph_path(get_entity_owner(ent), 1);
640 path->nodes[0] = member;
641 add_compound_ent_value_w_path(ent, val, path);
644 /* Copies the firm subgraph referenced by val to const_code_irg and adds
645 the node as constant initialization to ent.
646 The subgraph may not contain control flow operations.
648 copy_and_add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
649 ir_graph *rem = current_ir_graph;
651 assert(get_entity_variability(ent) != variability_uninitialized);
652 current_ir_graph = get_const_code_irg();
654 val = copy_const_value(val);
655 add_compound_ent_value(ent, val, member);
656 current_ir_graph = rem;
659 /* Copies the value i of the entity to current_block in current_ir_graph.
661 copy_compound_ent_value(entity *ent, int pos) {
662 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
663 return copy_const_value(ent->values[pos+1]);
667 get_compound_ent_value_member(entity *ent, int pos) {
668 compound_graph_path *path;
669 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
670 path = get_compound_ent_value_path(ent, pos);
672 return get_compound_graph_path_node(path, get_compound_graph_path_length(path)-1);
676 set_compound_ent_value(entity *ent, ir_node *val, entity *member, int pos) {
677 compound_graph_path *path;
678 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
679 path = get_compound_ent_value_path(ent, pos);
680 set_compound_graph_path_node(path, 0, member);
681 set_compound_ent_value_w_path(ent, val, path, pos);
685 set_array_entity_values(entity *ent, tarval **values, int num_vals) {
687 ir_graph *rem = current_ir_graph;
688 type *arrtp = get_entity_type(ent);
691 assert(is_array_type(arrtp));
692 assert(get_array_n_dimensions(arrtp) == 1);
693 /* One bound is sufficient, the nunmber of constant fields makes the
695 assert(get_array_lower_bound (arrtp, 0) || get_array_upper_bound (arrtp, 0));
696 assert(get_entity_variability(ent) != variability_uninitialized);
697 current_ir_graph = get_const_code_irg();
699 for (i = 0; i < num_vals; i++) {
700 val = new_Const(get_tarval_mode (values[i]), values[i]);
701 add_compound_ent_value(ent, val, get_array_element_entity(arrtp));
703 current_ir_graph = rem;
707 get_entity_offset (entity *ent) {
708 assert(ent && ent->kind == k_entity);
713 set_entity_offset (entity *ent, int offset) {
714 assert(ent && ent->kind == k_entity);
715 ent->offset = offset;
719 add_entity_overwrites (entity *ent, entity *overwritten) {
720 assert(ent && is_class_type(get_entity_owner(ent)));
721 ARR_APP1 (entity *, ent->overwrites, overwritten);
722 ARR_APP1 (entity *, overwritten->overwrittenby, ent);
726 get_entity_n_overwrites (entity *ent) {
727 assert(ent && is_class_type(get_entity_owner(ent)));
728 return (ARR_LEN (ent->overwrites));
732 get_entity_overwrites_index(entity *ent, entity *overwritten) {
734 assert(ent && is_class_type(get_entity_owner(ent)));
735 for (i = 0; i < get_entity_n_overwrites(ent); i++)
736 if (get_entity_overwrites(ent, i) == overwritten)
742 get_entity_overwrites (entity *ent, int pos) {
743 assert(ent && is_class_type(get_entity_owner(ent)));
744 assert(pos < get_entity_n_overwrites(ent));
745 return ent->overwrites[pos];
749 set_entity_overwrites (entity *ent, int pos, entity *overwritten) {
750 assert(ent && is_class_type(get_entity_owner(ent)));
751 assert(pos < get_entity_n_overwrites(ent));
752 ent->overwrites[pos] = overwritten;
756 remove_entity_overwrites(entity *ent, entity *overwritten) {
758 assert(ent && is_class_type(get_entity_owner(ent)));
759 for (i = 0; i < (ARR_LEN (ent->overwrites)); i++)
760 if (ent->overwrites[i] == overwritten) {
761 for(; i < (ARR_LEN (ent->overwrites))-1; i++)
762 ent->overwrites[i] = ent->overwrites[i+1];
763 ARR_SETLEN(entity*, ent->overwrites, ARR_LEN(ent->overwrites) - 1);
769 add_entity_overwrittenby (entity *ent, entity *overwrites) {
770 assert(ent && is_class_type(get_entity_owner(ent)));
771 add_entity_overwrites(overwrites, ent);
775 get_entity_n_overwrittenby (entity *ent) {
776 assert(ent && is_class_type(get_entity_owner(ent)));
777 return (ARR_LEN (ent->overwrittenby));
781 get_entity_overwrittenby_index(entity *ent, entity *overwrites) {
783 assert(ent && is_class_type(get_entity_owner(ent)));
784 for (i = 0; i < get_entity_n_overwrittenby(ent); i++)
785 if (get_entity_overwrittenby(ent, i) == overwrites)
791 get_entity_overwrittenby (entity *ent, int pos) {
792 assert(ent && is_class_type(get_entity_owner(ent)));
793 assert(pos < get_entity_n_overwrittenby(ent));
794 return ent->overwrittenby[pos];
798 set_entity_overwrittenby (entity *ent, int pos, entity *overwrites) {
799 assert(ent && is_class_type(get_entity_owner(ent)));
800 assert(pos < get_entity_n_overwrittenby(ent));
801 ent->overwrittenby[pos] = overwrites;
804 void remove_entity_overwrittenby(entity *ent, entity *overwrites) {
806 assert(ent && is_class_type(get_entity_owner(ent)));
807 for (i = 0; i < (ARR_LEN (ent->overwrittenby)); i++)
808 if (ent->overwrittenby[i] == overwrites) {
809 for(; i < (ARR_LEN (ent->overwrittenby))-1; i++)
810 ent->overwrittenby[i] = ent->overwrittenby[i+1];
811 ARR_SETLEN(entity*, ent->overwrittenby, ARR_LEN(ent->overwrittenby) - 1);
816 /* A link to store intermediate information */
818 get_entity_link(entity *ent) {
819 assert(ent && ent->kind == k_entity);
824 set_entity_link(entity *ent, void *l) {
825 assert(ent && ent->kind == k_entity);
830 get_entity_irg(entity *ent) {
831 assert(ent && ent->kind == k_entity);
832 assert(is_method_type(ent->type));
837 set_entity_irg(entity *ent, ir_graph *irg) {
838 assert(ent && is_method_type(get_entity_type(ent)));
839 /* Wie kann man die Referenz auf einen IRG löschen, z.B. wenn die
840 * Methode selbst nicht mehr aufgerufen werden kann, die Entität
841 * aber erhalten bleiben soll. */
843 assert(ent->peculiarity == peculiarity_existent);
847 int is_entity (void *thing) {
849 if (get_kind(thing) == k_entity)
855 int is_atomic_entity(entity *ent) {
856 type* t = get_entity_type(ent);
857 assert(ent && ent->kind == k_entity);
858 return (is_primitive_type(t) || is_pointer_type(t) ||
859 is_enumeration_type(t) || is_method_type(t));
862 int is_compound_entity(entity *ent) {
863 type* t = get_entity_type(ent);
864 assert(ent && ent->kind == k_entity);
865 return (is_class_type(t) || is_struct_type(t) ||
866 is_array_type(t) || is_union_type(t));
869 /* @@@ not implemnted!!! */
870 bool equal_entity(entity *ent1, entity *ent2) {
871 printf(" calling unimplemented equal entity!!! \n");
876 unsigned long get_entity_visited(entity *ent) {
877 assert(ent && ent->kind == k_entity);
880 void set_entity_visited(entity *ent, unsigned long num) {
881 assert(ent && ent->kind == k_entity);
884 /* Sets visited field in entity to entity_visited. */
885 void mark_entity_visited(entity *ent) {
886 assert(ent && ent->kind == k_entity);
887 ent->visit = type_visited;
891 bool entity_visited(entity *ent) {
892 assert(ent && ent->kind == k_entity);
893 return get_entity_visited(ent) >= type_visited;
896 bool entity_not_visited(entity *ent) {
897 assert(ent && ent->kind == k_entity);
898 return get_entity_visited(ent) < type_visited;
901 /* Need two routines because I want to assert the result. */
902 static entity *resolve_ent_polymorphy2 (type *dynamic_class, entity* static_ent) {
903 int i, n_overwrittenby;
906 if (get_entity_owner(static_ent) == dynamic_class) return static_ent;
908 n_overwrittenby = get_entity_n_overwrittenby(static_ent);
909 for (i = 0; i < n_overwrittenby; ++i) {
910 res = resolve_ent_polymorphy2(dynamic_class, get_entity_overwrittenby(static_ent, i));
917 /* Returns the dynamically referenced entity if the static entity and the
918 * dynamic type are given.
919 * Search downwards in overwritten tree. */
920 entity *resolve_ent_polymorphy(type *dynamic_class, entity* static_ent) {
922 assert(static_ent && static_ent->kind == k_entity);
924 res = resolve_ent_polymorphy2(dynamic_class, static_ent);
926 printf(" Could not find entity "); DDME(static_ent);
927 printf(" in "); DDMT(dynamic_class);
929 dump_entity(static_ent);
930 dump_type(get_entity_owner(static_ent));
931 dump_type(dynamic_class);
940 /*******************************************************************/
942 /*******************************************************************/
945 #if 1 || DEBUG_libfirm
946 int dump_node_opcode(FILE *F, ir_node *n); /* from irdump.c */
948 #define X(a) case a: printf(#a); break
949 void dump_entity (entity *ent) {
951 type *owner = get_entity_owner(ent);
952 type *type = get_entity_type(ent);
953 assert(ent && ent->kind == k_entity);
954 printf("entity %s (%ld)\n", get_entity_name(ent), get_entity_nr(ent));
955 printf(" type: %s (%ld)\n", get_type_name(type), get_type_nr(type));
956 printf(" owner: %s (%ld)\n", get_type_name(owner), get_type_nr(owner));
958 if (get_entity_n_overwrites(ent) > 0) {
959 printf (" overwrites:\n");
960 for (i = 0; i < get_entity_n_overwrites(ent); ++i) {
961 entity *ov = get_entity_overwrites(ent, i);
962 printf(" %d: %s of class %s\n", i, get_entity_name(ov), get_type_name(get_entity_owner(ov)));
965 printf(" Does not overwrite other entities. \n");
967 if (get_entity_n_overwrittenby(ent) > 0) {
968 printf (" overwritten by:\n");
969 for (i = 0; i < get_entity_n_overwrittenby(ent); ++i) {
970 entity *ov = get_entity_overwrittenby(ent, i);
971 printf(" %d: %s of class %s\n", i, get_entity_name(ov), get_type_name(get_entity_owner(ov)));
974 printf(" Is not overwriten by other entities. \n");
977 printf (" allocation: ");
978 switch (get_entity_allocation(ent)) {
979 X(allocation_dynamic);
980 X(allocation_automatic);
981 X(allocation_static);
982 X(allocation_parameter);
985 printf ("\n visibility: ");
986 switch (get_entity_visibility(ent)) {
988 X(visibility_external_visible);
989 X(visibility_external_allocated);
992 printf ("\n variability: ");
993 switch (get_entity_variability(ent)) {
994 X(variability_uninitialized);
995 X(variability_initialized);
996 X(variability_part_constant);
997 X(variability_constant);
1000 if (get_entity_variability(ent) != variability_uninitialized) {
1001 if (is_atomic_entity(ent)) {
1002 printf("\n atomic value: ");
1003 dump_node_opcode(stdout, get_atomic_ent_value(ent));
1005 printf("\n compound values:");
1006 for (i = 0; i < get_compound_ent_n_values(ent); ++i) {
1007 compound_graph_path *path = get_compound_ent_value_path(ent, i);
1008 entity *ent0 = get_compound_graph_path_node(path, 0);
1009 printf("\n %2d %s", get_entity_offset(ent0), get_entity_name(ent0));
1010 for (j = 1; j < get_compound_graph_path_length(path); ++j)
1011 printf(".%s", get_entity_name(get_compound_graph_path_node(path, j)));
1013 dump_node_opcode(stdout, get_compound_ent_value(ent, i));
1018 printf ("\n volatility: ");
1019 switch (get_entity_volatility(ent)) {
1020 X(volatility_non_volatile);
1021 X(volatility_is_volatile);
1024 printf("\n peculiarity: %s", get_peculiarity_string(get_entity_peculiarity(ent)));
1025 printf("\n ld_name: %s", ent->ld_name ? get_entity_ld_name(ent) : "no yet set");
1026 printf("\n offset: %d", get_entity_offset(ent));
1027 if (is_method_type(get_entity_type(ent))) {
1028 if (get_entity_irg(ent)) /* can be null */
1029 { printf ("\n irg = %ld", get_irg_graph_nr(get_entity_irg(ent))); }
1031 { printf ("\n irg = NULL"); }
1036 #else /* DEBUG_libfirm */
1037 void dump_entity (entity *ent) {}
1038 #endif /* DEBUG_libfirm */