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;
51 void free_type(type *tp) {
52 /* @@@ not implemented */
56 new_type(tp_op *type_op, ir_mode *mode, ident* name) {
60 assert(type_op != type_id);
62 node_size = offsetof (type, attr) + type_op->attr_size;
63 res = (type *) xmalloc (node_size);
64 add_irp_type(res); /* Remember the new type global. */
67 res->type_op = type_op;
70 res->state = layout_undefined;
78 void free_type_attrs(type *tp) {
79 switch(get_type_tpop_code(tp)) {
80 case tpo_class: { free_class_attrs(tp); } break;
81 case tpo_struct: { free_struct_attrs(tp); } break;
82 case tpo_method: { free_method_attrs(tp); } break;
83 case tpo_union: { free_union_attrs(tp); } break;
84 case tpo_array: { free_array_attrs(tp); } break;
85 case tpo_enumeration: { free_enumeration_attrs(tp); } break;
86 case tpo_pointer: { free_pointer_attrs(tp); } break;
87 case tpo_primitive: { free_primitive_attrs(tp); } break;
92 /* set/get the link field */
93 void *get_type_link(type *tp)
95 assert(tp && tp->kind == k_type);
99 void set_type_link(type *tp, void *l)
101 assert(tp && tp->kind == k_type);
105 tp_op* get_type_tpop(type *tp) {
106 assert(tp && tp->kind == k_type);
110 ident* get_type_tpop_nameid(type *tp) {
111 assert(tp && tp->kind == k_type);
112 return tp->type_op->name;
115 const char* get_type_tpop_name(type *tp) {
116 assert(tp && tp->kind == k_type);
117 return id_to_str(tp->type_op->name);
120 tp_opcode get_type_tpop_code(type *tp) {
121 assert(tp && tp->kind == k_type);
122 return tp->type_op->code;
125 ir_mode* get_type_mode(type *tp) {
126 assert(tp && tp->kind == k_type);
130 void set_type_mode(type *tp, ir_mode* m) {
131 assert(tp && tp->kind == k_type);
133 assert(((tp->type_op != type_primitive) || mode_is_data(m)) &&
134 /* Modes of primitives must be data */
135 ((tp->type_op != type_enumeration) || mode_is_int(m)));
136 /* Modes of enumerations must be integers */
138 if ((tp->type_op == type_primitive) || (tp->type_op == type_enumeration)) {
139 /* For pointer, primitive and enumeration size depends on the mode. */
140 tp->size = get_mode_size(m);
145 ident* get_type_ident(type *tp) {
146 assert(tp && tp->kind == k_type);
150 void set_type_ident(type *tp, ident* id) {
151 assert(tp && tp->kind == k_type);
155 const char* get_type_name(type *tp) {
156 assert(tp && tp->kind == k_type);
157 return (id_to_str(tp->name));
160 int get_type_size(type *tp) {
161 assert(tp && tp->kind == k_type);
166 set_type_size(type *tp, int size) {
167 assert(tp && tp->kind == k_type);
168 /* For pointer enumeration and primitive size depends on the mode.
169 Methods don't have a size. */
170 if ((tp->type_op != type_pointer) && (tp->type_op != type_primitive) &&
171 (tp->type_op != type_enumeration) && (tp->type_op != type_method))
176 get_type_state(type *tp) {
177 assert(tp && tp->kind == k_type);
182 set_type_state(type *tp, type_state state) {
183 assert(tp && tp->kind == k_type);
185 if ((tp->type_op == type_pointer) && (tp->type_op == type_primitive) &&
186 (tp->type_op == type_method))
189 /* Just a correctness check: */
190 if (state == layout_fixed) {
192 switch (get_type_tpop_code(tp)) {
195 assert(get_type_size(tp) > -1);
196 if (tp != get_glob_type())
197 for (i = 0; i < get_class_n_members(tp); i++) {
198 assert(get_entity_offset(get_class_member(tp, i)) > -1);
199 assert(is_method_type(get_entity_type(get_class_member(tp, i))) ||
200 (get_entity_allocation(get_class_member(tp, i)) == automatic_allocated));
201 /* @@@ lowerfirm geht nicht durch */
206 /* assert(get_type_size(tp) > -1); @@@ lowerfirm geht nicht durch */
207 for (i = 0; i < get_struct_n_members(tp); i++) {
208 assert(get_entity_offset(get_struct_member(tp, i)) > -1);
209 assert((get_entity_allocation(get_struct_member(tp, i)) == automatic_allocated));
218 Assure that only innermost dimension is dynamic? */
220 case tpo_enumeration:
222 assert(get_type_mode != NULL);
223 for (i = 0; i < get_enumeration_n_enums(tp); i++)
224 assert(get_enumeration_enum(tp, i) != NULL);
232 unsigned long get_type_visited(type *tp) {
233 assert(tp && tp->kind == k_type);
237 void set_type_visited(type *tp, unsigned long num) {
238 assert(tp && tp->kind == k_type);
241 /* Sets visited field in type to type_visited. */
242 void mark_type_visited(type *tp) {
243 assert(tp && tp->kind == k_type);
244 assert(tp->visit < type_visited);
245 tp->visit = type_visited;
248 int is_type (void *thing) {
250 if (get_kind(thing) == k_type)
256 /*******************************************************************/
258 /*******************************************************************/
260 /* create a new class type */
261 type *new_type_class (ident *name) {
264 res = new_type(type_class, NULL, name);
266 res->attr.ca.members = NEW_ARR_F (entity *, 1);
267 res->attr.ca.subtypes = NEW_ARR_F (type *, 1);
268 res->attr.ca.supertypes = NEW_ARR_F (type *, 1);
269 res->attr.ca.peculiarity = existent;
270 res->attr.ca.dfn = 0;
274 INLINE void free_class_attrs(type *clss) {
275 assert(clss && (clss->type_op == type_class));
276 DEL_ARR_F(clss->attr.ca.members);
277 DEL_ARR_F(clss->attr.ca.subtypes);
278 DEL_ARR_F(clss->attr.ca.supertypes);
281 /* manipulate private fields of class type */
282 void add_class_member (type *clss, entity *member) {
283 assert(clss && (clss->type_op == type_class));
284 ARR_APP1 (entity *, clss->attr.ca.members, member);
286 int get_class_n_members (type *clss) {
287 assert(clss && (clss->type_op == type_class));
288 return (ARR_LEN (clss->attr.ca.members))-1;
290 entity *get_class_member (type *clss, int pos) {
291 assert(clss && (clss->type_op == type_class));
292 assert(pos >= 0 && pos < get_class_n_members(clss));
293 return clss->attr.ca.members[pos+1];
295 void set_class_member (type *clss, entity *member, int pos) {
296 assert(clss && (clss->type_op == type_class));
297 assert(pos >= 0 && pos < get_class_n_members(clss));
298 clss->attr.ca.members[pos+1] = member;
300 void set_class_members (type *clss, entity **members, int arity) {
302 assert(clss && (clss->type_op == type_class));
303 DEL_ARR_F(clss->attr.ca.members);
304 clss->attr.ca.members = NEW_ARR_F (entity *, 1);
305 for (i = 0; i < arity; i++) {
306 set_entity_owner(members[i], clss);
307 ARR_APP1 (entity *, clss->attr.ca.members, members[i]);
310 void remove_class_member(type *clss, entity *member) {
312 assert(clss && (clss->type_op == type_class));
313 for (i = 1; i < (ARR_LEN (clss->attr.ca.members))-1; i++)
314 if (clss->attr.ca.members[i+1] == member) {
315 for(i++; i < (ARR_LEN (clss->attr.ca.members)) - 1; i++)
316 clss->attr.ca.members[i] = clss->attr.ca.members[i + 1];
317 ARR_SETLEN(entity*, clss->attr.ca.members, ARR_LEN(clss->attr.ca.members) - 1);
322 void add_class_subtype (type *clss, type *subtype) {
324 assert(clss && (clss->type_op == type_class));
325 ARR_APP1 (type *, clss->attr.ca.subtypes, subtype);
326 for (i = 0; i < get_class_n_supertypes(subtype); i++)
327 if (get_class_supertype(subtype, i) == clss)
328 /* Class already registered */
330 ARR_APP1 (type *, subtype->attr.ca.supertypes, clss);
332 int get_class_n_subtypes (type *clss) {
333 assert(clss && (clss->type_op == type_class));
334 return (ARR_LEN (clss->attr.ca.subtypes))-1;
336 type *get_class_subtype (type *clss, int pos) {
337 assert(clss && (clss->type_op == type_class));
338 assert(pos >= 0 && pos < get_class_n_subtypes(clss));
339 return clss->attr.ca.subtypes[pos+1] = skip_tid(clss->attr.ca.subtypes[pos+1]);
341 void set_class_subtype (type *clss, type *subtype, int pos) {
342 assert(clss && (clss->type_op == type_class));
343 assert(pos >= 0 && pos < get_class_n_subtypes(clss));
344 clss->attr.ca.subtypes[pos+1] = subtype;
346 void remove_class_subtype(type *clss, type *subtype) {
348 assert(clss && (clss->type_op == type_class));
349 for (i = 1; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
350 if (clss->attr.ca.subtypes[i+1] == subtype) {
351 for(i++; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
352 clss->attr.ca.subtypes[i] = clss->attr.ca.subtypes[i+1];
353 ARR_SETLEN(entity*, clss->attr.ca.subtypes, ARR_LEN(clss->attr.ca.subtypes) - 1);
358 void add_class_supertype (type *clss, type *supertype) {
360 assert(clss && (clss->type_op == type_class));
361 assert(supertype && (supertype -> type_op == type_class));
362 ARR_APP1 (type *, clss->attr.ca.supertypes, supertype);
363 for (i = 0; i < get_class_n_subtypes(supertype); i++)
364 if (get_class_subtype(supertype, i) == clss)
365 /* Class already registered */
367 ARR_APP1 (type *, supertype->attr.ca.subtypes, clss);
369 int get_class_n_supertypes (type *clss) {
370 assert(clss && (clss->type_op == type_class));
371 return (ARR_LEN (clss->attr.ca.supertypes))-1;
373 type *get_class_supertype (type *clss, int pos) {
374 assert(clss && (clss->type_op == type_class));
375 assert(pos >= 0 && pos < get_class_n_supertypes(clss));
376 return clss->attr.ca.supertypes[pos+1] = skip_tid(clss->attr.ca.supertypes[pos+1]);
378 void set_class_supertype (type *clss, type *supertype, int pos) {
379 assert(clss && (clss->type_op == type_class));
380 assert(pos >= 0 && pos < get_class_n_supertypes(clss));
381 clss->attr.ca.supertypes[pos+1] = supertype;
383 void remove_class_supertype(type *clss, type *supertype) {
385 assert(clss && (clss->type_op == type_class));
386 for (i = 1; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
387 if (clss->attr.ca.supertypes[i+1] == supertype) {
388 for(i++; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
389 clss->attr.ca.supertypes[i] = clss->attr.ca.supertypes[i+1];
390 ARR_SETLEN(entity*, clss->attr.ca.supertypes, ARR_LEN(clss->attr.ca.supertypes) - 1);
395 INLINE peculiarity get_class_peculiarity (type *clss) {
396 assert(clss && (clss->type_op == type_class));
397 return clss->attr.ca.peculiarity;
399 INLINE void set_class_peculiarity (type *clss, peculiarity pec) {
400 assert(clss && (clss->type_op == type_class));
401 assert(pec != inherited); /* There is no inheritance of types in libFirm. */
402 clss->attr.ca.peculiarity = pec;
405 void set_class_dfn (type *clss, int dfn)
407 clss->attr.ca.dfn = dfn;
410 int get_class_dfn (type *clss)
412 return (clss->attr.ca.dfn);
416 bool is_class_type(type *clss) {
418 if (clss->type_op == type_class) return 1; else return 0;
421 /*******************************************************************/
423 /*******************************************************************/
425 /* create a new type struct */
426 type *new_type_struct (ident *name) {
428 res = new_type(type_struct, NULL, name);
429 res->attr.sa.members = NEW_ARR_F (entity *, 1);
432 INLINE void free_struct_attrs (type *strct) {
433 assert(strct && (strct->type_op == type_struct));
434 DEL_ARR_F(strct->attr.sa.members);
437 /* manipulate private fields of struct */
438 int get_struct_n_members (type *strct) {
439 assert(strct && (strct->type_op == type_struct));
440 return (ARR_LEN (strct->attr.sa.members))-1;
442 void add_struct_member (type *strct, entity *member) {
443 assert(strct && (strct->type_op == type_struct));
444 assert(get_type_tpop(get_entity_type(member)) != type_method);
445 /* @@@ lowerfirm geht nicht durch */
446 ARR_APP1 (entity *, strct->attr.sa.members, member);
448 entity *get_struct_member (type *strct, int pos) {
449 assert(strct && (strct->type_op == type_struct));
450 assert(pos >= 0 && pos < get_struct_n_members(strct));
451 return strct->attr.sa.members[pos+1];
453 void set_struct_member (type *strct, int pos, entity *member) {
454 assert(strct && (strct->type_op == type_struct));
455 assert(pos >= 0 && pos < get_struct_n_members(strct));
456 assert(get_entity_type(member)->type_op != type_method);/* @@@ lowerfirm !!*/
457 strct->attr.sa.members[pos+1] = member;
459 void remove_struct_member(type *strct, entity *member) {
461 assert(strct && (strct->type_op == type_struct));
462 for (i = 1; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
463 if (strct->attr.sa.members[i+1] == member) {
464 for(i++; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
465 strct->attr.sa.members[i] = strct->attr.sa.members[i+1];
466 ARR_SETLEN(entity*, strct->attr.sa.members, ARR_LEN(strct->attr.sa.members) - 1);
472 bool is_struct_type(type *strct) {
474 if (strct->type_op == type_struct) return 1; else return 0;
477 /*******************************************************************/
479 /*******************************************************************/
481 /* Create a new method type.
482 N_param is the number of parameters, n_res the number of results. */
483 type *new_type_method (ident *name, int n_param, int n_res) {
485 res = new_type(type_method, mode_p, name);
486 res->state = layout_fixed;
487 res->size = get_mode_size(mode_p);
488 res->attr.ma.n_params = n_param;
489 res->attr.ma.param_type = (type **) xmalloc (sizeof (type *) * n_param);
490 res->attr.ma.n_res = n_res;
491 res->attr.ma.res_type = (type **) xmalloc (sizeof (type *) * n_res);
494 INLINE void free_method_attrs(type *method) {
495 assert(method && (method->type_op == type_method));
496 free(method->attr.ma.param_type);
497 free(method->attr.ma.res_type);
499 /* manipulate private fields of method. */
500 int get_method_n_params (type *method) {
501 assert(method && (method->type_op == type_method));
502 return method->attr.ma.n_params;
504 type *get_method_param_type(type *method, int pos) {
505 assert(method && (method->type_op == type_method));
506 assert(pos >= 0 && pos < get_method_n_params(method));
507 return method->attr.ma.param_type[pos] = skip_tid(method->attr.ma.param_type[pos]);
509 void set_method_param_type(type *method, int pos, type* type) {
510 assert(method && (method->type_op == type_method));
511 assert(pos >= 0 && pos < get_method_n_params(method));
512 method->attr.ma.param_type[pos] = type;
515 int get_method_n_ress (type *method) {
516 assert(method && (method->type_op == type_method));
517 return method->attr.ma.n_res;
519 type *get_method_res_type(type *method, int pos) {
520 assert(method && (method->type_op == type_method));
521 assert(pos >= 0 && pos < get_method_n_ress(method));
522 return method->attr.ma.res_type[pos] = skip_tid(method->attr.ma.res_type[pos]);
524 void set_method_res_type(type *method, int pos, type* type) {
525 assert(method && (method->type_op == type_method));
526 assert(pos >= 0 && pos < get_method_n_ress(method));
527 method->attr.ma.res_type[pos] = type;
531 bool is_method_type (type *method) {
533 if (method->type_op == type_method) return 1; else return 0;
537 /*******************************************************************/
539 /*******************************************************************/
541 /* create a new type uni */
542 type *new_type_uni (ident *name) {
544 res = new_type(type_union, NULL, name);
545 /*res->attr.ua.unioned_type = (type **) xmalloc (sizeof (type *) * n_types);
546 res->attr.ua.delim_names = (ident **) xmalloc (sizeof (ident *) * n_types); */
547 res->attr.ua.members = NEW_ARR_F (entity *, 1);
550 INLINE void free_union_attrs (type *uni) {
551 assert(uni && (uni->type_op == type_union));
552 DEL_ARR_F(uni->attr.ua.members);
554 /* manipulate private fields of union */
556 int get_union_n_types (type *uni) {
557 assert(uni && (uni->type_op == type_union));
558 return uni->attr.ua.n_types;
560 type *get_union_unioned_type (type *uni, int pos) {
561 assert(uni && (uni->type_op == type_union));
562 assert(pos >= 0 && pos < get_union_n_types(uni));
563 return uni->attr.ua.unioned_type[pos] = skip_tid(uni->attr.ua.unioned_type[pos]);
565 void set_union_unioned_type (type *uni, int pos, type *type) {
566 assert(uni && (uni->type_op == type_union));
567 assert(pos >= 0 && pos < get_union_n_types(uni));
568 uni->attr.ua.unioned_type[pos] = type;
570 ident *get_union_delim_nameid (type *uni, int pos) {
571 assert(uni && (uni->type_op == type_union));
572 assert(pos >= 0 && pos < get_union_n_types(uni));
573 return uni->attr.ua.delim_names[pos];
575 const char *get_union_delim_name (type *uni, int pos) {
576 assert(uni && (uni->type_op == type_union));
577 assert(pos >= 0 && pos < get_union_n_types(uni));
578 return id_to_str(uni->attr.ua.delim_names[pos]);
580 void set_union_delim_nameid (type *uni, int pos, ident *id) {
581 assert(uni && (uni->type_op == type_union));
582 assert(pos >= 0 && pos < get_union_n_types(uni));
583 uni->attr.ua.delim_names[pos] = id;
586 int get_union_n_members (type *uni) {
587 assert(uni && (uni->type_op == type_union));
588 return (ARR_LEN (uni->attr.ua.members))-1;
590 void add_union_member (type *uni, entity *member) {
591 assert(uni && (uni->type_op == type_union));
592 ARR_APP1 (entity *, uni->attr.ua.members, member);
594 entity *get_union_member (type *uni, int pos) {
595 assert(uni && (uni->type_op == type_union));
596 assert(pos >= 0 && pos < get_union_n_members(uni));
597 return uni->attr.ua.members[pos+1];
599 void set_union_member (type *uni, int pos, entity *member) {
600 assert(uni && (uni->type_op == type_union));
601 assert(pos >= 0 && pos < get_union_n_members(uni));
602 uni->attr.ua.members[pos+1] = member;
604 void remove_union_member(type *uni, entity *member) {
606 assert(uni && (uni->type_op == type_union));
607 for (i = 1; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
608 if (uni->attr.ua.members[i+1] == member) {
609 for(i++; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
610 uni->attr.ua.members[i] = uni->attr.ua.members[i+1];
611 ARR_SETLEN(entity*, uni->attr.ua.members, ARR_LEN(uni->attr.ua.members) - 1);
617 bool is_union_type (type *uni) {
619 if (uni->type_op == type_union) return 1; else return 0;
622 /*******************************************************************/
624 /*******************************************************************/
627 /* create a new type array -- set dimension sizes independently */
628 type *new_type_array (ident *name, int n_dimensions,
629 type *element_type) {
632 assert(!is_method_type(element_type));
633 res = new_type(type_array, NULL, name);
634 res->attr.aa.n_dimensions = n_dimensions;
635 res->attr.aa.lower_bound = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
636 res->attr.aa.upper_bound = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
637 res->attr.aa.order = (int *) xmalloc (sizeof (int) * n_dimensions);
639 for (i = 0; i < n_dimensions; i++) {
640 res->attr.aa.lower_bound[i] = NULL;
641 res->attr.aa.upper_bound[i] = NULL;
642 res->attr.aa.order[i] = i;
644 res->attr.aa.element_type = element_type;
645 new_entity(res, mangle_u(name, id_from_str("elem_ent", 8)), element_type);
649 INLINE void free_array_attrs (type *array) {
650 assert(array && (array->type_op == type_array));
651 free(array->attr.aa.lower_bound);
652 free(array->attr.aa.upper_bound);
655 /* manipulate private fields of array type */
656 int get_array_n_dimensions (type *array) {
657 assert(array && (array->type_op == type_array));
658 return array->attr.aa.n_dimensions;
662 set_array_bounds (type *array, int dimension, ir_node * lower_bound,
663 ir_node * upper_bound) {
664 assert(array && (array->type_op == type_array));
665 array->attr.aa.lower_bound[dimension] = lower_bound;
666 array->attr.aa.upper_bound[dimension] = upper_bound;
669 set_array_bounds_int (type *array, int dimension, int lower_bound,
671 ir_graph *rem = current_ir_graph;
672 current_ir_graph = get_const_code_irg();
673 set_array_bounds (array, dimension,
674 new_Const(mode_I, tarval_from_long (mode_I, lower_bound)),
675 new_Const(mode_I, tarval_from_long (mode_I, upper_bound)));
676 current_ir_graph = rem;
679 set_array_lower_bound (type *array, int dimension, ir_node * lower_bound) {
680 assert(array && (array->type_op == type_array));
681 array->attr.aa.lower_bound[dimension] = lower_bound;
683 void set_array_lower_bound_int (type *array, int dimension, int lower_bound) {
684 ir_graph *rem = current_ir_graph;
685 current_ir_graph = get_const_code_irg();
686 set_array_lower_bound (array, dimension,
687 new_Const(mode_I, tarval_from_long (mode_I, lower_bound)));
688 current_ir_graph = rem;
691 set_array_upper_bound (type *array, int dimension, ir_node * upper_bound) {
692 assert(array && (array->type_op == type_array));
693 array->attr.aa.upper_bound[dimension] = upper_bound;
695 void set_array_upper_bound_int (type *array, int dimension, int upper_bound) {
696 ir_graph *rem = current_ir_graph;
697 current_ir_graph = get_const_code_irg();
698 set_array_upper_bound (array, dimension,
699 new_Const(mode_I, tarval_from_long (mode_I, upper_bound)));
700 current_ir_graph = rem;
702 ir_node * get_array_lower_bound (type *array, int dimension) {
703 assert(array && (array->type_op == type_array));
704 return array->attr.aa.lower_bound[dimension];
706 ir_node * get_array_upper_bound (type *array, int dimension) {
707 assert(array && (array->type_op == type_array));
708 return array->attr.aa.upper_bound[dimension];
711 void set_array_order (type *array, int dimension, int order) {
712 assert(array && (array->type_op == type_array));
713 array->attr.aa.order[dimension] = order;
715 int get_array_order (type *array, int dimension) {
716 assert(array && (array->type_op == type_array));
717 return array->attr.aa.order[dimension];
720 void set_array_element_type (type *array, type *type) {
721 assert(array && (array->type_op == type_array));
722 assert(!is_method_type(type));
723 array->attr.aa.element_type = type;
725 type *get_array_element_type (type *array) {
726 assert(array && (array->type_op == type_array));
727 return array->attr.aa.element_type = skip_tid(array->attr.aa.element_type);
730 void set_array_element_entity (type *array, entity *ent) {
731 assert(array && (array->type_op == type_array));
732 assert((get_entity_type(ent)->type_op != type_method));
733 array->attr.aa.element_ent = ent;
734 array->attr.aa.element_type = get_entity_type(ent);
736 entity *get_array_element_entity (type *array) {
737 assert(array && (array->type_op == type_array));
738 return array->attr.aa.element_ent;
742 bool is_array_type (type *array) {
744 if (array->type_op == type_array) return 1; else return 0;
747 /*******************************************************************/
748 /** TYPE_ENUMERATION **/
749 /*******************************************************************/
751 /* create a new type enumeration -- set the enumerators independently */
752 type *new_type_enumeration (ident *name, int n_enums) {
755 res = new_type(type_enumeration, NULL, name);
756 res->attr.ea.n_enums = n_enums;
757 res->attr.ea.enumer = (tarval **) xmalloc (sizeof (tarval *) * n_enums);
758 res->attr.ea.enum_nameid = (ident **) xmalloc (sizeof (ident *) * n_enums);
759 for (i = 0; i < n_enums; i++) {
760 res->attr.ea.enumer[i] = NULL;
761 res->attr.ea.enum_nameid = NULL;
766 INLINE void free_enumeration_attrs(type *enumeration) {
767 assert(enumeration && (enumeration->type_op == type_enumeration));
768 free(enumeration->attr.ea.enumer);
769 free(enumeration->attr.ea.enum_nameid);
772 /* manipulate fields of enumeration type. */
773 int get_enumeration_n_enums (type *enumeration) {
774 assert(enumeration && (enumeration->type_op == type_enumeration));
775 return enumeration->attr.ea.n_enums;
777 void set_enumeration_enum (type *enumeration, int pos, tarval *con) {
778 assert(enumeration && (enumeration->type_op == type_enumeration));
779 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
780 enumeration->attr.ea.enumer[pos] = con;
782 tarval *get_enumeration_enum (type *enumeration, int pos) {
783 assert(enumeration && (enumeration->type_op == type_enumeration));
784 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
785 return enumeration->attr.ea.enumer[pos];
787 void set_enumeration_nameid (type *enumeration, int pos, ident *id) {
788 assert(enumeration && (enumeration->type_op == type_enumeration));
789 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
790 enumeration->attr.ea.enum_nameid[pos] = id;
792 ident *get_enumeration_nameid (type *enumeration, int pos) {
793 assert(enumeration && (enumeration->type_op == type_enumeration));
794 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
795 return enumeration->attr.ea.enum_nameid[pos];
797 const char *get_enumeration_name(type *enumeration, int pos) {
798 assert(enumeration && (enumeration->type_op == type_enumeration));
799 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
800 return id_to_str(enumeration->attr.ea.enum_nameid[pos]);
804 bool is_enumeration_type (type *enumeration) {
806 if (enumeration->type_op == type_enumeration) return 1; else return 0;
809 /*******************************************************************/
811 /*******************************************************************/
813 /* Create a new type pointer */
814 type *new_type_pointer (ident *name, type *points_to) {
816 res = new_type(type_pointer, mode_p, name);
817 res->attr.pa.points_to = points_to;
818 res->size = get_mode_size(res->mode);
819 res->state = layout_fixed;
822 INLINE void free_pointer_attrs (type *pointer) {
823 assert(pointer && (pointer->type_op == type_pointer));
825 /* manipulate fields of type_pointer */
826 void set_pointer_points_to_type (type *pointer, type *type) {
827 assert(pointer && (pointer->type_op == type_pointer));
828 pointer->attr.pa.points_to = type;
830 type *get_pointer_points_to_type (type *pointer) {
831 assert(pointer && (pointer->type_op == type_pointer));
832 return pointer->attr.pa.points_to = skip_tid(pointer->attr.pa.points_to);
836 bool is_pointer_type (type *pointer) {
838 if (pointer->type_op == type_pointer) return 1; else return 0;
842 /*******************************************************************/
843 /** TYPE_PRIMITIVE **/
844 /*******************************************************************/
846 /* create a new type primitive */
847 type *new_type_primitive (ident *name, ir_mode *mode) {
849 /* @@@ assert( mode_is_data(mode) && (!mode == mode_p)); */
850 res = new_type(type_primitive, mode, name);
851 res->size = get_mode_size(mode);
852 res->state = layout_fixed;
855 INLINE void free_primitive_attrs (type *primitive) {
856 assert(primitive && (primitive->type_op == type_primitive));
860 bool is_primitive_type (type *primitive) {
861 assert(primitive && primitive->kind == k_type);
862 if (primitive->type_op == type_primitive) return 1; else return 0;
865 /*******************************************************************/
866 /** common functionality **/
867 /*******************************************************************/
870 INLINE int is_atomic_type(type *tp) {
871 assert(tp && tp->kind == k_type);
872 return (is_primitive_type(tp) || is_pointer_type(tp) ||
873 is_enumeration_type(tp));
875 INLINE int is_compound_type(type *tp) {
876 assert(tp && tp->kind == k_type);
877 return (is_class_type(tp) || is_struct_type(tp) ||
878 is_array_type(tp) || is_union_type(tp));