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