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