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;
98 res->stickyness = stickyness_unsticky;
100 if (is_class_type(owner)) {
101 res->overwrites = NEW_ARR_F(entity *, 0);
102 res->overwrittenby = NEW_ARR_F(entity *, 0);
104 res->overwrites = NULL;
105 res->overwrittenby = NULL;
110 res->nr = get_irp_new_node_nr();
115 /* Remember entity in it's owner. */
116 insert_entity_in_owner (res);
120 new_d_entity (type *owner, ident *name, type *type, dbg_info *db) {
121 entity *res = new_entity(owner, name, type);
122 set_entity_dbg_info(res, db);
126 void free_compound_graph_path (compound_graph_path *gr);
127 int is_compound_graph_path(void *thing);
128 int get_compound_graph_path_length(compound_graph_path *gr);
129 entity *get_compound_graph_path_node(compound_graph_path *gr, int pos);
130 int get_compound_ent_n_values(entity *ent);
132 static void free_entity_attrs(entity *ent) {
134 if (get_type_tpop(get_entity_owner(ent)) == type_class) {
135 DEL_ARR_F(ent->overwrites); ent->overwrites = NULL;
136 DEL_ARR_F(ent->overwrittenby); ent->overwrittenby = NULL;
138 assert(ent->overwrites == NULL);
139 assert(ent->overwrittenby == NULL);
141 /* if (ent->values) DEL_ARR_F(ent->values); *//* @@@ warum nich? */
142 if (ent->val_paths) {
143 if (is_compound_entity(ent))
144 for (i = 0; i < get_compound_ent_n_values(ent); i++)
145 if (ent->val_paths[i]) ;
146 /* free_compound_graph_path(ent->val_paths[i]) ; * @@@ warum nich? */
147 /* Geht nich: wird mehrfach verwendet!!! ==> mehrfach frei gegeben. */
148 /* DEL_ARR_F(ent->val_paths); */
150 ent->val_paths = NULL;
155 copy_entity_own (entity *old, type *new_owner) {
157 assert(old && old->kind == k_entity);
158 assert_legal_owner_of_ent(new_owner);
160 if (old->owner == new_owner) return old;
161 new = (entity *) xmalloc (sizeof (entity));
162 memcpy (new, old, sizeof (entity));
163 new->owner = new_owner;
164 if (is_class_type(new_owner)) {
165 new->overwrites = NEW_ARR_F(entity *, 0);
166 new->overwrittenby = NEW_ARR_F(entity *, 0);
169 new->nr = get_irp_new_node_nr();
172 insert_entity_in_owner (new);
178 copy_entity_name (entity *old, ident *new_name) {
180 assert(old && old->kind == k_entity);
182 if (old->name == new_name) return old;
183 new = (entity *) xmalloc (sizeof (entity));
184 memcpy (new, old, sizeof (entity));
185 new->name = new_name;
187 if (is_class_type(new->owner)) {
188 new->overwrites = DUP_ARR_F(entity *, old->overwrites);
189 new->overwrittenby = DUP_ARR_F(entity *, old->overwrittenby);
192 new->nr = get_irp_new_node_nr();
195 insert_entity_in_owner (new);
202 free_entity (entity *ent) {
203 assert(ent && ent->kind == k_entity);
204 free_tarval_entity(ent);
205 free_entity_attrs(ent);
210 /* Outputs a unique number for this node */
212 get_entity_nr(entity *ent) {
213 assert(ent && ent->kind == k_entity);
222 (get_entity_name)(entity *ent) {
223 return __get_entity_name(ent);
227 (get_entity_ident)(entity *ent) {
228 return get_entity_ident(ent);
232 void set_entitye_ld_name (entity *, char *ld_name);
233 void set_entity_ld_ident (entity *, ident *ld_ident);
237 (get_entity_owner)(entity *ent) {
238 return __get_entity_owner(ent);
242 set_entity_owner (entity *ent, type *owner) {
243 assert(ent && ent->kind == k_entity);
244 assert_legal_owner_of_ent(owner);
248 void /* should this go into type.c? */
249 assert_legal_owner_of_ent(type *owner) {
250 assert(get_type_tpop_code(owner) == tpo_class ||
251 get_type_tpop_code(owner) == tpo_union ||
252 get_type_tpop_code(owner) == tpo_struct ||
253 get_type_tpop_code(owner) == tpo_array); /* Yes, array has an entity
254 -- to select fields! */
258 (get_entity_ld_ident)(entity *ent) {
259 return __get_entity_ld_ident(ent);
263 (set_entity_ld_ident)(entity *ent, ident *ld_ident) {
264 __set_entity_ld_ident(ent, ld_ident);
268 (get_entity_ld_name)(entity *ent) {
269 return __get_entity_ld_name(ent);
273 (get_entity_type)(entity *ent) {
274 return __get_entity_type(ent);
278 (set_entity_type)(entity *ent, type *type) {
279 __set_entity_type(ent, type);
283 (get_entity_allocation)(entity *ent) {
284 return __get_entity_allocation(ent);
288 (set_entity_allocation)(entity *ent, ent_allocation al) {
289 __set_entity_allocation(ent, al);
292 /* return the name of the visibility */
293 const char *get_allocation_name(ent_allocation all)
295 #define X(a) case a: return #a
297 X(allocation_automatic);
298 X(allocation_parameter);
299 X(allocation_dynamic);
300 X(allocation_static);
301 default: return "BAD VALUE";
308 (get_entity_visibility)(entity *ent) {
309 return __get_entity_visibility(ent);
313 set_entity_visibility (entity *ent, ent_visibility vis) {
314 assert(ent && ent->kind == k_entity);
315 if (vis != visibility_local)
316 assert((ent->allocation == allocation_static) ||
317 (ent->allocation == allocation_automatic));
318 /* @@@ Test that the owner type is not local, but how??
319 && get_class_visibility(get_entity_owner(ent)) != local));*/
320 ent->visibility = vis;
323 /* return the name of the visibility */
324 const char *get_visibility_name(ent_visibility vis)
326 #define X(a) case a: return #a
329 X(visibility_external_visible);
330 X(visibility_external_allocated);
331 default: return "BAD VALUE";
337 (get_entity_variability)(entity *ent) {
338 return __get_entity_variability(ent);
342 set_entity_variability (entity *ent, ent_variability var)
344 assert(ent && ent->kind == k_entity);
345 if (var == variability_part_constant)
346 assert(is_class_type(ent->type) || is_struct_type(ent->type));
348 if ((is_compound_type(ent->type)) &&
349 (ent->variability == variability_uninitialized) && (var != variability_uninitialized)) {
350 /* Allocate datastructures for constant values */
351 ent->values = NEW_ARR_F(ir_node *, 0);
352 ent->val_paths = NEW_ARR_F(compound_graph_path *, 0);
355 if ((is_compound_type(ent->type)) &&
356 (var == variability_uninitialized) && (ent->variability != variability_uninitialized)) {
357 /* Free datastructures for constant values */
358 DEL_ARR_F(ent->values); ent->values = NULL;
359 DEL_ARR_F(ent->val_paths); ent->val_paths = NULL;
361 ent->variability = var;
364 /* return the name of the variablity */
365 const char *get_variability_name(ent_variability var)
367 #define X(a) case a: return #a
369 X(variability_uninitialized);
370 X(variability_initialized);
371 X(variability_part_constant);
372 X(variability_constant);
373 default: return "BAD VALUE";
379 (get_entity_volatility)(entity *ent) {
380 return __get_entity_volatility(ent);
384 (set_entity_volatility)(entity *ent, ent_volatility vol) {
385 __set_entity_volatility(ent, vol);
388 /* return the name of the volatility */
389 const char *get_volatility_name(ent_volatility var)
391 #define X(a) case a: return #a
393 X(volatility_non_volatile);
394 X(volatility_is_volatile);
395 default: return "BAD VALUE";
401 (get_entity_peculiarity)(entity *ent) {
402 return __get_entity_peculiarity(ent);
406 (set_entity_peculiarity)(entity *ent, peculiarity pec) {
407 __set_entity_peculiarity(ent, pec);
410 /* return the name of the peculiarity */
411 const char *get_peculiarity_name(peculiarity var)
413 #define X(a) case a: return #a
415 X(peculiarity_description);
416 X(peculiarity_inherited);
417 X(peculiarity_existent);
418 default: return "BAD VALUE";
423 /* Get the entity's stickyness */
425 (get_entity_stickyness)(entity *ent) {
426 return __get_entity_stickyness(ent);
429 /* Set the entity's stickyness */
431 (set_entity_stickyness)(entity *ent, ent_stickyness stickyness) {
432 __set_entity_stickyness(ent, stickyness);
435 /* Set has no effect for existent entities of type method. */
437 get_atomic_ent_value(entity *ent)
439 assert(ent && is_atomic_entity(ent));
440 assert(ent->variability != variability_uninitialized);
441 return skip_Id (ent->value);
445 set_atomic_ent_value(entity *ent, ir_node *val) {
446 assert(is_atomic_entity(ent) && (ent->variability != variability_uninitialized));
447 if (is_method_type(ent->type) && (ent->peculiarity == peculiarity_existent))
452 /* Returns true if the the node is representable as code on
454 int is_irn_const_expression(ir_node *n) {
458 switch(get_irn_opcode(n)) {
469 if (is_irn_const_expression(get_binop_left(n)))
470 return is_irn_const_expression(get_binop_right(n));
473 return is_irn_const_expression(get_irn_n(n, 0));
482 ir_node *copy_const_value(ir_node *n) {
487 switch(get_irn_opcode(n)) {
489 nn = new_Const(m, get_Const_tarval(n)); break;
491 nn = new_SymConst(get_SymConst_type_or_id(n), get_SymConst_kind(n)); break;
493 nn = new_Add(copy_const_value(get_Add_left(n)),
494 copy_const_value(get_Add_right(n)), m); break;
496 nn = new_Sub(copy_const_value(get_Sub_left(n)),
497 copy_const_value(get_Sub_right(n)), m); break;
499 nn = new_Mul(copy_const_value(get_Mul_left(n)),
500 copy_const_value(get_Mul_right(n)), m); break;
502 nn = new_And(copy_const_value(get_And_left(n)),
503 copy_const_value(get_And_right(n)), m); break;
505 nn = new_Or(copy_const_value(get_Or_left(n)),
506 copy_const_value(get_Or_right(n)), m); break;
508 nn = new_Eor(copy_const_value(get_Eor_left(n)),
509 copy_const_value(get_Eor_right(n)), m); break;
511 nn = new_Cast(copy_const_value(get_Cast_op(n)), get_Cast_type(n)); break;
513 nn = new_Conv(copy_const_value(get_Conv_op(n)), m); break;
515 nn = new_Unknown(m); break;
518 assert(0 && "opdope invalid or not implemented");
525 compound_graph_path *
526 new_compound_graph_path(type *tp, int length) {
527 compound_graph_path *res;
528 assert(is_type(tp) && is_compound_type(tp));
531 res = (compound_graph_path *) malloc (sizeof(compound_graph_path) + (length-1) * sizeof(entity *));
532 res->kind = k_ir_compound_graph_path;
535 memset(res->nodes, 0, sizeof(entity *) * length);
540 free_compound_graph_path (compound_graph_path *gr) {
541 assert(gr && is_compound_graph_path(gr));
547 is_compound_graph_path(void *thing) {
548 return (get_kind(thing) == k_ir_compound_graph_path);
551 /* checks whether nodes 0..pos are correct (all lie on a path.) */
552 /* @@@ not implemented */
553 int is_proper_compound_graph_path(compound_graph_path *gr, int pos) {
556 type *owner = gr->tp;
557 for (i = 0; i <= pos; i++) {
558 node = get_compound_graph_path_node(gr, i);
559 if (get_entity_owner(node) != owner) return false;
560 owner = get_entity_type(node);
562 if (pos == get_compound_graph_path_length(gr))
563 if (!is_atomic_type(owner)) return false;
568 get_compound_graph_path_length(compound_graph_path *gr) {
569 assert(gr && is_compound_graph_path(gr));
574 get_compound_graph_path_node(compound_graph_path *gr, int pos) {
575 assert(gr && is_compound_graph_path(gr));
576 assert(pos >= 0 && pos < gr->len);
577 return gr->nodes[pos];
581 set_compound_graph_path_node(compound_graph_path *gr, int pos, entity *node) {
582 assert(gr && is_compound_graph_path(gr));
583 assert(pos >= 0 && pos < gr->len);
584 assert(is_entity(node));
585 gr->nodes[pos] = node;
586 assert(is_proper_compound_graph_path(gr, pos));
589 /* A value of a compound entity is a pair of value and the corresponding path to a member of
592 add_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path) {
593 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
594 ARR_APP1 (ir_node *, ent->values, val);
595 ARR_APP1 (compound_graph_path *, ent->val_paths, path);
599 set_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path, int pos) {
600 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
601 ent->values[pos] = val;
602 ent->val_paths[pos] = path;
606 get_compound_ent_n_values(entity *ent) {
607 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
608 return (ARR_LEN (ent->values));
612 get_compound_ent_value(entity *ent, int pos) {
613 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
614 return ent->values[pos];
617 compound_graph_path *
618 get_compound_ent_value_path(entity *ent, int pos) {
619 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
620 return ent->val_paths[pos];
624 remove_compound_ent_value(entity *ent, entity *value_ent) {
626 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
627 for (i = 0; i < (ARR_LEN (ent->val_paths)); i++) {
628 compound_graph_path *path = ent->val_paths[i];
629 if (path->nodes[path->len-1] == value_ent) {
630 for(; i < (ARR_LEN (ent->val_paths))-1; i++) {
631 ent->val_paths[i] = ent->val_paths[i+1];
632 ent->values[i] = ent->values[i+1];
634 ARR_SETLEN(entity*, ent->val_paths, ARR_LEN(ent->val_paths) - 1);
635 ARR_SETLEN(ir_node*, ent->values, ARR_LEN(ent->values) - 1);
642 add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
643 compound_graph_path *path;
644 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
645 path = new_compound_graph_path(get_entity_owner(ent), 1);
646 path->nodes[0] = member;
647 add_compound_ent_value_w_path(ent, val, path);
650 /* Copies the firm subgraph referenced by val to const_code_irg and adds
651 the node as constant initialization to ent.
652 The subgraph may not contain control flow operations.
654 copy_and_add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
655 ir_graph *rem = current_ir_graph;
657 assert(get_entity_variability(ent) != variability_uninitialized);
658 current_ir_graph = get_const_code_irg();
660 val = copy_const_value(val);
661 add_compound_ent_value(ent, val, member);
662 current_ir_graph = rem;
665 /* Copies the value i of the entity to current_block in current_ir_graph.
667 copy_compound_ent_value(entity *ent, int pos) {
668 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
669 return copy_const_value(ent->values[pos+1]);
673 get_compound_ent_value_member(entity *ent, int pos) {
674 compound_graph_path *path;
675 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
676 path = get_compound_ent_value_path(ent, pos);
678 return get_compound_graph_path_node(path, get_compound_graph_path_length(path)-1);
682 set_compound_ent_value(entity *ent, ir_node *val, entity *member, int pos) {
683 compound_graph_path *path;
684 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
685 path = get_compound_ent_value_path(ent, pos);
686 set_compound_graph_path_node(path, 0, member);
687 set_compound_ent_value_w_path(ent, val, path, pos);
691 set_array_entity_values(entity *ent, tarval **values, int num_vals) {
693 ir_graph *rem = current_ir_graph;
694 type *arrtp = get_entity_type(ent);
697 assert(is_array_type(arrtp));
698 assert(get_array_n_dimensions(arrtp) == 1);
699 /* One bound is sufficient, the nunmber of constant fields makes the
701 assert(get_array_lower_bound (arrtp, 0) || get_array_upper_bound (arrtp, 0));
702 assert(get_entity_variability(ent) != variability_uninitialized);
703 current_ir_graph = get_const_code_irg();
705 for (i = 0; i < num_vals; i++) {
706 val = new_Const(get_tarval_mode (values[i]), values[i]);
707 add_compound_ent_value(ent, val, get_array_element_entity(arrtp));
709 current_ir_graph = rem;
713 (get_entity_offset_bytes)(entity *ent) {
714 return __get_entity_offset_bytes(ent);
718 (get_entity_offset_bits)(entity *ent) {
719 return __get_entity_offset_bits(ent);
723 (set_entity_offset_bytes)(entity *ent, int offset) {
724 __set_entity_offset_bytes(ent, offset);
728 (set_entity_offset_bits)(entity *ent, int offset) {
729 __set_entity_offset_bits(ent, offset);
733 add_entity_overwrites(entity *ent, entity *overwritten) {
734 assert(ent && is_class_type(get_entity_owner(ent)));
735 ARR_APP1(entity *, ent->overwrites, overwritten);
736 ARR_APP1(entity *, overwritten->overwrittenby, ent);
740 get_entity_n_overwrites(entity *ent) {
741 assert(ent && is_class_type(get_entity_owner(ent)));
742 return (ARR_LEN(ent->overwrites));
746 get_entity_overwrites_index(entity *ent, entity *overwritten) {
748 assert(ent && is_class_type(get_entity_owner(ent)));
749 for (i = 0; i < get_entity_n_overwrites(ent); i++)
750 if (get_entity_overwrites(ent, i) == overwritten)
756 get_entity_overwrites (entity *ent, int pos) {
757 assert(ent && is_class_type(get_entity_owner(ent)));
758 assert(pos < get_entity_n_overwrites(ent));
759 return ent->overwrites[pos];
763 set_entity_overwrites (entity *ent, int pos, entity *overwritten) {
764 assert(ent && is_class_type(get_entity_owner(ent)));
765 assert(pos < get_entity_n_overwrites(ent));
766 ent->overwrites[pos] = overwritten;
770 remove_entity_overwrites(entity *ent, entity *overwritten) {
772 assert(ent && is_class_type(get_entity_owner(ent)));
773 for (i = 0; i < (ARR_LEN (ent->overwrites)); i++)
774 if (ent->overwrites[i] == overwritten) {
775 for(; i < (ARR_LEN (ent->overwrites))-1; i++)
776 ent->overwrites[i] = ent->overwrites[i+1];
777 ARR_SETLEN(entity*, ent->overwrites, ARR_LEN(ent->overwrites) - 1);
783 add_entity_overwrittenby (entity *ent, entity *overwrites) {
784 assert(ent && is_class_type(get_entity_owner(ent)));
785 add_entity_overwrites(overwrites, ent);
789 get_entity_n_overwrittenby (entity *ent) {
790 assert(ent && is_class_type(get_entity_owner(ent)));
791 return (ARR_LEN (ent->overwrittenby));
795 get_entity_overwrittenby_index(entity *ent, entity *overwrites) {
797 assert(ent && is_class_type(get_entity_owner(ent)));
798 for (i = 0; i < get_entity_n_overwrittenby(ent); i++)
799 if (get_entity_overwrittenby(ent, i) == overwrites)
805 get_entity_overwrittenby (entity *ent, int pos) {
806 assert(ent && is_class_type(get_entity_owner(ent)));
807 assert(pos < get_entity_n_overwrittenby(ent));
808 return ent->overwrittenby[pos];
812 set_entity_overwrittenby (entity *ent, int pos, entity *overwrites) {
813 assert(ent && is_class_type(get_entity_owner(ent)));
814 assert(pos < get_entity_n_overwrittenby(ent));
815 ent->overwrittenby[pos] = overwrites;
818 void remove_entity_overwrittenby(entity *ent, entity *overwrites) {
820 assert(ent && is_class_type(get_entity_owner(ent)));
821 for (i = 0; i < (ARR_LEN (ent->overwrittenby)); i++)
822 if (ent->overwrittenby[i] == overwrites) {
823 for(; i < (ARR_LEN (ent->overwrittenby))-1; i++)
824 ent->overwrittenby[i] = ent->overwrittenby[i+1];
825 ARR_SETLEN(entity*, ent->overwrittenby, ARR_LEN(ent->overwrittenby) - 1);
830 /* A link to store intermediate information */
832 (get_entity_link)(entity *ent) {
833 return __get_entity_link(ent);
837 (set_entity_link)(entity *ent, void *l) {
838 __set_entity_link(ent, l);
842 (get_entity_irg)(entity *ent) {
843 return __get_entity_irg(ent);
847 set_entity_irg(entity *ent, ir_graph *irg) {
848 assert(ent && is_method_type(get_entity_type(ent)));
849 /* Wie kann man die Referenz auf einen IRG löschen, z.B. wenn die
850 * Methode selbst nicht mehr aufgerufen werden kann, die Entität
851 * aber erhalten bleiben soll. */
853 assert((irg && ent->peculiarity == peculiarity_existent) ||
854 (!irg && ent->peculiarity == peculiarity_description) ||
855 (!irg && ent->peculiarity == peculiarity_inherited));
860 (is_entity)(void *thing) {
861 return __is_entity(thing);
864 int is_atomic_entity(entity *ent) {
865 type* t = get_entity_type(ent);
866 assert(ent && ent->kind == k_entity);
867 return (is_primitive_type(t) || is_pointer_type(t) ||
868 is_enumeration_type(t) || is_method_type(t));
871 int is_compound_entity(entity *ent) {
872 type* t = get_entity_type(ent);
873 assert(ent && ent->kind == k_entity);
874 return (is_class_type(t) || is_struct_type(t) ||
875 is_array_type(t) || is_union_type(t));
879 * @todo not implemnted!!! */
880 bool equal_entity(entity *ent1, entity *ent2) {
881 printf(" calling unimplemented equal entity!!! \n");
886 unsigned long get_entity_visited(entity *ent) {
887 assert(ent && ent->kind == k_entity);
890 void set_entity_visited(entity *ent, unsigned long num) {
891 assert(ent && ent->kind == k_entity);
894 /* Sets visited field in entity to entity_visited. */
895 void mark_entity_visited(entity *ent) {
896 assert(ent && ent->kind == k_entity);
897 ent->visit = type_visited;
901 bool entity_visited(entity *ent) {
902 assert(ent && ent->kind == k_entity);
903 return get_entity_visited(ent) >= type_visited;
906 bool entity_not_visited(entity *ent) {
907 assert(ent && ent->kind == k_entity);
908 return get_entity_visited(ent) < type_visited;
911 /* Need two routines because I want to assert the result. */
912 static entity *resolve_ent_polymorphy2 (type *dynamic_class, entity* static_ent) {
913 int i, n_overwrittenby;
916 if (get_entity_owner(static_ent) == dynamic_class) return static_ent;
918 n_overwrittenby = get_entity_n_overwrittenby(static_ent);
919 for (i = 0; i < n_overwrittenby; ++i) {
920 res = resolve_ent_polymorphy2(dynamic_class, get_entity_overwrittenby(static_ent, i));
927 /** Resolve polymorphy in the inheritance relation.
929 * Returns the dynamically referenced entity if the static entity and the
930 * dynamic type are given.
931 * Search downwards in overwritten tree. */
932 entity *resolve_ent_polymorphy(type *dynamic_class, entity* static_ent) {
934 assert(static_ent && static_ent->kind == k_entity);
936 res = resolve_ent_polymorphy2(dynamic_class, static_ent);
938 printf(" Could not find entity "); DDME(static_ent);
939 printf(" in "); DDMT(dynamic_class);
941 dump_entity(static_ent);
942 dump_type(get_entity_owner(static_ent));
943 dump_type(dynamic_class);
951 /*******************************************************************/
953 /*******************************************************************/
956 #if 1 || DEBUG_libfirm
957 int dump_node_opcode(FILE *F, ir_node *n); /* from irdump.c */
959 #define X(a) case a: printf(#a); break
960 void dump_entity (entity *ent) {
962 type *owner = get_entity_owner(ent);
963 type *type = get_entity_type(ent);
964 assert(ent && ent->kind == k_entity);
965 printf("entity %s (%ld)\n", get_entity_name(ent), get_entity_nr(ent));
966 printf(" type: %s (%ld)\n", get_type_name(type), get_type_nr(type));
967 printf(" owner: %s (%ld)\n", get_type_name(owner), get_type_nr(owner));
969 if (get_entity_n_overwrites(ent) > 0) {
970 printf (" overwrites:\n");
971 for (i = 0; i < get_entity_n_overwrites(ent); ++i) {
972 entity *ov = get_entity_overwrites(ent, i);
973 printf(" %d: %s of class %s\n", i, get_entity_name(ov), get_type_name(get_entity_owner(ov)));
976 printf(" Does not overwrite other entities. \n");
978 if (get_entity_n_overwrittenby(ent) > 0) {
979 printf (" overwritten by:\n");
980 for (i = 0; i < get_entity_n_overwrittenby(ent); ++i) {
981 entity *ov = get_entity_overwrittenby(ent, i);
982 printf(" %d: %s of class %s\n", i, get_entity_name(ov), get_type_name(get_entity_owner(ov)));
985 printf(" Is not overwriten by other entities. \n");
988 printf (" allocation: ");
989 switch (get_entity_allocation(ent)) {
990 X(allocation_dynamic);
991 X(allocation_automatic);
992 X(allocation_static);
993 X(allocation_parameter);
996 printf ("\n visibility: ");
997 switch (get_entity_visibility(ent)) {
999 X(visibility_external_visible);
1000 X(visibility_external_allocated);
1003 printf ("\n variability: ");
1004 switch (get_entity_variability(ent)) {
1005 X(variability_uninitialized);
1006 X(variability_initialized);
1007 X(variability_part_constant);
1008 X(variability_constant);
1011 if (get_entity_variability(ent) != variability_uninitialized) {
1012 if (is_atomic_entity(ent)) {
1013 printf("\n atomic value: ");
1014 dump_node_opcode(stdout, get_atomic_ent_value(ent));
1016 printf("\n compound values:");
1017 for (i = 0; i < get_compound_ent_n_values(ent); ++i) {
1018 compound_graph_path *path = get_compound_ent_value_path(ent, i);
1019 entity *ent0 = get_compound_graph_path_node(path, 0);
1020 printf("\n %3d %s", get_entity_offset_bits(ent0), get_entity_name(ent0));
1021 for (j = 1; j < get_compound_graph_path_length(path); ++j)
1022 printf(".%s", get_entity_name(get_compound_graph_path_node(path, j)));
1024 dump_node_opcode(stdout, get_compound_ent_value(ent, i));
1029 printf ("\n volatility: ");
1030 switch (get_entity_volatility(ent)) {
1031 X(volatility_non_volatile);
1032 X(volatility_is_volatile);
1035 printf("\n peculiarity: %s", get_peculiarity_string(get_entity_peculiarity(ent)));
1036 printf("\n ld_name: %s", ent->ld_name ? get_entity_ld_name(ent) : "no yet set");
1037 printf("\n offset: %d", get_entity_offset_bits(ent));
1038 if (is_method_type(get_entity_type(ent))) {
1039 if (get_entity_irg(ent)) /* can be null */
1040 { printf ("\n irg = %ld", get_irg_graph_nr(get_entity_irg(ent))); }
1042 { printf ("\n irg = NULL"); }
1047 #else /* DEBUG_libfirm */
1048 void dump_entity (entity *ent) {}
1049 #endif /* DEBUG_libfirm */