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)) {
87 res->variability = variability_constant;
88 rem = current_ir_graph;
89 current_ir_graph = get_const_code_irg();
90 res->value = new_SymConst(sym, symconst_addr_ent);
91 current_ir_graph = rem;
93 res->variability = variability_uninitialized;
96 res->val_paths = NULL;
98 res->peculiarity = peculiarity_existent;
99 res->volatility = volatility_non_volatile;
100 res->stickyness = stickyness_unsticky;
102 if (is_class_type(owner)) {
103 res->overwrites = NEW_ARR_F(entity *, 0);
104 res->overwrittenby = NEW_ARR_F(entity *, 0);
106 res->overwrites = NULL;
107 res->overwrittenby = NULL;
112 res->nr = get_irp_new_node_nr();
117 /* Remember entity in it's owner. */
118 insert_entity_in_owner (res);
122 new_d_entity (type *owner, ident *name, type *type, dbg_info *db) {
123 entity *res = new_entity(owner, name, type);
124 set_entity_dbg_info(res, db);
128 void free_compound_graph_path (compound_graph_path *gr);
129 int is_compound_graph_path(void *thing);
130 int get_compound_graph_path_length(compound_graph_path *gr);
131 entity *get_compound_graph_path_node(compound_graph_path *gr, int pos);
132 int get_compound_ent_n_values(entity *ent);
134 static void free_entity_attrs(entity *ent) {
136 if (get_type_tpop(get_entity_owner(ent)) == type_class) {
137 DEL_ARR_F(ent->overwrites); ent->overwrites = NULL;
138 DEL_ARR_F(ent->overwrittenby); ent->overwrittenby = NULL;
140 assert(ent->overwrites == NULL);
141 assert(ent->overwrittenby == NULL);
143 /* if (ent->values) DEL_ARR_F(ent->values); *//* @@@ warum nich? */
144 if (ent->val_paths) {
145 if (is_compound_entity(ent))
146 for (i = 0; i < get_compound_ent_n_values(ent); i++)
147 if (ent->val_paths[i]) ;
148 /* free_compound_graph_path(ent->val_paths[i]) ; * @@@ warum nich? */
149 /* Geht nich: wird mehrfach verwendet!!! ==> mehrfach frei gegeben. */
150 /* DEL_ARR_F(ent->val_paths); */
152 ent->val_paths = NULL;
157 copy_entity_own (entity *old, type *new_owner) {
159 assert(old && old->kind == k_entity);
160 assert_legal_owner_of_ent(new_owner);
162 if (old->owner == new_owner) return old;
163 new = (entity *) xmalloc (sizeof (entity));
164 memcpy (new, old, sizeof (entity));
165 new->owner = new_owner;
166 if (is_class_type(new_owner)) {
167 new->overwrites = NEW_ARR_F(entity *, 0);
168 new->overwrittenby = NEW_ARR_F(entity *, 0);
171 new->nr = get_irp_new_node_nr();
174 insert_entity_in_owner (new);
180 copy_entity_name (entity *old, ident *new_name) {
182 assert(old && old->kind == k_entity);
184 if (old->name == new_name) return old;
185 new = (entity *) xmalloc (sizeof (entity));
186 memcpy (new, old, sizeof (entity));
187 new->name = new_name;
189 if (is_class_type(new->owner)) {
190 new->overwrites = DUP_ARR_F(entity *, old->overwrites);
191 new->overwrittenby = DUP_ARR_F(entity *, old->overwrittenby);
194 new->nr = get_irp_new_node_nr();
197 insert_entity_in_owner (new);
204 free_entity (entity *ent) {
205 assert(ent && ent->kind == k_entity);
206 free_tarval_entity(ent);
207 free_entity_attrs(ent);
212 /* Outputs a unique number for this node */
214 get_entity_nr(entity *ent) {
215 assert(ent && ent->kind == k_entity);
224 (get_entity_name)(entity *ent) {
225 return __get_entity_name(ent);
229 (get_entity_ident)(entity *ent) {
230 return get_entity_ident(ent);
234 void set_entitye_ld_name (entity *, char *ld_name);
235 void set_entity_ld_ident (entity *, ident *ld_ident);
239 (get_entity_owner)(entity *ent) {
240 return __get_entity_owner(ent);
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) {
261 return __get_entity_ld_ident(ent);
265 (set_entity_ld_ident)(entity *ent, ident *ld_ident) {
266 __set_entity_ld_ident(ent, ld_ident);
270 (get_entity_ld_name)(entity *ent) {
271 return __get_entity_ld_name(ent);
275 (get_entity_type)(entity *ent) {
276 return __get_entity_type(ent);
280 (set_entity_type)(entity *ent, type *type) {
281 __set_entity_type(ent, type);
285 (get_entity_allocation)(entity *ent) {
286 return __get_entity_allocation(ent);
290 (set_entity_allocation)(entity *ent, ent_allocation al) {
291 __set_entity_allocation(ent, al);
294 /* return the name of the visibility */
295 const char *get_allocation_name(ent_allocation all)
297 #define X(a) case a: return #a
299 X(allocation_automatic);
300 X(allocation_parameter);
301 X(allocation_dynamic);
302 X(allocation_static);
303 default: return "BAD VALUE";
310 (get_entity_visibility)(entity *ent) {
311 return __get_entity_visibility(ent);
315 set_entity_visibility (entity *ent, ent_visibility vis) {
316 assert(ent && ent->kind == k_entity);
317 if (vis != visibility_local)
318 assert((ent->allocation == allocation_static) ||
319 (ent->allocation == allocation_automatic));
320 /* @@@ Test that the owner type is not local, but how??
321 && get_class_visibility(get_entity_owner(ent)) != local));*/
322 ent->visibility = vis;
325 /* return the name of the visibility */
326 const char *get_visibility_name(ent_visibility vis)
328 #define X(a) case a: return #a
331 X(visibility_external_visible);
332 X(visibility_external_allocated);
333 default: return "BAD VALUE";
339 (get_entity_variability)(entity *ent) {
340 return __get_entity_variability(ent);
344 set_entity_variability (entity *ent, ent_variability var)
346 assert(ent && ent->kind == k_entity);
347 if (var == variability_part_constant)
348 assert(is_class_type(ent->type) || is_struct_type(ent->type));
350 if ((is_compound_type(ent->type)) &&
351 (ent->variability == variability_uninitialized) && (var != variability_uninitialized)) {
352 /* Allocate datastructures for constant values */
353 ent->values = NEW_ARR_F(ir_node *, 0);
354 ent->val_paths = NEW_ARR_F(compound_graph_path *, 0);
357 if ((is_compound_type(ent->type)) &&
358 (var == variability_uninitialized) && (ent->variability != variability_uninitialized)) {
359 /* Free datastructures for constant values */
360 DEL_ARR_F(ent->values); ent->values = NULL;
361 DEL_ARR_F(ent->val_paths); ent->val_paths = NULL;
363 ent->variability = var;
366 /* return the name of the variablity */
367 const char *get_variability_name(ent_variability var)
369 #define X(a) case a: return #a
371 X(variability_uninitialized);
372 X(variability_initialized);
373 X(variability_part_constant);
374 X(variability_constant);
375 default: return "BAD VALUE";
381 (get_entity_volatility)(entity *ent) {
382 return __get_entity_volatility(ent);
386 (set_entity_volatility)(entity *ent, ent_volatility vol) {
387 __set_entity_volatility(ent, vol);
390 /* return the name of the volatility */
391 const char *get_volatility_name(ent_volatility var)
393 #define X(a) case a: return #a
395 X(volatility_non_volatile);
396 X(volatility_is_volatile);
397 default: return "BAD VALUE";
403 (get_entity_peculiarity)(entity *ent) {
404 return __get_entity_peculiarity(ent);
408 (set_entity_peculiarity)(entity *ent, peculiarity pec) {
409 __set_entity_peculiarity(ent, pec);
412 /* return the name of the peculiarity */
413 const char *get_peculiarity_name(peculiarity var)
415 #define X(a) case a: return #a
417 X(peculiarity_description);
418 X(peculiarity_inherited);
419 X(peculiarity_existent);
420 default: return "BAD VALUE";
425 /* Get the entity's stickyness */
427 (get_entity_stickyness)(entity *ent) {
428 return __get_entity_stickyness(ent);
431 /* Set the entity's stickyness */
433 (set_entity_stickyness)(entity *ent, ent_stickyness stickyness) {
434 __set_entity_stickyness(ent, stickyness);
437 /* Set has no effect for existent entities of type method. */
439 get_atomic_ent_value(entity *ent)
441 assert(ent && is_atomic_entity(ent));
442 assert(ent->variability != variability_uninitialized);
443 return skip_Id (ent->value);
447 set_atomic_ent_value(entity *ent, ir_node *val) {
448 assert(is_atomic_entity(ent) && (ent->variability != variability_uninitialized));
449 if (is_method_type(ent->type) && (ent->peculiarity == peculiarity_existent))
454 /* Returns true if the the node is representable as code on
456 int is_irn_const_expression(ir_node *n) {
460 switch(get_irn_opcode(n)) {
471 if (is_irn_const_expression(get_binop_left(n)))
472 return is_irn_const_expression(get_binop_right(n));
475 return is_irn_const_expression(get_irn_n(n, 0));
484 ir_node *copy_const_value(ir_node *n) {
489 switch(get_irn_opcode(n)) {
491 nn = new_Const(m, get_Const_tarval(n)); break;
494 nn = new_SymConst(get_SymConst_type_or_id(n), get_SymConst_kind(n));
497 nn = new_Add(copy_const_value(get_Add_left(n)),
498 copy_const_value(get_Add_right(n)), m); break;
500 nn = new_Sub(copy_const_value(get_Sub_left(n)),
501 copy_const_value(get_Sub_right(n)), m); break;
503 nn = new_Mul(copy_const_value(get_Mul_left(n)),
504 copy_const_value(get_Mul_right(n)), m); break;
506 nn = new_And(copy_const_value(get_And_left(n)),
507 copy_const_value(get_And_right(n)), m); break;
509 nn = new_Or(copy_const_value(get_Or_left(n)),
510 copy_const_value(get_Or_right(n)), m); break;
512 nn = new_Eor(copy_const_value(get_Eor_left(n)),
513 copy_const_value(get_Eor_right(n)), m); break;
515 nn = new_Cast(copy_const_value(get_Cast_op(n)), get_Cast_type(n)); break;
517 nn = new_Conv(copy_const_value(get_Conv_op(n)), m); break;
519 nn = new_Unknown(m); break;
522 assert(0 && "opdope invalid or not implemented");
529 compound_graph_path *
530 new_compound_graph_path(type *tp, int length) {
531 compound_graph_path *res;
532 assert(is_type(tp) && is_compound_type(tp));
535 res = (compound_graph_path *) malloc (sizeof(compound_graph_path) + (length-1) * sizeof(entity *));
536 res->kind = k_ir_compound_graph_path;
539 memset(res->nodes, 0, sizeof(entity *) * length);
544 free_compound_graph_path (compound_graph_path *gr) {
545 assert(gr && is_compound_graph_path(gr));
551 is_compound_graph_path(void *thing) {
552 return (get_kind(thing) == k_ir_compound_graph_path);
555 /* checks whether nodes 0..pos are correct (all lie on a path.) */
556 /* @@@ not implemented */
557 int is_proper_compound_graph_path(compound_graph_path *gr, int pos) {
560 type *owner = gr->tp;
561 for (i = 0; i <= pos; i++) {
562 node = get_compound_graph_path_node(gr, i);
563 if (get_entity_owner(node) != owner) return false;
564 owner = get_entity_type(node);
566 if (pos == get_compound_graph_path_length(gr))
567 if (!is_atomic_type(owner)) return false;
572 get_compound_graph_path_length(compound_graph_path *gr) {
573 assert(gr && is_compound_graph_path(gr));
578 get_compound_graph_path_node(compound_graph_path *gr, int pos) {
579 assert(gr && is_compound_graph_path(gr));
580 assert(pos >= 0 && pos < gr->len);
581 return gr->nodes[pos];
585 set_compound_graph_path_node(compound_graph_path *gr, int pos, entity *node) {
586 assert(gr && is_compound_graph_path(gr));
587 assert(pos >= 0 && pos < gr->len);
588 assert(is_entity(node));
589 gr->nodes[pos] = node;
590 assert(is_proper_compound_graph_path(gr, pos));
593 /* A value of a compound entity is a pair of value and the corresponding path to a member of
596 add_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path) {
597 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
598 ARR_APP1 (ir_node *, ent->values, val);
599 ARR_APP1 (compound_graph_path *, ent->val_paths, path);
603 set_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path, int pos) {
604 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
605 ent->values[pos] = val;
606 ent->val_paths[pos] = path;
610 get_compound_ent_n_values(entity *ent) {
611 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
612 return (ARR_LEN (ent->values));
616 get_compound_ent_value(entity *ent, int pos) {
617 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
618 return ent->values[pos];
621 compound_graph_path *
622 get_compound_ent_value_path(entity *ent, int pos) {
623 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
624 return ent->val_paths[pos];
628 remove_compound_ent_value(entity *ent, entity *value_ent) {
630 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
631 for (i = 0; i < (ARR_LEN (ent->val_paths)); i++) {
632 compound_graph_path *path = ent->val_paths[i];
633 if (path->nodes[path->len-1] == value_ent) {
634 for(; i < (ARR_LEN (ent->val_paths))-1; i++) {
635 ent->val_paths[i] = ent->val_paths[i+1];
636 ent->values[i] = ent->values[i+1];
638 ARR_SETLEN(entity*, ent->val_paths, ARR_LEN(ent->val_paths) - 1);
639 ARR_SETLEN(ir_node*, ent->values, ARR_LEN(ent->values) - 1);
646 add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
647 compound_graph_path *path;
648 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
649 path = new_compound_graph_path(get_entity_owner(ent), 1);
650 path->nodes[0] = member;
651 add_compound_ent_value_w_path(ent, val, path);
654 /* Copies the firm subgraph referenced by val to const_code_irg and adds
655 the node as constant initialization to ent.
656 The subgraph may not contain control flow operations.
658 copy_and_add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
659 ir_graph *rem = current_ir_graph;
661 assert(get_entity_variability(ent) != variability_uninitialized);
662 current_ir_graph = get_const_code_irg();
664 val = copy_const_value(val);
665 add_compound_ent_value(ent, val, member);
666 current_ir_graph = rem;
669 /* Copies the value i of the entity to current_block in current_ir_graph.
671 copy_compound_ent_value(entity *ent, int pos) {
672 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
673 return copy_const_value(ent->values[pos+1]);
677 get_compound_ent_value_member(entity *ent, int pos) {
678 compound_graph_path *path;
679 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
680 path = get_compound_ent_value_path(ent, pos);
682 return get_compound_graph_path_node(path, get_compound_graph_path_length(path)-1);
686 set_compound_ent_value(entity *ent, ir_node *val, entity *member, int pos) {
687 compound_graph_path *path;
688 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
689 path = get_compound_ent_value_path(ent, pos);
690 set_compound_graph_path_node(path, 0, member);
691 set_compound_ent_value_w_path(ent, val, path, pos);
695 set_array_entity_values(entity *ent, tarval **values, int num_vals) {
697 ir_graph *rem = current_ir_graph;
698 type *arrtp = get_entity_type(ent);
701 assert(is_array_type(arrtp));
702 assert(get_array_n_dimensions(arrtp) == 1);
703 /* One bound is sufficient, the nunmber of constant fields makes the
705 assert(get_array_lower_bound (arrtp, 0) || get_array_upper_bound (arrtp, 0));
706 assert(get_entity_variability(ent) != variability_uninitialized);
707 current_ir_graph = get_const_code_irg();
709 for (i = 0; i < num_vals; i++) {
710 val = new_Const(get_tarval_mode (values[i]), values[i]);
711 add_compound_ent_value(ent, val, get_array_element_entity(arrtp));
713 current_ir_graph = rem;
717 (get_entity_offset_bytes)(entity *ent) {
718 return __get_entity_offset_bytes(ent);
722 (get_entity_offset_bits)(entity *ent) {
723 return __get_entity_offset_bits(ent);
727 (set_entity_offset_bytes)(entity *ent, int offset) {
728 __set_entity_offset_bytes(ent, offset);
732 (set_entity_offset_bits)(entity *ent, int offset) {
733 __set_entity_offset_bits(ent, offset);
737 add_entity_overwrites(entity *ent, entity *overwritten) {
738 assert(ent && is_class_type(get_entity_owner(ent)));
739 ARR_APP1(entity *, ent->overwrites, overwritten);
740 ARR_APP1(entity *, overwritten->overwrittenby, ent);
744 get_entity_n_overwrites(entity *ent) {
745 assert(ent && is_class_type(get_entity_owner(ent)));
746 return (ARR_LEN(ent->overwrites));
750 get_entity_overwrites_index(entity *ent, entity *overwritten) {
752 assert(ent && is_class_type(get_entity_owner(ent)));
753 for (i = 0; i < get_entity_n_overwrites(ent); i++)
754 if (get_entity_overwrites(ent, i) == overwritten)
760 get_entity_overwrites (entity *ent, int pos) {
761 assert(ent && is_class_type(get_entity_owner(ent)));
762 assert(pos < get_entity_n_overwrites(ent));
763 return ent->overwrites[pos];
767 set_entity_overwrites (entity *ent, int pos, entity *overwritten) {
768 assert(ent && is_class_type(get_entity_owner(ent)));
769 assert(pos < get_entity_n_overwrites(ent));
770 ent->overwrites[pos] = overwritten;
774 remove_entity_overwrites(entity *ent, entity *overwritten) {
776 assert(ent && is_class_type(get_entity_owner(ent)));
777 for (i = 0; i < (ARR_LEN (ent->overwrites)); i++)
778 if (ent->overwrites[i] == overwritten) {
779 for(; i < (ARR_LEN (ent->overwrites))-1; i++)
780 ent->overwrites[i] = ent->overwrites[i+1];
781 ARR_SETLEN(entity*, ent->overwrites, ARR_LEN(ent->overwrites) - 1);
787 add_entity_overwrittenby (entity *ent, entity *overwrites) {
788 assert(ent && is_class_type(get_entity_owner(ent)));
789 add_entity_overwrites(overwrites, ent);
793 get_entity_n_overwrittenby (entity *ent) {
794 assert(ent && is_class_type(get_entity_owner(ent)));
795 return (ARR_LEN (ent->overwrittenby));
799 get_entity_overwrittenby_index(entity *ent, entity *overwrites) {
801 assert(ent && is_class_type(get_entity_owner(ent)));
802 for (i = 0; i < get_entity_n_overwrittenby(ent); i++)
803 if (get_entity_overwrittenby(ent, i) == overwrites)
809 get_entity_overwrittenby (entity *ent, int pos) {
810 assert(ent && is_class_type(get_entity_owner(ent)));
811 assert(pos < get_entity_n_overwrittenby(ent));
812 return ent->overwrittenby[pos];
816 set_entity_overwrittenby (entity *ent, int pos, entity *overwrites) {
817 assert(ent && is_class_type(get_entity_owner(ent)));
818 assert(pos < get_entity_n_overwrittenby(ent));
819 ent->overwrittenby[pos] = overwrites;
822 void remove_entity_overwrittenby(entity *ent, entity *overwrites) {
824 assert(ent && is_class_type(get_entity_owner(ent)));
825 for (i = 0; i < (ARR_LEN (ent->overwrittenby)); i++)
826 if (ent->overwrittenby[i] == overwrites) {
827 for(; i < (ARR_LEN (ent->overwrittenby))-1; i++)
828 ent->overwrittenby[i] = ent->overwrittenby[i+1];
829 ARR_SETLEN(entity*, ent->overwrittenby, ARR_LEN(ent->overwrittenby) - 1);
834 /* A link to store intermediate information */
836 (get_entity_link)(entity *ent) {
837 return __get_entity_link(ent);
841 (set_entity_link)(entity *ent, void *l) {
842 __set_entity_link(ent, l);
846 (get_entity_irg)(entity *ent) {
847 return __get_entity_irg(ent);
851 set_entity_irg(entity *ent, ir_graph *irg) {
852 assert(ent && is_method_type(get_entity_type(ent)));
853 /* Wie kann man die Referenz auf einen IRG löschen, z.B. wenn die
854 * Methode selbst nicht mehr aufgerufen werden kann, die Entität
855 * aber erhalten bleiben soll. */
857 assert((irg && ent->peculiarity == peculiarity_existent) ||
858 (!irg && ent->peculiarity == peculiarity_description) ||
859 (!irg && ent->peculiarity == peculiarity_inherited));
864 (is_entity)(void *thing) {
865 return __is_entity(thing);
868 int is_atomic_entity(entity *ent) {
869 type* t = get_entity_type(ent);
870 assert(ent && ent->kind == k_entity);
871 return (is_primitive_type(t) || is_pointer_type(t) ||
872 is_enumeration_type(t) || is_method_type(t));
875 int is_compound_entity(entity *ent) {
876 type* t = get_entity_type(ent);
877 assert(ent && ent->kind == k_entity);
878 return (is_class_type(t) || is_struct_type(t) ||
879 is_array_type(t) || is_union_type(t));
883 * @todo not implemnted!!! */
884 bool equal_entity(entity *ent1, entity *ent2) {
885 printf(" calling unimplemented equal entity!!! \n");
890 unsigned long get_entity_visited(entity *ent) {
891 assert(ent && ent->kind == k_entity);
894 void set_entity_visited(entity *ent, unsigned long num) {
895 assert(ent && ent->kind == k_entity);
898 /* Sets visited field in entity to entity_visited. */
899 void mark_entity_visited(entity *ent) {
900 assert(ent && ent->kind == k_entity);
901 ent->visit = type_visited;
905 bool entity_visited(entity *ent) {
906 assert(ent && ent->kind == k_entity);
907 return get_entity_visited(ent) >= type_visited;
910 bool entity_not_visited(entity *ent) {
911 assert(ent && ent->kind == k_entity);
912 return get_entity_visited(ent) < type_visited;
915 /* Need two routines because I want to assert the result. */
916 static entity *resolve_ent_polymorphy2 (type *dynamic_class, entity* static_ent) {
917 int i, n_overwrittenby;
920 if (get_entity_owner(static_ent) == dynamic_class) return static_ent;
922 n_overwrittenby = get_entity_n_overwrittenby(static_ent);
923 for (i = 0; i < n_overwrittenby; ++i) {
924 res = resolve_ent_polymorphy2(dynamic_class, get_entity_overwrittenby(static_ent, i));
931 /** Resolve polymorphy in the inheritance relation.
933 * Returns the dynamically referenced entity if the static entity and the
934 * dynamic type are given.
935 * Search downwards in overwritten tree. */
936 entity *resolve_ent_polymorphy(type *dynamic_class, entity* static_ent) {
938 assert(static_ent && static_ent->kind == k_entity);
940 res = resolve_ent_polymorphy2(dynamic_class, static_ent);
942 printf(" Could not find entity "); DDME(static_ent);
943 printf(" in "); DDMT(dynamic_class);
945 dump_entity(static_ent);
946 dump_type(get_entity_owner(static_ent));
947 dump_type(dynamic_class);
955 /*******************************************************************/
957 /*******************************************************************/
960 #if 1 || DEBUG_libfirm
961 int dump_node_opcode(FILE *F, ir_node *n); /* from irdump.c */
963 #define X(a) case a: printf(#a); break
964 void dump_entity (entity *ent) {
966 type *owner = get_entity_owner(ent);
967 type *type = get_entity_type(ent);
968 assert(ent && ent->kind == k_entity);
969 printf("entity %s (%ld)\n", get_entity_name(ent), get_entity_nr(ent));
970 printf(" type: %s (%ld)\n", get_type_name(type), get_type_nr(type));
971 printf(" owner: %s (%ld)\n", get_type_name(owner), get_type_nr(owner));
973 if (get_entity_n_overwrites(ent) > 0) {
974 printf (" overwrites:\n");
975 for (i = 0; i < get_entity_n_overwrites(ent); ++i) {
976 entity *ov = get_entity_overwrites(ent, i);
977 printf(" %d: %s of class %s\n", i, get_entity_name(ov), get_type_name(get_entity_owner(ov)));
980 printf(" Does not overwrite other entities. \n");
982 if (get_entity_n_overwrittenby(ent) > 0) {
983 printf (" overwritten by:\n");
984 for (i = 0; i < get_entity_n_overwrittenby(ent); ++i) {
985 entity *ov = get_entity_overwrittenby(ent, i);
986 printf(" %d: %s of class %s\n", i, get_entity_name(ov), get_type_name(get_entity_owner(ov)));
989 printf(" Is not overwriten by other entities. \n");
992 printf (" allocation: ");
993 switch (get_entity_allocation(ent)) {
994 X(allocation_dynamic);
995 X(allocation_automatic);
996 X(allocation_static);
997 X(allocation_parameter);
1000 printf ("\n visibility: ");
1001 switch (get_entity_visibility(ent)) {
1002 X(visibility_local);
1003 X(visibility_external_visible);
1004 X(visibility_external_allocated);
1007 printf ("\n variability: ");
1008 switch (get_entity_variability(ent)) {
1009 X(variability_uninitialized);
1010 X(variability_initialized);
1011 X(variability_part_constant);
1012 X(variability_constant);
1015 if (get_entity_variability(ent) != variability_uninitialized) {
1016 if (is_atomic_entity(ent)) {
1017 printf("\n atomic value: ");
1018 dump_node_opcode(stdout, get_atomic_ent_value(ent));
1020 printf("\n compound values:");
1021 for (i = 0; i < get_compound_ent_n_values(ent); ++i) {
1022 compound_graph_path *path = get_compound_ent_value_path(ent, i);
1023 entity *ent0 = get_compound_graph_path_node(path, 0);
1024 printf("\n %3d %s", get_entity_offset_bits(ent0), get_entity_name(ent0));
1025 for (j = 1; j < get_compound_graph_path_length(path); ++j)
1026 printf(".%s", get_entity_name(get_compound_graph_path_node(path, j)));
1028 dump_node_opcode(stdout, get_compound_ent_value(ent, i));
1033 printf ("\n volatility: ");
1034 switch (get_entity_volatility(ent)) {
1035 X(volatility_non_volatile);
1036 X(volatility_is_volatile);
1039 printf("\n peculiarity: %s", get_peculiarity_string(get_entity_peculiarity(ent)));
1040 printf("\n ld_name: %s", ent->ld_name ? get_entity_ld_name(ent) : "no yet set");
1041 printf("\n offset: %d", get_entity_offset_bits(ent));
1042 if (is_method_type(get_entity_type(ent))) {
1043 if (get_entity_irg(ent)) /* can be null */
1044 { printf ("\n irg = %ld", get_irg_graph_nr(get_entity_irg(ent))); }
1046 { printf ("\n irg = NULL"); }
1051 #else /* DEBUG_libfirm */
1052 void dump_entity (entity *ent) {}
1053 #endif /* DEBUG_libfirm */