8391547da6a6e3fea4f76cfd1398cfc40902673c
[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   default:
443     assert(0 && "opdope invalid or not implemented");
444     nn=NULL;
445     break;
446   }
447   return nn;
448 }
449
450 compound_graph_path *
451 new_compound_graph_path(type *tp, int length) {
452   compound_graph_path *res;
453   assert(is_type(tp) && is_compound_type(tp));
454   assert(length > 0);
455
456   res = (compound_graph_path *) malloc (sizeof(compound_graph_path) + (length-1) * sizeof(entity *));
457   res->kind = k_ir_compound_graph_path;
458   res->tp = tp;
459   res->len = length;
460   memset(res->nodes, 0, sizeof(entity *) * length);
461   return res;
462 }
463
464 INLINE void
465 free_compound_graph_path (compound_graph_path *gr) {
466   assert(gr && is_compound_graph_path(gr));
467   free(gr);
468 }
469
470 INLINE int
471 is_compound_graph_path(void *thing) {
472   return (get_kind(thing) == k_ir_compound_graph_path);
473 }
474
475 /* checks whether nodes 0..pos are correct (all lie on a path.) */
476 /* @@@ not implemented */
477 INLINE int is_proper_compound_graph_path(compound_graph_path *gr, int pos) {
478   int i;
479   entity *node;
480   type *owner = gr->tp;
481   for (i = 0; i <= pos; i++) {
482     node = get_compound_graph_path_node(gr, i);
483     if (get_entity_owner(node) != owner) return false;
484     owner = get_entity_type(node);
485   }
486   if (pos == get_compound_graph_path_length(gr) -1)
487     if (!is_atomic_type(owner)) return false;
488   return true;
489 }
490
491 INLINE int
492 get_compound_graph_path_length(compound_graph_path *gr) {
493   assert(gr && is_compound_graph_path(gr));
494   return gr->len;
495 }
496
497 INLINE entity *
498 get_compound_graph_path_node(compound_graph_path *gr, int pos) {
499   assert(gr && is_compound_graph_path(gr));
500   assert(pos >= 0 && pos < gr->len);
501   return gr->nodes[pos];
502 }
503
504 INLINE void
505 set_compound_graph_path_node(compound_graph_path *gr, int pos, entity *node) {
506   assert(gr && is_compound_graph_path(gr));
507   assert(pos >= 0 && pos < gr->len);
508   assert(is_entity(node));
509   gr->nodes[pos] = node;
510   assert(is_proper_compound_graph_path(gr, pos));
511 }
512
513 /* A value of a compound entity is a pair of value and the corresponding path to a member of
514    the compound. */
515 INLINE void
516 add_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path) {
517   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
518   ARR_APP1 (ir_node *, ent->values, val);
519   ARR_APP1 (compound_graph_path *, ent->val_paths, path);
520 }
521
522 INLINE void
523 set_compound_ent_value_w_path(entity *ent, ir_node *val, compound_graph_path *path, int pos) {
524   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
525   ent->values[pos+1] = val;
526   ent->val_paths[pos+1] = path;
527 }
528
529 INLINE int
530 get_compound_ent_n_values(entity *ent) {
531   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
532   return (ARR_LEN (ent->values))-1;
533 }
534
535 INLINE ir_node  *
536 get_compound_ent_value(entity *ent, int pos) {
537   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
538   return ent->values[pos+1];
539 }
540
541 INLINE compound_graph_path *
542 get_compound_ent_value_path(entity *ent, int pos) {
543   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
544   return ent->val_paths[pos+1];
545 }
546
547 void
548 remove_compound_ent_value(entity *ent, entity *value_ent) {
549   int i;
550   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
551   for (i = 1; i < (ARR_LEN (ent->val_paths)); i++) {
552     compound_graph_path *path = ent->val_paths[i];
553     if (path->nodes[path->len] == value_ent) {
554       for(; i < (ARR_LEN (ent->val_paths))-1; i++) {
555         ent->val_paths[i] = ent->val_paths[i+1];
556         ent->values[i]   = ent->values[i+1];
557       }
558       ARR_SETLEN(entity*,  ent->val_paths, ARR_LEN(ent->val_paths) - 1);
559       ARR_SETLEN(ir_node*, ent->values,   ARR_LEN(ent->values) - 1);
560       break;
561     }
562   }
563 }
564
565 INLINE void
566 add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
567   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
568   compound_graph_path *path = new_compound_graph_path(get_entity_owner(ent), 1);
569   path->nodes[0] = member;
570   add_compound_ent_value_w_path(ent, val, path);
571 }
572
573 /* Copies the firm subgraph referenced by val to const_code_irg and adds
574    the node as constant initialization to ent.
575    The subgraph may not contain control flow operations.
576 INLINE void
577 copy_and_add_compound_ent_value(entity *ent, ir_node *val, entity *member) {
578   ir_graph *rem = current_ir_graph;
579
580   assert(get_entity_variability(ent) != uninitialized);
581   current_ir_graph = get_const_code_irg();
582
583   val = copy_const_value(val);
584   add_compound_ent_value(ent, val, member);
585   current_ir_graph = rem;
586   }*/
587
588 /* Copies the value i of the entity to current_block in current_ir_graph.
589 ir_node *
590 copy_compound_ent_value(entity *ent, int pos) {
591   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
592   return copy_const_value(ent->values[pos+1]);
593   }*/
594
595 INLINE entity   *
596 get_compound_ent_value_member(entity *ent, int pos) {
597   compound_graph_path *path;
598   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
599   path = get_compound_ent_value_path(ent, pos);
600   assert(path->len == 1);
601
602   return get_compound_graph_path_node(path, 0);
603 }
604
605 INLINE void
606 set_compound_ent_value(entity *ent, ir_node *val, entity *member, int pos) {
607   compound_graph_path *path;
608   assert(ent && is_compound_entity(ent) && (ent->variability != uninitialized));
609   path = new_compound_graph_path(get_entity_owner(ent), 1);
610   set_compound_graph_path_node(path, 0, member);
611   set_compound_ent_value_w_path(ent, val, path, pos);
612 }
613
614 void
615 set_array_entity_values(entity *ent, tarval **values, int num_vals) {
616   int i;
617   ir_graph *rem = current_ir_graph;
618   type *arrtp = get_entity_type(ent);
619   ir_node *val;
620
621   assert(is_array_type(arrtp));
622   assert(get_array_n_dimensions(arrtp) == 1);
623   /* One bound is sufficient, the nunmber of constant fields makes the
624      size. */
625   assert(get_array_lower_bound (arrtp, 0) || get_array_upper_bound (arrtp, 0));
626   assert(get_entity_variability(ent) != uninitialized);
627   current_ir_graph = get_const_code_irg();
628
629   for (i = 0; i < num_vals; i++) {
630     val = new_Const(get_tarval_mode (values[i]), values[i]);
631     add_compound_ent_value(ent, val, get_array_element_entity(arrtp));
632   }
633   current_ir_graph = rem;
634 }
635
636 INLINE int
637 get_entity_offset (entity *ent) {
638   return ent->offset;
639 }
640
641 INLINE void
642 set_entity_offset (entity *ent, int offset) {
643   ent->offset = offset;
644 }
645
646 INLINE void
647 add_entity_overwrites   (entity *ent, entity *overwritten) {
648   assert(ent);
649   assert(is_class_type(get_entity_owner(ent)));
650   ARR_APP1 (entity *, ent->overwrites, overwritten);
651   ARR_APP1 (entity *, overwritten->overwrittenby, ent);
652 }
653
654 INLINE int
655 get_entity_n_overwrites (entity *ent) {
656   assert(ent);
657   assert(is_class_type(get_entity_owner(ent)));
658   return (ARR_LEN (ent->overwrites))-1;
659 }
660
661 int
662 get_entity_overwrites_index(entity *ent, entity *overwritten) {
663   int i;
664   assert(ent && is_class_type(get_entity_owner(ent)));
665   for (i = 0; i < get_entity_n_overwrites(ent); i++)
666     if (get_entity_overwrites(ent, i) == overwritten)
667       return i;
668   return -1;
669 }
670
671 INLINE entity *
672 get_entity_overwrites   (entity *ent, int pos) {
673   assert(ent);
674   assert(is_class_type(get_entity_owner(ent)));
675   assert(pos < get_entity_n_overwrites(ent));
676   return ent->overwrites[pos+1];
677 }
678
679 INLINE void
680 set_entity_overwrites   (entity *ent, int pos, entity *overwritten) {
681   assert(ent);
682   assert(is_class_type(get_entity_owner(ent)));
683   assert(pos < get_entity_n_overwrites(ent));
684   ent->overwrites[pos+1] = overwritten;
685 }
686
687 void
688 remove_entity_overwrites(entity *ent, entity *overwritten) {
689   int i;
690   assert(ent && is_class_type(get_entity_owner(ent)));
691   for (i = 1; i < (ARR_LEN (ent->overwrites)); i++)
692     if (ent->overwrites[i] == overwritten) {
693       for(; i < (ARR_LEN (ent->overwrites))-1; i++)
694         ent->overwrites[i] = ent->overwrites[i+1];
695       ARR_SETLEN(entity*, ent->overwrites, ARR_LEN(ent->overwrites) - 1);
696       break;
697     }
698 }
699
700 INLINE void
701 add_entity_overwrittenby   (entity *ent, entity *overwrites) {
702   assert(ent);
703   assert(is_class_type(get_entity_owner(ent)));
704   add_entity_overwrites(overwrites, ent);
705 }
706
707 INLINE int
708 get_entity_n_overwrittenby (entity *ent) {
709   assert(ent);
710   assert(is_class_type(get_entity_owner(ent)));
711   return (ARR_LEN (ent->overwrittenby))-1;
712 }
713
714 int
715 get_entity_overwrittenby_index(entity *ent, entity *overwrites) {
716   int i;
717   assert(ent && is_class_type(get_entity_owner(ent)));
718   for (i = 0; i < get_entity_n_overwrittenby(ent); i++)
719     if (get_entity_overwrittenby(ent, i) == overwrites)
720       return i;
721   return -1;
722 }
723
724 INLINE entity *
725 get_entity_overwrittenby   (entity *ent, int pos) {
726   assert(ent);
727   assert(is_class_type(get_entity_owner(ent)));
728   assert(pos < get_entity_n_overwrittenby(ent));
729   return ent->overwrittenby[pos+1];
730 }
731
732 INLINE void
733 set_entity_overwrittenby   (entity *ent, int pos, entity *overwrites) {
734   assert(ent);
735   assert(is_class_type(get_entity_owner(ent)));
736   assert(pos < get_entity_n_overwrittenby(ent));
737   ent->overwrittenby[pos+1] = overwrites;
738 }
739
740 void    remove_entity_overwrittenby(entity *ent, entity *overwrites) {
741   int i;
742   assert(ent && is_class_type(get_entity_owner(ent)));
743   for (i = 1; i < (ARR_LEN (ent->overwrittenby)); i++)
744     if (ent->overwrittenby[i] == overwrites) {
745       for(; i < (ARR_LEN (ent->overwrittenby))-1; i++)
746         ent->overwrittenby[i] = ent->overwrittenby[i+1];
747       ARR_SETLEN(entity*, ent->overwrittenby, ARR_LEN(ent->overwrittenby) - 1);
748       break;
749     }
750 }
751
752 /* A link to store intermediate information */
753 void *
754 get_entity_link(entity *ent) {
755   assert(ent);
756   return ent->link;
757 }
758
759 void
760 set_entity_link(entity *ent, void *l) {
761   assert(ent);
762   ent->link = l;
763 }
764
765 INLINE ir_graph *
766 get_entity_irg(entity *ent) {
767   assert (ent);
768   assert (is_method_type(ent->type));
769   return ent->irg;
770 }
771
772 INLINE void
773 set_entity_irg(entity *ent, ir_graph *irg) {
774   assert (ent && ent->type);
775   /* Wie kann man die Referenz auf einen IRG löschen, z.B. wenn die
776    * Methode selbst nicht mehr aufgerufen werden kann, die Entität
777    * aber erhalten bleiben soll. */
778   /* assert (irg); */
779   assert (is_method_type(ent->type));
780   assert (ent->peculiarity == existent);
781   ent->irg = irg;
782 }
783
784 int is_entity (void *thing) {
785   assert(thing);
786   if (get_kind(thing) == k_entity)
787     return 1;
788   else
789     return 0;
790 }
791
792 int is_atomic_entity(entity *ent) {
793   type* t = get_entity_type(ent);
794   return (is_primitive_type(t) || is_pointer_type(t) ||
795           is_enumeration_type(t) || is_method_type(t));
796 }
797
798 int is_compound_entity(entity *ent) {
799   type* t = get_entity_type(ent);
800   return (is_class_type(t) || is_struct_type(t) ||
801           is_array_type(t) || is_union_type(t));
802 }
803
804 /* @@@ not implemnted!!! */
805 bool equal_entity(entity *ent1, entity *ent2) {
806   printf(" calling unimplemented equal entity!!! \n");
807   return true;
808 }
809
810
811 unsigned long get_entity_visited(entity *ent) {
812   assert (ent);
813   return ent->visit;
814 }
815 void        set_entity_visited(entity *ent, unsigned long num) {
816   assert (ent);
817   ent->visit = num;
818 }
819 /* Sets visited field in entity to entity_visited. */
820 void        mark_entity_visited(entity *ent) {
821   assert (ent);
822   ent->visit = type_visited;
823 }
824
825
826 INLINE bool entity_visited(entity *ent) {
827   return get_entity_visited(ent) >= type_visited;
828 }
829 INLINE bool entity_not_visited(entity *ent) {
830   return get_entity_visited(ent) < type_visited;
831 }