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 if (tp != get_glob_type())
193 for (i = 0; i < get_class_n_member(tp); i++) {
194 assert(get_entity_offset(get_class_member(tp, i)) > -1);
195 /* assert(get_entity_allocation(get_class_member(tp, i)) == automatic_allocated); @@@ lowerfirm geht nicht durch */
200 /* assert(get_type_size(tp) > -1); @@@ lowerfirm geht nicht durch */
201 for (i = 0; i < get_struct_n_member(tp); i++) {
202 assert(get_entity_offset(get_struct_member(tp, i)) > -1);
203 /* assert(get_entity_allocation(get_struct_member(tp, i)) == automatic_allocated); @@@ lowerfirm geht nicht durch */
212 Assure that only innermost dimension is dynamic? */
214 case tpo_enumeration:
216 assert(get_type_mode != NULL);
217 for (i = 0; i < get_enumeration_n_enums(tp); i++)
218 assert(get_enumeration_enum(tp, i) != NULL);
226 unsigned long get_type_visited(type *tp) {
227 assert(tp && tp->kind == k_type);
231 void set_type_visited(type *tp, unsigned long num) {
232 assert(tp && tp->kind == k_type);
235 /* Sets visited field in type to type_visited. */
236 void mark_type_visited(type *tp) {
237 assert(tp && tp->kind == k_type);
238 assert(tp->visit < type_visited);
239 tp->visit = type_visited;
242 int is_type (void *thing) {
244 if (get_kind(thing) == k_type)
250 /*******************************************************************/
252 /*******************************************************************/
254 /* create a new class type */
255 type *new_type_class (ident *name) {
258 res = new_type(type_class, NULL, name);
260 res->attr.ca.members = NEW_ARR_F (entity *, 1);
261 res->attr.ca.subtypes = NEW_ARR_F (type *, 1);
262 res->attr.ca.supertypes = NEW_ARR_F (type *, 1);
266 inline void free_class_attrs(type *clss) {
267 assert(clss && (clss->type_op == type_class));
268 DEL_ARR_F(clss->attr.ca.members);
269 DEL_ARR_F(clss->attr.ca.subtypes);
270 DEL_ARR_F(clss->attr.ca.supertypes);
272 /* manipulate private fields of class type */
273 void add_class_member (type *clss, entity *member) {
274 assert(clss && (clss->type_op == type_class));
275 ARR_APP1 (entity *, clss->attr.ca.members, member);
277 int get_class_n_member (type *clss) {
278 assert(clss && (clss->type_op == type_class));
279 return (ARR_LEN (clss->attr.ca.members))-1;
281 entity *get_class_member (type *clss, int pos) {
282 assert(clss && (clss->type_op == type_class));
283 assert(pos >= 0 && pos < get_class_n_member(clss));
284 return clss->attr.ca.members[pos+1];
286 void set_class_member (type *clss, entity *member, int pos) {
287 assert(clss && (clss->type_op == type_class));
288 assert(pos >= 0 && pos < get_class_n_member(clss));
289 clss->attr.ca.members[pos+1] = member;
291 void set_class_members (type *clss, entity **members, int arity) {
293 assert(clss && (clss->type_op == type_class));
294 DEL_ARR_F(clss->attr.ca.members);
295 clss->attr.ca.members = NEW_ARR_F (entity *, 1);
296 for (i = 0; i < arity; i++) {
297 set_entity_owner(members[i], clss);
298 ARR_APP1 (entity *, clss->attr.ca.members, members[i]);
301 void remove_class_member(type *clss, entity *member) {
303 assert(clss && (clss->type_op == type_class));
304 for (i = 1; i < (ARR_LEN (clss->attr.ca.members))-1; i++)
305 if (clss->attr.ca.members[i+1] == member) {
306 for(i++; i < (ARR_LEN (clss->attr.ca.members)) - 1; i++)
307 clss->attr.ca.members[i] = clss->attr.ca.members[i + 1];
308 ARR_SETLEN(entity*, clss->attr.ca.members, ARR_LEN(clss->attr.ca.members) - 1);
313 void add_class_subtype (type *clss, type *subtype) {
315 assert(clss && (clss->type_op == type_class));
316 ARR_APP1 (type *, clss->attr.ca.subtypes, subtype);
317 for (i = 0; i < get_class_n_supertype(subtype); i++)
318 if (get_class_supertype(subtype, i) == clss)
319 /* Class already registered */
321 ARR_APP1 (type *, subtype->attr.ca.supertypes, clss);
323 int get_class_n_subtype (type *clss) {
324 assert(clss && (clss->type_op == type_class));
325 return (ARR_LEN (clss->attr.ca.subtypes))-1;
327 type *get_class_subtype (type *clss, int pos) {
328 assert(clss && (clss->type_op == type_class));
329 assert(pos >= 0 && pos < get_class_n_subtype(clss));
330 return clss->attr.ca.subtypes[pos+1] = skip_tid(clss->attr.ca.subtypes[pos+1]);
332 void set_class_subtype (type *clss, type *subtype, int pos) {
333 assert(clss && (clss->type_op == type_class));
334 assert(pos >= 0 && pos < get_class_n_subtype(clss));
335 clss->attr.ca.subtypes[pos+1] = subtype;
337 void remove_class_subtype(type *clss, type *subtype) {
339 assert(clss && (clss->type_op == type_class));
340 for (i = 1; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
341 if (clss->attr.ca.subtypes[i+1] == subtype) {
342 for(i++; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
343 clss->attr.ca.subtypes[i] = clss->attr.ca.subtypes[i+1];
344 ARR_SETLEN(entity*, clss->attr.ca.subtypes, ARR_LEN(clss->attr.ca.subtypes) - 1);
349 void add_class_supertype (type *clss, type *supertype) {
351 assert(clss && (clss->type_op == type_class));
352 assert(supertype && (supertype -> type_op == type_class));
353 ARR_APP1 (type *, clss->attr.ca.supertypes, supertype);
354 for (i = 0; i < get_class_n_subtype(supertype); i++)
355 if (get_class_subtype(supertype, i) == clss)
356 /* Class already registered */
358 ARR_APP1 (type *, supertype->attr.ca.subtypes, clss);
360 int get_class_n_supertype (type *clss) {
361 assert(clss && (clss->type_op == type_class));
362 return (ARR_LEN (clss->attr.ca.supertypes))-1;
364 type *get_class_supertype (type *clss, int pos) {
365 assert(clss && (clss->type_op == type_class));
366 assert(pos >= 0 && pos < get_class_n_supertype(clss));
367 return clss->attr.ca.supertypes[pos+1] = skip_tid(clss->attr.ca.supertypes[pos+1]);
369 void set_class_supertype (type *clss, type *supertype, int pos) {
370 assert(clss && (clss->type_op == type_class));
371 assert(pos >= 0 && pos < get_class_n_supertype(clss));
372 clss->attr.ca.supertypes[pos+1] = supertype;
374 void remove_class_supertype(type *clss, type *supertype) {
376 assert(clss && (clss->type_op == type_class));
377 for (i = 1; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
378 if (clss->attr.ca.supertypes[i+1] == supertype) {
379 for(i++; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
380 clss->attr.ca.supertypes[i] = clss->attr.ca.supertypes[i+1];
381 ARR_SETLEN(entity*, clss->attr.ca.supertypes, ARR_LEN(clss->attr.ca.supertypes) - 1);
386 bool is_class_type(type *clss) {
388 if (clss->type_op == type_class) return 1; else return 0;
391 /*******************************************************************/
393 /*******************************************************************/
395 /* create a new type struct */
396 type *new_type_struct (ident *name) {
398 res = new_type(type_struct, NULL, name);
399 res->attr.sa.members = NEW_ARR_F (entity *, 1);
402 inline void free_struct_attrs (type *strct) {
403 assert(strct && (strct->type_op == type_struct));
404 DEL_ARR_F(strct->attr.sa.members);
406 /* manipulate private fields of struct */
407 void add_struct_member (type *strct, entity *member) {
408 assert(strct && (strct->type_op == type_struct));
409 /*assert(get_type_tpop(get_entity_type(member)) != type_method); @@@ lowerfirm geht nicht durch */
410 ARR_APP1 (entity *, strct->attr.sa.members, member);
412 int get_struct_n_member (type *strct) {
413 assert(strct && (strct->type_op == type_struct));
414 return (ARR_LEN (strct->attr.sa.members))-1;
416 entity *get_struct_member (type *strct, int pos) {
417 assert(strct && (strct->type_op == type_struct));
418 assert(pos >= 0 && pos < get_struct_n_member(strct));
419 return strct->attr.sa.members[pos+1];
421 void set_struct_member (type *strct, int pos, entity *member) {
422 assert(strct && (strct->type_op == type_struct));
423 assert(pos >= 0 && pos < get_struct_n_member(strct));
424 /* assert(get_entity_type(member)->type_op != type_method); @@@ lowerfirm !!*/
425 strct->attr.sa.members[pos+1] = member;
427 void remove_struct_member(type *strct, entity *member) {
429 assert(strct && (strct->type_op == type_struct));
430 for (i = 1; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
431 if (strct->attr.sa.members[i+1] == member) {
432 for(i++; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
433 strct->attr.sa.members[i] = strct->attr.sa.members[i+1];
434 ARR_SETLEN(entity*, strct->attr.sa.members, ARR_LEN(strct->attr.sa.members) - 1);
439 bool is_struct_type(type *strct) {
441 if (strct->type_op == type_struct) return 1; else return 0;
444 /*******************************************************************/
446 /*******************************************************************/
448 /* Create a new method type.
449 N_param is the number of parameters, n_res the number of results. */
450 type *new_type_method (ident *name, int n_param, int n_res) {
452 res = new_type(type_method, mode_p, name);
453 res->state = layout_fixed;
454 res->size = get_mode_size(mode_p);
455 res->attr.ma.n_params = n_param;
456 res->attr.ma.param_type = (type **) xmalloc (sizeof (type *) * n_param);
457 res->attr.ma.n_res = n_res;
458 res->attr.ma.res_type = (type **) xmalloc (sizeof (type *) * n_res);
461 inline void free_method_attrs(type *method) {
462 assert(method && (method->type_op == type_method));
463 free(method->attr.ma.param_type);
464 free(method->attr.ma.res_type);
466 /* manipulate private fields of method. */
467 int get_method_n_params (type *method) {
468 assert(method && (method->type_op == type_method));
469 return method->attr.ma.n_params;
471 type *get_method_param_type(type *method, int pos) {
472 assert(method && (method->type_op == type_method));
473 assert(pos >= 0 && pos < get_method_n_params(method));
474 return method->attr.ma.param_type[pos] = skip_tid(method->attr.ma.param_type[pos]);
476 void set_method_param_type(type *method, int pos, type* type) {
477 assert(method && (method->type_op == type_method));
478 assert(pos >= 0 && pos < get_method_n_params(method));
479 method->attr.ma.param_type[pos] = type;
482 int get_method_n_res (type *method) {
483 assert(method && (method->type_op == type_method));
484 return method->attr.ma.n_res;
486 type *get_method_res_type(type *method, int pos) {
487 assert(method && (method->type_op == type_method));
488 assert(pos >= 0 && pos < get_method_n_res(method));
489 return method->attr.ma.res_type[pos] = skip_tid(method->attr.ma.res_type[pos]);
491 void set_method_res_type(type *method, int pos, type* type) {
492 assert(method && (method->type_op == type_method));
493 assert(pos >= 0 && pos < get_method_n_res(method));
494 method->attr.ma.res_type[pos] = type;
498 bool is_method_type (type *method) {
500 if (method->type_op == type_method) return 1; else return 0;
504 /*******************************************************************/
506 /*******************************************************************/
508 /* create a new type uni */
509 type *new_type_uni (ident *name) {
511 res = new_type(type_union, NULL, name);
512 /*res->attr.ua.unioned_type = (type **) xmalloc (sizeof (type *) * n_types);
513 res->attr.ua.delim_names = (ident **) xmalloc (sizeof (ident *) * n_types); */
514 res->attr.ua.members = NEW_ARR_F (entity *, 1);
517 inline void free_union_attrs (type *uni) {
518 assert(uni && (uni->type_op == type_union));
519 DEL_ARR_F(uni->attr.ua.members);
521 /* manipulate private fields of union */
523 int get_union_n_types (type *uni) {
524 assert(uni && (uni->type_op == type_union));
525 return uni->attr.ua.n_types;
527 type *get_union_unioned_type (type *uni, int pos) {
528 assert(uni && (uni->type_op == type_union));
529 assert(pos >= 0 && pos < get_union_n_types(uni));
530 return uni->attr.ua.unioned_type[pos] = skip_tid(uni->attr.ua.unioned_type[pos]);
532 void set_union_unioned_type (type *uni, int pos, type *type) {
533 assert(uni && (uni->type_op == type_union));
534 assert(pos >= 0 && pos < get_union_n_types(uni));
535 uni->attr.ua.unioned_type[pos] = type;
537 ident *get_union_delim_nameid (type *uni, int pos) {
538 assert(uni && (uni->type_op == type_union));
539 assert(pos >= 0 && pos < get_union_n_types(uni));
540 return uni->attr.ua.delim_names[pos];
542 const char *get_union_delim_name (type *uni, int pos) {
543 assert(uni && (uni->type_op == type_union));
544 assert(pos >= 0 && pos < get_union_n_types(uni));
545 return id_to_str(uni->attr.ua.delim_names[pos]);
547 void set_union_delim_nameid (type *uni, int pos, ident *id) {
548 assert(uni && (uni->type_op == type_union));
549 assert(pos >= 0 && pos < get_union_n_types(uni));
550 uni->attr.ua.delim_names[pos] = id;
553 int get_union_n_members (type *uni) {
554 assert(uni && (uni->type_op == type_union));
555 return (ARR_LEN (uni->attr.ua.members))-1;
557 void add_union_member (type *uni, entity *member) {
558 assert(uni && (uni->type_op == type_union));
559 ARR_APP1 (entity *, uni->attr.ua.members, member);
561 entity *get_union_member (type *uni, int pos) {
562 assert(uni && (uni->type_op == type_union));
563 assert(pos >= 0 && pos < get_union_n_members(uni));
564 return uni->attr.ua.members[pos+1];
566 void set_union_member (type *uni, int pos, entity *member) {
567 assert(uni && (uni->type_op == type_union));
568 assert(pos >= 0 && pos < get_union_n_members(uni));
569 uni->attr.ua.members[pos+1] = member;
571 void remove_union_member(type *uni, entity *member) {
573 assert(uni && (uni->type_op == type_union));
574 for (i = 1; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
575 if (uni->attr.ua.members[i+1] == member) {
576 for(i++; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
577 uni->attr.ua.members[i] = uni->attr.ua.members[i+1];
578 ARR_SETLEN(entity*, uni->attr.ua.members, ARR_LEN(uni->attr.ua.members) - 1);
584 bool is_union_type (type *uni) {
586 if (uni->type_op == type_union) return 1; else return 0;
589 /*******************************************************************/
591 /*******************************************************************/
594 /* create a new type array -- set dimension sizes independently */
595 type *new_type_array (ident *name, int n_dimensions,
596 type *element_type) {
599 assert((element_type->type_op != type_method));
600 assert(get_type_tpop(element_type) != type_method);
601 res = new_type(type_array, NULL, name);
602 res->attr.aa.n_dimensions = n_dimensions;
603 res->attr.aa.lower_bound = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
604 res->attr.aa.upper_bound = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
605 res->attr.aa.order = (int *) xmalloc (sizeof (int) * n_dimensions);
607 for (i = 0; i < n_dimensions; i++) {
608 res->attr.aa.lower_bound[i] = NULL;
609 res->attr.aa.upper_bound[i] = NULL;
610 res->attr.aa.order[i] = i;
612 res->attr.aa.element_type = element_type;
613 new_entity(res, mangle(name, id_from_str("elem_ent", 8)), element_type);
616 inline void free_array_attrs (type *array) {
617 assert(array && (array->type_op == type_array));
618 free(array->attr.aa.lower_bound);
619 free(array->attr.aa.upper_bound);
622 /* manipulate private fields of array type */
623 int get_array_n_dimensions (type *array) {
624 assert(array && (array->type_op == type_array));
625 return array->attr.aa.n_dimensions;
627 void set_array_bounds_int (type *array, int dimension, int lower_bound,
630 assert(array && (array->type_op == type_array));
631 rem = current_ir_graph;
632 current_ir_graph = get_const_code_irg();
633 array->attr.aa.lower_bound[dimension] =
634 new_Const(mode_I, tarval_from_long (mode_I, lower_bound));
635 array->attr.aa.upper_bound[dimension] =
636 new_Const(mode_I, tarval_from_long (mode_I, upper_bound));
637 current_ir_graph = rem;
640 void set_array_bounds (type *array, int dimension, ir_node * lower_bound,
641 ir_node * upper_bound) {
642 assert(array && (array->type_op == type_array));
643 array->attr.aa.lower_bound[dimension] = lower_bound;
644 array->attr.aa.upper_bound[dimension] = upper_bound;
646 void set_array_lower_bound (type *array, int dimension, ir_node * lower_bound) {
647 assert(array && (array->type_op == type_array));
648 array->attr.aa.lower_bound[dimension] = lower_bound;
650 void set_array_upper_bound (type *array, int dimension, ir_node * upper_bound) {
651 assert(array && (array->type_op == type_array));
652 array->attr.aa.upper_bound[dimension] = upper_bound;
654 ir_node * get_array_lower_bound (type *array, int dimension) {
655 assert(array && (array->type_op == type_array));
656 return array->attr.aa.lower_bound[dimension];
658 ir_node * get_array_upper_bound (type *array, int dimension) {
659 assert(array && (array->type_op == type_array));
660 return array->attr.aa.upper_bound[dimension];
662 void set_array_order (type *array, int dimension, int order) {
663 assert(array && (array->type_op == type_array));
664 array->attr.aa.order[dimension] = order;
666 int get_array_order (type *array, int dimension) {
667 assert(array && (array->type_op == type_array));
668 return array->attr.aa.order[dimension];
670 void set_array_element_type (type *array, type *type) {
671 assert(array && (array->type_op == type_array));
672 array->attr.aa.element_type = type;
674 type *get_array_element_type (type *array) {
675 assert(array && (array->type_op == type_array));
676 return array->attr.aa.element_type = skip_tid(array->attr.aa.element_type);
678 void set_array_element_entity (type *array, entity *ent) {
679 assert(array && (array->type_op == type_array));
680 assert((get_entity_type(ent)->type_op != type_method));
681 array->attr.aa.element_ent = ent;
682 array->attr.aa.element_type = get_entity_type(ent);
684 entity *get_array_element_entity (type *array) {
685 assert(array && (array->type_op == type_array));
686 return array->attr.aa.element_ent;
690 bool is_array_type (type *array) {
692 if (array->type_op == type_array) return 1; else return 0;
695 /*******************************************************************/
696 /** TYPE_ENUMERATION **/
697 /*******************************************************************/
699 /* create a new type enumeration -- set the enumerators independently */
700 type *new_type_enumeration (ident *name, int n_enums) {
703 res = new_type(type_enumeration, NULL, name);
704 res->attr.ea.n_enums = n_enums;
705 res->attr.ea.enumer = (tarval **) xmalloc (sizeof (tarval *) * n_enums);
706 res->attr.ea.enum_nameid = (ident **) xmalloc (sizeof (ident *) * n_enums);
707 for (i = 0; i < n_enums; i++) {
708 res->attr.ea.enumer[i] = NULL;
709 res->attr.ea.enum_nameid = NULL;
714 inline void free_enumeration_attrs(type *enumeration) {
715 assert(enumeration && (enumeration->type_op == type_enumeration));
716 free(enumeration->attr.ea.enumer);
717 free(enumeration->attr.ea.enum_nameid);
720 /* manipulate fields of enumeration type. */
721 int get_enumeration_n_enums (type *enumeration) {
722 assert(enumeration && (enumeration->type_op == type_enumeration));
723 return enumeration->attr.ea.n_enums;
725 void set_enumeration_enum (type *enumeration, int pos, tarval *con) {
726 assert(enumeration && (enumeration->type_op == type_enumeration));
727 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
728 enumeration->attr.ea.enumer[pos] = con;
730 tarval *get_enumeration_enum (type *enumeration, int pos) {
731 assert(enumeration && (enumeration->type_op == type_enumeration));
732 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
733 return enumeration->attr.ea.enumer[pos];
735 void set_enumeration_nameid (type *enumeration, int pos, ident *id) {
736 assert(enumeration && (enumeration->type_op == type_enumeration));
737 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
738 enumeration->attr.ea.enum_nameid[pos] = id;
740 ident *get_enumeration_nameid (type *enumeration, int pos) {
741 assert(enumeration && (enumeration->type_op == type_enumeration));
742 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
743 return enumeration->attr.ea.enum_nameid[pos];
745 const char *get_enumeration_name(type *enumeration, int pos) {
746 assert(enumeration && (enumeration->type_op == type_enumeration));
747 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
748 return id_to_str(enumeration->attr.ea.enum_nameid[pos]);
752 bool is_enumeration_type (type *enumeration) {
754 if (enumeration->type_op == type_enumeration) return 1; else return 0;
757 /*******************************************************************/
759 /*******************************************************************/
761 /* Create a new type pointer */
762 type *new_type_pointer (ident *name, type *points_to) {
764 res = new_type(type_pointer, mode_p, name);
765 res->attr.pa.points_to = points_to;
766 res->size = get_mode_size(res->mode);
767 res->state = layout_fixed;
770 inline void free_pointer_attrs (type *pointer) {
771 assert(pointer && (pointer->type_op == type_pointer));
773 /* manipulate fields of type_pointer */
774 void set_pointer_points_to_type (type *pointer, type *type) {
775 assert(pointer && (pointer->type_op == type_pointer));
776 pointer->attr.pa.points_to = type;
778 type *get_pointer_points_to_type (type *pointer) {
779 assert(pointer && (pointer->type_op == type_pointer));
780 return pointer->attr.pa.points_to = skip_tid(pointer->attr.pa.points_to);
784 bool is_pointer_type (type *pointer) {
786 if (pointer->type_op == type_pointer) return 1; else return 0;
790 /*******************************************************************/
791 /** TYPE_PRIMITIVE **/
792 /*******************************************************************/
794 /* create a new type primitive */
795 type *new_type_primitive (ident *name, ir_mode *mode) {
797 res = new_type(type_primitive, mode, name);
798 res->size = get_mode_size(mode);
799 res->state = layout_fixed;
802 inline void free_primitive_attrs (type *primitive) {
803 assert(primitive && (primitive->type_op == type_primitive));
807 bool is_primitive_type (type *primitive) {
808 assert(primitive && primitive->kind == k_type);
809 if (primitive->type_op == type_primitive) return 1; else return 0;
812 /*******************************************************************/
813 /** common functionality **/
814 /*******************************************************************/
817 inline int is_atomic_type(type *tp) {
818 assert(tp && tp->kind == k_type);
819 return (is_primitive_type(tp) || is_pointer_type(tp) ||
820 is_enumeration_type(tp));
822 inline int is_compound_type(type *tp) {
823 assert(tp && tp->kind == k_type);
824 return (is_class_type(tp) || is_struct_type(tp) ||
825 is_array_type(tp) || is_union_type(tp));