4 * file type.c - implementation of the datastructure to hold
7 * (C) 2001 by Universitaet Karlsruhe
9 * Martin Trapp, Christian Schaefer, Goetz Lindenmaier
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.
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
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.
38 # include "typegmod_t.h"
45 /*******************************************************************/
47 /*******************************************************************/
49 unsigned long type_visited;
52 new_type(tp_op *type_op, ir_mode *mode, ident* name) {
56 assert(type_op != type_id);
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. */
63 res->type_op = type_op;
66 res->state = layout_undefined;
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;
88 /* set/get the link field */
89 void *get_type_link(type *tp)
91 assert(tp && tp->kind == k_type);
95 void set_type_link(type *tp, void *l)
97 assert(tp && tp->kind == k_type);
101 tp_op* get_type_tpop(type *tp) {
102 assert(tp && tp->kind == k_type);
106 ident* get_type_tpop_nameid(type *tp) {
107 assert(tp && tp->kind == k_type);
108 return tp->type_op->name;
111 const char* get_type_tpop_name(type *tp) {
112 assert(tp && tp->kind == k_type);
113 return id_to_str(tp->type_op->name);
116 tp_opcode get_type_tpop_code(type *tp) {
117 assert(tp && tp->kind == k_type);
118 return tp->type_op->code;
121 ir_mode* get_type_mode(type *tp) {
122 assert(tp && tp->kind == k_type);
126 void set_type_mode(type *tp, ir_mode* m) {
127 assert(tp && tp->kind == k_type);
129 assert((tp->type_op != type_primitive) || mode_is_data(m) &&
130 /* Modes of primitives must be data */
131 (tp->type_op != type_enumeration) || mode_is_int(m));
132 /* Modes of enumerations must be integers */
134 if ((tp->type_op == type_primitive) || (tp->type_op == type_enumeration)) {
135 /* For pointer, primitive and enumeration size depends on the mode. */
136 tp->size == get_mode_size(m);
141 ident* get_type_ident(type *tp) {
142 assert(tp && tp->kind == k_type);
146 void set_type_ident(type *tp, ident* id) {
147 assert(tp && tp->kind == k_type);
151 const char* get_type_name(type *tp) {
152 assert(tp && tp->kind == k_type);
153 return id_to_str(tp->name);
156 int get_type_size(type *tp) {
157 assert(tp && tp->kind == k_type);
162 set_type_size(type *tp, int size) {
163 assert(tp && tp->kind == k_type);
164 /* For pointer enumeration and primitive size depends on the mode.
165 Methods don't have a size. */
166 if ((tp->type_op != type_pointer) && (tp->type_op != type_primitive) &&
167 (tp->type_op != type_enumeration) && (tp->type_op != type_method))
172 get_type_state(type *tp) {
173 assert(tp && tp->kind == k_type);
178 set_type_state(type *tp, type_state state) {
179 assert(tp && tp->kind == k_type);
181 if ((tp->type_op == type_pointer) && (tp->type_op == type_primitive) &&
182 (tp->type_op == type_method))
185 /* Just a correctness check: */
186 if (state == layout_fixed) {
188 switch (get_type_tpop_code(tp)) {
191 assert(get_type_size(tp) > -1);
192 for (i = 0; i < get_class_n_member(tp); i++)
193 assert(get_entity_offset(get_class_member(tp, i)) > -1);
194 assert(get_entity_allocation(get_class_member(tp, i)) == automatic_allocated);
198 assert(get_type_size(tp) > -1);
199 for (i = 0; i < get_struct_n_member(tp); i++) {
200 assert(get_entity_offset(get_struct_member(tp, i)) > -1);
201 assert(get_entity_allocation(get_struct_member(tp, i)) == automatic_allocated);
210 case tpo_enumeration:
212 assert(get_type_mode != NULL);
213 for (i = 0; i < get_enumeration_n_enums(tp); i++)
214 assert(get_enumeration_enum(tp, i) != NULL);
222 unsigned long get_type_visited(type *tp) {
223 assert(tp && tp->kind == k_type);
227 void set_type_visited(type *tp, unsigned long num) {
228 assert(tp && tp->kind == k_type);
231 /* Sets visited field in type to type_visited. */
232 void mark_type_visited(type *tp) {
233 assert(tp && tp->kind == k_type);
234 assert(tp->visit < type_visited);
235 tp->visit = type_visited;
238 int is_type (void *thing) {
240 if (get_kind(thing) == k_type)
246 /*******************************************************************/
248 /*******************************************************************/
250 /* create a new class type */
251 type *new_type_class (ident *name) {
254 res = new_type(type_class, NULL, name);
256 res->attr.ca.members = NEW_ARR_F (entity *, 1);
257 res->attr.ca.subtypes = NEW_ARR_F (type *, 1);
258 res->attr.ca.supertypes = NEW_ARR_F (type *, 1);
262 inline void free_class_attrs(type *clss) {
263 assert(clss && (clss->type_op == type_class));
264 DEL_ARR_F(clss->attr.ca.members);
265 DEL_ARR_F(clss->attr.ca.subtypes);
266 DEL_ARR_F(clss->attr.ca.supertypes);
268 /* manipulate private fields of class type */
269 void add_class_member (type *clss, entity *member) {
270 assert(clss && (clss->type_op == type_class));
271 ARR_APP1 (entity *, clss->attr.ca.members, member);
273 int get_class_n_member (type *clss) {
274 assert(clss && (clss->type_op == type_class));
275 return (ARR_LEN (clss->attr.ca.members))-1;
277 entity *get_class_member (type *clss, int pos) {
278 assert(clss && (clss->type_op == type_class));
279 assert(pos >= 0 && pos < get_class_n_member(clss));
280 return clss->attr.ca.members[pos+1];
282 void set_class_member (type *clss, entity *member, int pos) {
283 assert(clss && (clss->type_op == type_class));
284 assert(pos >= 0 && pos < get_class_n_member(clss));
285 clss->attr.ca.members[pos+1] = member;
287 void set_class_members (type *clss, entity **members, int arity) {
289 assert(clss && (clss->type_op == type_class));
290 DEL_ARR_F(clss->attr.ca.members);
291 clss->attr.ca.members = NEW_ARR_F (entity *, 1);
292 for (i = 0; i < arity; i++) {
293 set_entity_owner(members[i], clss);
294 ARR_APP1 (entity *, clss->attr.ca.members, members[i]);
297 void remove_class_member(type *clss, entity *member) {
299 assert(clss && (clss->type_op == type_class));
300 for (i = 1; i < (ARR_LEN (clss->attr.ca.members))-1; i++)
301 if (clss->attr.ca.members[i+1] == member) {
302 for(i++; i < (ARR_LEN (clss->attr.ca.members)) - 1; i++)
303 clss->attr.ca.members[i] = clss->attr.ca.members[i + 1];
304 ARR_SETLEN(entity*, clss->attr.ca.members, ARR_LEN(clss->attr.ca.members) - 1);
309 void add_class_subtype (type *clss, type *subtype) {
311 assert(clss && (clss->type_op == type_class));
312 ARR_APP1 (type *, clss->attr.ca.subtypes, subtype);
313 for (i = 0; i < get_class_n_supertype(subtype); i++)
314 if (get_class_supertype(subtype, i) == clss)
315 /* Class already registered */
317 ARR_APP1 (type *, subtype->attr.ca.supertypes, clss);
319 int get_class_n_subtype (type *clss) {
320 assert(clss && (clss->type_op == type_class));
321 return (ARR_LEN (clss->attr.ca.subtypes))-1;
323 type *get_class_subtype (type *clss, int pos) {
324 assert(clss && (clss->type_op == type_class));
325 assert(pos >= 0 && pos < get_class_n_subtype(clss));
326 return clss->attr.ca.subtypes[pos+1] = skip_tid(clss->attr.ca.subtypes[pos+1]);
328 void set_class_subtype (type *clss, type *subtype, int pos) {
329 assert(clss && (clss->type_op == type_class));
330 assert(pos >= 0 && pos < get_class_n_subtype(clss));
331 clss->attr.ca.subtypes[pos+1] = subtype;
333 void remove_class_subtype(type *clss, type *subtype) {
335 assert(clss && (clss->type_op == type_class));
336 for (i = 1; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
337 if (clss->attr.ca.subtypes[i+1] == subtype) {
338 for(i++; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
339 clss->attr.ca.subtypes[i] = clss->attr.ca.subtypes[i+1];
340 ARR_SETLEN(entity*, clss->attr.ca.subtypes, ARR_LEN(clss->attr.ca.subtypes) - 1);
345 void add_class_supertype (type *clss, type *supertype) {
347 assert(clss && (clss->type_op == type_class));
348 assert(supertype && (supertype -> type_op == type_class));
349 ARR_APP1 (type *, clss->attr.ca.supertypes, supertype);
350 for (i = 0; i < get_class_n_subtype(supertype); i++)
351 if (get_class_subtype(supertype, i) == clss)
352 /* Class already registered */
354 ARR_APP1 (type *, supertype->attr.ca.subtypes, clss);
356 int get_class_n_supertype (type *clss) {
357 assert(clss && (clss->type_op == type_class));
358 return (ARR_LEN (clss->attr.ca.supertypes))-1;
360 type *get_class_supertype (type *clss, int pos) {
361 assert(clss && (clss->type_op == type_class));
362 assert(pos >= 0 && pos < get_class_n_supertype(clss));
363 return clss->attr.ca.supertypes[pos+1] = skip_tid(clss->attr.ca.supertypes[pos+1]);
365 void set_class_supertype (type *clss, type *supertype, int pos) {
366 assert(clss && (clss->type_op == type_class));
367 assert(pos >= 0 && pos < get_class_n_supertype(clss));
368 clss->attr.ca.supertypes[pos+1] = supertype;
370 void remove_class_supertype(type *clss, type *supertype) {
372 assert(clss && (clss->type_op == type_class));
373 for (i = 1; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
374 if (clss->attr.ca.supertypes[i+1] == supertype) {
375 for(i++; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
376 clss->attr.ca.supertypes[i] = clss->attr.ca.supertypes[i+1];
377 ARR_SETLEN(entity*, clss->attr.ca.supertypes, ARR_LEN(clss->attr.ca.supertypes) - 1);
382 bool is_class_type(type *clss) {
384 if (clss->type_op == type_class) return 1; else return 0;
387 /*******************************************************************/
389 /*******************************************************************/
391 /* create a new type struct */
392 type *new_type_struct (ident *name) {
394 res = new_type(type_struct, NULL, name);
395 res->attr.sa.members = NEW_ARR_F (entity *, 1);
398 inline void free_struct_attrs (type *strct) {
399 assert(strct && (strct->type_op == type_struct));
400 DEL_ARR_F(strct->attr.sa.members);
402 /* manipulate private fields of struct */
403 void add_struct_member (type *strct, entity *member) {
404 assert(strct && (strct->type_op == type_struct));
405 assert(get_type_tpop(get_entity_type(member)) != type_method);
406 ARR_APP1 (entity *, strct->attr.sa.members, member);
408 int get_struct_n_member (type *strct) {
409 assert(strct && (strct->type_op == type_struct));
410 return (ARR_LEN (strct->attr.sa.members))-1;
412 entity *get_struct_member (type *strct, int pos) {
413 assert(strct && (strct->type_op == type_struct));
414 assert(pos >= 0 && pos < get_struct_n_member(strct));
415 return strct->attr.sa.members[pos+1];
417 void set_struct_member (type *strct, int pos, entity *member) {
418 assert(strct && (strct->type_op == type_struct));
419 assert(pos >= 0 && pos < get_struct_n_member(strct));
420 /* assert(get_entity_type(member)->type_op != type_method); @@@ lowerfirm !!*/
421 strct->attr.sa.members[pos+1] = member;
423 void remove_struct_member(type *strct, entity *member) {
425 assert(strct && (strct->type_op == type_struct));
426 for (i = 1; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
427 if (strct->attr.sa.members[i+1] == member) {
428 for(i++; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
429 strct->attr.sa.members[i] = strct->attr.sa.members[i+1];
430 ARR_SETLEN(entity*, strct->attr.sa.members, ARR_LEN(strct->attr.sa.members) - 1);
435 bool is_struct_type(type *strct) {
437 if (strct->type_op == type_struct) return 1; else return 0;
440 /*******************************************************************/
442 /*******************************************************************/
444 /* Create a new method type.
445 N_param is the number of parameters, n_res the number of results. */
446 type *new_type_method (ident *name, int n_param, int n_res) {
448 res = new_type(type_method, mode_p, name);
449 res->state = layout_fixed;
450 res->size = get_mode_size(mode_p);
451 res->attr.ma.n_params = n_param;
452 res->attr.ma.param_type = (type **) xmalloc (sizeof (type *) * n_param);
453 res->attr.ma.n_res = n_res;
454 res->attr.ma.res_type = (type **) xmalloc (sizeof (type *) * n_res);
457 inline void free_method_attrs(type *method) {
458 assert(method && (method->type_op == type_method));
459 free(method->attr.ma.param_type);
460 free(method->attr.ma.res_type);
462 /* manipulate private fields of method. */
463 int get_method_n_params (type *method) {
464 assert(method && (method->type_op == type_method));
465 return method->attr.ma.n_params;
467 type *get_method_param_type(type *method, int pos) {
468 assert(method && (method->type_op == type_method));
469 assert(pos >= 0 && pos < get_method_n_params(method));
470 return method->attr.ma.param_type[pos] = skip_tid(method->attr.ma.param_type[pos]);
472 void set_method_param_type(type *method, int pos, type* type) {
473 assert(method && (method->type_op == type_method));
474 assert(pos >= 0 && pos < get_method_n_params(method));
475 method->attr.ma.param_type[pos] = type;
478 int get_method_n_res (type *method) {
479 assert(method && (method->type_op == type_method));
480 return method->attr.ma.n_res;
482 type *get_method_res_type(type *method, int pos) {
483 assert(method && (method->type_op == type_method));
484 assert(pos >= 0 && pos < get_method_n_res(method));
485 return method->attr.ma.res_type[pos] = skip_tid(method->attr.ma.res_type[pos]);
487 void set_method_res_type(type *method, int pos, type* type) {
488 assert(method && (method->type_op == type_method));
489 assert(pos >= 0 && pos < get_method_n_res(method));
490 method->attr.ma.res_type[pos] = type;
494 bool is_method_type (type *method) {
496 if (method->type_op == type_method) return 1; else return 0;
500 /*******************************************************************/
502 /*******************************************************************/
504 /* create a new type uni */
505 type *new_type_uni (ident *name) {
507 res = new_type(type_union, NULL, name);
508 /*res->attr.ua.unioned_type = (type **) xmalloc (sizeof (type *) * n_types);
509 res->attr.ua.delim_names = (ident **) xmalloc (sizeof (ident *) * n_types); */
510 res->attr.ua.members = NEW_ARR_F (entity *, 1);
513 inline void free_union_attrs (type *uni) {
514 assert(uni && (uni->type_op == type_union));
515 DEL_ARR_F(uni->attr.ua.members);
517 /* manipulate private fields of union */
519 int get_union_n_types (type *uni) {
520 assert(uni && (uni->type_op == type_union));
521 return uni->attr.ua.n_types;
523 type *get_union_unioned_type (type *uni, int pos) {
524 assert(uni && (uni->type_op == type_union));
525 assert(pos >= 0 && pos < get_union_n_types(uni));
526 return uni->attr.ua.unioned_type[pos] = skip_tid(uni->attr.ua.unioned_type[pos]);
528 void set_union_unioned_type (type *uni, int pos, type *type) {
529 assert(uni && (uni->type_op == type_union));
530 assert(pos >= 0 && pos < get_union_n_types(uni));
531 uni->attr.ua.unioned_type[pos] = type;
533 ident *get_union_delim_nameid (type *uni, int pos) {
534 assert(uni && (uni->type_op == type_union));
535 assert(pos >= 0 && pos < get_union_n_types(uni));
536 return uni->attr.ua.delim_names[pos];
538 const char *get_union_delim_name (type *uni, int pos) {
539 assert(uni && (uni->type_op == type_union));
540 assert(pos >= 0 && pos < get_union_n_types(uni));
541 return id_to_str(uni->attr.ua.delim_names[pos]);
543 void set_union_delim_nameid (type *uni, int pos, ident *id) {
544 assert(uni && (uni->type_op == type_union));
545 assert(pos >= 0 && pos < get_union_n_types(uni));
546 uni->attr.ua.delim_names[pos] = id;
549 int get_union_n_members (type *uni) {
550 assert(uni && (uni->type_op == type_union));
551 return (ARR_LEN (uni->attr.ua.members))-1;
553 void add_union_member (type *uni, entity *member) {
554 assert(uni && (uni->type_op == type_union));
555 ARR_APP1 (entity *, uni->attr.ua.members, member);
557 entity *get_union_member (type *uni, int pos) {
558 assert(uni && (uni->type_op == type_union));
559 assert(pos >= 0 && pos < get_union_n_members(uni));
560 return uni->attr.ua.members[pos+1];
562 void set_union_member (type *uni, int pos, entity *member) {
563 assert(uni && (uni->type_op == type_union));
564 assert(pos >= 0 && pos < get_union_n_members(uni));
565 uni->attr.ua.members[pos+1] = member;
567 void remove_union_member(type *uni, entity *member) {
569 assert(uni && (uni->type_op == type_union));
570 for (i = 1; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
571 if (uni->attr.ua.members[i+1] == member) {
572 for(i++; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
573 uni->attr.ua.members[i] = uni->attr.ua.members[i+1];
574 ARR_SETLEN(entity*, uni->attr.ua.members, ARR_LEN(uni->attr.ua.members) - 1);
580 bool is_union_type (type *uni) {
582 if (uni->type_op == type_union) return 1; else return 0;
585 /*******************************************************************/
587 /*******************************************************************/
590 /* create a new type array -- set dimension sizes independently */
591 type *new_type_array (ident *name, int n_dimensions,
592 type *element_type) {
595 assert((element_type->type_op != type_method));
596 assert(get_type_tpop(element_type) != type_method);
597 res = new_type(type_array, NULL, name);
598 res->attr.aa.n_dimensions = n_dimensions;
599 res->attr.aa.lower_bound = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
600 res->attr.aa.upper_bound = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
601 res->attr.aa.order = (int *) xmalloc (sizeof (int) * n_dimensions);
603 for (i = 0; i < n_dimensions; i++) {
604 res->attr.aa.lower_bound[i] = NULL;
605 res->attr.aa.upper_bound[i] = NULL;
606 res->attr.aa.order[i] = i;
608 res->attr.aa.element_type = element_type;
609 new_entity(res, mangle(name, id_from_str("elem_ent", 8)), element_type);
612 inline void free_array_attrs (type *array) {
613 assert(array && (array->type_op == type_array));
614 free(array->attr.aa.lower_bound);
615 free(array->attr.aa.upper_bound);
618 /* manipulate private fields of array type */
619 int get_array_n_dimensions (type *array) {
620 assert(array && (array->type_op == type_array));
621 return array->attr.aa.n_dimensions;
623 void set_array_bounds_int (type *array, int dimension, int lower_bound,
626 assert(array && (array->type_op == type_array));
627 rem = current_ir_graph;
628 current_ir_graph = get_const_code_irg();
629 array->attr.aa.lower_bound[dimension] =
630 new_Const(mode_I, tarval_from_long (mode_I, lower_bound));
631 array->attr.aa.upper_bound[dimension] =
632 new_Const(mode_I, tarval_from_long (mode_I, upper_bound));
633 current_ir_graph = rem;
636 void set_array_bounds (type *array, int dimension, ir_node * lower_bound,
637 ir_node * upper_bound) {
638 assert(array && (array->type_op == type_array));
639 array->attr.aa.lower_bound[dimension] = lower_bound;
640 array->attr.aa.upper_bound[dimension] = upper_bound;
642 void set_array_lower_bound (type *array, int dimension, ir_node * lower_bound) {
643 assert(array && (array->type_op == type_array));
644 array->attr.aa.lower_bound[dimension] = lower_bound;
646 void set_array_upper_bound (type *array, int dimension, ir_node * upper_bound) {
647 assert(array && (array->type_op == type_array));
648 array->attr.aa.upper_bound[dimension] = upper_bound;
650 ir_node * get_array_lower_bound (type *array, int dimension) {
651 assert(array && (array->type_op == type_array));
652 return array->attr.aa.lower_bound[dimension];
654 ir_node * get_array_upper_bound (type *array, int dimension) {
655 assert(array && (array->type_op == type_array));
656 return array->attr.aa.upper_bound[dimension];
658 void set_array_order (type *array, int dimension, int order) {
659 assert(array && (array->type_op == type_array));
660 array->attr.aa.order[dimension] = order;
662 int get_array_order (type *array, int dimension) {
663 assert(array && (array->type_op == type_array));
664 return array->attr.aa.order[dimension];
666 void set_array_element_type (type *array, type *type) {
667 assert(array && (array->type_op == type_array));
668 array->attr.aa.element_type = type;
670 type *get_array_element_type (type *array) {
671 assert(array && (array->type_op == type_array));
672 return array->attr.aa.element_type = skip_tid(array->attr.aa.element_type);
674 void set_array_element_entity (type *array, entity *ent) {
675 assert(array && (array->type_op == type_array));
676 assert((get_entity_type(ent)->type_op != type_method));
677 array->attr.aa.element_ent = ent;
678 array->attr.aa.element_type = get_entity_type(ent);
680 entity *get_array_element_entity (type *array) {
681 assert(array && (array->type_op == type_array));
682 return array->attr.aa.element_ent;
686 bool is_array_type (type *array) {
688 if (array->type_op == type_array) return 1; else return 0;
691 /*******************************************************************/
692 /** TYPE_ENUMERATION **/
693 /*******************************************************************/
695 /* create a new type enumeration -- set the enumerators independently */
696 type *new_type_enumeration (ident *name, int n_enums) {
699 res = new_type(type_enumeration, NULL, name);
700 res->attr.ea.n_enums = n_enums;
701 res->attr.ea.enumer = (tarval **) xmalloc (sizeof (tarval *) * n_enums);
702 res->attr.ea.enum_nameid = (ident **) xmalloc (sizeof (ident *) * n_enums);
703 for (i = 0; i < n_enums; i++) {
704 res->attr.ea.enumer[i] = NULL;
705 res->attr.ea.enum_nameid = NULL;
710 inline void free_enumeration_attrs(type *enumeration) {
711 assert(enumeration && (enumeration->type_op == type_enumeration));
712 free(enumeration->attr.ea.enumer);
713 free(enumeration->attr.ea.enum_nameid);
716 /* manipulate fields of enumeration type. */
717 int get_enumeration_n_enums (type *enumeration) {
718 assert(enumeration && (enumeration->type_op == type_enumeration));
719 return enumeration->attr.ea.n_enums;
721 void set_enumeration_enum (type *enumeration, int pos, tarval *con) {
722 assert(enumeration && (enumeration->type_op == type_enumeration));
723 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
724 enumeration->attr.ea.enumer[pos] = con;
726 tarval *get_enumeration_enum (type *enumeration, int pos) {
727 assert(enumeration && (enumeration->type_op == type_enumeration));
728 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
729 return enumeration->attr.ea.enumer[pos];
731 void set_enumeration_nameid (type *enumeration, int pos, ident *id) {
732 assert(enumeration && (enumeration->type_op == type_enumeration));
733 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
734 enumeration->attr.ea.enum_nameid[pos] = id;
736 ident *get_enumeration_nameid (type *enumeration, int pos) {
737 assert(enumeration && (enumeration->type_op == type_enumeration));
738 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
739 return enumeration->attr.ea.enum_nameid[pos];
741 const char *get_enumeration_name(type *enumeration, int pos) {
742 assert(enumeration && (enumeration->type_op == type_enumeration));
743 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
744 return id_to_str(enumeration->attr.ea.enum_nameid[pos]);
748 bool is_enumeration_type (type *enumeration) {
750 if (enumeration->type_op == type_enumeration) return 1; else return 0;
753 /*******************************************************************/
755 /*******************************************************************/
757 /* Create a new type pointer */
758 type *new_type_pointer (ident *name, type *points_to) {
760 res = new_type(type_pointer, mode_p, name);
761 res->attr.pa.points_to = points_to;
762 res->size = get_mode_size(res->mode);
763 res->state = layout_fixed;
766 inline void free_pointer_attrs (type *pointer) {
767 assert(pointer && (pointer->type_op == type_pointer));
769 /* manipulate fields of type_pointer */
770 void set_pointer_points_to_type (type *pointer, type *type) {
771 assert(pointer && (pointer->type_op == type_pointer));
772 pointer->attr.pa.points_to = type;
774 type *get_pointer_points_to_type (type *pointer) {
775 assert(pointer && (pointer->type_op == type_pointer));
776 return pointer->attr.pa.points_to = skip_tid(pointer->attr.pa.points_to);
780 bool is_pointer_type (type *pointer) {
782 if (pointer->type_op == type_pointer) return 1; else return 0;
786 /*******************************************************************/
787 /** TYPE_PRIMITIVE **/
788 /*******************************************************************/
790 /* create a new type primitive */
791 type *new_type_primitive (ident *name, ir_mode *mode) {
793 res = new_type(type_primitive, mode, name);
794 res->size = get_mode_size(mode);
795 res->state = layout_fixed;
798 inline void free_primitive_attrs (type *primitive) {
799 assert(primitive && (primitive->type_op == type_primitive));
803 bool is_primitive_type (type *primitive) {
804 assert(primitive && primitive->kind == k_type);
805 if (primitive->type_op == type_primitive) return 1; else return 0;
808 /*******************************************************************/
809 /** common functionality **/
810 /*******************************************************************/
813 inline int is_atomic_type(type *tp) {
814 assert(tp && tp->kind == k_type);
815 return (is_primitive_type(tp) || is_pointer_type(tp) ||
816 is_enumeration_type(tp));
818 inline int is_compound_type(type *tp) {
819 assert(tp && tp->kind == k_type);
820 return (is_class_type(tp) || is_struct_type(tp) ||
821 is_array_type(tp) || is_union_type(tp));