Convert comments to doxygen
[libfirm] / ir / tr / type.c
1 /**
2  *
3  *   file type.c - implementation of the datastructure to hold
4  *   type information.
5  *  (C) 2001 by Universitaet Karlsruhe
6  *  Martin Trapp, Christian Schaefer, Goetz Lindenmaier
7  *
8  *  This module supplies a datastructure to represent all types
9  *  known in the compiled program.  This includes types specified
10  *  in the program as well as types defined by the language.  In the
11  *  view of the intermediate representation there is no difference
12  *  between these types.
13  *
14  *  There exist several kinds of types, arranged by the structure of
15  *  the type.  A type is described by a set of attributes.  Some of
16  *  these attributes are common to all types, others depend on the
17  *  kind of the type.
18  *
19  *  Types are different from the modes defined in irmode:  Types are
20  *  on the level of the programming language, modes at the level of
21  *  the target processor.
22  *
23  * @see  type_t.h type tpop
24  */
25
26 /* $Id$ */
27
28 # include <stdlib.h>
29 # include <stddef.h>
30 # include <string.h>
31 # include "type_t.h"
32 # include "tpop_t.h"
33 # include "typegmod_t.h"
34 # include "array.h"
35 # include "irprog.h"
36 # include "mangle.h"
37 # include "tv.h"
38 # include "ircons.h"
39
40 /*******************************************************************/
41 /** TYPE                                                          **/
42 /*******************************************************************/
43
44 unsigned long type_visited;
45 INLINE void set_master_type_visited(unsigned long val) { type_visited = val; }
46 INLINE unsigned long get_master_type_visited() { return type_visited; }
47 INLINE void inc_master_type_visited() { type_visited++; }
48
49 void        free_type(type *tp) {
50   /* Remove from list of all types */
51   remove_irp_type(tp);
52   /* Free the attributes of the type. */
53   free_type_attrs(tp);
54   /* Free entities automatically allocated with the type */
55   if (is_array_type(tp))
56     free_entity(get_array_element_entity(tp));
57   /* And now the type itself... */
58   free(tp);
59 }
60
61 INLINE type *
62 new_type(tp_op *type_op, ir_mode *mode, ident* name) {
63   type *res;
64   int node_size ;
65
66   assert(type_op != type_id);
67
68   node_size = offsetof (type, attr) +  type_op->attr_size;
69   res = (type *) xmalloc (node_size);
70   add_irp_type(res);   /* Remember the new type global. */
71
72   res->kind = k_type;
73   res->type_op = type_op;
74   res->mode = mode;
75   res->name = name;
76   res->state = layout_undefined;
77   res->size = -1;
78   res->visit = 0;
79   res -> link = NULL;
80
81   return res;
82 }
83
84 void free_type_attrs(type *tp) {
85   switch(get_type_tpop_code(tp)) {
86   case tpo_class:       { free_class_attrs(tp);       } break;
87   case tpo_struct:      { free_struct_attrs(tp);      } break;
88   case tpo_method:      { free_method_attrs(tp);      } break;
89   case tpo_union:       { free_union_attrs(tp);       } break;
90   case tpo_array:       { free_array_attrs(tp);       } break;
91   case tpo_enumeration: { free_enumeration_attrs(tp); } break;
92   case tpo_pointer:     { free_pointer_attrs(tp);     } break;
93   case tpo_primitive:   { free_primitive_attrs(tp);   } break;
94   default: break;
95   }
96 }
97
98 /* set/get the link field */
99 void *get_type_link(type *tp)
100 {
101   assert(tp && tp->kind == k_type);
102   return(tp -> link);
103 }
104
105 void set_type_link(type *tp, void *l)
106 {
107   assert(tp && tp->kind == k_type);
108   tp -> link = l;
109 }
110
111 tp_op*      get_type_tpop(type *tp) {
112   assert(tp && tp->kind == k_type);
113   return tp->type_op;
114 }
115
116 ident*      get_type_tpop_nameid(type *tp) {
117   assert(tp && tp->kind == k_type);
118   return tp->type_op->name;
119 }
120
121 const char* get_type_tpop_name(type *tp) {
122   assert(tp && tp->kind == k_type);
123   return id_to_str(tp->type_op->name);
124 }
125
126 tp_opcode    get_type_tpop_code(type *tp) {
127   assert(tp && tp->kind == k_type);
128   return tp->type_op->code;
129 }
130
131 ir_mode*    get_type_mode(type *tp) {
132   assert(tp && tp->kind == k_type);
133   return tp->mode;
134 }
135
136 void        set_type_mode(type *tp, ir_mode* m) {
137   assert(tp && tp->kind == k_type);
138
139   assert(((tp->type_op != type_primitive) || mode_is_data(m)) &&
140          /* Modes of primitives must be data */
141          ((tp->type_op != type_enumeration) || mode_is_int(m)));
142          /* Modes of enumerations must be integers */
143
144   if ((tp->type_op == type_primitive) || (tp->type_op == type_enumeration)) {
145     /* For pointer, primitive and enumeration size depends on the mode. */
146     tp->size = get_mode_size(m);
147     tp->mode = m;
148   }
149 }
150
151 ident*      get_type_ident(type *tp) {
152   assert(tp && tp->kind == k_type);
153   return tp->name;
154 }
155
156 void        set_type_ident(type *tp, ident* id) {
157   assert(tp && tp->kind == k_type);
158   tp->name = id;
159 }
160
161 const char* get_type_name(type *tp) {
162   assert(tp && tp->kind == k_type);
163   return (id_to_str(tp->name));
164 }
165
166 int         get_type_size(type *tp) {
167   assert(tp && tp->kind == k_type);
168   return tp->size;
169 }
170
171 void
172 set_type_size(type *tp, int size) {
173   assert(tp && tp->kind == k_type);
174   /* For pointer enumeration and primitive size depends on the mode.
175      Methods don't have a size. */
176   if ((tp->type_op != type_pointer) && (tp->type_op != type_primitive) &&
177       (tp->type_op != type_enumeration) && (tp->type_op != type_method))
178     tp->size = size;
179 }
180
181 type_state
182 get_type_state(type *tp) {
183   assert(tp && tp->kind == k_type);
184   return tp->state;
185 }
186
187 void
188 set_type_state(type *tp, type_state state) {
189   assert(tp && tp->kind == k_type);
190
191   if ((tp->type_op == type_pointer) && (tp->type_op == type_primitive) &&
192       (tp->type_op == type_method))
193     return;
194
195   /* Just a correctness check: */
196   if (state == layout_fixed) {
197     int i;
198     switch (get_type_tpop_code(tp)) {
199     case tpo_class:
200       {
201         assert(get_type_size(tp) > -1);
202         if (tp != get_glob_type())
203           for (i = 0; i < get_class_n_members(tp); i++) {
204             assert(get_entity_offset(get_class_member(tp, i)) > -1);
205             assert(is_method_type(get_entity_type(get_class_member(tp, i))) ||
206                    (get_entity_allocation(get_class_member(tp, i)) == automatic_allocated));
207           }
208       } break;
209     case tpo_struct:
210       {
211         /* assert(get_type_size(tp) > -1);    @@@ lowerfirm geht nicht durch */
212         for (i = 0; i < get_struct_n_members(tp); i++) {
213           assert(get_entity_offset(get_struct_member(tp, i)) > -1);
214           assert((get_entity_allocation(get_struct_member(tp, i)) == automatic_allocated));
215         }
216       } break;
217     case tpo_union:
218       { /* ?? */
219       } break;
220     case tpo_array:
221       { /* ??
222          Check order?
223          Assure that only innermost dimension is dynamic? */
224       } break;
225     case tpo_enumeration:
226       {
227         assert(get_type_mode != NULL);
228         for (i = 0; i < get_enumeration_n_enums(tp); i++)
229           assert(get_enumeration_enum(tp, i) != NULL);
230       } break;
231     default: break;
232     } /* switch (tp) */
233   }
234   tp->state = state;
235 }
236
237 unsigned long get_type_visited(type *tp) {
238   assert(tp && tp->kind == k_type);
239   return tp->visit;
240 }
241
242 void        set_type_visited(type *tp, unsigned long num) {
243   assert(tp && tp->kind == k_type);
244   tp->visit = num;
245 }
246 /* Sets visited field in type to type_visited. */
247 void        mark_type_visited(type *tp) {
248   assert(tp && tp->kind == k_type);
249   assert(tp->visit < type_visited);
250   tp->visit = type_visited;
251 }
252 /* @@@ name clash with master flag
253 bool          type_visited(type *tp) {
254   assert(tp && tp->kind == k_type);
255   return tp->visit >= type_visited;
256   }*/
257 bool          type_not_visited(type *tp) {
258   assert(tp && tp->kind == k_type);
259   return tp->visit  < type_visited;
260 }
261
262
263 int is_type            (void *thing) {
264   assert(thing);
265   if (get_kind(thing) == k_type)
266     return 1;
267   else
268     return 0;
269 }
270
271
272 bool equal_type(type *typ1, type *typ2) {
273   entity **m;
274   type **t;
275   int i, j;
276
277   if (typ1 == typ2) return true;
278
279   if ((get_type_tpop_code(typ1) != get_type_tpop_code(typ2)) ||
280       (get_type_name(typ1) != get_type_name(typ2)) ||
281       (get_type_mode(typ1) != get_type_mode(typ2)) ||
282       (get_type_state(typ1) != get_type_state(typ2)))
283     return false;
284   if ((get_type_state(typ1) == layout_fixed) &&
285       (get_type_size(typ1) != get_type_size(typ2)))
286     return false;
287
288   switch(get_type_tpop_code(typ1)) {
289   case tpo_class:       {
290     if (get_class_n_members(typ1) != get_class_n_members(typ2)) return false;
291     if (get_class_n_subtypes(typ1) != get_class_n_subtypes(typ2)) return false;
292     if (get_class_n_supertypes(typ1) != get_class_n_supertypes(typ2)) return false;
293     if (get_class_peculiarity(typ1) != get_class_peculiarity(typ2)) return false;
294     /** Compare the members **/
295     m = alloca(sizeof(entity *) * get_class_n_members(typ1));
296     memset(m, 0, sizeof(entity *) * get_class_n_members(typ1));
297     /* First sort the members of typ2 */
298     for (i = 0; i < get_class_n_members(typ1); i++) {
299       entity *e1 = get_class_member(typ1, i);
300       for (j = 0; j < get_class_n_members(typ2); j++) {
301         entity *e2 = get_class_member(typ2, j);
302         if (get_entity_name(e1) == get_entity_name(e2))
303           m[i] = e2;
304       }
305     }
306     for (i = 0; i < get_class_n_members(typ1); i++) {
307       if (!m[i]  ||  /* Found no counterpart */
308           !equal_entity(get_class_member(typ1, i), m[i]))
309         return false;
310     }
311     /** Compare the supertypes **/
312     t = alloca(sizeof(entity *) * get_class_n_supertypes(typ1));
313     memset(t, 0, sizeof(entity *) * get_class_n_supertypes(typ1));
314     /* First sort the supertypes of typ2 */
315     for (i = 0; i < get_class_n_supertypes(typ1); i++) {
316       type *t1 = get_class_supertype(typ1, i);
317       for (j = 0; j < get_class_n_supertypes(typ2); j++) {
318         type *t2 = get_class_supertype(typ2, j);
319         if (get_type_name(t2) == get_type_name(t1))
320           t[i] = t2;
321       }
322     }
323     for (i = 0; i < get_class_n_supertypes(typ1); i++) {
324       if (!t[i]  ||  /* Found no counterpart */
325           get_class_supertype(typ1, i) != t[i])
326         return false;
327     }
328   } break;
329   case tpo_struct:      {
330     if (get_struct_n_members(typ1) != get_struct_n_members(typ2)) return false;
331     m = alloca(sizeof(entity *) * get_struct_n_members(typ1));
332     memset(m, 0, sizeof(entity *) * get_struct_n_members(typ1));
333     /* First sort the members of lt */
334     for (i = 0; i < get_struct_n_members(typ1); i++) {
335       entity *e1 = get_struct_member(typ1, i);
336       for (j = 0; j < get_struct_n_members(typ2); j++) {
337         entity *e2 = get_struct_member(typ2, j);
338         if (get_entity_name(e1) == get_entity_name(e2))
339           m[i] = e2;
340       }
341     }
342     for (i = 0; i < get_struct_n_members(typ1); i++) {
343       if (!m[i]  ||  /* Found no counterpart */
344           !equal_entity(get_struct_member(typ1, i), m[i]))
345         return false;
346     }
347   } break;
348   case tpo_method:      {
349     if (get_method_variadicity(typ1) != get_method_variadicity(typ2)) return false;
350     if (get_method_n_params(typ1) != get_method_n_params(typ2)) return false;
351     if (get_method_n_ress(typ1) != get_method_n_ress(typ2)) return false;
352     for (i = 0; i < get_method_n_params(typ1); i++) {
353       if (!equal_type(get_method_param_type(typ1, i), get_method_param_type(typ2, i)))
354         return false;
355     }
356     for (i = 0; i < get_method_n_ress(typ1); i++) {
357       if (!equal_type(get_method_res_type(typ1, i), get_method_res_type(typ2, i)))
358         return false;
359     }
360   } break;
361   case tpo_union:       {
362     if (get_union_n_members(typ1) != get_union_n_members(typ2)) return false;
363     m = alloca(sizeof(entity *) * get_union_n_members(typ1));
364     memset(m, 0, sizeof(entity *) * get_union_n_members(typ1));
365     /* First sort the members of lt */
366     for (i = 0; i < get_union_n_members(typ1); i++) {
367       entity *e1 = get_union_member(typ1, i);
368       for (j = 0; j < get_union_n_members(typ2); j++) {
369         entity *e2 = get_union_member(typ2, j);
370         if (get_entity_name(e1) == get_entity_name(e2))
371           m[i] = e2;
372       }
373     }
374     for (i = 0; i < get_union_n_members(typ1); i++) {
375       if (!m[i]  ||  /* Found no counterpart */
376           !equal_entity(get_union_member(typ1, i), m[i]))
377         return false;
378     }
379   } break;
380   case tpo_array:       {
381     if (get_array_n_dimensions(typ1) != get_array_n_dimensions(typ2))
382       return false;
383     if (!equal_type(get_array_element_type(typ1), get_array_element_type(typ2)))
384       return false;
385     for(i = 0; i < get_array_n_dimensions(typ1); i++) {
386       if (get_array_lower_bound(typ1, i) != get_array_lower_bound(typ2, i) ||
387           get_array_upper_bound(typ1, i) != get_array_upper_bound(typ2, i))
388         return false;
389       if (get_array_order(typ1, i) != get_array_order(typ2, i))
390         assert(0 && "type compare with different dimension orders not implemented");
391     }
392   } break;
393   case tpo_enumeration: {
394     assert(0 && "enumerations not implemented");
395   } break;
396   case tpo_pointer:     {
397     if (get_pointer_points_to_type(typ1) != get_pointer_points_to_type(typ2))
398       return false;
399   } break;
400   case tpo_primitive:   {
401   } break;
402   default: break;
403   }
404   return true;
405 }
406
407 bool smaller_type (type *st, type *lt) {
408   entity **m;
409   int i, j;
410
411   if (st == lt) return true;
412
413   if (get_type_tpop_code(st) != get_type_tpop_code(lt))
414     return false;
415
416   switch(get_type_tpop_code(st)) {
417   case tpo_class:       {
418     return is_subclass_of(st, lt);
419   } break;
420   case tpo_struct:      {
421     if (get_struct_n_members(st) != get_struct_n_members(lt)) return false;
422     m = alloca(sizeof(entity *) * get_struct_n_members(st));
423     memset(m, 0, sizeof(entity *) * get_struct_n_members(st));
424     /* First sort the members of lt */
425     for (i = 0; i < get_struct_n_members(st); i++) {
426       entity *se = get_struct_member(st, i);
427       for (j = 0; j < get_struct_n_members(lt); j++) {
428         entity *le = get_struct_member(lt, j);
429         if (get_entity_name(le) == get_entity_name(se))
430           m[i] = le;
431       }
432     }
433     for (i = 0; i < get_struct_n_members(st); i++) {
434       if (!m[i]  ||  /* Found no counterpart */
435           !smaller_type(get_entity_type(get_struct_member(st, i)),
436                         get_entity_type(m[i])))
437         return false;
438     }
439   } break;
440   case tpo_method:      {
441     if (get_method_variadicity(st) != get_method_variadicity(lt)) return false;
442     if (get_method_n_params(st) != get_method_n_params(lt)) return false;
443     if (get_method_n_ress(st) != get_method_n_ress(lt)) return false;
444     for (i = 0; i < get_method_n_params(st); i++) {
445       if (!smaller_type(get_method_param_type(st, i), get_method_param_type(lt, i)))
446         return false;
447     }
448     for (i = 0; i < get_method_n_ress(st); i++) {
449       if (!smaller_type(get_method_res_type(st, i), get_method_res_type(lt, i)))
450         return false;
451     }
452   } break;
453   case tpo_union:       {
454     if (get_union_n_members(st) != get_union_n_members(lt)) return false;
455     m = alloca(sizeof(entity *) * get_union_n_members(st));
456     memset(m, 0, sizeof(entity *) * get_union_n_members(st));
457     /* First sort the members of lt */
458     for (i = 0; i < get_union_n_members(st); i++) {
459       entity *se = get_union_member(st, i);
460       for (j = 0; j < get_union_n_members(lt); j++) {
461         entity *le = get_union_member(lt, j);
462         if (get_entity_name(le) == get_entity_name(se))
463           m[i] = le;
464       }
465     }
466     for (i = 0; i < get_union_n_members(st); i++) {
467       if (!m[i]  ||  /* Found no counterpart */
468           !smaller_type(get_entity_type(get_union_member(st, i)),
469                         get_entity_type(m[i])))
470         return false;
471     }
472   } break;
473   case tpo_array:       {
474     type *set, *let;  /* small/large elt. type */
475     if (get_array_n_dimensions(st) != get_array_n_dimensions(lt))
476       return false;
477     set = get_array_element_type(st);
478     let = get_array_element_type(lt);
479     if (set != let) {
480       /* If the elt types are different, set must be convertible
481          to let, and they must have the same size so that address
482          computations work out.  To have a size the layout must
483          be fixed. */
484       if ((get_type_state(set) != layout_fixed) ||
485           (get_type_state(let) != layout_fixed))
486         return false;
487       if (!smaller_type(set, let) ||
488           get_type_size(set) != get_type_size(let))
489         return false;
490     }
491     for(i = 0; i < get_array_n_dimensions(st); i++) {
492       if (get_array_lower_bound(lt, i))
493         if(get_array_lower_bound(st, i) != get_array_lower_bound(lt, i))
494           return false;
495       if (get_array_upper_bound(lt, i))
496         if(get_array_upper_bound(st, i) != get_array_upper_bound(lt, i))
497           return false;
498     }
499   } break;
500   case tpo_enumeration: {
501     assert(0 && "enumerations not implemented");
502   } break;
503   case tpo_pointer:     {
504     if (!smaller_type(get_pointer_points_to_type(st),
505                       get_pointer_points_to_type(lt)))
506       return false;
507   } break;
508   case tpo_primitive:   {
509     if (!smaller_mode(get_type_mode(st), get_type_mode(lt)))
510       return false;
511   } break;
512   default: break;
513   }
514   return true;
515 }
516
517 /*******************************************************************/
518 /** TYPE_CLASS                                                    **/
519 /*******************************************************************/
520
521 /* create a new class type */
522 INLINE type   *new_type_class (ident *name) {
523   type *res;
524
525   res = new_type(type_class, NULL, name);
526
527   res->attr.ca.members    = NEW_ARR_F (entity *, 1);
528   res->attr.ca.subtypes   = NEW_ARR_F (type *, 1);
529   res->attr.ca.supertypes = NEW_ARR_F (type *, 1);
530   res->attr.ca.peculiarity = existent;
531   res->attr.ca.dfn        = 0;
532
533   return res;
534 }
535 type   *new_d_type_class (ident *name, dbg_info* db) {
536   type *res = new_type_class (name);
537   set_type_dbg_info(res, db);
538   return res;
539 }
540 INLINE void free_class_attrs(type *clss) {
541   assert(clss && (clss->type_op == type_class));
542   DEL_ARR_F(clss->attr.ca.members);
543   DEL_ARR_F(clss->attr.ca.subtypes);
544   DEL_ARR_F(clss->attr.ca.supertypes);
545 }
546
547 /* manipulate private fields of class type  */
548 void    add_class_member   (type *clss, entity *member) {
549   assert(clss && (clss->type_op == type_class));
550   ARR_APP1 (entity *, clss->attr.ca.members, member);
551 }
552 int     get_class_n_members (type *clss) {
553   assert(clss && (clss->type_op == type_class));
554   return (ARR_LEN (clss->attr.ca.members))-1;
555 }
556 int     get_class_member_index(type *clss, entity *mem) {
557   int i;
558   assert(clss && (clss->type_op == type_class));
559   for (i = 0; i < get_class_n_members(clss); i++)
560     if (get_class_member(clss, i) == mem)
561       return i;
562   return -1;
563 }
564 entity *get_class_member   (type *clss, int pos) {
565   assert(clss && (clss->type_op == type_class));
566   assert(pos >= 0 && pos < get_class_n_members(clss));
567   return clss->attr.ca.members[pos+1];
568 }
569 void    set_class_member   (type *clss, entity *member, int pos) {
570   assert(clss && (clss->type_op == type_class));
571   assert(pos >= 0 && pos < get_class_n_members(clss));
572   clss->attr.ca.members[pos+1] = member;
573 }
574 void    set_class_members  (type *clss, entity **members, int arity) {
575   int i;
576   assert(clss && (clss->type_op == type_class));
577   DEL_ARR_F(clss->attr.ca.members);
578   clss->attr.ca.members    = NEW_ARR_F (entity *, 1);
579   for (i = 0; i < arity; i++) {
580     set_entity_owner(members[i], clss);
581     ARR_APP1 (entity *, clss->attr.ca.members, members[i]);
582   }
583 }
584 void    remove_class_member(type *clss, entity *member) {
585   int i;
586   assert(clss && (clss->type_op == type_class));
587   for (i = 1; i < (ARR_LEN (clss->attr.ca.members)); i++) {
588     if (clss->attr.ca.members[i] == member) {
589       for(; i < (ARR_LEN (clss->attr.ca.members)) - 1; i++)
590         clss->attr.ca.members[i] = clss->attr.ca.members[i + 1];
591       ARR_SETLEN(entity*, clss->attr.ca.members, ARR_LEN(clss->attr.ca.members) - 1);
592       break;
593     }
594   }
595 }
596
597 void    add_class_subtype   (type *clss, type *subtype) {
598   int i;
599   assert(clss && (clss->type_op == type_class));
600   ARR_APP1 (type *, clss->attr.ca.subtypes, subtype);
601   for (i = 0; i < get_class_n_supertypes(subtype); i++)
602     if (get_class_supertype(subtype, i) == clss)
603       /* Class already registered */
604       return;
605   ARR_APP1 (type *, subtype->attr.ca.supertypes, clss);
606 }
607 int     get_class_n_subtypes (type *clss) {
608   assert(clss && (clss->type_op == type_class));
609   return (ARR_LEN (clss->attr.ca.subtypes))-1;
610 }
611 type   *get_class_subtype   (type *clss, int pos) {
612   assert(clss && (clss->type_op == type_class));
613   assert(pos >= 0 && pos < get_class_n_subtypes(clss));
614   return clss->attr.ca.subtypes[pos+1] = skip_tid(clss->attr.ca.subtypes[pos+1]);
615 }
616 void    set_class_subtype   (type *clss, type *subtype, int pos) {
617   assert(clss && (clss->type_op == type_class));
618   assert(pos >= 0 && pos < get_class_n_subtypes(clss));
619   clss->attr.ca.subtypes[pos+1] = subtype;
620 }
621 void    remove_class_subtype(type *clss, type *subtype) {
622   int i;
623   assert(clss && (clss->type_op == type_class));
624   for (i = 1; i < (ARR_LEN (clss->attr.ca.subtypes)); i++)
625     if (clss->attr.ca.subtypes[i] == subtype) {
626       for(; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
627         clss->attr.ca.subtypes[i] = clss->attr.ca.subtypes[i+1];
628       ARR_SETLEN(entity*, clss->attr.ca.subtypes, ARR_LEN(clss->attr.ca.subtypes) - 1);
629       break;
630     }
631 }
632
633 void    add_class_supertype   (type *clss, type *supertype) {
634   int i;
635   assert(clss && (clss->type_op == type_class));
636   assert(supertype && (supertype -> type_op == type_class));
637   ARR_APP1 (type *, clss->attr.ca.supertypes, supertype);
638   for (i = 0; i < get_class_n_subtypes(supertype); i++)
639     if (get_class_subtype(supertype, i) == clss)
640       /* Class already registered */
641       return;
642   ARR_APP1 (type *, supertype->attr.ca.subtypes, clss);
643 }
644 int     get_class_n_supertypes (type *clss) {
645   assert(clss && (clss->type_op == type_class));
646   return (ARR_LEN (clss->attr.ca.supertypes))-1;
647 }
648 int get_class_supertype_index(type *clss, type *super_clss) {
649   int i;
650   assert(clss && (clss->type_op == type_class));
651   assert(super_clss && (super_clss->type_op == type_class));
652   for (i = 0; i < get_class_n_supertypes(clss); i++)
653     if (get_class_supertype(clss, i) == super_clss)
654       return i;
655   return -1;
656 }
657 type   *get_class_supertype   (type *clss, int pos) {
658   assert(clss && (clss->type_op == type_class));
659   assert(pos >= 0 && pos < get_class_n_supertypes(clss));
660   return clss->attr.ca.supertypes[pos+1] = skip_tid(clss->attr.ca.supertypes[pos+1]);
661 }
662 void    set_class_supertype   (type *clss, type *supertype, int pos) {
663   assert(clss && (clss->type_op == type_class));
664   assert(pos >= 0 && pos < get_class_n_supertypes(clss));
665   clss->attr.ca.supertypes[pos+1] = supertype;
666 }
667 void    remove_class_supertype(type *clss, type *supertype) {
668   int i;
669   assert(clss && (clss->type_op == type_class));
670   for (i = 1; i < (ARR_LEN (clss->attr.ca.supertypes)); i++)
671     if (clss->attr.ca.supertypes[i] == supertype) {
672       for(; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
673         clss->attr.ca.supertypes[i] = clss->attr.ca.supertypes[i+1];
674       ARR_SETLEN(entity*, clss->attr.ca.supertypes, ARR_LEN(clss->attr.ca.supertypes) - 1);
675       break;
676     }
677 }
678
679 INLINE peculiarity get_class_peculiarity (type *clss) {
680   assert(clss && (clss->type_op == type_class));
681   return clss->attr.ca.peculiarity;
682 }
683 INLINE void        set_class_peculiarity (type *clss, peculiarity pec) {
684   assert(clss && (clss->type_op == type_class));
685   assert(pec != inherited);  /* There is no inheritance of types in libFirm. */
686   clss->attr.ca.peculiarity = pec;
687 }
688
689 void set_class_dfn (type *clss, int dfn)
690 {
691   clss->attr.ca.dfn        = dfn;
692 }
693
694 int get_class_dfn (type *clss)
695 {
696   return (clss->attr.ca.dfn);
697 }
698
699 /* typecheck */
700 bool    is_class_type(type *clss) {
701   assert(clss);
702   if (clss->type_op == type_class) return 1; else return 0;
703 }
704
705 bool is_subclass_of(type *low, type *high) {
706   int i;
707   assert(is_class_type(low) && is_class_type(high));
708   if (low == high) return true;
709   /* depth first search from high downwards. */
710   for (i = 0; i < get_class_n_subtypes(high); i++) {
711     if (low == get_class_subtype(high, i))
712       return true;
713     if (is_subclass_of(low, get_class_subtype(high, i)))
714       return true;
715   }
716   return false;
717 }
718
719 /*******************************************************************/
720 /** TYPE_STRUCT                                                   **/
721 /*******************************************************************/
722
723 /* create a new type struct */
724 INLINE type   *new_type_struct (ident *name) {
725   type *res;
726   res = new_type(type_struct, NULL, name);
727   res->attr.sa.members = NEW_ARR_F (entity *, 1);
728   return res;
729 }
730 type   *new_d_type_struct (ident *name, dbg_info* db) {
731   type *res = new_type_struct (name);
732   set_type_dbg_info(res, db);
733   return res;
734 }
735 INLINE void free_struct_attrs (type *strct) {
736   assert(strct && (strct->type_op == type_struct));
737   DEL_ARR_F(strct->attr.sa.members);
738 }
739
740 /* manipulate private fields of struct */
741 int     get_struct_n_members (type *strct) {
742   assert(strct && (strct->type_op == type_struct));
743   return (ARR_LEN (strct->attr.sa.members))-1;
744 }
745 void    add_struct_member   (type *strct, entity *member) {
746   assert(strct && (strct->type_op == type_struct));
747   assert(get_type_tpop(get_entity_type(member)) != type_method);
748     /*    @@@ lowerfirm geht nicht durch */
749   ARR_APP1 (entity *, strct->attr.sa.members, member);
750 }
751 entity *get_struct_member   (type *strct, int pos) {
752   assert(strct && (strct->type_op == type_struct));
753   assert(pos >= 0 && pos < get_struct_n_members(strct));
754   return strct->attr.sa.members[pos+1];
755 }
756 void    set_struct_member   (type *strct, int pos, entity *member) {
757   assert(strct && (strct->type_op == type_struct));
758   assert(pos >= 0 && pos < get_struct_n_members(strct));
759   assert(get_entity_type(member)->type_op != type_method);/* @@@ lowerfirm !!*/
760   strct->attr.sa.members[pos+1] = member;
761 }
762 void    remove_struct_member(type *strct, entity *member) {
763   int i;
764   assert(strct && (strct->type_op == type_struct));
765   for (i = 1; i < (ARR_LEN (strct->attr.sa.members)); i++)
766     if (strct->attr.sa.members[i] == member) {
767       for(; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
768         strct->attr.sa.members[i] = strct->attr.sa.members[i+1];
769       ARR_SETLEN(entity*, strct->attr.sa.members, ARR_LEN(strct->attr.sa.members) - 1);
770       break;
771     }
772 }
773
774 /* typecheck */
775 bool    is_struct_type(type *strct) {
776   assert(strct);
777   if (strct->type_op == type_struct) return 1; else return 0;
778 }
779
780 /*******************************************************************/
781 /** TYPE_METHOD                                                   **/
782 /*******************************************************************/
783
784 /* Create a new method type.
785    N_param is the number of parameters, n_res the number of results.  */
786 INLINE type *new_type_method (ident *name, int n_param, int n_res) {
787   type *res;
788   res = new_type(type_method, mode_P, name);
789   res->state = layout_fixed;
790   res->size = get_mode_size(mode_P);
791   res->attr.ma.n_params   = n_param;
792   res->attr.ma.param_type = (type **) xmalloc (sizeof (type *) * n_param);
793   res->attr.ma.n_res      = n_res;
794   res->attr.ma.res_type   = (type **) xmalloc (sizeof (type *) * n_res);
795   res->attr.ma.variadicity = non_variadic;
796   return res;
797 }
798 type *new_d_type_method (ident *name, int n_param, int n_res, dbg_info* db) {
799   type *res = new_type_method (name, n_param, n_res);
800   set_type_dbg_info(res, db);
801   return res;
802 }
803 INLINE void free_method_attrs(type *method) {
804   assert(method && (method->type_op == type_method));
805   free(method->attr.ma.param_type);
806   free(method->attr.ma.res_type);
807 }
808 /* manipulate private fields of method. */
809 int   get_method_n_params  (type *method) {
810   assert(method && (method->type_op == type_method));
811   return method->attr.ma.n_params;
812 }
813 type *get_method_param_type(type *method, int pos) {
814   assert(method && (method->type_op == type_method));
815   assert(pos >= 0 && pos < get_method_n_params(method));
816   return method->attr.ma.param_type[pos] = skip_tid(method->attr.ma.param_type[pos]);
817 }
818 void  set_method_param_type(type *method, int pos, type* tp) {
819   assert(method && (method->type_op == type_method));
820   assert(pos >= 0 && pos < get_method_n_params(method));
821   method->attr.ma.param_type[pos] = tp;
822 }
823
824 int   get_method_n_ress   (type *method) {
825   assert(method && (method->type_op == type_method));
826   return method->attr.ma.n_res;
827 }
828 type *get_method_res_type(type *method, int pos) {
829   assert(method && (method->type_op == type_method));
830   assert(pos >= 0 && pos < get_method_n_ress(method));
831   return method->attr.ma.res_type[pos] = skip_tid(method->attr.ma.res_type[pos]);
832 }
833 void  set_method_res_type(type *method, int pos, type* tp) {
834   assert(method && (method->type_op == type_method));
835   assert(pos >= 0 && pos < get_method_n_ress(method));
836   method->attr.ma.res_type[pos] = tp;
837 }
838
839 variadicity get_method_variadicity(type *method)
840 {
841   assert(method && (method->type_op == type_method));
842   return method->attr.ma.variadicity;
843 }
844
845 void set_method_variadicity(type *method, variadicity vari)
846 {
847   assert(method && (method->type_op == type_method));
848   method->attr.ma.variadicity = vari;
849 }
850
851 /* typecheck */
852 bool  is_method_type     (type *method) {
853   assert(method);
854   if (method->type_op == type_method) return 1; else return 0;
855 }
856
857 /*******************************************************************/
858 /** TYPE_UNION                                                    **/
859 /*******************************************************************/
860
861 /* create a new type uni */
862 INLINE type  *new_type_union (ident *name) {
863   type *res;
864   res = new_type(type_union, NULL, name);
865   /*res->attr.ua.unioned_type = (type **)  xmalloc (sizeof (type *)  * n_types);
866     res->attr.ua.delim_names  = (ident **) xmalloc (sizeof (ident *) * n_types); */
867   res->attr.ua.members = NEW_ARR_F (entity *, 1);
868   return res;
869 }
870 type  *new_d_type_union (ident *name, dbg_info* db) {
871   type *res = new_type_union (name);
872   set_type_dbg_info(res, db);
873   return res;
874 }
875 INLINE void free_union_attrs (type *uni) {
876   assert(uni && (uni->type_op == type_union));
877   DEL_ARR_F(uni->attr.ua.members);
878 }
879 /* manipulate private fields of union */
880 #if 0
881 int    get_union_n_types      (type *uni) {
882   assert(uni && (uni->type_op == type_union));
883   return uni->attr.ua.n_types;
884 }
885 type  *get_union_unioned_type (type *uni, int pos) {
886   assert(uni && (uni->type_op == type_union));
887   assert(pos >= 0 && pos < get_union_n_types(uni));
888   return uni->attr.ua.unioned_type[pos] = skip_tid(uni->attr.ua.unioned_type[pos]);
889 }
890 void   set_union_unioned_type (type *uni, int pos, type *tp) {
891   assert(uni && (uni->type_op == type_union));
892   assert(pos >= 0 && pos < get_union_n_types(uni));
893   uni->attr.ua.unioned_type[pos] = tp;
894 }
895 ident *get_union_delim_nameid (type *uni, int pos) {
896   assert(uni && (uni->type_op == type_union));
897   assert(pos >= 0 && pos < get_union_n_types(uni));
898   return uni->attr.ua.delim_names[pos];
899 }
900 const char *get_union_delim_name (type *uni, int pos) {
901   assert(uni && (uni->type_op == type_union));
902   assert(pos >= 0 && pos < get_union_n_types(uni));
903   return id_to_str(uni->attr.ua.delim_names[pos]);
904 }
905 void   set_union_delim_nameid (type *uni, int pos, ident *id) {
906   assert(uni && (uni->type_op == type_union));
907   assert(pos >= 0 && pos < get_union_n_types(uni));
908   uni->attr.ua.delim_names[pos] = id;
909 }
910 #endif
911 int    get_union_n_members      (type *uni) {
912   assert(uni && (uni->type_op == type_union));
913   return (ARR_LEN (uni->attr.ua.members))-1;
914 }
915 void    add_union_member   (type *uni, entity *member) {
916   assert(uni && (uni->type_op == type_union));
917   ARR_APP1 (entity *, uni->attr.ua.members, member);
918 }
919 entity  *get_union_member (type *uni, int pos) {
920   assert(uni && (uni->type_op == type_union));
921   assert(pos >= 0 && pos < get_union_n_members(uni));
922   return uni->attr.ua.members[pos+1];
923 }
924 void   set_union_member (type *uni, int pos, entity *member) {
925   assert(uni && (uni->type_op == type_union));
926   assert(pos >= 0 && pos < get_union_n_members(uni));
927   uni->attr.ua.members[pos+1] = member;
928 }
929 void   remove_union_member(type *uni, entity *member) {
930   int i;
931   assert(uni && (uni->type_op == type_union));
932   for (i = 1; i < (ARR_LEN (uni->attr.ua.members)); i++)
933     if (uni->attr.ua.members[i] == member) {
934       for(; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
935         uni->attr.ua.members[i] = uni->attr.ua.members[i+1];
936       ARR_SETLEN(entity*, uni->attr.ua.members, ARR_LEN(uni->attr.ua.members) - 1);
937       break;
938     }
939 }
940
941 /* typecheck */
942 bool   is_union_type         (type *uni) {
943   assert(uni);
944   if (uni->type_op == type_union) return 1; else return 0;
945 }
946
947 /*******************************************************************/
948 /** TYPE_ARRAY                                                    **/
949 /*******************************************************************/
950
951
952 /* create a new type array -- set dimension sizes independently */
953 INLINE type *new_type_array         (ident *name, int n_dimensions,
954                               type *element_type) {
955   type *res;
956   int i;
957   assert(!is_method_type(element_type));
958   res = new_type(type_array, NULL, name);
959   res->attr.aa.n_dimensions = n_dimensions;
960   res->attr.aa.lower_bound  = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
961   res->attr.aa.upper_bound  = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
962   res->attr.aa.order  = (int *) xmalloc (sizeof (int) * n_dimensions);
963
964   for (i = 0; i < n_dimensions; i++) {
965     res->attr.aa.lower_bound[i]  = NULL;
966     res->attr.aa.upper_bound[i]  = NULL;
967     res->attr.aa.order[i] = i;
968   }
969   res->attr.aa.element_type = element_type;
970   new_entity(res, mangle_u(name, id_from_str("elem_ent", 8)), element_type);
971   return res;
972 }
973 type *new_d_type_array (ident *name, int n_dimensions,
974                         type *element_type, dbg_info* db) {
975   type *res = new_type_array (name, n_dimensions, element_type);
976   set_type_dbg_info(res, db);
977   return res;
978 }
979
980 INLINE void free_array_attrs (type *array) {
981   assert(array && (array->type_op == type_array));
982   free(array->attr.aa.lower_bound);
983   free(array->attr.aa.upper_bound);
984 }
985
986 /* manipulate private fields of array type */
987 int   get_array_n_dimensions (type *array) {
988   assert(array && (array->type_op == type_array));
989   return array->attr.aa.n_dimensions;
990 }
991
992 INLINE void
993 set_array_bounds (type *array, int dimension, ir_node * lower_bound,
994                   ir_node * upper_bound) {
995   assert(array && (array->type_op == type_array));
996   array->attr.aa.lower_bound[dimension] = lower_bound;
997   array->attr.aa.upper_bound[dimension] = upper_bound;
998 }
999 void
1000 set_array_bounds_int (type *array, int dimension, int lower_bound,
1001                       int upper_bound) {
1002   ir_graph *rem = current_ir_graph;
1003   current_ir_graph = get_const_code_irg();
1004   set_array_bounds (array, dimension,
1005                     new_Const(mode_Iu, tarval_from_long (mode_Iu, lower_bound)),
1006                     new_Const(mode_Iu, tarval_from_long (mode_Iu, upper_bound)));
1007   current_ir_graph = rem;
1008 }
1009 INLINE void
1010 set_array_lower_bound  (type *array, int dimension, ir_node * lower_bound) {
1011   assert(array && (array->type_op == type_array));
1012   array->attr.aa.lower_bound[dimension] = lower_bound;
1013 }
1014 void  set_array_lower_bound_int (type *array, int dimension, int lower_bound) {
1015   ir_graph *rem = current_ir_graph;
1016   current_ir_graph = get_const_code_irg();
1017   set_array_lower_bound  (array, dimension,
1018                           new_Const(mode_Iu, tarval_from_long (mode_Iu, lower_bound)));
1019   current_ir_graph = rem;
1020 }
1021 INLINE void
1022 set_array_upper_bound  (type *array, int dimension, ir_node * upper_bound) {
1023   assert(array && (array->type_op == type_array));
1024   array->attr.aa.upper_bound[dimension] = upper_bound;
1025 }
1026 void  set_array_upper_bound_int (type *array, int dimension, int upper_bound) {
1027   ir_graph *rem = current_ir_graph;
1028   current_ir_graph = get_const_code_irg();
1029   set_array_upper_bound  (array, dimension,
1030                           new_Const(mode_Iu, tarval_from_long (mode_Iu, upper_bound)));
1031   current_ir_graph = rem;
1032 }
1033 ir_node * get_array_lower_bound  (type *array, int dimension) {
1034   assert(array && (array->type_op == type_array));
1035   return array->attr.aa.lower_bound[dimension];
1036 }
1037 ir_node * get_array_upper_bound  (type *array, int dimension) {
1038   assert(array && (array->type_op == type_array));
1039   return array->attr.aa.upper_bound[dimension];
1040 }
1041
1042 void set_array_order (type *array, int dimension, int order) {
1043   assert(array && (array->type_op == type_array));
1044   array->attr.aa.order[dimension] = order;
1045 }
1046 int  get_array_order (type *array, int dimension) {
1047   assert(array && (array->type_op == type_array));
1048   return array->attr.aa.order[dimension];
1049 }
1050
1051 void  set_array_element_type (type *array, type *tp) {
1052   assert(array && (array->type_op == type_array));
1053   assert(!is_method_type(tp));
1054   array->attr.aa.element_type = tp;
1055 }
1056 type *get_array_element_type (type *array) {
1057   assert(array && (array->type_op == type_array));
1058   return array->attr.aa.element_type = skip_tid(array->attr.aa.element_type);
1059 }
1060
1061 void  set_array_element_entity (type *array, entity *ent) {
1062   assert(array && (array->type_op == type_array));
1063   assert((get_entity_type(ent)->type_op != type_method));
1064   array->attr.aa.element_ent = ent;
1065   array->attr.aa.element_type = get_entity_type(ent);
1066 }
1067 entity *get_array_element_entity (type *array) {
1068   assert(array && (array->type_op == type_array));
1069   return array->attr.aa.element_ent;
1070 }
1071
1072 /* typecheck */
1073 bool   is_array_type         (type *array) {
1074   assert(array);
1075   if (array->type_op == type_array) return 1; else return 0;
1076 }
1077
1078 /*******************************************************************/
1079 /** TYPE_ENUMERATION                                              **/
1080 /*******************************************************************/
1081
1082 /* create a new type enumeration -- set the enumerators independently */
1083 INLINE type   *new_type_enumeration    (ident *name, int n_enums) {
1084   type *res;
1085   int i;
1086   res = new_type(type_enumeration, NULL, name);
1087   res->attr.ea.n_enums     = n_enums;
1088   res->attr.ea.enumer      = (tarval **) xmalloc (sizeof (tarval *) * n_enums);
1089   res->attr.ea.enum_nameid = (ident  **) xmalloc (sizeof (ident  *) * n_enums);
1090   for (i = 0; i < n_enums; i++) {
1091     res->attr.ea.enumer[i] = NULL;
1092     res->attr.ea.enum_nameid  = NULL;
1093   }
1094   return res;
1095 }
1096 type   *new_d_type_enumeration    (ident *name, int n_enums, dbg_info* db) {
1097   type *res = new_type_enumeration (name, n_enums);
1098   set_type_dbg_info(res, db);
1099   return res;
1100 }
1101
1102 INLINE void free_enumeration_attrs(type *enumeration) {
1103   assert(enumeration && (enumeration->type_op == type_enumeration));
1104   free(enumeration->attr.ea.enumer);
1105   free(enumeration->attr.ea.enum_nameid);
1106 }
1107
1108 /* manipulate fields of enumeration type. */
1109 int     get_enumeration_n_enums (type *enumeration) {
1110   assert(enumeration && (enumeration->type_op == type_enumeration));
1111   return enumeration->attr.ea.n_enums;
1112 }
1113 void    set_enumeration_enum    (type *enumeration, int pos, tarval *con) {
1114   assert(enumeration && (enumeration->type_op == type_enumeration));
1115   assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1116   enumeration->attr.ea.enumer[pos] = con;
1117 }
1118 tarval *get_enumeration_enum    (type *enumeration, int pos) {
1119   assert(enumeration && (enumeration->type_op == type_enumeration));
1120   assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1121   return enumeration->attr.ea.enumer[pos];
1122 }
1123 void    set_enumeration_nameid  (type *enumeration, int pos, ident *id) {
1124   assert(enumeration && (enumeration->type_op == type_enumeration));
1125   assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1126   enumeration->attr.ea.enum_nameid[pos] = id;
1127 }
1128 ident  *get_enumeration_nameid  (type *enumeration, int pos) {
1129   assert(enumeration && (enumeration->type_op == type_enumeration));
1130   assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1131   return enumeration->attr.ea.enum_nameid[pos];
1132 }
1133 const char *get_enumeration_name(type *enumeration, int pos) {
1134   assert(enumeration && (enumeration->type_op == type_enumeration));
1135   assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1136   return id_to_str(enumeration->attr.ea.enum_nameid[pos]);
1137 }
1138
1139 /* typecheck */
1140 bool    is_enumeration_type     (type *enumeration) {
1141   assert(enumeration);
1142   if (enumeration->type_op == type_enumeration) return 1; else return 0;
1143 }
1144
1145 /*******************************************************************/
1146 /** TYPE_POINTER                                                  **/
1147 /*******************************************************************/
1148
1149 /* Create a new type pointer */
1150 INLINE type *new_type_pointer           (ident *name, type *points_to) {
1151   type *res;
1152   res = new_type(type_pointer, mode_P, name);
1153   res->attr.pa.points_to = points_to;
1154   res->size = get_mode_size(res->mode);
1155   res->state = layout_fixed;
1156   return res;
1157 }
1158 type *new_d_type_pointer           (ident *name, type *points_to, dbg_info* db) {
1159   type *res = new_type_pointer (name, points_to);
1160   set_type_dbg_info(res, db);
1161   return res;
1162 }
1163 INLINE void free_pointer_attrs (type *pointer) {
1164   assert(pointer && (pointer->type_op == type_pointer));
1165 }
1166 /* manipulate fields of type_pointer */
1167 void  set_pointer_points_to_type (type *pointer, type *tp) {
1168   assert(pointer && (pointer->type_op == type_pointer));
1169   pointer->attr.pa.points_to = tp;
1170 }
1171 type *get_pointer_points_to_type (type *pointer) {
1172   assert(pointer && (pointer->type_op == type_pointer));
1173   return pointer->attr.pa.points_to = skip_tid(pointer->attr.pa.points_to);
1174 }
1175
1176 /* typecheck */
1177 bool  is_pointer_type            (type *pointer) {
1178   assert(pointer);
1179   if (pointer->type_op == type_pointer) return 1; else return 0;
1180 }
1181
1182
1183 /*******************************************************************/
1184 /** TYPE_PRIMITIVE                                                **/
1185 /*******************************************************************/
1186
1187 /* create a new type primitive */
1188 INLINE type *new_type_primitive (ident *name, ir_mode *mode) {
1189   type *res;
1190   /* @@@ assert( mode_is_data(mode) && (!mode == mode_P)); */
1191   res = new_type(type_primitive, mode, name);
1192   res->size = get_mode_size(mode);
1193   res->state = layout_fixed;
1194   return res;
1195 }
1196 type *new_d_type_primitive (ident *name, ir_mode *mode, dbg_info* db) {
1197   type *res = new_type_primitive (name, mode);
1198   set_type_dbg_info(res, db);
1199   return res;
1200 }
1201 INLINE void free_primitive_attrs (type *primitive) {
1202   assert(primitive && (primitive->type_op == type_primitive));
1203 }
1204
1205 /* typecheck */
1206 bool  is_primitive_type  (type *primitive) {
1207   assert(primitive && primitive->kind == k_type);
1208   if (primitive->type_op == type_primitive) return 1; else return 0;
1209 }
1210
1211 /*******************************************************************/
1212 /** common functionality                                          **/
1213 /*******************************************************************/
1214
1215
1216 INLINE int is_atomic_type(type *tp) {
1217   assert(tp && tp->kind == k_type);
1218   return (is_primitive_type(tp) || is_pointer_type(tp) ||
1219           is_enumeration_type(tp));
1220 }
1221 INLINE int is_compound_type(type *tp) {
1222   assert(tp && tp->kind == k_type);
1223   return (is_class_type(tp) || is_struct_type(tp) ||
1224           is_array_type(tp) || is_union_type(tp));
1225 }