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