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