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