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(is_method_type(get_entity_type(get_class_member(tp, i))) ||
196 (get_entity_allocation(get_class_member(tp, i)) == automatic_allocated));
197 /* @@@ lowerfirm geht nicht durch */
202 /* assert(get_type_size(tp) > -1); @@@ lowerfirm geht nicht durch */
203 for (i = 0; i < get_struct_n_member(tp); i++) {
204 assert(get_entity_offset(get_struct_member(tp, i)) > -1);
205 assert((get_entity_allocation(get_struct_member(tp, i)) == automatic_allocated));
214 Assure that only innermost dimension is dynamic? */
216 case tpo_enumeration:
218 assert(get_type_mode != NULL);
219 for (i = 0; i < get_enumeration_n_enums(tp); i++)
220 assert(get_enumeration_enum(tp, i) != NULL);
228 unsigned long get_type_visited(type *tp) {
229 assert(tp && tp->kind == k_type);
233 void set_type_visited(type *tp, unsigned long num) {
234 assert(tp && tp->kind == k_type);
237 /* Sets visited field in type to type_visited. */
238 void mark_type_visited(type *tp) {
239 assert(tp && tp->kind == k_type);
240 assert(tp->visit < type_visited);
241 tp->visit = type_visited;
244 int is_type (void *thing) {
246 if (get_kind(thing) == k_type)
252 /*******************************************************************/
254 /*******************************************************************/
256 /* create a new class type */
257 type *new_type_class (ident *name) {
260 res = new_type(type_class, NULL, name);
262 res->attr.ca.members = NEW_ARR_F (entity *, 1);
263 res->attr.ca.subtypes = NEW_ARR_F (type *, 1);
264 res->attr.ca.supertypes = NEW_ARR_F (type *, 1);
265 res->attr.ca.peculiarity = existent;
269 inline void free_class_attrs(type *clss) {
270 assert(clss && (clss->type_op == type_class));
271 DEL_ARR_F(clss->attr.ca.members);
272 DEL_ARR_F(clss->attr.ca.subtypes);
273 DEL_ARR_F(clss->attr.ca.supertypes);
275 /* manipulate private fields of class type */
276 void add_class_member (type *clss, entity *member) {
277 assert(clss && (clss->type_op == type_class));
278 ARR_APP1 (entity *, clss->attr.ca.members, member);
280 int get_class_n_member (type *clss) {
281 assert(clss && (clss->type_op == type_class));
282 return (ARR_LEN (clss->attr.ca.members))-1;
284 entity *get_class_member (type *clss, int pos) {
285 assert(clss && (clss->type_op == type_class));
286 assert(pos >= 0 && pos < get_class_n_member(clss));
287 return clss->attr.ca.members[pos+1];
289 void set_class_member (type *clss, entity *member, int pos) {
290 assert(clss && (clss->type_op == type_class));
291 assert(pos >= 0 && pos < get_class_n_member(clss));
292 clss->attr.ca.members[pos+1] = member;
294 void set_class_members (type *clss, entity **members, int arity) {
296 assert(clss && (clss->type_op == type_class));
297 DEL_ARR_F(clss->attr.ca.members);
298 clss->attr.ca.members = NEW_ARR_F (entity *, 1);
299 for (i = 0; i < arity; i++) {
300 set_entity_owner(members[i], clss);
301 ARR_APP1 (entity *, clss->attr.ca.members, members[i]);
304 void remove_class_member(type *clss, entity *member) {
306 assert(clss && (clss->type_op == type_class));
307 for (i = 1; i < (ARR_LEN (clss->attr.ca.members))-1; i++)
308 if (clss->attr.ca.members[i+1] == member) {
309 for(i++; i < (ARR_LEN (clss->attr.ca.members)) - 1; i++)
310 clss->attr.ca.members[i] = clss->attr.ca.members[i + 1];
311 ARR_SETLEN(entity*, clss->attr.ca.members, ARR_LEN(clss->attr.ca.members) - 1);
316 void add_class_subtype (type *clss, type *subtype) {
318 assert(clss && (clss->type_op == type_class));
319 ARR_APP1 (type *, clss->attr.ca.subtypes, subtype);
320 for (i = 0; i < get_class_n_supertype(subtype); i++)
321 if (get_class_supertype(subtype, i) == clss)
322 /* Class already registered */
324 ARR_APP1 (type *, subtype->attr.ca.supertypes, clss);
326 int get_class_n_subtype (type *clss) {
327 assert(clss && (clss->type_op == type_class));
328 return (ARR_LEN (clss->attr.ca.subtypes))-1;
330 type *get_class_subtype (type *clss, int pos) {
331 assert(clss && (clss->type_op == type_class));
332 assert(pos >= 0 && pos < get_class_n_subtype(clss));
333 return clss->attr.ca.subtypes[pos+1] = skip_tid(clss->attr.ca.subtypes[pos+1]);
335 void set_class_subtype (type *clss, type *subtype, int pos) {
336 assert(clss && (clss->type_op == type_class));
337 assert(pos >= 0 && pos < get_class_n_subtype(clss));
338 clss->attr.ca.subtypes[pos+1] = subtype;
340 void remove_class_subtype(type *clss, type *subtype) {
342 assert(clss && (clss->type_op == type_class));
343 for (i = 1; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
344 if (clss->attr.ca.subtypes[i+1] == subtype) {
345 for(i++; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
346 clss->attr.ca.subtypes[i] = clss->attr.ca.subtypes[i+1];
347 ARR_SETLEN(entity*, clss->attr.ca.subtypes, ARR_LEN(clss->attr.ca.subtypes) - 1);
352 void add_class_supertype (type *clss, type *supertype) {
354 assert(clss && (clss->type_op == type_class));
355 assert(supertype && (supertype -> type_op == type_class));
356 ARR_APP1 (type *, clss->attr.ca.supertypes, supertype);
357 for (i = 0; i < get_class_n_subtype(supertype); i++)
358 if (get_class_subtype(supertype, i) == clss)
359 /* Class already registered */
361 ARR_APP1 (type *, supertype->attr.ca.subtypes, clss);
363 int get_class_n_supertype (type *clss) {
364 assert(clss && (clss->type_op == type_class));
365 return (ARR_LEN (clss->attr.ca.supertypes))-1;
367 type *get_class_supertype (type *clss, int pos) {
368 assert(clss && (clss->type_op == type_class));
369 assert(pos >= 0 && pos < get_class_n_supertype(clss));
370 return clss->attr.ca.supertypes[pos+1] = skip_tid(clss->attr.ca.supertypes[pos+1]);
372 void set_class_supertype (type *clss, type *supertype, int pos) {
373 assert(clss && (clss->type_op == type_class));
374 assert(pos >= 0 && pos < get_class_n_supertype(clss));
375 clss->attr.ca.supertypes[pos+1] = supertype;
377 void remove_class_supertype(type *clss, type *supertype) {
379 assert(clss && (clss->type_op == type_class));
380 for (i = 1; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
381 if (clss->attr.ca.supertypes[i+1] == supertype) {
382 for(i++; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
383 clss->attr.ca.supertypes[i] = clss->attr.ca.supertypes[i+1];
384 ARR_SETLEN(entity*, clss->attr.ca.supertypes, ARR_LEN(clss->attr.ca.supertypes) - 1);
389 inline peculiarity get_class_peculiarity (type *clss) {
390 assert(clss && (clss->type_op == type_class));
391 return clss->attr.ca.peculiarity;
393 inline void set_class_peculiarity (type *clss, peculiarity pec) {
394 assert(clss && (clss->type_op == type_class));
395 clss->attr.ca.peculiarity = pec;
399 bool is_class_type(type *clss) {
401 if (clss->type_op == type_class) return 1; else return 0;
404 /*******************************************************************/
406 /*******************************************************************/
408 /* create a new type struct */
409 type *new_type_struct (ident *name) {
411 res = new_type(type_struct, NULL, name);
412 res->attr.sa.members = NEW_ARR_F (entity *, 1);
415 inline void free_struct_attrs (type *strct) {
416 assert(strct && (strct->type_op == type_struct));
417 DEL_ARR_F(strct->attr.sa.members);
419 /* manipulate private fields of struct */
420 void add_struct_member (type *strct, entity *member) {
421 assert(strct && (strct->type_op == type_struct));
422 assert(get_type_tpop(get_entity_type(member)) != type_method);
423 /* @@@ lowerfirm geht nicht durch */
424 ARR_APP1 (entity *, strct->attr.sa.members, member);
426 int get_struct_n_member (type *strct) {
427 assert(strct && (strct->type_op == type_struct));
428 return (ARR_LEN (strct->attr.sa.members))-1;
430 entity *get_struct_member (type *strct, int pos) {
431 assert(strct && (strct->type_op == type_struct));
432 assert(pos >= 0 && pos < get_struct_n_member(strct));
433 return strct->attr.sa.members[pos+1];
435 void set_struct_member (type *strct, int pos, entity *member) {
436 assert(strct && (strct->type_op == type_struct));
437 assert(pos >= 0 && pos < get_struct_n_member(strct));
438 assert(get_entity_type(member)->type_op != type_method);/* @@@ lowerfirm !!*/
439 strct->attr.sa.members[pos+1] = member;
441 void remove_struct_member(type *strct, entity *member) {
443 assert(strct && (strct->type_op == type_struct));
444 for (i = 1; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
445 if (strct->attr.sa.members[i+1] == member) {
446 for(i++; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
447 strct->attr.sa.members[i] = strct->attr.sa.members[i+1];
448 ARR_SETLEN(entity*, strct->attr.sa.members, ARR_LEN(strct->attr.sa.members) - 1);
453 bool is_struct_type(type *strct) {
455 if (strct->type_op == type_struct) return 1; else return 0;
458 /*******************************************************************/
460 /*******************************************************************/
462 /* Create a new method type.
463 N_param is the number of parameters, n_res the number of results. */
464 type *new_type_method (ident *name, int n_param, int n_res) {
466 res = new_type(type_method, mode_p, name);
467 res->state = layout_fixed;
468 res->size = get_mode_size(mode_p);
469 res->attr.ma.n_params = n_param;
470 res->attr.ma.param_type = (type **) xmalloc (sizeof (type *) * n_param);
471 res->attr.ma.n_res = n_res;
472 res->attr.ma.res_type = (type **) xmalloc (sizeof (type *) * n_res);
475 inline void free_method_attrs(type *method) {
476 assert(method && (method->type_op == type_method));
477 free(method->attr.ma.param_type);
478 free(method->attr.ma.res_type);
480 /* manipulate private fields of method. */
481 int get_method_n_params (type *method) {
482 assert(method && (method->type_op == type_method));
483 return method->attr.ma.n_params;
485 type *get_method_param_type(type *method, int pos) {
486 assert(method && (method->type_op == type_method));
487 assert(pos >= 0 && pos < get_method_n_params(method));
488 return method->attr.ma.param_type[pos] = skip_tid(method->attr.ma.param_type[pos]);
490 void set_method_param_type(type *method, int pos, type* type) {
491 assert(method && (method->type_op == type_method));
492 assert(pos >= 0 && pos < get_method_n_params(method));
493 method->attr.ma.param_type[pos] = type;
496 int get_method_n_res (type *method) {
497 assert(method && (method->type_op == type_method));
498 return method->attr.ma.n_res;
500 type *get_method_res_type(type *method, int pos) {
501 assert(method && (method->type_op == type_method));
502 assert(pos >= 0 && pos < get_method_n_res(method));
503 return method->attr.ma.res_type[pos] = skip_tid(method->attr.ma.res_type[pos]);
505 void set_method_res_type(type *method, int pos, type* type) {
506 assert(method && (method->type_op == type_method));
507 assert(pos >= 0 && pos < get_method_n_res(method));
508 method->attr.ma.res_type[pos] = type;
512 bool is_method_type (type *method) {
514 if (method->type_op == type_method) return 1; else return 0;
518 /*******************************************************************/
520 /*******************************************************************/
522 /* create a new type uni */
523 type *new_type_uni (ident *name) {
525 res = new_type(type_union, NULL, name);
526 /*res->attr.ua.unioned_type = (type **) xmalloc (sizeof (type *) * n_types);
527 res->attr.ua.delim_names = (ident **) xmalloc (sizeof (ident *) * n_types); */
528 res->attr.ua.members = NEW_ARR_F (entity *, 1);
531 inline void free_union_attrs (type *uni) {
532 assert(uni && (uni->type_op == type_union));
533 DEL_ARR_F(uni->attr.ua.members);
535 /* manipulate private fields of union */
537 int get_union_n_types (type *uni) {
538 assert(uni && (uni->type_op == type_union));
539 return uni->attr.ua.n_types;
541 type *get_union_unioned_type (type *uni, int pos) {
542 assert(uni && (uni->type_op == type_union));
543 assert(pos >= 0 && pos < get_union_n_types(uni));
544 return uni->attr.ua.unioned_type[pos] = skip_tid(uni->attr.ua.unioned_type[pos]);
546 void set_union_unioned_type (type *uni, int pos, type *type) {
547 assert(uni && (uni->type_op == type_union));
548 assert(pos >= 0 && pos < get_union_n_types(uni));
549 uni->attr.ua.unioned_type[pos] = type;
551 ident *get_union_delim_nameid (type *uni, int pos) {
552 assert(uni && (uni->type_op == type_union));
553 assert(pos >= 0 && pos < get_union_n_types(uni));
554 return uni->attr.ua.delim_names[pos];
556 const char *get_union_delim_name (type *uni, int pos) {
557 assert(uni && (uni->type_op == type_union));
558 assert(pos >= 0 && pos < get_union_n_types(uni));
559 return id_to_str(uni->attr.ua.delim_names[pos]);
561 void set_union_delim_nameid (type *uni, int pos, ident *id) {
562 assert(uni && (uni->type_op == type_union));
563 assert(pos >= 0 && pos < get_union_n_types(uni));
564 uni->attr.ua.delim_names[pos] = id;
567 int get_union_n_members (type *uni) {
568 assert(uni && (uni->type_op == type_union));
569 return (ARR_LEN (uni->attr.ua.members))-1;
571 void add_union_member (type *uni, entity *member) {
572 assert(uni && (uni->type_op == type_union));
573 ARR_APP1 (entity *, uni->attr.ua.members, member);
575 entity *get_union_member (type *uni, int pos) {
576 assert(uni && (uni->type_op == type_union));
577 assert(pos >= 0 && pos < get_union_n_members(uni));
578 return uni->attr.ua.members[pos+1];
580 void set_union_member (type *uni, int pos, entity *member) {
581 assert(uni && (uni->type_op == type_union));
582 assert(pos >= 0 && pos < get_union_n_members(uni));
583 uni->attr.ua.members[pos+1] = member;
585 void remove_union_member(type *uni, entity *member) {
587 assert(uni && (uni->type_op == type_union));
588 for (i = 1; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
589 if (uni->attr.ua.members[i+1] == member) {
590 for(i++; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
591 uni->attr.ua.members[i] = uni->attr.ua.members[i+1];
592 ARR_SETLEN(entity*, uni->attr.ua.members, ARR_LEN(uni->attr.ua.members) - 1);
598 bool is_union_type (type *uni) {
600 if (uni->type_op == type_union) return 1; else return 0;
603 /*******************************************************************/
605 /*******************************************************************/
608 /* create a new type array -- set dimension sizes independently */
609 type *new_type_array (ident *name, int n_dimensions,
610 type *element_type) {
613 assert((element_type->type_op != type_method));
614 assert(get_type_tpop(element_type) != type_method);
615 res = new_type(type_array, NULL, name);
616 res->attr.aa.n_dimensions = n_dimensions;
617 res->attr.aa.lower_bound = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
618 res->attr.aa.upper_bound = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
619 res->attr.aa.order = (int *) xmalloc (sizeof (int) * n_dimensions);
621 for (i = 0; i < n_dimensions; i++) {
622 res->attr.aa.lower_bound[i] = NULL;
623 res->attr.aa.upper_bound[i] = NULL;
624 res->attr.aa.order[i] = i;
626 res->attr.aa.element_type = element_type;
627 new_entity(res, mangle_u(name, id_from_str("elem_ent", 8)), element_type);
630 inline void free_array_attrs (type *array) {
631 assert(array && (array->type_op == type_array));
632 free(array->attr.aa.lower_bound);
633 free(array->attr.aa.upper_bound);
636 /* manipulate private fields of array type */
637 int get_array_n_dimensions (type *array) {
638 assert(array && (array->type_op == type_array));
639 return array->attr.aa.n_dimensions;
641 void set_array_bounds_int (type *array, int dimension, int lower_bound,
644 assert(array && (array->type_op == type_array));
645 rem = current_ir_graph;
646 current_ir_graph = get_const_code_irg();
647 array->attr.aa.lower_bound[dimension] =
648 new_Const(mode_I, tarval_from_long (mode_I, lower_bound));
649 array->attr.aa.upper_bound[dimension] =
650 new_Const(mode_I, tarval_from_long (mode_I, upper_bound));
651 current_ir_graph = rem;
654 void set_array_bounds (type *array, int dimension, ir_node * lower_bound,
655 ir_node * upper_bound) {
656 assert(array && (array->type_op == type_array));
657 array->attr.aa.lower_bound[dimension] = lower_bound;
658 array->attr.aa.upper_bound[dimension] = upper_bound;
660 void set_array_lower_bound_int (type *array, int dimension, int lower_bound) {
662 assert(array && (array->type_op == type_array));
663 rem = current_ir_graph;
664 current_ir_graph = get_const_code_irg();
665 array->attr.aa.lower_bound[dimension] =
666 new_Const(mode_I, tarval_from_long (mode_I, lower_bound));
667 current_ir_graph = rem;
669 void set_array_lower_bound (type *array, int dimension, ir_node * lower_bound) {
670 assert(array && (array->type_op == type_array));
671 array->attr.aa.lower_bound[dimension] = lower_bound;
673 void set_array_upper_bound (type *array, int dimension, ir_node * upper_bound) {
674 assert(array && (array->type_op == type_array));
675 array->attr.aa.upper_bound[dimension] = upper_bound;
677 ir_node * get_array_lower_bound (type *array, int dimension) {
678 assert(array && (array->type_op == type_array));
679 return array->attr.aa.lower_bound[dimension];
681 ir_node * get_array_upper_bound (type *array, int dimension) {
682 assert(array && (array->type_op == type_array));
683 return array->attr.aa.upper_bound[dimension];
685 void set_array_order (type *array, int dimension, int order) {
686 assert(array && (array->type_op == type_array));
687 array->attr.aa.order[dimension] = order;
689 int get_array_order (type *array, int dimension) {
690 assert(array && (array->type_op == type_array));
691 return array->attr.aa.order[dimension];
693 void set_array_element_type (type *array, type *type) {
694 assert(array && (array->type_op == type_array));
695 array->attr.aa.element_type = type;
697 type *get_array_element_type (type *array) {
698 assert(array && (array->type_op == type_array));
699 return array->attr.aa.element_type = skip_tid(array->attr.aa.element_type);
701 void set_array_element_entity (type *array, entity *ent) {
702 assert(array && (array->type_op == type_array));
703 assert((get_entity_type(ent)->type_op != type_method));
704 array->attr.aa.element_ent = ent;
705 array->attr.aa.element_type = get_entity_type(ent);
707 entity *get_array_element_entity (type *array) {
708 assert(array && (array->type_op == type_array));
709 return array->attr.aa.element_ent;
713 bool is_array_type (type *array) {
715 if (array->type_op == type_array) return 1; else return 0;
718 /*******************************************************************/
719 /** TYPE_ENUMERATION **/
720 /*******************************************************************/
722 /* create a new type enumeration -- set the enumerators independently */
723 type *new_type_enumeration (ident *name, int n_enums) {
726 res = new_type(type_enumeration, NULL, name);
727 res->attr.ea.n_enums = n_enums;
728 res->attr.ea.enumer = (tarval **) xmalloc (sizeof (tarval *) * n_enums);
729 res->attr.ea.enum_nameid = (ident **) xmalloc (sizeof (ident *) * n_enums);
730 for (i = 0; i < n_enums; i++) {
731 res->attr.ea.enumer[i] = NULL;
732 res->attr.ea.enum_nameid = NULL;
737 inline void free_enumeration_attrs(type *enumeration) {
738 assert(enumeration && (enumeration->type_op == type_enumeration));
739 free(enumeration->attr.ea.enumer);
740 free(enumeration->attr.ea.enum_nameid);
743 /* manipulate fields of enumeration type. */
744 int get_enumeration_n_enums (type *enumeration) {
745 assert(enumeration && (enumeration->type_op == type_enumeration));
746 return enumeration->attr.ea.n_enums;
748 void set_enumeration_enum (type *enumeration, int pos, tarval *con) {
749 assert(enumeration && (enumeration->type_op == type_enumeration));
750 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
751 enumeration->attr.ea.enumer[pos] = con;
753 tarval *get_enumeration_enum (type *enumeration, int pos) {
754 assert(enumeration && (enumeration->type_op == type_enumeration));
755 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
756 return enumeration->attr.ea.enumer[pos];
758 void set_enumeration_nameid (type *enumeration, int pos, ident *id) {
759 assert(enumeration && (enumeration->type_op == type_enumeration));
760 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
761 enumeration->attr.ea.enum_nameid[pos] = id;
763 ident *get_enumeration_nameid (type *enumeration, int pos) {
764 assert(enumeration && (enumeration->type_op == type_enumeration));
765 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
766 return enumeration->attr.ea.enum_nameid[pos];
768 const char *get_enumeration_name(type *enumeration, int pos) {
769 assert(enumeration && (enumeration->type_op == type_enumeration));
770 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
771 return id_to_str(enumeration->attr.ea.enum_nameid[pos]);
775 bool is_enumeration_type (type *enumeration) {
777 if (enumeration->type_op == type_enumeration) return 1; else return 0;
780 /*******************************************************************/
782 /*******************************************************************/
784 /* Create a new type pointer */
785 type *new_type_pointer (ident *name, type *points_to) {
787 res = new_type(type_pointer, mode_p, name);
788 res->attr.pa.points_to = points_to;
789 res->size = get_mode_size(res->mode);
790 res->state = layout_fixed;
793 inline void free_pointer_attrs (type *pointer) {
794 assert(pointer && (pointer->type_op == type_pointer));
796 /* manipulate fields of type_pointer */
797 void set_pointer_points_to_type (type *pointer, type *type) {
798 assert(pointer && (pointer->type_op == type_pointer));
799 pointer->attr.pa.points_to = type;
801 type *get_pointer_points_to_type (type *pointer) {
802 assert(pointer && (pointer->type_op == type_pointer));
803 return pointer->attr.pa.points_to = skip_tid(pointer->attr.pa.points_to);
807 bool is_pointer_type (type *pointer) {
809 if (pointer->type_op == type_pointer) return 1; else return 0;
813 /*******************************************************************/
814 /** TYPE_PRIMITIVE **/
815 /*******************************************************************/
817 /* create a new type primitive */
818 type *new_type_primitive (ident *name, ir_mode *mode) {
820 /* @@@ assert( mode_is_data(mode) && (!mode == mode_p)); */
821 res = new_type(type_primitive, mode, name);
822 res->size = get_mode_size(mode);
823 res->state = layout_fixed;
826 inline void free_primitive_attrs (type *primitive) {
827 assert(primitive && (primitive->type_op == type_primitive));
831 bool is_primitive_type (type *primitive) {
832 assert(primitive && primitive->kind == k_type);
833 if (primitive->type_op == type_primitive) return 1; else return 0;
836 /*******************************************************************/
837 /** common functionality **/
838 /*******************************************************************/
841 inline int is_atomic_type(type *tp) {
842 assert(tp && tp->kind == k_type);
843 return (is_primitive_type(tp) || is_pointer_type(tp) ||
844 is_enumeration_type(tp));
846 inline int is_compound_type(type *tp) {
847 assert(tp && tp->kind == k_type);
848 return (is_class_type(tp) || is_struct_type(tp) ||
849 is_array_type(tp) || is_union_type(tp));