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 assert(ent && ent->kind == k_entity);
224 return get_id_str(get_entity_ident(ent));
228 get_entity_ident (entity *ent) {
229 assert(ent && ent->kind == k_entity);
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 assert(ent && ent->kind == k_entity);
241 return ent->owner = skip_tid(ent->owner);
245 set_entity_owner (entity *ent, type *owner) {
246 assert(ent && ent->kind == k_entity);
247 assert_legal_owner_of_ent(owner);
251 void /* should this go into type.c? */
252 assert_legal_owner_of_ent(type *owner) {
253 assert(get_type_tpop_code(owner) == tpo_class ||
254 get_type_tpop_code(owner) == tpo_union ||
255 get_type_tpop_code(owner) == tpo_struct ||
256 get_type_tpop_code(owner) == tpo_array); /* Yes, array has an entity
257 -- to select fields! */
261 get_entity_ld_ident (entity *ent)
263 assert(ent && ent->kind == k_entity);
264 if (ent->ld_name == NULL)
265 ent->ld_name = mangle_entity (ent);
270 set_entity_ld_ident (entity *ent, ident *ld_ident) {
271 assert(ent && ent->kind == k_entity);
272 ent->ld_name = ld_ident;
276 get_entity_ld_name (entity *ent) {
277 assert(ent && ent->kind == k_entity);
278 return get_id_str(get_entity_ld_ident(ent));
282 char *get_entity_ld_name (entity *);
283 void set_entity_ld_name (entity *, char *ld_name);
287 get_entity_type (entity *ent) {
288 assert(ent && ent->kind == k_entity);
289 return ent->type = skip_tid(ent->type);
293 set_entity_type (entity *ent, type *type) {
294 assert(ent && ent->kind == k_entity);
300 get_entity_allocation (entity *ent) {
301 assert(ent && ent->kind == k_entity);
302 return ent->allocation;
306 set_entity_allocation (entity *ent, ent_allocation al) {
307 assert(ent && ent->kind == k_entity);
308 ent->allocation = al;
311 /* return the name of the visibility */
312 const char *get_allocation_name(ent_allocation all)
314 #define X(a) case a: return #a
316 X(allocation_automatic);
317 X(allocation_parameter);
318 X(allocation_dynamic);
319 X(allocation_static);
320 default: return "BAD VALUE";
327 get_entity_visibility (entity *ent) {
328 assert(ent && ent->kind == k_entity);
329 return ent->visibility;
333 set_entity_visibility (entity *ent, ent_visibility vis) {
334 assert(ent && ent->kind == k_entity);
335 if (vis != visibility_local)
336 assert((ent->allocation == allocation_static) ||
337 (ent->allocation == allocation_automatic));
338 /* @@@ Test that the owner type is not local, but how??
339 && get_class_visibility(get_entity_owner(ent)) != local));*/
340 ent->visibility = vis;
343 /* return the name of the visibility */
344 const char *get_visibility_name(ent_visibility vis)
346 #define X(a) case a: return #a
349 X(visibility_external_visible);
350 X(visibility_external_allocated);
351 default: return "BAD VALUE";
357 get_entity_variability (entity *ent) {
358 assert(ent && ent->kind == k_entity);
359 return ent->variability;
363 set_entity_variability (entity *ent, ent_variability var)
365 assert(ent && ent->kind == k_entity);
366 if (var == variability_part_constant)
367 assert(is_class_type(ent->type) || is_struct_type(ent->type));
369 if ((is_compound_type(ent->type)) &&
370 (ent->variability == variability_uninitialized) && (var != variability_uninitialized)) {
371 /* Allocate datastructures for constant values */
372 ent->values = NEW_ARR_F(ir_node *, 0);
373 ent->val_paths = NEW_ARR_F(compound_graph_path *, 0);
376 if ((is_compound_type(ent->type)) &&
377 (var == variability_uninitialized) && (ent->variability != variability_uninitialized)) {
378 /* Free datastructures for constant values */
379 DEL_ARR_F(ent->values); ent->values = NULL;
380 DEL_ARR_F(ent->val_paths); ent->val_paths = NULL;
382 ent->variability = var;
385 /* return the name of the variablity */
386 const char *get_variability_name(ent_variability var)
388 #define X(a) case a: return #a
390 X(variability_uninitialized);
391 X(variability_initialized);
392 X(variability_part_constant);
393 X(variability_constant);
394 default: return "BAD VALUE";
400 get_entity_volatility (entity *ent) {
401 assert(ent && ent->kind == k_entity);
402 return ent->volatility;
406 set_entity_volatility (entity *ent, ent_volatility vol) {
407 assert(ent && ent->kind == k_entity);
408 ent->volatility = vol;
411 /* return the name of the volatility */
412 const char *get_volatility_name(ent_volatility var)
414 #define X(a) case a: return #a
416 X(volatility_non_volatile);
417 X(volatility_is_volatile);
418 default: return "BAD VALUE";
424 get_entity_peculiarity (entity *ent) {
425 assert(ent && ent->kind == k_entity);
426 return ent->peculiarity;
430 set_entity_peculiarity (entity *ent, peculiarity pec) {
431 assert(ent && ent->kind == k_entity);
432 /* @@@ why peculiarity only for methods? */
433 assert(is_method_type(ent->type));
434 ent->peculiarity = pec;
437 /* return the name of the peculiarity */
438 const char *get_peculiarity_name(peculiarity var)
440 #define X(a) case a: return #a
442 X(peculiarity_description);
443 X(peculiarity_inherited);
444 X(peculiarity_existent);
445 default: return "BAD VALUE";
450 /** Get the entity's stickyness */
451 ent_stickyness get_entity_stickyness (entity *ent)
453 assert (ent && is_entity (ent));
455 return (ent->stickyness);
458 /** Set the entity's stickyness */
459 void set_entity_stickyness (entity *ent, ent_stickyness stickyness)
461 assert (ent && is_entity (ent));
463 ent->stickyness = stickyness;
466 /* Set has no effect for existent entities of type method. */
468 get_atomic_ent_value(entity *ent)
470 assert(ent && is_atomic_entity(ent));
471 assert(ent->variability != variability_uninitialized);
472 return skip_Id (ent->value);
476 set_atomic_ent_value(entity *ent, ir_node *val) {
477 assert(is_atomic_entity(ent) && (ent->variability != variability_uninitialized));
478 if (is_method_type(ent->type) && (ent->peculiarity == peculiarity_existent))
483 /* Returns true if the the node is representable as code on
485 int is_irn_const_expression(ir_node *n) {
489 switch(get_irn_opcode(n)) {
495 if (is_irn_const_expression(get_Add_left(n)))
496 return is_irn_const_expression(get_Add_right(n));
499 return is_irn_const_expression(get_irn_n(n, 0));
508 ir_node *copy_const_value(ir_node *n) {
513 switch(get_irn_opcode(n)) {
515 nn = new_Const(m, get_Const_tarval(n)); break;
517 nn = new_SymConst(get_SymConst_type_or_id(n), get_SymConst_kind(n)); break;
519 nn = new_Add(copy_const_value(get_Add_left(n)),
520 copy_const_value(get_Add_right(n)), m); break;
522 nn = new_Cast(copy_const_value(get_Cast_op(n)), get_Cast_type(n)); break;
524 nn = new_Conv(copy_const_value(get_Conv_op(n)), m); break;
526 nn = new_Unknown(m); break;
529 assert(0 && "opdope invalid or not implemented");
536 compound_graph_path *
537 new_compound_graph_path(type *tp, int length) {
538 compound_graph_path *res;
539 assert(is_type(tp) && is_compound_type(tp));
542 res = (compound_graph_path *) malloc (sizeof(compound_graph_path) + (length-1) * sizeof(entity *));
543 res->kind = k_ir_compound_graph_path;
546 memset(res->nodes, 0, sizeof(entity *) * length);
551 free_compound_graph_path (compound_graph_path *gr) {
552 assert(gr && is_compound_graph_path(gr));
558 is_compound_graph_path(void *thing) {
559 return (get_kind(thing) == k_ir_compound_graph_path);
562 /* checks whether nodes 0..pos are correct (all lie on a path.) */
563 /* @@@ not implemented */
564 int is_proper_compound_graph_path(compound_graph_path *gr, int pos) {
567 type *owner = gr->tp;
568 for (i = 0; i <= pos; i++) {
569 node = get_compound_graph_path_node(gr, i);
570 if (get_entity_owner(node) != owner) return false;
571 owner = get_entity_type(node);
573 if (pos == get_compound_graph_path_length(gr))
574 if (!is_atomic_type(owner)) return false;
579 get_compound_graph_path_length(compound_graph_path *gr) {
580 assert(gr && is_compound_graph_path(gr));
585 get_compound_graph_path_node(compound_graph_path *gr, int pos) {
586 assert(gr && is_compound_graph_path(gr));
587 assert(pos >= 0 && pos < gr->len);
588 return gr->nodes[pos];
592 set_compound_graph_path_node(compound_graph_path *gr, int pos, entity *node) {
593 assert(gr && is_compound_graph_path(gr));
594 assert(pos >= 0 && pos < gr->len);
595 assert(is_entity(node));
596 gr->nodes[pos] = node;
597 assert(is_proper_compound_graph_path(gr, pos));
600 /* A value of a compound entity is a pair of value and the corresponding path to a member of
603 add_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path) {
604 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
605 ARR_APP1 (ir_node *, ent->values, val);
606 ARR_APP1 (compound_graph_path *, ent->val_paths, path);
610 set_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path, int pos) {
611 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
612 ent->values[pos] = val;
613 ent->val_paths[pos] = path;
617 get_compound_ent_n_values(entity *ent) {
618 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
619 return (ARR_LEN (ent->values));
623 get_compound_ent_value(entity *ent, int pos) {
624 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
625 return ent->values[pos];
628 compound_graph_path *
629 get_compound_ent_value_path(entity *ent, int pos) {
630 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
631 return ent->val_paths[pos];
635 remove_compound_ent_value(entity *ent, entity *value_ent) {
637 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
638 for (i = 0; i < (ARR_LEN (ent->val_paths)); i++) {
639 compound_graph_path *path = ent->val_paths[i];
640 if (path->nodes[path->len-1] == value_ent) {
641 for(; i < (ARR_LEN (ent->val_paths))-1; i++) {
642 ent->val_paths[i] = ent->val_paths[i+1];
643 ent->values[i] = ent->values[i+1];
645 ARR_SETLEN(entity*, ent->val_paths, ARR_LEN(ent->val_paths) - 1);
646 ARR_SETLEN(ir_node*, ent->values, ARR_LEN(ent->values) - 1);
653 add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
654 compound_graph_path *path;
655 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
656 path = new_compound_graph_path(get_entity_owner(ent), 1);
657 path->nodes[0] = member;
658 add_compound_ent_value_w_path(ent, val, path);
661 /* Copies the firm subgraph referenced by val to const_code_irg and adds
662 the node as constant initialization to ent.
663 The subgraph may not contain control flow operations.
665 copy_and_add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
666 ir_graph *rem = current_ir_graph;
668 assert(get_entity_variability(ent) != variability_uninitialized);
669 current_ir_graph = get_const_code_irg();
671 val = copy_const_value(val);
672 add_compound_ent_value(ent, val, member);
673 current_ir_graph = rem;
676 /* Copies the value i of the entity to current_block in current_ir_graph.
678 copy_compound_ent_value(entity *ent, int pos) {
679 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
680 return copy_const_value(ent->values[pos+1]);
684 get_compound_ent_value_member(entity *ent, int pos) {
685 compound_graph_path *path;
686 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
687 path = get_compound_ent_value_path(ent, pos);
689 return get_compound_graph_path_node(path, get_compound_graph_path_length(path)-1);
693 set_compound_ent_value(entity *ent, ir_node *val, entity *member, int pos) {
694 compound_graph_path *path;
695 assert(is_compound_entity(ent) && (ent->variability != variability_uninitialized));
696 path = get_compound_ent_value_path(ent, pos);
697 set_compound_graph_path_node(path, 0, member);
698 set_compound_ent_value_w_path(ent, val, path, pos);
702 set_array_entity_values(entity *ent, tarval **values, int num_vals) {
704 ir_graph *rem = current_ir_graph;
705 type *arrtp = get_entity_type(ent);
708 assert(is_array_type(arrtp));
709 assert(get_array_n_dimensions(arrtp) == 1);
710 /* One bound is sufficient, the nunmber of constant fields makes the
712 assert(get_array_lower_bound (arrtp, 0) || get_array_upper_bound (arrtp, 0));
713 assert(get_entity_variability(ent) != variability_uninitialized);
714 current_ir_graph = get_const_code_irg();
716 for (i = 0; i < num_vals; i++) {
717 val = new_Const(get_tarval_mode (values[i]), values[i]);
718 add_compound_ent_value(ent, val, get_array_element_entity(arrtp));
720 current_ir_graph = rem;
724 get_entity_offset (entity *ent) {
725 assert(ent && ent->kind == k_entity);
730 set_entity_offset (entity *ent, int offset) {
731 assert(ent && ent->kind == k_entity);
732 ent->offset = offset;
736 add_entity_overwrites (entity *ent, entity *overwritten) {
737 assert(ent && is_class_type(get_entity_owner(ent)));
738 ARR_APP1 (entity *, ent->overwrites, overwritten);
739 ARR_APP1 (entity *, overwritten->overwrittenby, ent);
743 get_entity_n_overwrites (entity *ent) {
744 assert(ent && is_class_type(get_entity_owner(ent)));
745 return (ARR_LEN (ent->overwrites));
749 get_entity_overwrites_index(entity *ent, entity *overwritten) {
751 assert(ent && is_class_type(get_entity_owner(ent)));
752 for (i = 0; i < get_entity_n_overwrites(ent); i++)
753 if (get_entity_overwrites(ent, i) == overwritten)
759 get_entity_overwrites (entity *ent, int pos) {
760 assert(ent && is_class_type(get_entity_owner(ent)));
761 assert(pos < get_entity_n_overwrites(ent));
762 return ent->overwrites[pos];
766 set_entity_overwrites (entity *ent, int pos, entity *overwritten) {
767 assert(ent && is_class_type(get_entity_owner(ent)));
768 assert(pos < get_entity_n_overwrites(ent));
769 ent->overwrites[pos] = overwritten;
773 remove_entity_overwrites(entity *ent, entity *overwritten) {
775 assert(ent && is_class_type(get_entity_owner(ent)));
776 for (i = 0; i < (ARR_LEN (ent->overwrites)); i++)
777 if (ent->overwrites[i] == overwritten) {
778 for(; i < (ARR_LEN (ent->overwrites))-1; i++)
779 ent->overwrites[i] = ent->overwrites[i+1];
780 ARR_SETLEN(entity*, ent->overwrites, ARR_LEN(ent->overwrites) - 1);
786 add_entity_overwrittenby (entity *ent, entity *overwrites) {
787 assert(ent && is_class_type(get_entity_owner(ent)));
788 add_entity_overwrites(overwrites, ent);
792 get_entity_n_overwrittenby (entity *ent) {
793 assert(ent && is_class_type(get_entity_owner(ent)));
794 return (ARR_LEN (ent->overwrittenby));
798 get_entity_overwrittenby_index(entity *ent, entity *overwrites) {
800 assert(ent && is_class_type(get_entity_owner(ent)));
801 for (i = 0; i < get_entity_n_overwrittenby(ent); i++)
802 if (get_entity_overwrittenby(ent, i) == overwrites)
808 get_entity_overwrittenby (entity *ent, int pos) {
809 assert(ent && is_class_type(get_entity_owner(ent)));
810 assert(pos < get_entity_n_overwrittenby(ent));
811 return ent->overwrittenby[pos];
815 set_entity_overwrittenby (entity *ent, int pos, entity *overwrites) {
816 assert(ent && is_class_type(get_entity_owner(ent)));
817 assert(pos < get_entity_n_overwrittenby(ent));
818 ent->overwrittenby[pos] = overwrites;
821 void remove_entity_overwrittenby(entity *ent, entity *overwrites) {
823 assert(ent && is_class_type(get_entity_owner(ent)));
824 for (i = 0; i < (ARR_LEN (ent->overwrittenby)); i++)
825 if (ent->overwrittenby[i] == overwrites) {
826 for(; i < (ARR_LEN (ent->overwrittenby))-1; i++)
827 ent->overwrittenby[i] = ent->overwrittenby[i+1];
828 ARR_SETLEN(entity*, ent->overwrittenby, ARR_LEN(ent->overwrittenby) - 1);
833 /* A link to store intermediate information */
835 get_entity_link(entity *ent) {
836 assert(ent && ent->kind == k_entity);
841 set_entity_link(entity *ent, void *l) {
842 assert(ent && ent->kind == k_entity);
847 get_entity_irg(entity *ent) {
848 assert(ent && ent->kind == k_entity);
849 assert(is_method_type(ent->type));
854 set_entity_irg(entity *ent, ir_graph *irg) {
855 assert(ent && is_method_type(get_entity_type(ent)));
856 /* Wie kann man die Referenz auf einen IRG löschen, z.B. wenn die
857 * Methode selbst nicht mehr aufgerufen werden kann, die Entität
858 * aber erhalten bleiben soll. */
860 assert((irg && ent->peculiarity == peculiarity_existent) ||
861 (!irg && ent->peculiarity == peculiarity_description) ||
862 (!irg && ent->peculiarity == peculiarity_inherited));
866 int is_entity (void *thing) {
868 if (get_kind(thing) == k_entity)
874 int is_atomic_entity(entity *ent) {
875 type* t = get_entity_type(ent);
876 assert(ent && ent->kind == k_entity);
877 return (is_primitive_type(t) || is_pointer_type(t) ||
878 is_enumeration_type(t) || is_method_type(t));
881 int is_compound_entity(entity *ent) {
882 type* t = get_entity_type(ent);
883 assert(ent && ent->kind == k_entity);
884 return (is_class_type(t) || is_struct_type(t) ||
885 is_array_type(t) || is_union_type(t));
888 /* @@@ not implemnted!!! */
889 bool equal_entity(entity *ent1, entity *ent2) {
890 printf(" calling unimplemented equal entity!!! \n");
895 unsigned long get_entity_visited(entity *ent) {
896 assert(ent && ent->kind == k_entity);
899 void set_entity_visited(entity *ent, unsigned long num) {
900 assert(ent && ent->kind == k_entity);
903 /* Sets visited field in entity to entity_visited. */
904 void mark_entity_visited(entity *ent) {
905 assert(ent && ent->kind == k_entity);
906 ent->visit = type_visited;
910 bool entity_visited(entity *ent) {
911 assert(ent && ent->kind == k_entity);
912 return get_entity_visited(ent) >= type_visited;
915 bool entity_not_visited(entity *ent) {
916 assert(ent && ent->kind == k_entity);
917 return get_entity_visited(ent) < type_visited;
920 /* Need two routines because I want to assert the result. */
921 static entity *resolve_ent_polymorphy2 (type *dynamic_class, entity* static_ent) {
922 int i, n_overwrittenby;
925 if (get_entity_owner(static_ent) == dynamic_class) return static_ent;
927 n_overwrittenby = get_entity_n_overwrittenby(static_ent);
928 for (i = 0; i < n_overwrittenby; ++i) {
929 res = resolve_ent_polymorphy2(dynamic_class, get_entity_overwrittenby(static_ent, i));
936 /* Returns the dynamically referenced entity if the static entity and the
937 * dynamic type are given.
938 * Search downwards in overwritten tree. */
939 entity *resolve_ent_polymorphy(type *dynamic_class, entity* static_ent) {
941 assert(static_ent && static_ent->kind == k_entity);
943 res = resolve_ent_polymorphy2(dynamic_class, static_ent);
945 printf(" Could not find entity "); DDME(static_ent);
946 printf(" in "); DDMT(dynamic_class);
948 dump_entity(static_ent);
949 dump_type(get_entity_owner(static_ent));
950 dump_type(dynamic_class);
959 /*******************************************************************/
961 /*******************************************************************/
964 #if 1 || DEBUG_libfirm
965 int dump_node_opcode(FILE *F, ir_node *n); /* from irdump.c */
967 #define X(a) case a: printf(#a); break
968 void dump_entity (entity *ent) {
970 type *owner = get_entity_owner(ent);
971 type *type = get_entity_type(ent);
972 assert(ent && ent->kind == k_entity);
973 printf("entity %s (%ld)\n", get_entity_name(ent), get_entity_nr(ent));
974 printf(" type: %s (%ld)\n", get_type_name(type), get_type_nr(type));
975 printf(" owner: %s (%ld)\n", get_type_name(owner), get_type_nr(owner));
977 if (get_entity_n_overwrites(ent) > 0) {
978 printf (" overwrites:\n");
979 for (i = 0; i < get_entity_n_overwrites(ent); ++i) {
980 entity *ov = get_entity_overwrites(ent, i);
981 printf(" %d: %s of class %s\n", i, get_entity_name(ov), get_type_name(get_entity_owner(ov)));
984 printf(" Does not overwrite other entities. \n");
986 if (get_entity_n_overwrittenby(ent) > 0) {
987 printf (" overwritten by:\n");
988 for (i = 0; i < get_entity_n_overwrittenby(ent); ++i) {
989 entity *ov = get_entity_overwrittenby(ent, i);
990 printf(" %d: %s of class %s\n", i, get_entity_name(ov), get_type_name(get_entity_owner(ov)));
993 printf(" Is not overwriten by other entities. \n");
996 printf (" allocation: ");
997 switch (get_entity_allocation(ent)) {
998 X(allocation_dynamic);
999 X(allocation_automatic);
1000 X(allocation_static);
1001 X(allocation_parameter);
1004 printf ("\n visibility: ");
1005 switch (get_entity_visibility(ent)) {
1006 X(visibility_local);
1007 X(visibility_external_visible);
1008 X(visibility_external_allocated);
1011 printf ("\n variability: ");
1012 switch (get_entity_variability(ent)) {
1013 X(variability_uninitialized);
1014 X(variability_initialized);
1015 X(variability_part_constant);
1016 X(variability_constant);
1019 if (get_entity_variability(ent) != variability_uninitialized) {
1020 if (is_atomic_entity(ent)) {
1021 printf("\n atomic value: ");
1022 dump_node_opcode(stdout, get_atomic_ent_value(ent));
1024 printf("\n compound values:");
1025 for (i = 0; i < get_compound_ent_n_values(ent); ++i) {
1026 compound_graph_path *path = get_compound_ent_value_path(ent, i);
1027 entity *ent0 = get_compound_graph_path_node(path, 0);
1028 printf("\n %2d %s", get_entity_offset(ent0), get_entity_name(ent0));
1029 for (j = 1; j < get_compound_graph_path_length(path); ++j)
1030 printf(".%s", get_entity_name(get_compound_graph_path_node(path, j)));
1032 dump_node_opcode(stdout, get_compound_ent_value(ent, i));
1037 printf ("\n volatility: ");
1038 switch (get_entity_volatility(ent)) {
1039 X(volatility_non_volatile);
1040 X(volatility_is_volatile);
1043 printf("\n peculiarity: %s", get_peculiarity_string(get_entity_peculiarity(ent)));
1044 printf("\n ld_name: %s", ent->ld_name ? get_entity_ld_name(ent) : "no yet set");
1045 printf("\n offset: %d", get_entity_offset(ent));
1046 if (is_method_type(get_entity_type(ent))) {
1047 if (get_entity_irg(ent)) /* can be null */
1048 { printf ("\n irg = %ld", get_irg_graph_nr(get_entity_irg(ent))); }
1050 { printf ("\n irg = NULL"); }
1055 #else /* DEBUG_libfirm */
1056 void dump_entity (entity *ent) {}
1057 #endif /* DEBUG_libfirm */