Some access routines for visited flags in entity.h, irnode.h,
[libfirm] / ir / tr / type.c
1 /****h* libfirm/type.c
2  *
3  * NAME
4  *   file type.c - implementation of the datastructure to hold
5  *   type information.
6  * COPYRIGHT
7  *  (C) 2001 by Universitaet Karlsruhe
8  * AUTHORS
9  *  Martin Trapp, Christian Schaefer, Goetz Lindenmaier
10  *
11  * NOTES
12  *  This module supplies a datastructure to represent all types
13  *  known in the compiled program.  This includes types specified
14  *  in the program as well as types defined by the language.  In the
15  *  view of the intermediate representation there is no difference
16  *  between these types.
17  *
18  *  There exist several kinds of types, arranged by the structure of
19  *  the type.  A type is described by a set of attributes.  Some of
20  *  these attributes are common to all types, others depend on the
21  *  kind of the type.
22  *
23  *  Types are different from the modes defined in irmode:  Types are
24  *  on the level of the programming language, modes at the level of
25  *  the target processor.
26  *
27  * SEE ALSO
28  *   type_t.h type tpop
29  *****
30  */
31
32 /* $Id$ */
33
34 # include <stdlib.h>
35 # include <stddef.h>
36 # include "type_t.h"
37 # include "tpop_t.h"
38 # include "typegmod_t.h"
39 # include "array.h"
40 # include "irprog.h"
41 # include "mangle.h"
42 # include "tv.h"
43 # include "ircons.h"
44
45 /*******************************************************************/
46 /** TYPE                                                          **/
47 /*******************************************************************/
48
49 unsigned long type_visited;
50
51 inline type *
52 new_type(tp_op *type_op, ir_mode *mode, ident* name) {
53   type *res;
54   int node_size ;
55
56   assert(type_op != type_id);
57
58   node_size = offsetof (type, attr) +  type_op->attr_size;
59   res = (type *) xmalloc (node_size);
60   add_irp_type(res);   /* Remember the new type global. */
61
62   res->kind = k_type;
63   res->type_op = type_op;
64   res->mode = mode;
65   res->name = name;
66   res->state = layout_undefined;
67   res->size = -1;
68   res->visit = 0;
69   res -> link = NULL;
70
71   return res;
72 }
73
74 void free_type_attrs(type *tp) {
75   switch(get_type_tpop_code(tp)) {
76   case tpo_class:       { free_class_attrs(tp);       } break;
77   case tpo_struct:      { free_struct_attrs(tp);      } break;
78   case tpo_method:      { free_method_attrs(tp);      } break;
79   case tpo_union:       { free_union_attrs(tp);       } break;
80   case tpo_array:       { free_array_attrs(tp);       } break;
81   case tpo_enumeration: { free_enumeration_attrs(tp); } break;
82   case tpo_pointer:     { free_pointer_attrs(tp);     } break;
83   case tpo_primitive:   { free_primitive_attrs(tp);   } break;
84   default: break;
85   }
86 }
87
88 /* set/get the link field */
89 void *get_type_link(type *tp)
90 {
91   assert(tp);
92   return(tp -> link);
93 }
94
95 void set_type_link(type *tp, void *l)
96 {
97   assert(tp);
98   tp -> link = l;
99 }
100
101 tp_op*      get_type_tpop(type *tp) {
102   assert(tp);
103   return tp->type_op;
104 }
105
106 ident*      get_type_tpop_nameid(type *tp) {
107   assert(tp);
108   return tp->type_op->name;
109 }
110
111 const char* get_type_tpop_name(type *tp) {
112   assert(tp);
113   return id_to_str(tp->type_op->name);
114 }
115
116 tp_opcode    get_type_tpop_code(type *tp) {
117   assert(tp);
118   return tp->type_op->code;
119 }
120
121 ir_mode*    get_type_mode(type *tp) {
122   assert(tp);
123   return tp->mode;
124 }
125
126 void        set_type_mode(type *tp, ir_mode* m) {
127   assert(tp);
128   tp->mode = m;
129   /* For pointer and primitive size depends on the mode. */
130   if ((tp->type_op == type_pointer) || (tp->type_op == type_primitive))
131     tp->size == get_mode_size(m);
132 }
133
134 ident*      get_type_ident(type *tp) {
135   assert(tp);
136   return tp->name;
137 }
138
139 void        set_type_ident(type *tp, ident* id) {
140   assert(tp);
141   tp->name = id;
142 }
143
144 const char* get_type_name(type *tp) {
145   assert(tp);
146   return id_to_str(tp->name);
147 }
148
149 int         get_type_size(type *tp) {
150   assert(tp);
151   return tp->size;
152 }
153
154 void
155 set_type_size(type *tp, int size) {
156   assert(tp);
157   /* For pointer and primitive size depends on the mode. */
158   if ((tp->type_op != type_pointer) && (tp->type_op != type_primitive))
159     tp->size = size;
160 }
161
162 type_state
163 get_type_state(type *tp) {
164   assert(tp);
165   return tp->state;
166 }
167
168 void
169 set_type_state(type *tp, type_state state) {
170   assert(tp);
171   /* For pointer and primitive always fixed. */
172   if ((tp->type_op != type_pointer) && (tp->type_op != type_primitive)) {
173     /* @@@ assert that the layout really is fixed!!! */
174     tp->state = state;
175   }
176 }
177
178 unsigned long get_type_visited(type *tp) {
179   assert(tp);
180   return tp->visit;
181 }
182
183 void        set_type_visited(type *tp, unsigned long num) {
184   assert(tp);
185   tp->visit = num;
186 }
187 /* Sets visited field in type to type_visited. */
188 void        mark_type_visited(type *tp) {
189   assert(tp);
190   assert(tp->visit < type_visited);
191   tp->visit = type_visited;
192 }
193
194 int is_type            (void *thing) {
195   assert(thing);
196   if (get_kind(thing) == k_type)
197     return 1;
198   else
199     return 0;
200 }
201
202 /*******************************************************************/
203 /** TYPE_CLASS                                                    **/
204 /*******************************************************************/
205
206 /* create a new class type */
207 type   *new_type_class (ident *name) {
208   type *res;
209
210   res = new_type(type_class, NULL, name);
211
212   res->attr.ca.members    = NEW_ARR_F (entity *, 1);
213   res->attr.ca.subtypes   = NEW_ARR_F (type *, 1);
214   res->attr.ca.supertypes = NEW_ARR_F (type *, 1);
215
216   return res;
217 }
218 inline void free_class_attrs(type *clss) {
219   assert(clss && (clss->type_op == type_class));
220   DEL_ARR_F(clss->attr.ca.members);
221   DEL_ARR_F(clss->attr.ca.subtypes);
222   DEL_ARR_F(clss->attr.ca.supertypes);
223 }
224 /* manipulate private fields of class type  */
225 void    add_class_member   (type *clss, entity *member) {
226   assert(clss && (clss->type_op == type_class));
227   ARR_APP1 (entity *, clss->attr.ca.members, member);
228 }
229 int     get_class_n_member (type *clss) {
230   assert(clss && (clss->type_op == type_class));
231   return (ARR_LEN (clss->attr.ca.members))-1;
232 }
233 entity *get_class_member   (type *clss, int pos) {
234   assert(clss && (clss->type_op == type_class));
235   return clss->attr.ca.members[pos+1];
236 }
237 void    set_class_member   (type *clss, entity *member, int pos) {
238   assert(clss && (clss->type_op == type_class));
239   clss->attr.ca.members[pos+1] = member;
240 }
241 void    remove_class_member(type *clss, entity *member) {
242   int i;
243   assert(clss && (clss->type_op == type_class));
244   for (i = 1; i < (ARR_LEN (clss->attr.ca.members))-1; i++)
245     if (clss->attr.ca.members[i+1] == member) {
246       for(i++; i < (ARR_LEN (clss->attr.ca.members)) - 1; i++)
247         clss->attr.ca.members[i] = clss->attr.ca.members[i + 1];
248       ARR_SETLEN(entity*, clss->attr.ca.members, ARR_LEN(clss->attr.ca.members) - 1);
249       break;
250     }
251 }
252
253 void    add_class_subtype   (type *clss, type *subtype) {
254   int i;
255   assert(clss && (clss->type_op == type_class));
256   ARR_APP1 (type *, clss->attr.ca.subtypes, subtype);
257   for (i = 0; i < get_class_n_supertype(subtype); i++)
258     if (get_class_supertype(subtype, i) == clss)
259       /* Class already registered */
260       return;
261   ARR_APP1 (type *, subtype->attr.ca.supertypes, clss);
262 }
263 int     get_class_n_subtype (type *clss) {
264   assert(clss && (clss->type_op == type_class));
265   return (ARR_LEN (clss->attr.ca.subtypes))-1;
266 }
267 type   *get_class_subtype   (type *clss, int pos) {
268   assert(clss && (clss->type_op == type_class));
269   return clss->attr.ca.subtypes[pos+1] = skip_tid(clss->attr.ca.subtypes[pos+1]);
270 }
271 void    set_class_subtype   (type *clss, type *subtype, int pos) {
272   assert(clss && (clss->type_op == type_class));
273   clss->attr.ca.subtypes[pos+1] = subtype;
274 }
275 void    remove_class_subtype(type *clss, type *subtype) {
276   int i;
277   assert(clss && (clss->type_op == type_class));
278   for (i = 1; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
279     if (clss->attr.ca.subtypes[i+1] == subtype) {
280       for(i++; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
281         clss->attr.ca.subtypes[i] = clss->attr.ca.subtypes[i+1];
282       ARR_SETLEN(entity*, clss->attr.ca.subtypes, ARR_LEN(clss->attr.ca.subtypes) - 1);
283       break;
284     }
285 }
286
287 void    add_class_supertype   (type *clss, type *supertype) {
288   int i;
289   assert(clss && (clss->type_op == type_class));
290   assert(supertype && (supertype -> type_op == type_class));
291   ARR_APP1 (type *, clss->attr.ca.supertypes, supertype);
292   for (i = 0; i < get_class_n_subtype(supertype); i++)
293     if (get_class_subtype(supertype, i) == clss)
294       /* Class already registered */
295       return;
296   ARR_APP1 (type *, supertype->attr.ca.subtypes, clss);
297 }
298 int     get_class_n_supertype (type *clss) {
299   assert(clss && (clss->type_op == type_class));
300   return (ARR_LEN (clss->attr.ca.supertypes))-1;
301 }
302 type   *get_class_supertype   (type *clss, int pos) {
303   assert(clss && (clss->type_op == type_class));
304   return clss->attr.ca.supertypes[pos+1] = skip_tid(clss->attr.ca.supertypes[pos+1]);
305 }
306 void    set_class_supertype   (type *clss, type *supertype, int pos) {
307   assert(clss && (clss->type_op == type_class));
308   clss->attr.ca.supertypes[pos+1] = supertype;
309 }
310 void    remove_class_supertype(type *clss, type *supertype) {
311   int i;
312   assert(clss && (clss->type_op == type_class));
313   for (i = 1; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
314     if (clss->attr.ca.supertypes[i+1] == supertype) {
315       for(i++; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
316         clss->attr.ca.supertypes[i] = clss->attr.ca.supertypes[i+1];
317       ARR_SETLEN(entity*, clss->attr.ca.supertypes, ARR_LEN(clss->attr.ca.supertypes) - 1);
318       break;
319     }
320 }
321 /* typecheck */
322 bool    is_class_type(type *clss) {
323   assert(clss);
324   if (clss->type_op == type_class) return 1; else return 0;
325 }
326
327 /*******************************************************************/
328 /** TYPE_STRUCT                                                   **/
329 /*******************************************************************/
330
331 /* create a new type struct */
332 type   *new_type_struct (ident *name) {
333   type *res;
334   res = new_type(type_struct, NULL, name);
335   res->attr.sa.members = NEW_ARR_F (entity *, 1);
336   return res;
337 }
338 inline void free_struct_attrs (type *strct) {
339   assert(strct && (strct->type_op == type_struct));
340   DEL_ARR_F(strct->attr.sa.members);
341 }
342 /* manipulate private fields of struct */
343 void    add_struct_member   (type *strct, entity *member) {
344   assert(strct && (strct->type_op == type_struct));
345   ARR_APP1 (entity *, strct->attr.sa.members, member);
346 }
347 int     get_struct_n_member (type *strct) {
348   assert(strct && (strct->type_op == type_struct));
349   return (ARR_LEN (strct->attr.sa.members))-1;
350 }
351 entity *get_struct_member   (type *strct, int pos) {
352   assert(strct && (strct->type_op == type_struct));
353   return strct->attr.sa.members[pos+1];
354 }
355 void    set_struct_member   (type *strct, int pos, entity *member) {
356   assert(strct && (strct->type_op == type_struct));
357   strct->attr.sa.members[pos+1] = member;
358 }
359 void    remove_struct_member(type *strct, entity *member) {
360   int i;
361   assert(strct && (strct->type_op == type_struct));
362   for (i = 1; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
363     if (strct->attr.sa.members[i+1] == member) {
364       for(i++; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
365         strct->attr.sa.members[i] = strct->attr.sa.members[i+1];
366       ARR_SETLEN(entity*, strct->attr.sa.members, ARR_LEN(strct->attr.sa.members) - 1);
367       break;
368     }
369 }
370 /* typecheck */
371 bool    is_struct_type(type *strct) {
372   assert(strct);
373   if (strct->type_op == type_struct) return 1; else return 0;
374 }
375
376 /*******************************************************************/
377 /** TYPE_METHOD                                                   **/
378 /*******************************************************************/
379
380 /* Create a new method type.
381    N_param is the number of parameters, n_res the number of results.  */
382 type *new_type_method (ident *name, int n_param, int n_res) {
383   type *res;
384   res = new_type(type_method, NULL, name);
385   res->attr.ma.n_params   = n_param;
386   res->attr.ma.param_type = (type **) xmalloc (sizeof (type *) * n_param);
387   res->attr.ma.n_res      = n_res;
388   res->attr.ma.res_type   = (type **) xmalloc (sizeof (type *) * n_res);
389   return res;
390 }
391 inline void free_method_attrs(type *method) {
392   assert(method && (method->type_op == type_method));
393   free(method->attr.ma.param_type);
394   free(method->attr.ma.res_type);
395 }
396 /* manipulate private fields of method. */
397 int   get_method_n_params  (type *method) {
398   assert(method && (method->type_op == type_method));
399   return method->attr.ma.n_params;
400 }
401 type *get_method_param_type(type *method, int pos) {
402   assert(method && (method->type_op == type_method));
403   return method->attr.ma.param_type[pos] = skip_tid(method->attr.ma.param_type[pos]);
404 }
405 void  set_method_param_type(type *method, int pos, type* type) {
406   assert(method && (method->type_op == type_method));
407   method->attr.ma.param_type[pos] = type;
408 }
409
410 int   get_method_n_res   (type *method) {
411   assert(method && (method->type_op == type_method));
412   return method->attr.ma.n_res;
413 }
414 type *get_method_res_type(type *method, int pos) {
415   assert(method && (method->type_op == type_method));
416   return method->attr.ma.res_type[pos] = skip_tid(method->attr.ma.res_type[pos]);
417 }
418 void  set_method_res_type(type *method, int pos, type* type) {
419   assert(method && (method->type_op == type_method));
420   method->attr.ma.res_type[pos] = type;
421 }
422
423 /* typecheck */
424 bool  is_method_type     (type *method) {
425   assert(method);
426   if (method->type_op == type_method) return 1; else return 0;
427 }
428 /*****/
429
430 /*******************************************************************/
431 /** TYPE_UNION                                                    **/
432 /*******************************************************************/
433
434 /* create a new type uni */
435 type  *new_type_uni (ident *name) {
436   type *res;
437   res = new_type(type_union, NULL, name);
438   /*res->attr.ua.unioned_type = (type **)  xmalloc (sizeof (type *)  * n_types);
439     res->attr.ua.delim_names  = (ident **) xmalloc (sizeof (ident *) * n_types); */
440   res->attr.ua.members = NEW_ARR_F (entity *, 1);
441   return res;
442 }
443 inline void free_union_attrs (type *uni) {
444   assert(uni && (uni->type_op == type_union));
445   DEL_ARR_F(uni->attr.ua.members);
446 }
447 /* manipulate private fields of struct */
448 #if 0
449 int    get_union_n_types      (type *uni) {
450   assert(uni && (uni->type_op == type_union));
451   return uni->attr.ua.n_types;
452 }
453 type  *get_union_unioned_type (type *uni, int pos) {
454   assert(uni && (uni->type_op == type_union));
455   return uni->attr.ua.unioned_type[pos] = skip_tid(uni->attr.ua.unioned_type[pos]);
456 }
457 void   set_union_unioned_type (type *uni, int pos, type *type) {
458   assert(uni && (uni->type_op == type_union));
459   uni->attr.ua.unioned_type[pos] = type;
460 }
461 ident *get_union_delim_nameid (type *uni, int pos) {
462   assert(uni && (uni->type_op == type_union));
463   return uni->attr.ua.delim_names[pos];
464 }
465 const char *get_union_delim_name (type *uni, int pos) {
466   assert(uni && (uni->type_op == type_union));
467   return id_to_str(uni->attr.ua.delim_names[pos]);
468 }
469 void   set_union_delim_nameid (type *uni, int pos, ident *id) {
470   assert(uni && (uni->type_op == type_union));
471   uni->attr.ua.delim_names[pos] = id;
472 }
473 #endif
474 int    get_union_n_members      (type *uni) {
475   assert(uni && (uni->type_op == type_union));
476   return (ARR_LEN (uni->attr.ua.members))-1;
477 }
478 void    add_union_member   (type *uni, entity *member) {
479   assert(uni && (uni->type_op == type_union));
480   ARR_APP1 (entity *, uni->attr.ua.members, member);
481 }
482 entity  *get_union_member (type *uni, int pos) {
483   assert(uni && (uni->type_op == type_union));
484   return uni->attr.ua.members[pos+1];
485 }
486 void   set_union_member (type *uni, int pos, entity *member) {
487   assert(uni && (uni->type_op == type_union));
488   uni->attr.ua.members[pos+1] = member;
489 }
490 void   remove_union_member(type *uni, entity *member) {
491   int i;
492   assert(uni && (uni->type_op == type_union));
493   for (i = 1; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
494     if (uni->attr.ua.members[i+1] == member) {
495       for(i++; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
496         uni->attr.ua.members[i] = uni->attr.ua.members[i+1];
497       ARR_SETLEN(entity*, uni->attr.ua.members, ARR_LEN(uni->attr.ua.members) - 1);
498       break;
499     }
500 }
501
502 /* typecheck */
503 bool   is_union_type         (type *uni) {
504   assert(uni);
505   if (uni->type_op == type_union) return 1; else return 0;
506 }
507
508 /*******************************************************************/
509 /** TYPE_ARRAY                                                    **/
510 /*******************************************************************/
511
512
513 /* create a new type array -- set dimension sizes independently */
514 type *new_type_array         (ident *name, int n_dimensions,
515                               type *element_type) {
516   type *res;
517   res = new_type(type_array, NULL, name);
518   res->attr.aa.n_dimensions = n_dimensions;
519   res->attr.aa.lower_bound  = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
520   res->attr.aa.upper_bound  = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
521   res->attr.aa.element_type = element_type;
522   new_entity(res, mangle(name, id_from_str("elem_ent", 8)), element_type);
523   return res;
524 }
525 inline void free_array_attrs (type *array) {
526   assert(array && (array->type_op == type_array));
527   free(array->attr.aa.lower_bound);
528   free(array->attr.aa.upper_bound);
529 }
530
531 /* manipulate private fields of array type */
532 int   get_array_n_dimensions (type *array) {
533   assert(array && (array->type_op == type_array));
534   return array->attr.aa.n_dimensions;
535 }
536 void  set_array_bounds_int (type *array, int dimension, int lower_bound,
537                             int upper_bound) {
538   ir_graph *rem;
539   assert(array && (array->type_op == type_array));
540   rem = current_ir_graph;
541   current_ir_graph = get_const_code_irg();
542   array->attr.aa.lower_bound[dimension] =
543     new_Const(mode_I, tarval_from_long (mode_I, lower_bound));
544   array->attr.aa.upper_bound[dimension] =
545     new_Const(mode_I, tarval_from_long (mode_I, upper_bound));
546   current_ir_graph = rem;
547 }
548
549 void  set_array_bounds (type *array, int dimension, ir_node * lower_bound,
550                         ir_node * upper_bound) {
551   assert(array && (array->type_op == type_array));
552   array->attr.aa.lower_bound[dimension] = lower_bound;
553   array->attr.aa.upper_bound[dimension] = upper_bound;
554 }
555 void  set_array_lower_bound  (type *array, int dimension, ir_node * lower_bound) {
556   assert(array && (array->type_op == type_array));
557   array->attr.aa.lower_bound[dimension] = lower_bound;
558 }
559 void  set_array_upper_bound  (type *array, int dimension, ir_node * upper_bound) {
560   assert(array && (array->type_op == type_array));
561   array->attr.aa.upper_bound[dimension] = upper_bound;
562 }
563 ir_node * get_array_lower_bound  (type *array, int dimension) {
564   assert(array && (array->type_op == type_array));
565   return array->attr.aa.lower_bound[dimension];
566 }
567 ir_node * get_array_upper_bound  (type *array, int dimension) {
568   assert(array && (array->type_op == type_array));
569   return array->attr.aa.upper_bound[dimension];
570 }
571 void  set_array_element_type (type *array, type *type) {
572   assert(array && (array->type_op == type_array));
573   array->attr.aa.element_type = type;
574 }
575 type *get_array_element_type (type *array) {
576   assert(array && (array->type_op == type_array));
577   return array->attr.aa.element_type = skip_tid(array->attr.aa.element_type);
578 }
579 void  set_array_element_entity (type *array, entity *ent) {
580   assert(array && (array->type_op == type_array));
581   array->attr.aa.element_ent = ent;
582 }
583 entity *get_array_element_entity (type *array) {
584   assert(array && (array->type_op == type_array));
585   return array->attr.aa.element_ent;
586 }
587
588 /* typecheck */
589 bool   is_array_type         (type *array) {
590   assert(array);
591   if (array->type_op == type_array) return 1; else return 0;
592 }
593
594 /*******************************************************************/
595 /** TYPE_ENUMERATION                                              **/
596 /*******************************************************************/
597
598 /* create a new type enumeration -- set the enumerators independently */
599 type   *new_type_enumeration    (ident *name, int n_enums) {
600   type *res;
601   res = new_type(type_enumeration, NULL, name);
602   res->attr.ea.n_enums     = n_enums;
603   res->attr.ea.enumer      = (tarval **) xmalloc (sizeof (tarval *) * n_enums);
604   res->attr.ea.enum_nameid = (ident  **) xmalloc (sizeof (ident  *) * n_enums);
605   return res;
606 }
607 inline void free_enumeration_attrs(type *enumeration) {
608   assert(enumeration && (enumeration->type_op == type_enumeration));
609   free(enumeration->attr.ea.enumer);
610   free(enumeration->attr.ea.enum_nameid);
611 }
612
613 /* manipulate fields of enumeration type. */
614 int     get_enumeration_n_enums (type *enumeration) {
615   assert(enumeration && (enumeration->type_op == type_enumeration));
616   return enumeration->attr.ea.n_enums;
617 }
618 void    set_enumeration_enum    (type *enumeration, int pos, tarval *con) {
619   assert(enumeration && (enumeration->type_op == type_enumeration));
620   enumeration->attr.ea.enumer[pos] = con;
621 }
622 tarval *get_enumeration_enum    (type *enumeration, int pos) {
623   assert(enumeration && (enumeration->type_op == type_enumeration));
624   return enumeration->attr.ea.enumer[pos];
625 }
626 void    set_enumeration_nameid  (type *enumeration, int pos, ident *id) {
627   assert(enumeration && (enumeration->type_op == type_enumeration));
628   enumeration->attr.ea.enum_nameid[pos] = id;
629 }
630 ident  *get_enumeration_nameid  (type *enumeration, int pos) {
631   assert(enumeration && (enumeration->type_op == type_enumeration));
632   return enumeration->attr.ea.enum_nameid[pos];
633 }
634 const char *get_enumeration_name(type *enumeration, int pos) {
635   assert(enumeration && (enumeration->type_op == type_enumeration));
636   return id_to_str(enumeration->attr.ea.enum_nameid[pos]);
637 }
638
639 /* typecheck */
640 bool    is_enumeration_type     (type *enumeration) {
641   assert(enumeration);
642   if (enumeration->type_op == type_enumeration) return 1; else return 0;
643 }
644
645 /*******************************************************************/
646 /** TYPE_POINTER                                                  **/
647 /*******************************************************************/
648
649 /* Create a new type pointer */
650 type *new_type_pointer           (ident *name, type *points_to) {
651   type *res;
652   res = new_type(type_pointer, mode_p, name);
653   res->attr.pa.points_to = points_to;
654   res->size = get_mode_size(res->mode);
655   res->state = layout_fixed;
656   return res;
657 }
658 inline void free_pointer_attrs (type *pointer) {
659   assert(pointer && (pointer->type_op == type_pointer));
660 }
661 /* manipulate fields of type_pointer */
662 void  set_pointer_points_to_type (type *pointer, type *type) {
663   assert(pointer && (pointer->type_op == type_pointer));
664   pointer->attr.pa.points_to = type;
665 }
666 type *get_pointer_points_to_type (type *pointer) {
667   assert(pointer && (pointer->type_op == type_pointer));
668   return pointer->attr.pa.points_to = skip_tid(pointer->attr.pa.points_to);
669 }
670
671 /* typecheck */
672 bool  is_pointer_type            (type *pointer) {
673   assert(pointer);
674   if (pointer->type_op == type_pointer) return 1; else return 0;
675 }
676
677
678 /*******************************************************************/
679 /** TYPE_PRIMITIVE                                                **/
680 /*******************************************************************/
681
682 /* create a new type primitive */
683 type *new_type_primitive (ident *name, ir_mode *mode) {
684   type *res;
685   res = new_type(type_primitive, mode, name);
686   res->size = get_mode_size(mode);
687   res->state = layout_fixed;
688   return res;
689 }
690 inline void free_primitive_attrs (type *primitive) {
691   assert(primitive && (primitive->type_op == type_primitive));
692 }
693
694 /* typecheck */
695 bool  is_primitive_type  (type *primitive) {
696   assert(primitive);
697   if (primitive->type_op == type_primitive) return 1; else return 0;
698 }
699
700 int is_atomic_type(type *tp) {
701   return (is_primitive_type(tp) || is_pointer_type(tp) ||
702           is_enumeration_type(tp));
703 }
704 int is_compound_type(type *tp) {
705   return (is_class_type(tp) || is_struct_type(tp) ||
706           is_array_type(tp) || is_union_type(tp));
707 }