added copyright information
[libfirm] / ir / tr / entity.c
1 /*
2  * Project:     libFIRM
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
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
16
17 # include <stdlib.h>
18 # include <stddef.h>
19 # include <string.h>
20
21 # include "entity_t.h"
22 # include "mangle.h"
23 # include "typegmod.h"
24 # include "array.h"
25 /* All this is needed to build the constant node for methods: */
26 # include "irprog_t.h"
27 # include "ircons.h"
28 # include "tv_t.h"
29
30 /*******************************************************************/
31 /** general                                                       **/
32 /*******************************************************************/
33
34 void
35 init_entity (void)
36 {
37 }
38
39 /*******************************************************************/
40 /** ENTITY                                                        **/
41 /*******************************************************************/
42
43 /* redeclared to declare INLINE. */
44 INLINE entity *get_entity_overwrites   (entity *ent, int pos);
45 INLINE entity *get_entity_overwrittenby   (entity *ent, int pos);
46 INLINE type   *get_entity_owner (entity *ent);
47
48 INLINE void insert_entity_in_owner (entity *ent) {
49   type *owner = ent->owner;
50   switch (get_type_tpop_code(owner)) {
51   case tpo_class: {
52     add_class_member (owner, ent);
53   } break;
54   case tpo_struct: {
55     add_struct_member (owner, ent);
56   } break;
57   case tpo_union: {
58     add_union_member (owner, ent);
59   } break;
60   case tpo_array: {
61     set_array_element_entity(owner, ent);
62   } break;
63   default: assert(0);
64   }
65 }
66
67 entity *
68 new_entity (type *owner, ident *name, type *type)
69 {
70   entity *res;
71   ir_graph *rem;
72
73   assert(!id_contains_char(name, ' ') && "entity name should not contain spaces");
74
75   res = (entity *) xmalloc (sizeof (entity));
76   res->kind = k_entity;
77   assert_legal_owner_of_ent(owner);
78   res->owner = owner;
79   res->name = name;
80   res->type = type;
81   if (get_type_tpop(type) == type_method)
82     res->allocation = static_allocated;
83   else
84     res->allocation = automatic_allocated;
85   res->visibility = local;
86   res->offset = -1;
87   if (is_method_type(type)) {
88     res->variability = constant;
89     rem = current_ir_graph;
90     current_ir_graph = get_const_code_irg();
91     res->value = new_Const(mode_P_mach, new_tarval_from_entity(res, mode_P_mach));
92     current_ir_graph = rem;
93   } else {
94     res->variability = uninitialized;
95     res->value = NULL;
96     res->values = NULL;
97   }
98   res->peculiarity = existent;
99   res->volatility = non_volatile;
100   res->ld_name = NULL;
101   res->overwrites = NEW_ARR_F(entity *, 1);
102   res->overwrittenby = NEW_ARR_F(entity *, 1);
103
104   res->irg = NULL;
105
106 #ifdef DEBUG_libfirm
107   res->nr = get_irp_new_node_nr();
108 #endif
109
110   res->visit = 0;
111
112   /* Remember entity in it's owner. */
113   insert_entity_in_owner (res);
114   return res;
115 }
116 entity *
117 new_d_entity (type *owner, ident *name, type *type, dbg_info *db) {
118   entity *res = new_entity(owner, name, type);
119   set_entity_dbg_info(res, db);
120   return res;
121 }
122 INLINE void free_entity_attrs(entity *ent) {
123   assert(ent);
124   if (get_type_tpop(get_entity_owner(ent)) == type_class) {
125     DEL_ARR_F(ent->overwrites);
126     DEL_ARR_F(ent->overwrittenby);
127   }
128 }
129
130 entity *
131 copy_entity_own (entity *old, type *new_owner) {
132   entity *new;
133
134   assert_legal_owner_of_ent(new_owner);
135   if (old->owner == new_owner) return old;
136   new = (entity *) xmalloc (sizeof (entity));
137   memcpy (new, old, sizeof (entity));
138   new->owner = new_owner;
139   /*
140   if ((get_type_tpop(get_entity_owner(old)) == type_class) &&
141       (get_type_tpop(new_owner) == type_class)) {
142     new->overwrites = DUP_ARR_F(entity *, old->overwrites);
143     new->overwrittenby = DUP_ARR_F(entity *, old->overwrittenby);
144   } else if ((get_type_tpop(get_entity_owner(old)) != type_class) &&
145              (get_type_tpop(new_owner) == type_class)) {
146     new->overwrites = NEW_ARR_F(entity *, 1);
147     new->overwrittenby = NEW_ARR_F(entity *, 1);
148   }
149   */
150   if (is_class_type(new_owner)) {
151     new->overwrites = NEW_ARR_F(entity *, 1);
152     new->overwrittenby = NEW_ARR_F(entity *, 1);
153   }
154 #ifdef DEBUG_libfirm
155   new->nr = get_irp_new_node_nr();
156 #endif
157
158   insert_entity_in_owner (new);
159
160   return new;
161 }
162
163 entity *
164 copy_entity_name (entity *old, ident *new_name) {
165   entity *new;
166
167   if (old->name == new_name) return old;
168   new = (entity *) xmalloc (sizeof (entity));
169   memcpy (new, old, sizeof (entity));
170   new->name = new_name;
171   new->ld_name = NULL;
172   if (is_class_type(new->owner)) {
173     new->overwrites = DUP_ARR_F(entity *, old->overwrites);
174     new->overwrittenby = DUP_ARR_F(entity *, old->overwrittenby);
175   }
176 #ifdef DEBUG_libfirm
177   new->nr = get_irp_new_node_nr();
178 #endif
179
180   insert_entity_in_owner (new);
181
182   return new;
183 }
184
185
186 void
187 free_entity (entity *ent) {
188   free_tarval_entity(ent);
189   free_entity_attrs(ent);
190   free(ent);
191 }
192
193 /* Outputs a unique number for this node */
194 INLINE long
195 get_entity_nr(entity *ent) {
196   assert(ent);
197 #ifdef DEBUG_libfirm
198   return ent->nr;
199 #else
200   return 0;
201 #endif
202 }
203
204 INLINE const char *
205 get_entity_name (entity *ent) {
206   assert (ent);
207   return get_id_str(get_entity_ident(ent));
208 }
209
210 ident *
211 get_entity_ident    (entity *ent) {
212   assert(ent);
213   return ent->name;
214 }
215
216 /*
217 void   set_entitye_ld_name  (entity *, char *ld_name);
218 void   set_entity_ld_ident (entity *, ident *ld_ident);
219 */
220
221 INLINE type *
222 get_entity_owner (entity *ent) {
223   return ent->owner = skip_tid(ent->owner);
224 }
225
226 INLINE void
227 set_entity_owner (entity *ent, type *owner) {
228   assert_legal_owner_of_ent(owner);
229   ent->owner = owner;
230 }
231
232 INLINE void   /* should this go into type.c? */
233 assert_legal_owner_of_ent(type *owner) {
234   assert (get_type_tpop_code(owner) == tpo_class ||
235           get_type_tpop_code(owner) == tpo_union ||
236           get_type_tpop_code(owner) == tpo_struct ||
237           get_type_tpop_code(owner) == tpo_array);   /* Yes, array has an entity
238                                                         -- to select fields! */
239 }
240
241 INLINE ident *
242 get_entity_ld_ident (entity *ent)
243 {
244   if (ent->ld_name == NULL)
245     ent->ld_name = mangle_entity (ent);
246   return ent->ld_name;
247 }
248
249 INLINE void
250 set_entity_ld_ident (entity *ent, ident *ld_ident) {
251   ent->ld_name = ld_ident;
252 }
253
254 INLINE const char *
255 get_entity_ld_name (entity *ent) {
256   return get_id_str(get_entity_ld_ident(ent));
257 }
258
259 /*
260 char  *get_entity_ld_name  (entity *);
261 void   set_entity_ld_name  (entity *, char *ld_name);
262 */
263
264 INLINE type *
265 get_entity_type (entity *ent) {
266   return ent->type = skip_tid(ent->type);
267 }
268
269 INLINE void
270 set_entity_type (entity *ent, type *type) {
271   ent->type = type;
272 }
273
274
275 INLINE ent_allocation
276 get_entity_allocation (entity *ent) {
277   return ent->allocation;
278 }
279
280 INLINE void
281 set_entity_allocation (entity *ent, ent_allocation al) {
282   ent->allocation = al;
283 }
284
285 /* return the name of the visibility */
286 const char *get_allocation_name(ent_allocation all)
287 {
288 #define X(a)    case a: return #a
289   switch (all) {
290     X(automatic_allocated);
291     X(parameter_allocated);
292     X(dynamic_allocated);
293     X(static_allocated);
294     default: return "BAD VALUE";
295   }
296 #undef X
297 }
298
299
300 INLINE ent_visibility
301 get_entity_visibility (entity *ent) {
302   return ent->visibility;
303 }
304
305 INLINE void
306 set_entity_visibility (entity *ent, ent_visibility vis) {
307   if (vis != local)
308     assert((ent->allocation == static_allocated) ||
309            (ent->allocation == automatic_allocated));
310   /* @@@ Test that the owner type is not local, but how??
311          && get_class_visibility(get_entity_owner(ent)) != local));*/
312   ent->visibility = vis;
313 }
314
315 /* return the name of the visibility */
316 const char *get_visibility_name(ent_visibility vis)
317 {
318 #define X(a)    case a: return #a
319   switch (vis) {
320     X(local);
321     X(external_visible);
322     X(external_allocated);
323     default: return "BAD VALUE";
324   }
325 #undef X
326 }
327
328 INLINE ent_variability
329 get_entity_variability (entity *ent) {
330   return ent->variability;
331 }
332
333 INLINE void
334 set_entity_variability (entity *ent, ent_variability var){
335   if (var == part_constant)
336     assert(is_class_type(ent->type) || is_struct_type(ent->type));
337   if ((is_compound_type(ent->type)) &&
338       (ent->variability == uninitialized) && (var != uninitialized)) {
339     /* Allocate datastructures for constant values */
340     ent->values = NEW_ARR_F(ir_node *, 1);
341     ent->val_paths = NEW_ARR_F(compound_graph_path *, 1);
342   }
343   if ((is_compound_type(ent->type)) &&
344       (var == uninitialized) && (ent->variability != uninitialized)) {
345     /* Free datastructures for constant values */
346     DEL_ARR_F(ent->values);
347     DEL_ARR_F(ent->val_paths);
348   }
349   ent->variability = var;
350 }
351
352 /* return the name of the variablity */
353 const char *get_variability_name(ent_variability var)
354 {
355 #define X(a)    case a: return #a
356   switch (var) {
357     X(uninitialized);
358     X(initialized);
359     X(part_constant);
360     X(constant);
361     default: return "BAD VALUE";
362   }
363 #undef X
364 }
365
366 INLINE ent_volatility
367 get_entity_volatility (entity *ent) {
368   assert (ent);
369   return ent->volatility;
370 }
371
372 INLINE void
373 set_entity_volatility (entity *ent, ent_volatility vol) {
374   assert (ent);
375   ent->volatility = vol;
376 }
377
378 /* return the name of the volatility */
379 const char *get_volatility_name(ent_volatility var)
380 {
381 #define X(a)    case a: return #a
382   switch (var) {
383     X(non_volatile);
384     X(is_volatile);
385     default: return "BAD VALUE";
386   }
387 #undef X
388 }
389
390 INLINE peculiarity
391 get_entity_peculiarity (entity *ent) {
392   assert (ent);
393   return ent->peculiarity;
394 }
395
396 INLINE void
397 set_entity_peculiarity (entity *ent, peculiarity pec) {
398   assert (ent);
399   /* @@@ why peculiarity only for methods? */
400   assert (is_method_type(ent->type));
401   ent->peculiarity = pec;
402 }
403
404 /* return the name of the peculiarity */
405 const char *get_peculiarity_name(peculiarity var)
406 {
407 #define X(a)    case a: return #a
408   switch (var) {
409     X(description);
410     X(inherited);
411     X(existent);
412     default: return "BAD VALUE";
413   }
414 #undef X
415 }
416
417 /* Set has no effect for existent entities of type method. */
418 INLINE ir_node *
419 get_atomic_ent_value(entity *ent) {
420   assert(ent); assert(is_atomic_entity(ent));
421   assert((ent->variability != uninitialized));
422   return ent->value;
423 }
424
425 INLINE void
426 set_atomic_ent_value(entity *ent, ir_node *val) {
427   assert(ent && is_atomic_entity(ent) && (ent->variability != uninitialized));
428   if ((is_method_type(ent->type)) && (ent->peculiarity==existent)) return;
429   ent->value = val;
430 }
431
432
433 ir_node *copy_const_value(ir_node *n) {
434   ir_node *nn;
435   ir_mode *m;
436
437   m = get_irn_mode(n);
438   switch(get_irn_opcode(n)) {
439   case iro_Const:
440     nn = new_Const(m, get_Const_tarval(n)); break;
441   case iro_SymConst:
442     nn = new_SymConst(get_SymConst_type_or_id(n), get_SymConst_kind(n)); break;
443   case iro_Add:
444     nn = new_Add(copy_const_value(get_Add_left(n)), copy_const_value(get_Add_right(n)), m); break;
445   case iro_Unknown:
446     nn = new_Unknown(); break;
447   default:
448     DDMN(n);
449     assert(0 && "opdope invalid or not implemented");
450     nn = NULL;
451     break;
452   }
453   return nn;
454 }
455
456 compound_graph_path *
457 new_compound_graph_path(type *tp, int length) {
458   compound_graph_path *res;
459   assert(is_type(tp) && is_compound_type(tp));
460   assert(length > 0);
461
462   res = (compound_graph_path *) malloc (sizeof(compound_graph_path) + (length-1) * sizeof(entity *));
463   res->kind = k_ir_compound_graph_path;
464   res->tp = tp;
465   res->len = length;
466   memset(res->nodes, 0, sizeof(entity *) * length);
467   return res;
468 }
469
470 INLINE void
471 free_compound_graph_path (compound_graph_path *gr) {
472   assert(gr && is_compound_graph_path(gr));
473   free(gr);
474 }
475
476 INLINE int
477 is_compound_graph_path(void *thing) {
478   return (get_kind(thing) == k_ir_compound_graph_path);
479 }
480
481 /* checks whether nodes 0..pos are correct (all lie on a path.) */
482 /* @@@ not implemented */
483 INLINE int is_proper_compound_graph_path(compound_graph_path *gr, int pos) {
484   int i;
485   entity *node;
486   type *owner = gr->tp;
487   for (i = 0; i <= pos; i++) {
488     node = get_compound_graph_path_node(gr, i);
489     if (get_entity_owner(node) != owner) return false;
490     owner = get_entity_type(node);
491   }
492   if (pos == get_compound_graph_path_length(gr) -1)
493     if (!is_atomic_type(owner)) return false;
494   return true;
495 }
496
497 INLINE int
498 get_compound_graph_path_length(compound_graph_path *gr) {
499   assert(gr && is_compound_graph_path(gr));
500   return gr->len;
501 }
502
503 INLINE entity *
504 get_compound_graph_path_node(compound_graph_path *gr, int pos) {
505   assert(gr && is_compound_graph_path(gr));
506   assert(pos >= 0 && pos < gr->len);
507   return gr->nodes[pos];
508 }
509
510 INLINE void
511 set_compound_graph_path_node(compound_graph_path *gr, int pos, entity *node) {
512   assert(gr && is_compound_graph_path(gr));
513   assert(pos >= 0 && pos < gr->len);
514   assert(is_entity(node));
515   gr->nodes[pos] = node;
516   assert(is_proper_compound_graph_path(gr, pos));
517 }
518
519 /* A value of a compound entity is a pair of value and the corresponding path to a member of
520    the compound. */
521 INLINE void
522 add_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path) {
523   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
524   ARR_APP1 (ir_node *, ent->values, val);
525   ARR_APP1 (compound_graph_path *, ent->val_paths, path);
526 }
527
528 INLINE void
529 set_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path, int pos) {
530   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
531   ent->values[pos+1] = val;
532   ent->val_paths[pos+1] = path;
533 }
534
535 INLINE int
536 get_compound_ent_n_values(entity *ent) {
537   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
538   return (ARR_LEN (ent->values))-1;
539 }
540
541 INLINE ir_node  *
542 get_compound_ent_value(entity *ent, int pos) {
543   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
544   return ent->values[pos+1];
545 }
546
547 INLINE compound_graph_path *
548 get_compound_ent_value_path(entity *ent, int pos) {
549   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
550   return ent->val_paths[pos+1];
551 }
552
553 void
554 remove_compound_ent_value(entity *ent, entity *value_ent) {
555   int i;
556   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
557   for (i = 1; i < (ARR_LEN (ent->val_paths)); i++) {
558     compound_graph_path *path = ent->val_paths[i];
559     if (path->nodes[path->len-1] == value_ent) {
560       for(; i < (ARR_LEN (ent->val_paths))-1; i++) {
561         ent->val_paths[i] = ent->val_paths[i+1];
562         ent->values[i]   = ent->values[i+1];
563       }
564       ARR_SETLEN(entity*,  ent->val_paths, ARR_LEN(ent->val_paths) - 1);
565       ARR_SETLEN(ir_node*, ent->values,    ARR_LEN(ent->values)    - 1);
566       break;
567     }
568   }
569 }
570
571 INLINE void
572 add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
573   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
574   compound_graph_path *path = new_compound_graph_path(get_entity_owner(ent), 1);
575   path->nodes[0] = member;
576   add_compound_ent_value_w_path(ent, val, path);
577 }
578
579 /* Copies the firm subgraph referenced by val to const_code_irg and adds
580    the node as constant initialization to ent.
581    The subgraph may not contain control flow operations.
582 INLINE void
583 copy_and_add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
584   ir_graph *rem = current_ir_graph;
585
586   assert(get_entity_variability(ent) != uninitialized);
587   current_ir_graph = get_const_code_irg();
588
589   val = copy_const_value(val);
590   add_compound_ent_value(ent, val, member);
591   current_ir_graph = rem;
592   }*/
593
594 /* Copies the value i of the entity to current_block in current_ir_graph.
595 ir_node *
596 copy_compound_ent_value(entity *ent, int pos) {
597   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
598   return copy_const_value(ent->values[pos+1]);
599   }*/
600
601 INLINE entity   *
602 get_compound_ent_value_member(entity *ent, int pos) {
603   compound_graph_path *path;
604   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
605   path = get_compound_ent_value_path(ent, pos);
606   assert(path->len == 1);
607
608   return get_compound_graph_path_node(path, get_compound_graph_path_length(path)-1);
609 }
610
611 INLINE void
612 set_compound_ent_value(entity *ent, ir_node *val, entity *member, int pos) {
613   compound_graph_path *path;
614   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
615   path = get_compound_ent_value_path(ent, pos);
616   set_compound_graph_path_node(path, 0, member);
617   set_compound_ent_value_w_path(ent, val, path, pos);
618 }
619
620 void
621 set_array_entity_values(entity *ent, tarval **values, int num_vals) {
622   int i;
623   ir_graph *rem = current_ir_graph;
624   type *arrtp = get_entity_type(ent);
625   ir_node *val;
626
627   assert(is_array_type(arrtp));
628   assert(get_array_n_dimensions(arrtp) == 1);
629   /* One bound is sufficient, the nunmber of constant fields makes the
630      size. */
631   assert(get_array_lower_bound (arrtp, 0) || get_array_upper_bound (arrtp, 0));
632   assert(get_entity_variability(ent) != uninitialized);
633   current_ir_graph = get_const_code_irg();
634
635   for (i = 0; i < num_vals; i++) {
636     val = new_Const(get_tarval_mode (values[i]), values[i]);
637     add_compound_ent_value(ent, val, get_array_element_entity(arrtp));
638   }
639   current_ir_graph = rem;
640 }
641
642 INLINE int
643 get_entity_offset (entity *ent) {
644   return ent->offset;
645 }
646
647 INLINE void
648 set_entity_offset (entity *ent, int offset) {
649   ent->offset = offset;
650 }
651
652 INLINE void
653 add_entity_overwrites   (entity *ent, entity *overwritten) {
654   assert(ent);
655   assert(is_class_type(get_entity_owner(ent)));
656   ARR_APP1 (entity *, ent->overwrites, overwritten);
657   ARR_APP1 (entity *, overwritten->overwrittenby, ent);
658 }
659
660 INLINE int
661 get_entity_n_overwrites (entity *ent) {
662   assert(ent);
663   assert(is_class_type(get_entity_owner(ent)));
664   return (ARR_LEN (ent->overwrites))-1;
665 }
666
667 int
668 get_entity_overwrites_index(entity *ent, entity *overwritten) {
669   int i;
670   assert(ent && is_class_type(get_entity_owner(ent)));
671   for (i = 0; i < get_entity_n_overwrites(ent); i++)
672     if (get_entity_overwrites(ent, i) == overwritten)
673       return i;
674   return -1;
675 }
676
677 INLINE entity *
678 get_entity_overwrites   (entity *ent, int pos) {
679   assert(ent);
680   assert(is_class_type(get_entity_owner(ent)));
681   assert(pos < get_entity_n_overwrites(ent));
682   return ent->overwrites[pos+1];
683 }
684
685 INLINE void
686 set_entity_overwrites   (entity *ent, int pos, entity *overwritten) {
687   assert(ent);
688   assert(is_class_type(get_entity_owner(ent)));
689   assert(pos < get_entity_n_overwrites(ent));
690   ent->overwrites[pos+1] = overwritten;
691 }
692
693 void
694 remove_entity_overwrites(entity *ent, entity *overwritten) {
695   int i;
696   assert(ent && is_class_type(get_entity_owner(ent)));
697   for (i = 1; i < (ARR_LEN (ent->overwrites)); i++)
698     if (ent->overwrites[i] == overwritten) {
699       for(; i < (ARR_LEN (ent->overwrites))-1; i++)
700         ent->overwrites[i] = ent->overwrites[i+1];
701       ARR_SETLEN(entity*, ent->overwrites, ARR_LEN(ent->overwrites) - 1);
702       break;
703     }
704 }
705
706 INLINE void
707 add_entity_overwrittenby   (entity *ent, entity *overwrites) {
708   assert(ent);
709   assert(is_class_type(get_entity_owner(ent)));
710   add_entity_overwrites(overwrites, ent);
711 }
712
713 INLINE int
714 get_entity_n_overwrittenby (entity *ent) {
715   assert(ent);
716   assert(is_class_type(get_entity_owner(ent)));
717   return (ARR_LEN (ent->overwrittenby))-1;
718 }
719
720 int
721 get_entity_overwrittenby_index(entity *ent, entity *overwrites) {
722   int i;
723   assert(ent && is_class_type(get_entity_owner(ent)));
724   for (i = 0; i < get_entity_n_overwrittenby(ent); i++)
725     if (get_entity_overwrittenby(ent, i) == overwrites)
726       return i;
727   return -1;
728 }
729
730 INLINE entity *
731 get_entity_overwrittenby   (entity *ent, int pos) {
732   assert(ent);
733   assert(is_class_type(get_entity_owner(ent)));
734   assert(pos < get_entity_n_overwrittenby(ent));
735   return ent->overwrittenby[pos+1];
736 }
737
738 INLINE void
739 set_entity_overwrittenby   (entity *ent, int pos, entity *overwrites) {
740   assert(ent);
741   assert(is_class_type(get_entity_owner(ent)));
742   assert(pos < get_entity_n_overwrittenby(ent));
743   ent->overwrittenby[pos+1] = overwrites;
744 }
745
746 void    remove_entity_overwrittenby(entity *ent, entity *overwrites) {
747   int i;
748   assert(ent && is_class_type(get_entity_owner(ent)));
749   for (i = 1; i < (ARR_LEN (ent->overwrittenby)); i++)
750     if (ent->overwrittenby[i] == overwrites) {
751       for(; i < (ARR_LEN (ent->overwrittenby))-1; i++)
752         ent->overwrittenby[i] = ent->overwrittenby[i+1];
753       ARR_SETLEN(entity*, ent->overwrittenby, ARR_LEN(ent->overwrittenby) - 1);
754       break;
755     }
756 }
757
758 /* A link to store intermediate information */
759 void *
760 get_entity_link(entity *ent) {
761   assert(ent);
762   return ent->link;
763 }
764
765 void
766 set_entity_link(entity *ent, void *l) {
767   assert(ent);
768   ent->link = l;
769 }
770
771 INLINE ir_graph *
772 get_entity_irg(entity *ent) {
773   assert (ent);
774   assert (is_method_type(ent->type));
775   return ent->irg;
776 }
777
778 INLINE void
779 set_entity_irg(entity *ent, ir_graph *irg) {
780   assert (ent && ent->type);
781   /* Wie kann man die Referenz auf einen IRG löschen, z.B. wenn die
782    * Methode selbst nicht mehr aufgerufen werden kann, die Entität
783    * aber erhalten bleiben soll. */
784   /* assert (irg); */
785   assert (is_method_type(ent->type));
786   assert (ent->peculiarity == existent);
787   ent->irg = irg;
788 }
789
790 int is_entity (void *thing) {
791   assert(thing);
792   if (get_kind(thing) == k_entity)
793     return 1;
794   else
795     return 0;
796 }
797
798 int is_atomic_entity(entity *ent) {
799   type* t = get_entity_type(ent);
800   return (is_primitive_type(t) || is_pointer_type(t) ||
801           is_enumeration_type(t) || is_method_type(t));
802 }
803
804 int is_compound_entity(entity *ent) {
805   type* t = get_entity_type(ent);
806   return (is_class_type(t) || is_struct_type(t) ||
807           is_array_type(t) || is_union_type(t));
808 }
809
810 /* @@@ not implemnted!!! */
811 bool equal_entity(entity *ent1, entity *ent2) {
812   printf(" calling unimplemented equal entity!!! \n");
813   return true;
814 }
815
816
817 unsigned long get_entity_visited(entity *ent) {
818   assert (ent);
819   return ent->visit;
820 }
821 void        set_entity_visited(entity *ent, unsigned long num) {
822   assert (ent);
823   ent->visit = num;
824 }
825 /* Sets visited field in entity to entity_visited. */
826 void        mark_entity_visited(entity *ent) {
827   assert (ent);
828   ent->visit = type_visited;
829 }
830
831
832 INLINE bool entity_visited(entity *ent) {
833   return get_entity_visited(ent) >= type_visited;
834 }
835 INLINE bool entity_not_visited(entity *ent) {
836   return get_entity_visited(ent) < type_visited;
837 }