3 * File name: ir/tr/type.c
4 * Purpose: Representation of types.
5 * Author: Goetz Lindenmaier
9 * Copyright: (c) 2001-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
15 * file type.c - implementation of the datastructure to hold
17 * (C) 2001 by Universitaet Karlsruhe
20 * This module supplies a datastructure to represent all types
21 * known in the compiled program. This includes types specified
22 * in the program as well as types defined by the language. In the
23 * view of the intermediate representation there is no difference
24 * between these types.
26 * There exist several kinds of types, arranged by the structure of
27 * the type. A type is described by a set of attributes. Some of
28 * these attributes are common to all types, others depend on the
31 * Types are different from the modes defined in irmode: Types are
32 * on the level of the programming language, modes at the level of
33 * the target processor.
35 * @see type_t.h type tpop
48 # include "irprog_t.h"
49 # include "typegmod.h"
56 /*******************************************************************/
58 /*******************************************************************/
60 type *none_type; type *get_none_type(void) { return none_type; }
61 type *unknown_type; type *get_unknown_type(void) { return unknown_type; }
65 /** Returns a new, unique number to number nodes or the like. */
66 int get_irp_new_node_nr(void);
69 /* Suffixes added to types used for pass-by-value representations. */
70 static ident *value_params_suffix = NULL;
71 static ident *value_ress_suffix = NULL;
73 void init_type(void) {
74 value_params_suffix = new_id_from_str(VALUE_PARAMS_SUFFIX);
75 value_ress_suffix = new_id_from_str(VALUE_RESS_SUFFIX);
77 /* construct none and unknown type. */
78 none_type = new_type(tpop_none, mode_BAD, new_id_from_str("type_none"));
79 set_type_size (none_type, 0);
80 set_type_state (none_type, layout_fixed);
81 remove_irp_type(none_type);
82 unknown_type = new_type(tpop_unknown, mode_ANY, new_id_from_str("type_unknown"));
83 set_type_size (unknown_type, 0);
84 set_type_state (unknown_type, layout_fixed);
85 remove_irp_type(unknown_type);
88 unsigned long type_visited;
89 INLINE void set_master_type_visited(unsigned long val) { type_visited = val; }
90 INLINE unsigned long get_master_type_visited() { return type_visited; }
91 INLINE void inc_master_type_visited() { type_visited++; }
93 void free_type(type *tp) {
94 if ((get_type_tpop(tp) == tpop_none) || (get_type_tpop(tp) == tpop_unknown))
96 /* Remove from list of all types */
98 /* Free the attributes of the type. */
100 /* Free entities automatically allocated with the type */
101 if (is_array_type(tp))
102 free_entity(get_array_element_entity(tp));
103 /* And now the type itself... */
109 new_type(tp_op *type_op, ir_mode *mode, ident* name) {
113 assert(type_op != type_id);
114 assert(!id_contains_char(name, ' ') && "type name should not contain spaces");
116 node_size = offsetof (type, attr) + type_op->attr_size;
117 res = (type *) xmalloc (node_size);
118 add_irp_type(res); /* Remember the new type global. */
121 res->type_op = type_op;
124 res->state = layout_undefined;
129 res->nr = get_irp_new_node_nr();
135 void free_type_attrs(type *tp) {
136 switch(get_type_tpop_code(tp)) {
137 case tpo_class: { free_class_attrs(tp); } break;
138 case tpo_struct: { free_struct_attrs(tp); } break;
139 case tpo_method: { free_method_attrs(tp); } break;
140 case tpo_union: { free_union_attrs(tp); } break;
141 case tpo_array: { free_array_attrs(tp); } break;
142 case tpo_enumeration: { free_enumeration_attrs(tp); } break;
143 case tpo_pointer: { free_pointer_attrs(tp); } break;
144 case tpo_primitive: { free_primitive_attrs(tp); } break;
149 /* set/get the link field */
150 void *get_type_link(type *tp)
152 assert(tp && tp->kind == k_type);
156 void set_type_link(type *tp, void *l)
158 assert(tp && tp->kind == k_type);
162 tp_op* get_type_tpop(type *tp) {
163 assert(tp && tp->kind == k_type);
167 ident* get_type_tpop_nameid(type *tp) {
168 assert(tp && tp->kind == k_type);
169 return tp->type_op->name;
172 const char* get_type_tpop_name(type *tp) {
173 assert(tp && tp->kind == k_type);
174 return get_id_str(tp->type_op->name);
177 tp_opcode get_type_tpop_code(type *tp) {
178 assert(tp && tp->kind == k_type);
179 return tp->type_op->code;
182 ir_mode* get_type_mode(type *tp) {
183 assert(tp && tp->kind == k_type);
187 void set_type_mode(type *tp, ir_mode* m) {
188 assert(tp && tp->kind == k_type);
190 assert(((tp->type_op != type_primitive) || mode_is_data(m)) &&
191 /* Modes of primitives must be data */
192 ((tp->type_op != type_enumeration) || mode_is_int(m)) &&
193 /* Modes of enumerations must be integers */
194 ((tp->type_op != type_pointer) || mode_is_reference(m)) );
195 /* Modes of pointers must be references. */
197 if ((tp->type_op == type_primitive) ||
198 (tp->type_op == type_enumeration) ||
199 (tp->type_op == type_pointer) ) {
200 /* For pointer, primitive and enumeration size depends on the mode. */
201 assert((get_mode_size_bytes(m) != -1) && "unorthodox modes not implemented");
202 tp->size = get_mode_size_bytes(m);
207 ident* get_type_ident(type *tp) {
208 assert(tp && tp->kind == k_type);
212 void set_type_ident(type *tp, ident* id) {
213 assert(tp && tp->kind == k_type);
217 /* Outputs a unique number for this node */
219 get_type_nr(type *tp) {
228 const char* get_type_name(type *tp) {
229 assert(tp && tp->kind == k_type);
230 return (get_id_str(tp->name));
233 int get_type_size(type *tp) {
234 assert(tp && tp->kind == k_type);
239 set_type_size(type *tp, int size) {
240 assert(tp && tp->kind == k_type);
241 /* For pointer enumeration and primitive size depends on the mode.
242 Methods don't have a size. */
243 if ((tp->type_op != type_pointer) && (tp->type_op != type_primitive) &&
244 (tp->type_op != type_enumeration) && (tp->type_op != type_method))
249 get_type_state(type *tp) {
250 assert(tp && tp->kind == k_type);
255 set_type_state(type *tp, type_state state) {
256 assert(tp && tp->kind == k_type);
258 if ((tp->type_op == type_pointer) || (tp->type_op == type_primitive) ||
259 (tp->type_op == type_method))
262 /* Just a correctness check: */
263 if (state == layout_fixed) {
265 switch (get_type_tpop_code(tp)) {
268 assert(get_type_size(tp) > -1);
269 if (tp != get_glob_type())
270 for (i = 0; i < get_class_n_members(tp); i++) {
271 if (get_entity_offset(get_class_member(tp, i)) <= -1)
272 { DDMT(tp); DDME(get_class_member(tp, i)); }
273 assert(get_entity_offset(get_class_member(tp, i)) > -1);
274 assert(is_method_type(get_entity_type(get_class_member(tp, i))) ||
275 (get_entity_allocation(get_class_member(tp, i)) == allocation_automatic));
280 assert(get_type_size(tp) > -1);
281 for (i = 0; i < get_struct_n_members(tp); i++) {
282 assert(get_entity_offset(get_struct_member(tp, i)) > -1);
283 assert((get_entity_allocation(get_struct_member(tp, i)) == allocation_automatic));
292 Assure that only innermost dimension is dynamic? */
294 case tpo_enumeration:
296 assert(get_type_mode != NULL);
297 for (i = 0; i < get_enumeration_n_enums(tp); i++)
298 assert(get_enumeration_enum(tp, i) != NULL);
306 unsigned long get_type_visited(type *tp) {
307 assert(tp && tp->kind == k_type);
311 void set_type_visited(type *tp, unsigned long num) {
312 assert(tp && tp->kind == k_type);
315 /* Sets visited field in type to type_visited. */
316 void mark_type_visited(type *tp) {
317 assert(tp && tp->kind == k_type);
318 assert(tp->visit < type_visited);
319 tp->visit = type_visited;
321 /* @@@ name clash with master flag
322 bool type_visited(type *tp) {
323 assert(tp && tp->kind == k_type);
324 return tp->visit >= type_visited;
326 bool type_not_visited(type *tp) {
327 assert(tp && tp->kind == k_type);
328 return tp->visit < type_visited;
332 int is_type (void *thing) {
334 if (get_kind(thing) == k_type)
341 bool equal_type(type *typ1, type *typ2) {
346 if (typ1 == typ2) return true;
348 if ((get_type_tpop_code(typ1) != get_type_tpop_code(typ2)) ||
349 (get_type_ident(typ1) != get_type_ident(typ2)) ||
350 (get_type_mode(typ1) != get_type_mode(typ2)) ||
351 (get_type_state(typ1) != get_type_state(typ2)))
353 if ((get_type_state(typ1) == layout_fixed) &&
354 (get_type_size(typ1) != get_type_size(typ2)))
357 switch(get_type_tpop_code(typ1)) {
359 if (get_class_n_members(typ1) != get_class_n_members(typ2)) return false;
360 if (get_class_n_subtypes(typ1) != get_class_n_subtypes(typ2)) return false;
361 if (get_class_n_supertypes(typ1) != get_class_n_supertypes(typ2)) return false;
362 if (get_class_peculiarity(typ1) != get_class_peculiarity(typ2)) return false;
363 /** Compare the members **/
364 m = alloca(sizeof(entity *) * get_class_n_members(typ1));
365 memset(m, 0, sizeof(entity *) * get_class_n_members(typ1));
366 /* First sort the members of typ2 */
367 for (i = 0; i < get_class_n_members(typ1); i++) {
368 entity *e1 = get_class_member(typ1, i);
369 for (j = 0; j < get_class_n_members(typ2); j++) {
370 entity *e2 = get_class_member(typ2, j);
371 if (get_entity_name(e1) == get_entity_name(e2))
375 for (i = 0; i < get_class_n_members(typ1); i++) {
376 if (!m[i] || /* Found no counterpart */
377 !equal_entity(get_class_member(typ1, i), m[i]))
380 /** Compare the supertypes **/
381 t = alloca(sizeof(entity *) * get_class_n_supertypes(typ1));
382 memset(t, 0, sizeof(entity *) * get_class_n_supertypes(typ1));
383 /* First sort the supertypes of typ2 */
384 for (i = 0; i < get_class_n_supertypes(typ1); i++) {
385 type *t1 = get_class_supertype(typ1, i);
386 for (j = 0; j < get_class_n_supertypes(typ2); j++) {
387 type *t2 = get_class_supertype(typ2, j);
388 if (get_type_ident(t2) == get_type_ident(t1))
392 for (i = 0; i < get_class_n_supertypes(typ1); i++) {
393 if (!t[i] || /* Found no counterpart */
394 get_class_supertype(typ1, i) != t[i])
399 if (get_struct_n_members(typ1) != get_struct_n_members(typ2)) return false;
400 m = alloca(sizeof(entity *) * get_struct_n_members(typ1));
401 memset(m, 0, sizeof(entity *) * get_struct_n_members(typ1));
402 /* First sort the members of lt */
403 for (i = 0; i < get_struct_n_members(typ1); i++) {
404 entity *e1 = get_struct_member(typ1, i);
405 for (j = 0; j < get_struct_n_members(typ2); j++) {
406 entity *e2 = get_struct_member(typ2, j);
407 if (get_entity_name(e1) == get_entity_name(e2))
411 for (i = 0; i < get_struct_n_members(typ1); i++) {
412 if (!m[i] || /* Found no counterpart */
413 !equal_entity(get_struct_member(typ1, i), m[i]))
418 if (get_method_variadicity(typ1) != get_method_variadicity(typ2)) return false;
419 if (get_method_n_params(typ1) != get_method_n_params(typ2)) return false;
420 if (get_method_n_ress(typ1) != get_method_n_ress(typ2)) return false;
421 for (i = 0; i < get_method_n_params(typ1); i++) {
422 if (!equal_type(get_method_param_type(typ1, i), get_method_param_type(typ2, i)))
425 for (i = 0; i < get_method_n_ress(typ1); i++) {
426 if (!equal_type(get_method_res_type(typ1, i), get_method_res_type(typ2, i)))
431 if (get_union_n_members(typ1) != get_union_n_members(typ2)) return false;
432 m = alloca(sizeof(entity *) * get_union_n_members(typ1));
433 memset(m, 0, sizeof(entity *) * get_union_n_members(typ1));
434 /* First sort the members of lt */
435 for (i = 0; i < get_union_n_members(typ1); i++) {
436 entity *e1 = get_union_member(typ1, i);
437 for (j = 0; j < get_union_n_members(typ2); j++) {
438 entity *e2 = get_union_member(typ2, j);
439 if (get_entity_name(e1) == get_entity_name(e2))
443 for (i = 0; i < get_union_n_members(typ1); i++) {
444 if (!m[i] || /* Found no counterpart */
445 !equal_entity(get_union_member(typ1, i), m[i]))
450 if (get_array_n_dimensions(typ1) != get_array_n_dimensions(typ2))
452 if (!equal_type(get_array_element_type(typ1), get_array_element_type(typ2)))
454 for(i = 0; i < get_array_n_dimensions(typ1); i++) {
455 if (get_array_lower_bound(typ1, i) != get_array_lower_bound(typ2, i) ||
456 get_array_upper_bound(typ1, i) != get_array_upper_bound(typ2, i))
458 if (get_array_order(typ1, i) != get_array_order(typ2, i))
459 assert(0 && "type compare with different dimension orders not implemented");
462 case tpo_enumeration: {
463 assert(0 && "enumerations not implemented");
466 if (get_pointer_points_to_type(typ1) != get_pointer_points_to_type(typ2))
469 case tpo_primitive: {
476 bool smaller_type (type *st, type *lt) {
480 if (st == lt) return true;
482 if (get_type_tpop_code(st) != get_type_tpop_code(lt))
485 switch(get_type_tpop_code(st)) {
487 return is_subclass_of(st, lt);
490 if (get_struct_n_members(st) != get_struct_n_members(lt)) return false;
491 m = alloca(sizeof(entity *) * get_struct_n_members(st));
492 memset(m, 0, sizeof(entity *) * get_struct_n_members(st));
493 /* First sort the members of lt */
494 for (i = 0; i < get_struct_n_members(st); i++) {
495 entity *se = get_struct_member(st, i);
496 for (j = 0; j < get_struct_n_members(lt); j++) {
497 entity *le = get_struct_member(lt, j);
498 if (get_entity_name(le) == get_entity_name(se))
502 for (i = 0; i < get_struct_n_members(st); i++) {
503 if (!m[i] || /* Found no counterpart */
504 !smaller_type(get_entity_type(get_struct_member(st, i)),
505 get_entity_type(m[i])))
510 if (get_method_variadicity(st) != get_method_variadicity(lt)) return false;
511 if (get_method_n_params(st) != get_method_n_params(lt)) return false;
512 if (get_method_n_ress(st) != get_method_n_ress(lt)) return false;
513 for (i = 0; i < get_method_n_params(st); i++) {
514 if (!smaller_type(get_method_param_type(st, i), get_method_param_type(lt, i)))
517 for (i = 0; i < get_method_n_ress(st); i++) {
518 if (!smaller_type(get_method_res_type(st, i), get_method_res_type(lt, i)))
523 if (get_union_n_members(st) != get_union_n_members(lt)) return false;
524 m = alloca(sizeof(entity *) * get_union_n_members(st));
525 memset(m, 0, sizeof(entity *) * get_union_n_members(st));
526 /* First sort the members of lt */
527 for (i = 0; i < get_union_n_members(st); i++) {
528 entity *se = get_union_member(st, i);
529 for (j = 0; j < get_union_n_members(lt); j++) {
530 entity *le = get_union_member(lt, j);
531 if (get_entity_name(le) == get_entity_name(se))
535 for (i = 0; i < get_union_n_members(st); i++) {
536 if (!m[i] || /* Found no counterpart */
537 !smaller_type(get_entity_type(get_union_member(st, i)),
538 get_entity_type(m[i])))
543 type *set, *let; /* small/large elt. type */
544 if (get_array_n_dimensions(st) != get_array_n_dimensions(lt))
546 set = get_array_element_type(st);
547 let = get_array_element_type(lt);
549 /* If the elt types are different, set must be convertible
550 to let, and they must have the same size so that address
551 computations work out. To have a size the layout must
553 if ((get_type_state(set) != layout_fixed) ||
554 (get_type_state(let) != layout_fixed))
556 if (!smaller_type(set, let) ||
557 get_type_size(set) != get_type_size(let))
560 for(i = 0; i < get_array_n_dimensions(st); i++) {
561 if (get_array_lower_bound(lt, i))
562 if(get_array_lower_bound(st, i) != get_array_lower_bound(lt, i))
564 if (get_array_upper_bound(lt, i))
565 if(get_array_upper_bound(st, i) != get_array_upper_bound(lt, i))
569 case tpo_enumeration: {
570 assert(0 && "enumerations not implemented");
573 if (!smaller_type(get_pointer_points_to_type(st),
574 get_pointer_points_to_type(lt)))
577 case tpo_primitive: {
578 if (!smaller_mode(get_type_mode(st), get_type_mode(lt)))
586 /*******************************************************************/
588 /*******************************************************************/
590 /* create a new class type */
591 INLINE type *new_type_class (ident *name) {
594 res = new_type(type_class, NULL, name);
596 res->attr.ca.members = NEW_ARR_F (entity *, 1);
597 res->attr.ca.subtypes = NEW_ARR_F (type *, 1);
598 res->attr.ca.supertypes = NEW_ARR_F (type *, 1);
599 res->attr.ca.peculiarity = peculiarity_existent;
600 res->attr.ca.dfn = 0;
604 type *new_d_type_class (ident *name, dbg_info* db) {
605 type *res = new_type_class (name);
606 set_type_dbg_info(res, db);
609 INLINE void free_class_attrs(type *clss) {
610 assert(clss && (clss->type_op == type_class));
611 DEL_ARR_F(clss->attr.ca.members);
612 DEL_ARR_F(clss->attr.ca.subtypes);
613 DEL_ARR_F(clss->attr.ca.supertypes);
616 /* manipulate private fields of class type */
617 void add_class_member (type *clss, entity *member) {
618 assert(clss && (clss->type_op == type_class));
619 ARR_APP1 (entity *, clss->attr.ca.members, member);
621 int get_class_n_members (type *clss) {
622 assert(clss && (clss->type_op == type_class));
623 return (ARR_LEN (clss->attr.ca.members))-1;
625 int get_class_member_index(type *clss, entity *mem) {
627 assert(clss && (clss->type_op == type_class));
628 for (i = 0; i < get_class_n_members(clss); i++)
629 if (get_class_member(clss, i) == mem)
633 entity *get_class_member (type *clss, int pos) {
634 assert(clss && (clss->type_op == type_class));
635 assert(pos >= 0 && pos < get_class_n_members(clss));
636 return clss->attr.ca.members[pos+1];
638 void set_class_member (type *clss, entity *member, int pos) {
639 assert(clss && (clss->type_op == type_class));
640 assert(pos >= 0 && pos < get_class_n_members(clss));
641 clss->attr.ca.members[pos+1] = member;
643 void set_class_members (type *clss, entity **members, int arity) {
645 assert(clss && (clss->type_op == type_class));
646 DEL_ARR_F(clss->attr.ca.members);
647 clss->attr.ca.members = NEW_ARR_F (entity *, 1);
648 for (i = 0; i < arity; i++) {
649 set_entity_owner(members[i], clss);
650 ARR_APP1 (entity *, clss->attr.ca.members, members[i]);
653 void remove_class_member(type *clss, entity *member) {
655 assert(clss && (clss->type_op == type_class));
656 for (i = 1; i < (ARR_LEN (clss->attr.ca.members)); i++) {
657 if (clss->attr.ca.members[i] == member) {
658 for(; i < (ARR_LEN (clss->attr.ca.members)) - 1; i++)
659 clss->attr.ca.members[i] = clss->attr.ca.members[i + 1];
660 ARR_SETLEN(entity*, clss->attr.ca.members, ARR_LEN(clss->attr.ca.members) - 1);
666 void add_class_subtype (type *clss, type *subtype) {
668 assert(clss && (clss->type_op == type_class));
669 ARR_APP1 (type *, clss->attr.ca.subtypes, subtype);
670 for (i = 0; i < get_class_n_supertypes(subtype); i++)
671 if (get_class_supertype(subtype, i) == clss)
672 /* Class already registered */
674 ARR_APP1 (type *, subtype->attr.ca.supertypes, clss);
676 int get_class_n_subtypes (type *clss) {
677 assert(clss && (clss->type_op == type_class));
678 return (ARR_LEN (clss->attr.ca.subtypes))-1;
680 type *get_class_subtype (type *clss, int pos) {
681 assert(clss && (clss->type_op == type_class));
682 assert(pos >= 0 && pos < get_class_n_subtypes(clss));
683 return clss->attr.ca.subtypes[pos+1] = skip_tid(clss->attr.ca.subtypes[pos+1]);
685 void set_class_subtype (type *clss, type *subtype, int pos) {
686 assert(clss && (clss->type_op == type_class));
687 assert(pos >= 0 && pos < get_class_n_subtypes(clss));
688 clss->attr.ca.subtypes[pos+1] = subtype;
690 void remove_class_subtype(type *clss, type *subtype) {
692 assert(clss && (clss->type_op == type_class));
693 for (i = 1; i < (ARR_LEN (clss->attr.ca.subtypes)); i++)
694 if (clss->attr.ca.subtypes[i] == subtype) {
695 for(; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
696 clss->attr.ca.subtypes[i] = clss->attr.ca.subtypes[i+1];
697 ARR_SETLEN(entity*, clss->attr.ca.subtypes, ARR_LEN(clss->attr.ca.subtypes) - 1);
702 void add_class_supertype (type *clss, type *supertype) {
704 assert(clss && (clss->type_op == type_class));
705 assert(supertype && (supertype -> type_op == type_class));
706 ARR_APP1 (type *, clss->attr.ca.supertypes, supertype);
707 for (i = 0; i < get_class_n_subtypes(supertype); i++)
708 if (get_class_subtype(supertype, i) == clss)
709 /* Class already registered */
711 ARR_APP1 (type *, supertype->attr.ca.subtypes, clss);
713 int get_class_n_supertypes (type *clss) {
714 assert(clss && (clss->type_op == type_class));
715 return (ARR_LEN (clss->attr.ca.supertypes))-1;
717 int get_class_supertype_index(type *clss, type *super_clss) {
719 assert(clss && (clss->type_op == type_class));
720 assert(super_clss && (super_clss->type_op == type_class));
721 for (i = 0; i < get_class_n_supertypes(clss); i++)
722 if (get_class_supertype(clss, i) == super_clss)
726 type *get_class_supertype (type *clss, int pos) {
727 assert(clss && (clss->type_op == type_class));
728 assert(pos >= 0 && pos < get_class_n_supertypes(clss));
729 return clss->attr.ca.supertypes[pos+1] = skip_tid(clss->attr.ca.supertypes[pos+1]);
731 void set_class_supertype (type *clss, type *supertype, int pos) {
732 assert(clss && (clss->type_op == type_class));
733 assert(pos >= 0 && pos < get_class_n_supertypes(clss));
734 clss->attr.ca.supertypes[pos+1] = supertype;
736 void remove_class_supertype(type *clss, type *supertype) {
738 assert(clss && (clss->type_op == type_class));
739 for (i = 1; i < (ARR_LEN (clss->attr.ca.supertypes)); i++)
740 if (clss->attr.ca.supertypes[i] == supertype) {
741 for(; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
742 clss->attr.ca.supertypes[i] = clss->attr.ca.supertypes[i+1];
743 ARR_SETLEN(entity*, clss->attr.ca.supertypes, ARR_LEN(clss->attr.ca.supertypes) - 1);
748 char *get_peculiarity_string(peculiarity p) {
749 if (p == peculiarity_description)
750 return "peculiarity_description";
751 if (p == peculiarity_inherited)
752 return "peculiarity_inherited";
753 return "peculiarity_existent";
756 INLINE peculiarity get_class_peculiarity (type *clss) {
757 assert(clss && (clss->type_op == type_class));
758 return clss->attr.ca.peculiarity;
760 INLINE void set_class_peculiarity (type *clss, peculiarity pec) {
761 assert(clss && (clss->type_op == type_class));
762 assert(pec != peculiarity_inherited); /* There is no inheritance of types in libFirm. */
763 clss->attr.ca.peculiarity = pec;
766 void set_class_dfn (type *clss, int dfn)
768 clss->attr.ca.dfn = dfn;
771 int get_class_dfn (type *clss)
773 return (clss->attr.ca.dfn);
777 bool is_class_type(type *clss) {
779 if (clss->type_op == type_class) return 1; else return 0;
782 bool is_subclass_of(type *low, type *high) {
784 assert(is_class_type(low) && is_class_type(high));
785 if (low == high) return true;
786 /* depth first search from high downwards. */
787 for (i = 0; i < get_class_n_subtypes(high); i++) {
788 if (low == get_class_subtype(high, i))
790 if (is_subclass_of(low, get_class_subtype(high, i)))
796 /*******************************************************************/
798 /*******************************************************************/
800 /* create a new type struct */
801 INLINE type *new_type_struct (ident *name) {
803 res = new_type(type_struct, NULL, name);
804 res->attr.sa.members = NEW_ARR_F (entity *, 1);
807 type *new_d_type_struct (ident *name, dbg_info* db) {
808 type *res = new_type_struct (name);
809 set_type_dbg_info(res, db);
812 INLINE void free_struct_attrs (type *strct) {
813 assert(strct && (strct->type_op == type_struct));
814 DEL_ARR_F(strct->attr.sa.members);
817 /* manipulate private fields of struct */
818 int get_struct_n_members (type *strct) {
819 assert(strct && (strct->type_op == type_struct));
820 return (ARR_LEN (strct->attr.sa.members))-1;
822 void add_struct_member (type *strct, entity *member) {
823 assert(strct && (strct->type_op == type_struct));
824 assert(get_type_tpop(get_entity_type(member)) != type_method);
825 /* @@@ lowerfirm geht nicht durch */
826 ARR_APP1 (entity *, strct->attr.sa.members, member);
828 entity *get_struct_member (type *strct, int pos) {
829 assert(strct && (strct->type_op == type_struct));
830 assert(pos >= 0 && pos < get_struct_n_members(strct));
831 return strct->attr.sa.members[pos+1];
833 void set_struct_member (type *strct, int pos, entity *member) {
834 assert(strct && (strct->type_op == type_struct));
835 assert(pos >= 0 && pos < get_struct_n_members(strct));
836 assert(get_entity_type(member)->type_op != type_method);/* @@@ lowerfirm !!*/
837 strct->attr.sa.members[pos+1] = member;
839 void remove_struct_member(type *strct, entity *member) {
841 assert(strct && (strct->type_op == type_struct));
842 for (i = 1; i < (ARR_LEN (strct->attr.sa.members)); i++)
843 if (strct->attr.sa.members[i] == member) {
844 for(; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
845 strct->attr.sa.members[i] = strct->attr.sa.members[i+1];
846 ARR_SETLEN(entity*, strct->attr.sa.members, ARR_LEN(strct->attr.sa.members) - 1);
852 bool is_struct_type(type *strct) {
854 if (strct->type_op == type_struct) return 1; else return 0;
857 /*******************************************************************/
859 /*******************************************************************/
861 /* Lazy construction of value argument / result representation. */
863 build_value_type(ident *name, int len, type **tps) {
865 type *res = new_type_struct(name);
866 /* Remove type from type list. Must be treated differently than other types. */
867 remove_irp_type_from_list(res);
868 for (i = 0; i < len; i++) {
869 type *elt_type = res; /* use res as default if corresponding type is not yet set. */
870 if (tps[i]) elt_type = tps[i];
871 new_entity(res, mangle_u(name, get_type_ident(elt_type)), elt_type);
876 /* Create a new method type.
877 N_param is the number of parameters, n_res the number of results. */
878 INLINE type *new_type_method (ident *name, int n_param, int n_res) {
880 res = new_type(type_method, mode_P_mach, name);
881 res->state = layout_fixed;
882 assert((get_mode_size_bytes(mode_P_mach) != -1) && "unorthodox modes not implemented");
883 res->size = get_mode_size_bytes(mode_P_mach);
884 res->attr.ma.n_params = n_param;
885 res->attr.ma.param_type = (type **) xmalloc (sizeof (type *) * n_param);
886 res->attr.ma.value_params = NULL;
887 res->attr.ma.n_res = n_res;
888 res->attr.ma.res_type = (type **) xmalloc (sizeof (type *) * n_res);
889 res->attr.ma.value_ress = NULL;
890 res->attr.ma.variadicity = variadicity_non_variadic;
895 type *new_d_type_method (ident *name, int n_param, int n_res, dbg_info* db) {
896 type *res = new_type_method (name, n_param, n_res);
897 set_type_dbg_info(res, db);
901 INLINE void free_method_attrs(type *method) {
902 assert(method && (method->type_op == type_method));
903 free(method->attr.ma.param_type);
904 free(method->attr.ma.res_type);
907 /* manipulate private fields of method. */
908 int get_method_n_params (type *method) {
909 assert(method && (method->type_op == type_method));
910 return method->attr.ma.n_params;
912 type *get_method_param_type(type *method, int pos) {
913 assert(method && (method->type_op == type_method));
914 assert(pos >= 0 && pos < get_method_n_params(method));
915 return method->attr.ma.param_type[pos] = skip_tid(method->attr.ma.param_type[pos]);
917 void set_method_param_type(type *method, int pos, type* tp) {
918 assert(method && (method->type_op == type_method));
919 assert(pos >= 0 && pos < get_method_n_params(method));
920 method->attr.ma.param_type[pos] = tp;
921 /* If information constructed set pass-by-value representation. */
922 if (method->attr.ma.value_params) {
923 assert(get_method_n_params(method) == get_struct_n_members(method->attr.ma.value_params));
924 set_entity_type(get_struct_member(method->attr.ma.value_params, pos), tp);
927 /* Returns an entity that represents the copied value argument. Only necessary
928 for compounds passed by value. */
929 entity *get_method_value_param_ent(type *method, int pos) {
930 assert(method && (method->type_op == type_method));
931 assert(pos >= 0 && pos < get_method_n_params(method));
932 if (!method->attr.ma.value_params)
933 method->attr.ma.value_params
934 = build_value_type(mangle_u(get_type_ident(method), value_params_suffix),
935 get_method_n_params(method), method->attr.ma.param_type);
936 assert((get_entity_type(get_struct_member(method->attr.ma.value_params, pos))
937 != method->attr.ma.value_params)
938 && "param type not yet set");
939 return get_struct_member(method->attr.ma.value_params, pos);
942 type *get_method_value_res_type(type *method) {
943 assert(method && (method->type_op == type_method));
944 return method->attr.ma.value_params;
948 int get_method_n_ress (type *method) {
949 assert(method && (method->type_op == type_method));
950 return method->attr.ma.n_res;
952 type *get_method_res_type(type *method, int pos) {
953 assert(method && (method->type_op == type_method));
954 assert(pos >= 0 && pos < get_method_n_ress(method));
955 return method->attr.ma.res_type[pos] = skip_tid(method->attr.ma.res_type[pos]);
957 void set_method_res_type(type *method, int pos, type* tp) {
958 assert(method && (method->type_op == type_method));
959 assert(pos >= 0 && pos < get_method_n_ress(method));
960 /* set the result type */
961 method->attr.ma.res_type[pos] = tp;
962 /* If information constructed set pass-by-value representation. */
963 if (method->attr.ma.value_ress) {
964 assert(get_method_n_ress(method) == get_struct_n_members(method->attr.ma.value_ress));
965 set_entity_type(get_struct_member(method->attr.ma.value_ress, pos), tp);
968 /* Returns an entity that represents the copied value result. Only necessary
969 for compounds passed by value. */
970 entity *get_method_value_res_ent(type *method, int pos) {
971 assert(method && (method->type_op == type_method));
972 assert(pos >= 0 && pos < get_method_n_ress(method));
973 if (!method->attr.ma.value_ress)
974 method->attr.ma.value_ress
975 = build_value_type(mangle_u(get_type_ident(method), value_ress_suffix),
976 get_method_n_ress(method), method->attr.ma.res_type);
977 assert((get_entity_type(get_struct_member(method->attr.ma.value_ress, pos)) != method->attr.ma.value_ress)
978 && "result type not yet set");
979 return get_struct_member(method->attr.ma.value_ress, pos);
982 /* Returns the null-terminated name of this variadicity. */
983 const char *get_variadicity_name(variadicity vari)
985 #define X(a) case a: return #a
987 X(variadicity_non_variadic);
988 X(variadicity_variadic);
995 variadicity get_method_variadicity(type *method)
997 assert(method && (method->type_op == type_method));
998 return method->attr.ma.variadicity;
1001 void set_method_variadicity(type *method, variadicity vari)
1003 assert(method && (method->type_op == type_method));
1004 method->attr.ma.variadicity = vari;
1008 bool is_method_type (type *method) {
1010 if (method->type_op == type_method) return 1; else return 0;
1013 /*******************************************************************/
1015 /*******************************************************************/
1017 /* create a new type uni */
1018 INLINE type *new_type_union (ident *name) {
1020 res = new_type(type_union, NULL, name);
1021 /*res->attr.ua.unioned_type = (type **) xmalloc (sizeof (type *) * n_types);
1022 res->attr.ua.delim_names = (ident **) xmalloc (sizeof (ident *) * n_types); */
1023 res->attr.ua.members = NEW_ARR_F (entity *, 1);
1026 type *new_d_type_union (ident *name, dbg_info* db) {
1027 type *res = new_type_union (name);
1028 set_type_dbg_info(res, db);
1031 INLINE void free_union_attrs (type *uni) {
1032 assert(uni && (uni->type_op == type_union));
1033 DEL_ARR_F(uni->attr.ua.members);
1035 /* manipulate private fields of union */
1037 int get_union_n_types (type *uni) {
1038 assert(uni && (uni->type_op == type_union));
1039 return uni->attr.ua.n_types;
1041 type *get_union_unioned_type (type *uni, int pos) {
1042 assert(uni && (uni->type_op == type_union));
1043 assert(pos >= 0 && pos < get_union_n_types(uni));
1044 return uni->attr.ua.unioned_type[pos] = skip_tid(uni->attr.ua.unioned_type[pos]);
1046 void set_union_unioned_type (type *uni, int pos, type *tp) {
1047 assert(uni && (uni->type_op == type_union));
1048 assert(pos >= 0 && pos < get_union_n_types(uni));
1049 uni->attr.ua.unioned_type[pos] = tp;
1051 ident *get_union_delim_nameid (type *uni, int pos) {
1052 assert(uni && (uni->type_op == type_union));
1053 assert(pos >= 0 && pos < get_union_n_types(uni));
1054 return uni->attr.ua.delim_names[pos];
1056 const char *get_union_delim_name (type *uni, int pos) {
1057 assert(uni && (uni->type_op == type_union));
1058 assert(pos >= 0 && pos < get_union_n_types(uni));
1059 return get_id_str(uni->attr.ua.delim_names[pos]);
1061 void set_union_delim_nameid (type *uni, int pos, ident *id) {
1062 assert(uni && (uni->type_op == type_union));
1063 assert(pos >= 0 && pos < get_union_n_types(uni));
1064 uni->attr.ua.delim_names[pos] = id;
1067 int get_union_n_members (type *uni) {
1068 assert(uni && (uni->type_op == type_union));
1069 return (ARR_LEN (uni->attr.ua.members))-1;
1071 void add_union_member (type *uni, entity *member) {
1072 assert(uni && (uni->type_op == type_union));
1073 ARR_APP1 (entity *, uni->attr.ua.members, member);
1075 entity *get_union_member (type *uni, int pos) {
1076 assert(uni && (uni->type_op == type_union));
1077 assert(pos >= 0 && pos < get_union_n_members(uni));
1078 return uni->attr.ua.members[pos+1];
1080 void set_union_member (type *uni, int pos, entity *member) {
1081 assert(uni && (uni->type_op == type_union));
1082 assert(pos >= 0 && pos < get_union_n_members(uni));
1083 uni->attr.ua.members[pos+1] = member;
1085 void remove_union_member(type *uni, entity *member) {
1087 assert(uni && (uni->type_op == type_union));
1088 for (i = 1; i < (ARR_LEN (uni->attr.ua.members)); i++)
1089 if (uni->attr.ua.members[i] == member) {
1090 for(; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
1091 uni->attr.ua.members[i] = uni->attr.ua.members[i+1];
1092 ARR_SETLEN(entity*, uni->attr.ua.members, ARR_LEN(uni->attr.ua.members) - 1);
1098 bool is_union_type (type *uni) {
1100 if (uni->type_op == type_union) return 1; else return 0;
1103 /*******************************************************************/
1105 /*******************************************************************/
1108 /* create a new type array -- set dimension sizes independently */
1109 INLINE type *new_type_array (ident *name, int n_dimensions,
1110 type *element_type) {
1113 ir_graph *rem = current_ir_graph;
1114 assert(!is_method_type(element_type));
1116 res = new_type(type_array, NULL, name);
1117 res->attr.aa.n_dimensions = n_dimensions;
1118 res->attr.aa.lower_bound = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
1119 res->attr.aa.upper_bound = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
1120 res->attr.aa.order = (int *) xmalloc (sizeof (int) * n_dimensions);
1122 current_ir_graph = get_const_code_irg();
1123 for (i = 0; i < n_dimensions; i++) {
1124 res->attr.aa.lower_bound[i] = new_Unknown();
1125 res->attr.aa.upper_bound[i] = new_Unknown();
1126 res->attr.aa.order[i] = i;
1128 current_ir_graph = rem;
1130 res->attr.aa.element_type = element_type;
1131 new_entity(res, mangle_u(name, id_from_str("elem_ent", 8)), element_type);
1135 type *new_d_type_array (ident *name, int n_dimensions,
1136 type *element_type, dbg_info* db) {
1137 type *res = new_type_array (name, n_dimensions, element_type);
1138 set_type_dbg_info(res, db);
1142 INLINE void free_array_attrs (type *array) {
1143 assert(array && (array->type_op == type_array));
1144 free(array->attr.aa.lower_bound);
1145 free(array->attr.aa.upper_bound);
1148 /* manipulate private fields of array type */
1149 int get_array_n_dimensions (type *array) {
1150 assert(array && (array->type_op == type_array));
1151 return array->attr.aa.n_dimensions;
1155 set_array_bounds (type *array, int dimension, ir_node * lower_bound,
1156 ir_node * upper_bound) {
1157 assert(array && (array->type_op == type_array));
1158 assert(lower_bound && "lower_bound node may not be NULL.");
1159 assert(upper_bound && "upper_bound node may not be NULL.");
1160 assert(dimension < array->attr.aa.n_dimensions && dimension >= 0);
1161 array->attr.aa.lower_bound[dimension] = lower_bound;
1162 array->attr.aa.upper_bound[dimension] = upper_bound;
1165 set_array_bounds_int (type *array, int dimension, int lower_bound,
1167 ir_graph *rem = current_ir_graph;
1168 current_ir_graph = get_const_code_irg();
1169 set_array_bounds (array, dimension,
1170 new_Const(mode_Iu, new_tarval_from_long (lower_bound, mode_Iu)),
1171 new_Const(mode_Iu, new_tarval_from_long (upper_bound, mode_Iu )));
1172 current_ir_graph = rem;
1175 set_array_lower_bound (type *array, int dimension, ir_node * lower_bound) {
1176 assert(array && (array->type_op == type_array));
1177 assert(lower_bound && "lower_bound node may not be NULL.");
1178 array->attr.aa.lower_bound[dimension] = lower_bound;
1180 void set_array_lower_bound_int (type *array, int dimension, int lower_bound) {
1181 ir_graph *rem = current_ir_graph;
1182 current_ir_graph = get_const_code_irg();
1183 set_array_lower_bound (array, dimension,
1184 new_Const(mode_Iu, new_tarval_from_long (lower_bound, mode_Iu)));
1185 current_ir_graph = rem;
1188 set_array_upper_bound (type *array, int dimension, ir_node * upper_bound) {
1189 assert(array && (array->type_op == type_array));
1190 assert(upper_bound && "upper_bound node may not be NULL.");
1191 array->attr.aa.upper_bound[dimension] = upper_bound;
1193 void set_array_upper_bound_int (type *array, int dimension, int upper_bound) {
1194 ir_graph *rem = current_ir_graph;
1195 current_ir_graph = get_const_code_irg();
1196 set_array_upper_bound (array, dimension,
1197 new_Const(mode_Iu, new_tarval_from_long (upper_bound, mode_Iu)));
1198 current_ir_graph = rem;
1200 int has_array_lower_bound (type *array, int dimension) {
1201 assert(array && (array->type_op == type_array));
1202 return (get_irn_op(array->attr.aa.lower_bound[dimension]) != op_Unknown);
1204 ir_node * get_array_lower_bound (type *array, int dimension) {
1205 assert(array && (array->type_op == type_array));
1206 return array->attr.aa.lower_bound[dimension];
1208 int has_array_upper_bound (type *array, int dimension) {
1209 assert(array && (array->type_op == type_array));
1210 return (get_irn_op(array->attr.aa.upper_bound[dimension]) != op_Unknown);
1212 ir_node * get_array_upper_bound (type *array, int dimension) {
1213 assert(array && (array->type_op == type_array));
1214 return array->attr.aa.upper_bound[dimension];
1217 void set_array_order (type *array, int dimension, int order) {
1218 assert(array && (array->type_op == type_array));
1219 array->attr.aa.order[dimension] = order;
1221 int get_array_order (type *array, int dimension) {
1222 assert(array && (array->type_op == type_array));
1223 return array->attr.aa.order[dimension];
1226 void set_array_element_type (type *array, type *tp) {
1227 assert(array && (array->type_op == type_array));
1228 assert(!is_method_type(tp));
1229 array->attr.aa.element_type = tp;
1231 type *get_array_element_type (type *array) {
1232 assert(array && (array->type_op == type_array));
1233 return array->attr.aa.element_type = skip_tid(array->attr.aa.element_type);
1236 void set_array_element_entity (type *array, entity *ent) {
1237 assert(array && (array->type_op == type_array));
1238 assert((get_entity_type(ent)->type_op != type_method));
1239 array->attr.aa.element_ent = ent;
1240 array->attr.aa.element_type = get_entity_type(ent);
1242 entity *get_array_element_entity (type *array) {
1243 assert(array && (array->type_op == type_array));
1244 return array->attr.aa.element_ent;
1248 bool is_array_type (type *array) {
1250 if (array->type_op == type_array) return 1; else return 0;
1253 /*******************************************************************/
1254 /** TYPE_ENUMERATION **/
1255 /*******************************************************************/
1257 /* create a new type enumeration -- set the enumerators independently */
1258 INLINE type *new_type_enumeration (ident *name, int n_enums) {
1261 res = new_type(type_enumeration, NULL, name);
1262 res->attr.ea.n_enums = n_enums;
1263 res->attr.ea.enumer = (tarval **) xmalloc (sizeof (tarval *) * n_enums);
1264 res->attr.ea.enum_nameid = (ident **) xmalloc (sizeof (ident *) * n_enums);
1265 for (i = 0; i < n_enums; i++) {
1266 res->attr.ea.enumer[i] = NULL;
1267 res->attr.ea.enum_nameid = NULL;
1271 type *new_d_type_enumeration (ident *name, int n_enums, dbg_info* db) {
1272 type *res = new_type_enumeration (name, n_enums);
1273 set_type_dbg_info(res, db);
1277 INLINE void free_enumeration_attrs(type *enumeration) {
1278 assert(enumeration && (enumeration->type_op == type_enumeration));
1279 free(enumeration->attr.ea.enumer);
1280 free(enumeration->attr.ea.enum_nameid);
1283 /* manipulate fields of enumeration type. */
1284 int get_enumeration_n_enums (type *enumeration) {
1285 assert(enumeration && (enumeration->type_op == type_enumeration));
1286 return enumeration->attr.ea.n_enums;
1288 void set_enumeration_enum (type *enumeration, int pos, tarval *con) {
1289 assert(enumeration && (enumeration->type_op == type_enumeration));
1290 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1291 enumeration->attr.ea.enumer[pos] = con;
1293 tarval *get_enumeration_enum (type *enumeration, int pos) {
1294 assert(enumeration && (enumeration->type_op == type_enumeration));
1295 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1296 return enumeration->attr.ea.enumer[pos];
1298 void set_enumeration_nameid (type *enumeration, int pos, ident *id) {
1299 assert(enumeration && (enumeration->type_op == type_enumeration));
1300 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1301 enumeration->attr.ea.enum_nameid[pos] = id;
1303 ident *get_enumeration_nameid (type *enumeration, int pos) {
1304 assert(enumeration && (enumeration->type_op == type_enumeration));
1305 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1306 return enumeration->attr.ea.enum_nameid[pos];
1308 const char *get_enumeration_name(type *enumeration, int pos) {
1309 assert(enumeration && (enumeration->type_op == type_enumeration));
1310 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1311 return get_id_str(enumeration->attr.ea.enum_nameid[pos]);
1315 bool is_enumeration_type (type *enumeration) {
1316 assert(enumeration);
1317 if (enumeration->type_op == type_enumeration) return 1; else return 0;
1320 /*******************************************************************/
1321 /** TYPE_POINTER **/
1322 /*******************************************************************/
1324 /* Create a new type pointer */
1325 INLINE type *new_type_pointer_mode (ident *name, type *points_to, ir_mode *ptr_mode) {
1327 assert(mode_is_reference(ptr_mode));
1328 res = new_type(type_pointer, ptr_mode, name);
1329 res->attr.pa.points_to = points_to;
1330 assert((get_mode_size_bytes(res->mode) != -1) && "unorthodox modes not implemented");
1331 res->size = get_mode_size_bytes(res->mode);
1332 res->state = layout_fixed;
1335 type *new_d_type_pointer (ident *name, type *points_to, ir_mode *ptr_mode, dbg_info* db) {
1336 type *res = new_type_pointer_mode (name, points_to, ptr_mode);
1337 set_type_dbg_info(res, db);
1340 INLINE void free_pointer_attrs (type *pointer) {
1341 assert(pointer && (pointer->type_op == type_pointer));
1343 /* manipulate fields of type_pointer */
1344 void set_pointer_points_to_type (type *pointer, type *tp) {
1345 assert(pointer && (pointer->type_op == type_pointer));
1346 pointer->attr.pa.points_to = tp;
1348 type *get_pointer_points_to_type (type *pointer) {
1349 assert(pointer && (pointer->type_op == type_pointer));
1350 return pointer->attr.pa.points_to = skip_tid(pointer->attr.pa.points_to);
1354 bool is_pointer_type (type *pointer) {
1356 if (pointer->type_op == type_pointer) return 1; else return 0;
1359 /* Returns the first pointer type that has as points_to tp.
1360 * Not efficient: O(#types).
1361 * If not found returns unknown_type. */
1362 type *find_pointer_type_to_type (type *tp) {
1364 for (i = 0; i < get_irp_n_types(); ++i) {
1365 type *found = get_irp_type(i);
1366 if (is_pointer_type(found) && get_pointer_points_to_type(found) == tp)
1369 return unknown_type;
1374 /*******************************************************************/
1375 /** TYPE_PRIMITIVE **/
1376 /*******************************************************************/
1378 /* create a new type primitive */
1379 INLINE type *new_type_primitive (ident *name, ir_mode *mode) {
1381 /* @@@ assert( mode_is_data(mode) && (!mode_is_reference(mode))); */
1382 res = new_type(type_primitive, mode, name);
1383 assert((get_mode_size_bytes(mode) != -1) && "unorthodox modes not implemented");
1384 res->size = get_mode_size_bytes(mode);
1385 res->state = layout_fixed;
1388 type *new_d_type_primitive (ident *name, ir_mode *mode, dbg_info* db) {
1389 type *res = new_type_primitive (name, mode);
1390 set_type_dbg_info(res, db);
1393 INLINE void free_primitive_attrs (type *primitive) {
1394 assert(primitive && (primitive->type_op == type_primitive));
1398 bool is_primitive_type (type *primitive) {
1399 assert(primitive && primitive->kind == k_type);
1400 if (primitive->type_op == type_primitive) return 1; else return 0;
1403 /*******************************************************************/
1404 /** common functionality **/
1405 /*******************************************************************/
1408 INLINE int is_atomic_type(type *tp) {
1409 assert(tp && tp->kind == k_type);
1410 return (is_primitive_type(tp) || is_pointer_type(tp) ||
1411 is_enumeration_type(tp));
1415 * Gets the number of elements in a firm compound type.
1417 int get_compound_n_members(type *tp)
1421 if (is_struct_type(tp))
1422 res = get_struct_n_members(tp);
1423 else if (is_class_type(tp))
1424 res = get_class_n_members(tp);
1425 else if (is_union_type(tp))
1426 res = get_union_n_members(tp);
1428 assert(0 && "need struct, union or class for member count");
1434 * Gets the member of a firm compound type at position pos.
1436 entity *get_compound_member(type *tp, int pos)
1440 if (is_struct_type(tp))
1441 res = get_struct_member(tp, pos);
1442 else if (is_class_type(tp))
1443 res = get_class_member(tp, pos);
1444 else if (is_union_type(tp))
1445 res = get_union_member(tp, pos);
1448 assert(0 && "need struct, union or class to get a member");
1456 INLINE int is_compound_type(type *tp) {
1457 assert(tp && tp->kind == k_type);
1458 return (is_class_type(tp) || is_struct_type(tp) ||
1459 is_array_type(tp) || is_union_type(tp));