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... */
108 new_type(tp_op *type_op, ir_mode *mode, ident* name) {
112 assert(type_op != type_id);
113 assert(!id_contains_char(name, ' ') && "type name should not contain spaces");
115 node_size = offsetof (type, attr) + type_op->attr_size;
116 res = (type *) xmalloc (node_size);
117 add_irp_type(res); /* Remember the new type global. */
120 res->type_op = type_op;
123 res->state = layout_undefined;
128 res->nr = get_irp_new_node_nr();
134 void free_type_attrs(type *tp) {
135 switch(get_type_tpop_code(tp)) {
136 case tpo_class: { free_class_attrs(tp); } break;
137 case tpo_struct: { free_struct_attrs(tp); } break;
138 case tpo_method: { free_method_attrs(tp); } break;
139 case tpo_union: { free_union_attrs(tp); } break;
140 case tpo_array: { free_array_attrs(tp); } break;
141 case tpo_enumeration: { free_enumeration_attrs(tp); } break;
142 case tpo_pointer: { free_pointer_attrs(tp); } break;
143 case tpo_primitive: { free_primitive_attrs(tp); } break;
148 /* set/get the link field */
149 void *get_type_link(type *tp)
151 assert(tp && tp->kind == k_type);
155 void set_type_link(type *tp, void *l)
157 assert(tp && tp->kind == k_type);
161 tp_op* get_type_tpop(type *tp) {
162 assert(tp && tp->kind == k_type);
166 ident* get_type_tpop_nameid(type *tp) {
167 assert(tp && tp->kind == k_type);
168 return tp->type_op->name;
171 const char* get_type_tpop_name(type *tp) {
172 assert(tp && tp->kind == k_type);
173 return get_id_str(tp->type_op->name);
176 tp_opcode get_type_tpop_code(type *tp) {
177 assert(tp && tp->kind == k_type);
178 return tp->type_op->code;
181 ir_mode* get_type_mode(type *tp) {
182 assert(tp && tp->kind == k_type);
186 void set_type_mode(type *tp, ir_mode* m) {
187 assert(tp && tp->kind == k_type);
189 assert(((tp->type_op != type_primitive) || mode_is_data(m)) &&
190 /* Modes of primitives must be data */
191 ((tp->type_op != type_enumeration) || mode_is_int(m)) &&
192 /* Modes of enumerations must be integers */
193 ((tp->type_op != type_pointer) || mode_is_reference(m)) );
194 /* Modes of pointers must be references. */
196 if ((tp->type_op == type_primitive) ||
197 (tp->type_op == type_enumeration) ||
198 (tp->type_op == type_pointer) ) {
199 /* For pointer, primitive and enumeration size depends on the mode. */
200 assert((get_mode_size_bytes(m) != -1) && "unorthodox modes not implemented");
201 tp->size = get_mode_size_bytes(m);
206 ident* get_type_ident(type *tp) {
207 assert(tp && tp->kind == k_type);
211 void set_type_ident(type *tp, ident* id) {
212 assert(tp && tp->kind == k_type);
216 /* Outputs a unique number for this node */
218 get_type_nr(type *tp) {
227 const char* get_type_name(type *tp) {
228 assert(tp && tp->kind == k_type);
229 return (get_id_str(tp->name));
232 int get_type_size(type *tp) {
233 assert(tp && tp->kind == k_type);
238 set_type_size(type *tp, int size) {
239 assert(tp && tp->kind == k_type);
240 /* For pointer enumeration and primitive size depends on the mode.
241 Methods don't have a size. */
242 if ((tp->type_op != type_pointer) && (tp->type_op != type_primitive) &&
243 (tp->type_op != type_enumeration) && (tp->type_op != type_method))
248 get_type_state(type *tp) {
249 assert(tp && tp->kind == k_type);
254 set_type_state(type *tp, type_state state) {
255 assert(tp && tp->kind == k_type);
257 if ((tp->type_op == type_pointer) || (tp->type_op == type_primitive) ||
258 (tp->type_op == type_method))
261 /* Just a correctness check: */
262 if (state == layout_fixed) {
264 switch (get_type_tpop_code(tp)) {
267 assert(get_type_size(tp) > -1);
268 if (tp != get_glob_type())
269 for (i = 0; i < get_class_n_members(tp); i++) {
270 if (get_entity_offset(get_class_member(tp, i)) <= -1)
271 { DDMT(tp); DDME(get_class_member(tp, i)); }
272 assert(get_entity_offset(get_class_member(tp, i)) > -1);
273 assert(is_method_type(get_entity_type(get_class_member(tp, i))) ||
274 (get_entity_allocation(get_class_member(tp, i)) == allocation_automatic));
279 assert(get_type_size(tp) > -1);
280 for (i = 0; i < get_struct_n_members(tp); i++) {
281 assert(get_entity_offset(get_struct_member(tp, i)) > -1);
282 assert((get_entity_allocation(get_struct_member(tp, i)) == allocation_automatic));
291 Assure that only innermost dimension is dynamic? */
293 case tpo_enumeration:
295 assert(get_type_mode != NULL);
296 for (i = 0; i < get_enumeration_n_enums(tp); i++)
297 assert(get_enumeration_enum(tp, i) != NULL);
305 unsigned long get_type_visited(type *tp) {
306 assert(tp && tp->kind == k_type);
310 void set_type_visited(type *tp, unsigned long num) {
311 assert(tp && tp->kind == k_type);
314 /* Sets visited field in type to type_visited. */
315 void mark_type_visited(type *tp) {
316 assert(tp && tp->kind == k_type);
317 assert(tp->visit < type_visited);
318 tp->visit = type_visited;
320 /* @@@ name clash with master flag
321 bool type_visited(type *tp) {
322 assert(tp && tp->kind == k_type);
323 return tp->visit >= type_visited;
325 bool type_not_visited(type *tp) {
326 assert(tp && tp->kind == k_type);
327 return tp->visit < type_visited;
331 int is_type (void *thing) {
333 if (get_kind(thing) == k_type)
340 bool equal_type(type *typ1, type *typ2) {
345 if (typ1 == typ2) return true;
347 if ((get_type_tpop_code(typ1) != get_type_tpop_code(typ2)) ||
348 (get_type_ident(typ1) != get_type_ident(typ2)) ||
349 (get_type_mode(typ1) != get_type_mode(typ2)) ||
350 (get_type_state(typ1) != get_type_state(typ2)))
352 if ((get_type_state(typ1) == layout_fixed) &&
353 (get_type_size(typ1) != get_type_size(typ2)))
356 switch(get_type_tpop_code(typ1)) {
358 if (get_class_n_members(typ1) != get_class_n_members(typ2)) return false;
359 if (get_class_n_subtypes(typ1) != get_class_n_subtypes(typ2)) return false;
360 if (get_class_n_supertypes(typ1) != get_class_n_supertypes(typ2)) return false;
361 if (get_class_peculiarity(typ1) != get_class_peculiarity(typ2)) return false;
362 /** Compare the members **/
363 m = alloca(sizeof(entity *) * get_class_n_members(typ1));
364 memset(m, 0, sizeof(entity *) * get_class_n_members(typ1));
365 /* First sort the members of typ2 */
366 for (i = 0; i < get_class_n_members(typ1); i++) {
367 entity *e1 = get_class_member(typ1, i);
368 for (j = 0; j < get_class_n_members(typ2); j++) {
369 entity *e2 = get_class_member(typ2, j);
370 if (get_entity_name(e1) == get_entity_name(e2))
374 for (i = 0; i < get_class_n_members(typ1); i++) {
375 if (!m[i] || /* Found no counterpart */
376 !equal_entity(get_class_member(typ1, i), m[i]))
379 /** Compare the supertypes **/
380 t = alloca(sizeof(entity *) * get_class_n_supertypes(typ1));
381 memset(t, 0, sizeof(entity *) * get_class_n_supertypes(typ1));
382 /* First sort the supertypes of typ2 */
383 for (i = 0; i < get_class_n_supertypes(typ1); i++) {
384 type *t1 = get_class_supertype(typ1, i);
385 for (j = 0; j < get_class_n_supertypes(typ2); j++) {
386 type *t2 = get_class_supertype(typ2, j);
387 if (get_type_ident(t2) == get_type_ident(t1))
391 for (i = 0; i < get_class_n_supertypes(typ1); i++) {
392 if (!t[i] || /* Found no counterpart */
393 get_class_supertype(typ1, i) != t[i])
398 if (get_struct_n_members(typ1) != get_struct_n_members(typ2)) return false;
399 m = alloca(sizeof(entity *) * get_struct_n_members(typ1));
400 memset(m, 0, sizeof(entity *) * get_struct_n_members(typ1));
401 /* First sort the members of lt */
402 for (i = 0; i < get_struct_n_members(typ1); i++) {
403 entity *e1 = get_struct_member(typ1, i);
404 for (j = 0; j < get_struct_n_members(typ2); j++) {
405 entity *e2 = get_struct_member(typ2, j);
406 if (get_entity_name(e1) == get_entity_name(e2))
410 for (i = 0; i < get_struct_n_members(typ1); i++) {
411 if (!m[i] || /* Found no counterpart */
412 !equal_entity(get_struct_member(typ1, i), m[i]))
417 if (get_method_variadicity(typ1) != get_method_variadicity(typ2)) return false;
418 if (get_method_n_params(typ1) != get_method_n_params(typ2)) return false;
419 if (get_method_n_ress(typ1) != get_method_n_ress(typ2)) return false;
420 for (i = 0; i < get_method_n_params(typ1); i++) {
421 if (!equal_type(get_method_param_type(typ1, i), get_method_param_type(typ2, i)))
424 for (i = 0; i < get_method_n_ress(typ1); i++) {
425 if (!equal_type(get_method_res_type(typ1, i), get_method_res_type(typ2, i)))
430 if (get_union_n_members(typ1) != get_union_n_members(typ2)) return false;
431 m = alloca(sizeof(entity *) * get_union_n_members(typ1));
432 memset(m, 0, sizeof(entity *) * get_union_n_members(typ1));
433 /* First sort the members of lt */
434 for (i = 0; i < get_union_n_members(typ1); i++) {
435 entity *e1 = get_union_member(typ1, i);
436 for (j = 0; j < get_union_n_members(typ2); j++) {
437 entity *e2 = get_union_member(typ2, j);
438 if (get_entity_name(e1) == get_entity_name(e2))
442 for (i = 0; i < get_union_n_members(typ1); i++) {
443 if (!m[i] || /* Found no counterpart */
444 !equal_entity(get_union_member(typ1, i), m[i]))
449 if (get_array_n_dimensions(typ1) != get_array_n_dimensions(typ2))
451 if (!equal_type(get_array_element_type(typ1), get_array_element_type(typ2)))
453 for(i = 0; i < get_array_n_dimensions(typ1); i++) {
454 if (get_array_lower_bound(typ1, i) != get_array_lower_bound(typ2, i) ||
455 get_array_upper_bound(typ1, i) != get_array_upper_bound(typ2, i))
457 if (get_array_order(typ1, i) != get_array_order(typ2, i))
458 assert(0 && "type compare with different dimension orders not implemented");
461 case tpo_enumeration: {
462 assert(0 && "enumerations not implemented");
465 if (get_pointer_points_to_type(typ1) != get_pointer_points_to_type(typ2))
468 case tpo_primitive: {
475 bool smaller_type (type *st, type *lt) {
479 if (st == lt) return true;
481 if (get_type_tpop_code(st) != get_type_tpop_code(lt))
484 switch(get_type_tpop_code(st)) {
486 return is_subclass_of(st, lt);
489 if (get_struct_n_members(st) != get_struct_n_members(lt)) return false;
490 m = alloca(sizeof(entity *) * get_struct_n_members(st));
491 memset(m, 0, sizeof(entity *) * get_struct_n_members(st));
492 /* First sort the members of lt */
493 for (i = 0; i < get_struct_n_members(st); i++) {
494 entity *se = get_struct_member(st, i);
495 for (j = 0; j < get_struct_n_members(lt); j++) {
496 entity *le = get_struct_member(lt, j);
497 if (get_entity_name(le) == get_entity_name(se))
501 for (i = 0; i < get_struct_n_members(st); i++) {
502 if (!m[i] || /* Found no counterpart */
503 !smaller_type(get_entity_type(get_struct_member(st, i)),
504 get_entity_type(m[i])))
509 if (get_method_variadicity(st) != get_method_variadicity(lt)) return false;
510 if (get_method_n_params(st) != get_method_n_params(lt)) return false;
511 if (get_method_n_ress(st) != get_method_n_ress(lt)) return false;
512 for (i = 0; i < get_method_n_params(st); i++) {
513 if (!smaller_type(get_method_param_type(st, i), get_method_param_type(lt, i)))
516 for (i = 0; i < get_method_n_ress(st); i++) {
517 if (!smaller_type(get_method_res_type(st, i), get_method_res_type(lt, i)))
522 if (get_union_n_members(st) != get_union_n_members(lt)) return false;
523 m = alloca(sizeof(entity *) * get_union_n_members(st));
524 memset(m, 0, sizeof(entity *) * get_union_n_members(st));
525 /* First sort the members of lt */
526 for (i = 0; i < get_union_n_members(st); i++) {
527 entity *se = get_union_member(st, i);
528 for (j = 0; j < get_union_n_members(lt); j++) {
529 entity *le = get_union_member(lt, j);
530 if (get_entity_name(le) == get_entity_name(se))
534 for (i = 0; i < get_union_n_members(st); i++) {
535 if (!m[i] || /* Found no counterpart */
536 !smaller_type(get_entity_type(get_union_member(st, i)),
537 get_entity_type(m[i])))
542 type *set, *let; /* small/large elt. type */
543 if (get_array_n_dimensions(st) != get_array_n_dimensions(lt))
545 set = get_array_element_type(st);
546 let = get_array_element_type(lt);
548 /* If the elt types are different, set must be convertible
549 to let, and they must have the same size so that address
550 computations work out. To have a size the layout must
552 if ((get_type_state(set) != layout_fixed) ||
553 (get_type_state(let) != layout_fixed))
555 if (!smaller_type(set, let) ||
556 get_type_size(set) != get_type_size(let))
559 for(i = 0; i < get_array_n_dimensions(st); i++) {
560 if (get_array_lower_bound(lt, i))
561 if(get_array_lower_bound(st, i) != get_array_lower_bound(lt, i))
563 if (get_array_upper_bound(lt, i))
564 if(get_array_upper_bound(st, i) != get_array_upper_bound(lt, i))
568 case tpo_enumeration: {
569 assert(0 && "enumerations not implemented");
572 if (!smaller_type(get_pointer_points_to_type(st),
573 get_pointer_points_to_type(lt)))
576 case tpo_primitive: {
577 if (!smaller_mode(get_type_mode(st), get_type_mode(lt)))
585 /*******************************************************************/
587 /*******************************************************************/
589 /* create a new class type */
590 INLINE type *new_type_class (ident *name) {
593 res = new_type(type_class, NULL, name);
595 res->attr.ca.members = NEW_ARR_F (entity *, 1);
596 res->attr.ca.subtypes = NEW_ARR_F (type *, 1);
597 res->attr.ca.supertypes = NEW_ARR_F (type *, 1);
598 res->attr.ca.peculiarity = peculiarity_existent;
599 res->attr.ca.dfn = 0;
603 type *new_d_type_class (ident *name, dbg_info* db) {
604 type *res = new_type_class (name);
605 set_type_dbg_info(res, db);
608 INLINE void free_class_attrs(type *clss) {
609 assert(clss && (clss->type_op == type_class));
610 DEL_ARR_F(clss->attr.ca.members);
611 DEL_ARR_F(clss->attr.ca.subtypes);
612 DEL_ARR_F(clss->attr.ca.supertypes);
615 /* manipulate private fields of class type */
616 void add_class_member (type *clss, entity *member) {
617 assert(clss && (clss->type_op == type_class));
618 ARR_APP1 (entity *, clss->attr.ca.members, member);
620 int get_class_n_members (type *clss) {
621 assert(clss && (clss->type_op == type_class));
622 return (ARR_LEN (clss->attr.ca.members))-1;
624 int get_class_member_index(type *clss, entity *mem) {
626 assert(clss && (clss->type_op == type_class));
627 for (i = 0; i < get_class_n_members(clss); i++)
628 if (get_class_member(clss, i) == mem)
632 entity *get_class_member (type *clss, int pos) {
633 assert(clss && (clss->type_op == type_class));
634 assert(pos >= 0 && pos < get_class_n_members(clss));
635 return clss->attr.ca.members[pos+1];
637 void set_class_member (type *clss, entity *member, int pos) {
638 assert(clss && (clss->type_op == type_class));
639 assert(pos >= 0 && pos < get_class_n_members(clss));
640 clss->attr.ca.members[pos+1] = member;
642 void set_class_members (type *clss, entity **members, int arity) {
644 assert(clss && (clss->type_op == type_class));
645 DEL_ARR_F(clss->attr.ca.members);
646 clss->attr.ca.members = NEW_ARR_F (entity *, 1);
647 for (i = 0; i < arity; i++) {
648 set_entity_owner(members[i], clss);
649 ARR_APP1 (entity *, clss->attr.ca.members, members[i]);
652 void remove_class_member(type *clss, entity *member) {
654 assert(clss && (clss->type_op == type_class));
655 for (i = 1; i < (ARR_LEN (clss->attr.ca.members)); i++) {
656 if (clss->attr.ca.members[i] == member) {
657 for(; i < (ARR_LEN (clss->attr.ca.members)) - 1; i++)
658 clss->attr.ca.members[i] = clss->attr.ca.members[i + 1];
659 ARR_SETLEN(entity*, clss->attr.ca.members, ARR_LEN(clss->attr.ca.members) - 1);
665 void add_class_subtype (type *clss, type *subtype) {
667 assert(clss && (clss->type_op == type_class));
668 ARR_APP1 (type *, clss->attr.ca.subtypes, subtype);
669 for (i = 0; i < get_class_n_supertypes(subtype); i++)
670 if (get_class_supertype(subtype, i) == clss)
671 /* Class already registered */
673 ARR_APP1 (type *, subtype->attr.ca.supertypes, clss);
675 int get_class_n_subtypes (type *clss) {
676 assert(clss && (clss->type_op == type_class));
677 return (ARR_LEN (clss->attr.ca.subtypes))-1;
679 type *get_class_subtype (type *clss, int pos) {
680 assert(clss && (clss->type_op == type_class));
681 assert(pos >= 0 && pos < get_class_n_subtypes(clss));
682 return clss->attr.ca.subtypes[pos+1] = skip_tid(clss->attr.ca.subtypes[pos+1]);
684 void set_class_subtype (type *clss, type *subtype, int pos) {
685 assert(clss && (clss->type_op == type_class));
686 assert(pos >= 0 && pos < get_class_n_subtypes(clss));
687 clss->attr.ca.subtypes[pos+1] = subtype;
689 void remove_class_subtype(type *clss, type *subtype) {
691 assert(clss && (clss->type_op == type_class));
692 for (i = 1; i < (ARR_LEN (clss->attr.ca.subtypes)); i++)
693 if (clss->attr.ca.subtypes[i] == subtype) {
694 for(; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
695 clss->attr.ca.subtypes[i] = clss->attr.ca.subtypes[i+1];
696 ARR_SETLEN(entity*, clss->attr.ca.subtypes, ARR_LEN(clss->attr.ca.subtypes) - 1);
701 void add_class_supertype (type *clss, type *supertype) {
703 assert(clss && (clss->type_op == type_class));
704 assert(supertype && (supertype -> type_op == type_class));
705 ARR_APP1 (type *, clss->attr.ca.supertypes, supertype);
706 for (i = 0; i < get_class_n_subtypes(supertype); i++)
707 if (get_class_subtype(supertype, i) == clss)
708 /* Class already registered */
710 ARR_APP1 (type *, supertype->attr.ca.subtypes, clss);
712 int get_class_n_supertypes (type *clss) {
713 assert(clss && (clss->type_op == type_class));
714 return (ARR_LEN (clss->attr.ca.supertypes))-1;
716 int get_class_supertype_index(type *clss, type *super_clss) {
718 assert(clss && (clss->type_op == type_class));
719 assert(super_clss && (super_clss->type_op == type_class));
720 for (i = 0; i < get_class_n_supertypes(clss); i++)
721 if (get_class_supertype(clss, i) == super_clss)
725 type *get_class_supertype (type *clss, int pos) {
726 assert(clss && (clss->type_op == type_class));
727 assert(pos >= 0 && pos < get_class_n_supertypes(clss));
728 return clss->attr.ca.supertypes[pos+1] = skip_tid(clss->attr.ca.supertypes[pos+1]);
730 void set_class_supertype (type *clss, type *supertype, int pos) {
731 assert(clss && (clss->type_op == type_class));
732 assert(pos >= 0 && pos < get_class_n_supertypes(clss));
733 clss->attr.ca.supertypes[pos+1] = supertype;
735 void remove_class_supertype(type *clss, type *supertype) {
737 assert(clss && (clss->type_op == type_class));
738 for (i = 1; i < (ARR_LEN (clss->attr.ca.supertypes)); i++)
739 if (clss->attr.ca.supertypes[i] == supertype) {
740 for(; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
741 clss->attr.ca.supertypes[i] = clss->attr.ca.supertypes[i+1];
742 ARR_SETLEN(entity*, clss->attr.ca.supertypes, ARR_LEN(clss->attr.ca.supertypes) - 1);
747 INLINE peculiarity get_class_peculiarity (type *clss) {
748 assert(clss && (clss->type_op == type_class));
749 return clss->attr.ca.peculiarity;
751 INLINE void set_class_peculiarity (type *clss, peculiarity pec) {
752 assert(clss && (clss->type_op == type_class));
753 assert(pec != peculiarity_inherited); /* There is no inheritance of types in libFirm. */
754 clss->attr.ca.peculiarity = pec;
757 void set_class_dfn (type *clss, int dfn)
759 clss->attr.ca.dfn = dfn;
762 int get_class_dfn (type *clss)
764 return (clss->attr.ca.dfn);
768 bool is_class_type(type *clss) {
770 if (clss->type_op == type_class) return 1; else return 0;
773 bool is_subclass_of(type *low, type *high) {
775 assert(is_class_type(low) && is_class_type(high));
776 if (low == high) return true;
777 /* depth first search from high downwards. */
778 for (i = 0; i < get_class_n_subtypes(high); i++) {
779 if (low == get_class_subtype(high, i))
781 if (is_subclass_of(low, get_class_subtype(high, i)))
787 /*******************************************************************/
789 /*******************************************************************/
791 /* create a new type struct */
792 INLINE type *new_type_struct (ident *name) {
794 res = new_type(type_struct, NULL, name);
795 res->attr.sa.members = NEW_ARR_F (entity *, 1);
798 type *new_d_type_struct (ident *name, dbg_info* db) {
799 type *res = new_type_struct (name);
800 set_type_dbg_info(res, db);
803 INLINE void free_struct_attrs (type *strct) {
804 assert(strct && (strct->type_op == type_struct));
805 DEL_ARR_F(strct->attr.sa.members);
808 /* manipulate private fields of struct */
809 int get_struct_n_members (type *strct) {
810 assert(strct && (strct->type_op == type_struct));
811 return (ARR_LEN (strct->attr.sa.members))-1;
813 void add_struct_member (type *strct, entity *member) {
814 assert(strct && (strct->type_op == type_struct));
815 assert(get_type_tpop(get_entity_type(member)) != type_method);
816 /* @@@ lowerfirm geht nicht durch */
817 ARR_APP1 (entity *, strct->attr.sa.members, member);
819 entity *get_struct_member (type *strct, int pos) {
820 assert(strct && (strct->type_op == type_struct));
821 assert(pos >= 0 && pos < get_struct_n_members(strct));
822 return strct->attr.sa.members[pos+1];
824 void set_struct_member (type *strct, int pos, entity *member) {
825 assert(strct && (strct->type_op == type_struct));
826 assert(pos >= 0 && pos < get_struct_n_members(strct));
827 assert(get_entity_type(member)->type_op != type_method);/* @@@ lowerfirm !!*/
828 strct->attr.sa.members[pos+1] = member;
830 void remove_struct_member(type *strct, entity *member) {
832 assert(strct && (strct->type_op == type_struct));
833 for (i = 1; i < (ARR_LEN (strct->attr.sa.members)); i++)
834 if (strct->attr.sa.members[i] == member) {
835 for(; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
836 strct->attr.sa.members[i] = strct->attr.sa.members[i+1];
837 ARR_SETLEN(entity*, strct->attr.sa.members, ARR_LEN(strct->attr.sa.members) - 1);
843 bool is_struct_type(type *strct) {
845 if (strct->type_op == type_struct) return 1; else return 0;
848 /*******************************************************************/
850 /*******************************************************************/
852 /* Lazy construction of value argument / result representation. */
854 build_value_type(ident *name, int len, type **tps) {
856 type *res = new_type_struct(name);
857 /* Remove type from type list. Must be treated differently than other types. */
858 remove_irp_type_from_list(res);
859 for (i = 0; i < len; i++) {
860 type *elt_type = res; /* use res as default if corresponding type is not yet set. */
861 if (tps[i]) elt_type = tps[i];
862 new_entity(res, mangle_u(name, get_type_ident(elt_type)), elt_type);
867 /* Create a new method type.
868 N_param is the number of parameters, n_res the number of results. */
869 INLINE type *new_type_method (ident *name, int n_param, int n_res) {
871 res = new_type(type_method, mode_P_mach, name);
872 res->state = layout_fixed;
873 assert((get_mode_size_bytes(mode_P_mach) != -1) && "unorthodox modes not implemented");
874 res->size = get_mode_size_bytes(mode_P_mach);
875 res->attr.ma.n_params = n_param;
876 res->attr.ma.param_type = (type **) xmalloc (sizeof (type *) * n_param);
877 res->attr.ma.value_params = NULL;
878 res->attr.ma.n_res = n_res;
879 res->attr.ma.res_type = (type **) xmalloc (sizeof (type *) * n_res);
880 res->attr.ma.value_ress = NULL;
881 res->attr.ma.variadicity = variadicity_non_variadic;
886 type *new_d_type_method (ident *name, int n_param, int n_res, dbg_info* db) {
887 type *res = new_type_method (name, n_param, n_res);
888 set_type_dbg_info(res, db);
892 INLINE void free_method_attrs(type *method) {
893 assert(method && (method->type_op == type_method));
894 free(method->attr.ma.param_type);
895 free(method->attr.ma.res_type);
898 /* manipulate private fields of method. */
899 int get_method_n_params (type *method) {
900 assert(method && (method->type_op == type_method));
901 return method->attr.ma.n_params;
903 type *get_method_param_type(type *method, int pos) {
904 assert(method && (method->type_op == type_method));
905 assert(pos >= 0 && pos < get_method_n_params(method));
906 return method->attr.ma.param_type[pos] = skip_tid(method->attr.ma.param_type[pos]);
908 void set_method_param_type(type *method, int pos, type* tp) {
909 assert(method && (method->type_op == type_method));
910 assert(pos >= 0 && pos < get_method_n_params(method));
911 method->attr.ma.param_type[pos] = tp;
912 /* If information constructed set pass-by-value representation. */
913 if (method->attr.ma.value_params) {
914 assert(get_method_n_params(method) == get_struct_n_members(method->attr.ma.value_params));
915 set_entity_type(get_struct_member(method->attr.ma.value_params, pos), tp);
918 /* Returns an entity that represents the copied value argument. Only necessary
919 for compounds passed by value. */
920 entity *get_method_value_param_ent(type *method, int pos) {
921 assert(method && (method->type_op == type_method));
922 assert(pos >= 0 && pos < get_method_n_params(method));
923 if (!method->attr.ma.value_params)
924 method->attr.ma.value_params
925 = build_value_type(mangle_u(get_type_ident(method), value_params_suffix),
926 get_method_n_params(method), method->attr.ma.param_type);
927 assert((get_entity_type(get_struct_member(method->attr.ma.value_params, pos)) != method->attr.ma.value_params)
928 && "param type not yet set");
929 return get_struct_member(method->attr.ma.value_params, pos);
932 int get_method_n_ress (type *method) {
933 assert(method && (method->type_op == type_method));
934 return method->attr.ma.n_res;
936 type *get_method_res_type(type *method, int pos) {
937 assert(method && (method->type_op == type_method));
938 assert(pos >= 0 && pos < get_method_n_ress(method));
939 return method->attr.ma.res_type[pos] = skip_tid(method->attr.ma.res_type[pos]);
941 void set_method_res_type(type *method, int pos, type* tp) {
942 assert(method && (method->type_op == type_method));
943 assert(pos >= 0 && pos < get_method_n_ress(method));
944 /* set the result type */
945 method->attr.ma.res_type[pos] = tp;
946 /* If information constructed set pass-by-value representation. */
947 if (method->attr.ma.value_ress) {
948 assert(get_method_n_ress(method) == get_struct_n_members(method->attr.ma.value_ress));
949 set_entity_type(get_struct_member(method->attr.ma.value_ress, pos), tp);
952 /* Returns an entity that represents the copied value result. Only necessary
953 for compounds passed by value. */
954 entity *get_method_value_res_ent(type *method, int pos) {
955 assert(method && (method->type_op == type_method));
956 assert(pos >= 0 && pos < get_method_n_ress(method));
957 if (!method->attr.ma.value_ress)
958 method->attr.ma.value_ress
959 = build_value_type(mangle_u(get_type_ident(method), value_ress_suffix),
960 get_method_n_ress(method), method->attr.ma.res_type);
961 assert((get_entity_type(get_struct_member(method->attr.ma.value_ress, pos)) != method->attr.ma.value_ress)
962 && "result type not yet set");
963 return get_struct_member(method->attr.ma.value_ress, pos);
966 /* Returns the null-terminated name of this variadicity. */
967 const char *get_variadicity_name(variadicity vari)
969 #define X(a) case a: return #a
971 X(variadicity_non_variadic);
972 X(variadicity_variadic);
979 variadicity get_method_variadicity(type *method)
981 assert(method && (method->type_op == type_method));
982 return method->attr.ma.variadicity;
985 void set_method_variadicity(type *method, variadicity vari)
987 assert(method && (method->type_op == type_method));
988 method->attr.ma.variadicity = vari;
992 bool is_method_type (type *method) {
994 if (method->type_op == type_method) return 1; else return 0;
997 /*******************************************************************/
999 /*******************************************************************/
1001 /* create a new type uni */
1002 INLINE type *new_type_union (ident *name) {
1004 res = new_type(type_union, NULL, name);
1005 /*res->attr.ua.unioned_type = (type **) xmalloc (sizeof (type *) * n_types);
1006 res->attr.ua.delim_names = (ident **) xmalloc (sizeof (ident *) * n_types); */
1007 res->attr.ua.members = NEW_ARR_F (entity *, 1);
1010 type *new_d_type_union (ident *name, dbg_info* db) {
1011 type *res = new_type_union (name);
1012 set_type_dbg_info(res, db);
1015 INLINE void free_union_attrs (type *uni) {
1016 assert(uni && (uni->type_op == type_union));
1017 DEL_ARR_F(uni->attr.ua.members);
1019 /* manipulate private fields of union */
1021 int get_union_n_types (type *uni) {
1022 assert(uni && (uni->type_op == type_union));
1023 return uni->attr.ua.n_types;
1025 type *get_union_unioned_type (type *uni, int pos) {
1026 assert(uni && (uni->type_op == type_union));
1027 assert(pos >= 0 && pos < get_union_n_types(uni));
1028 return uni->attr.ua.unioned_type[pos] = skip_tid(uni->attr.ua.unioned_type[pos]);
1030 void set_union_unioned_type (type *uni, int pos, type *tp) {
1031 assert(uni && (uni->type_op == type_union));
1032 assert(pos >= 0 && pos < get_union_n_types(uni));
1033 uni->attr.ua.unioned_type[pos] = tp;
1035 ident *get_union_delim_nameid (type *uni, int pos) {
1036 assert(uni && (uni->type_op == type_union));
1037 assert(pos >= 0 && pos < get_union_n_types(uni));
1038 return uni->attr.ua.delim_names[pos];
1040 const char *get_union_delim_name (type *uni, int pos) {
1041 assert(uni && (uni->type_op == type_union));
1042 assert(pos >= 0 && pos < get_union_n_types(uni));
1043 return get_id_str(uni->attr.ua.delim_names[pos]);
1045 void set_union_delim_nameid (type *uni, int pos, ident *id) {
1046 assert(uni && (uni->type_op == type_union));
1047 assert(pos >= 0 && pos < get_union_n_types(uni));
1048 uni->attr.ua.delim_names[pos] = id;
1051 int get_union_n_members (type *uni) {
1052 assert(uni && (uni->type_op == type_union));
1053 return (ARR_LEN (uni->attr.ua.members))-1;
1055 void add_union_member (type *uni, entity *member) {
1056 assert(uni && (uni->type_op == type_union));
1057 ARR_APP1 (entity *, uni->attr.ua.members, member);
1059 entity *get_union_member (type *uni, int pos) {
1060 assert(uni && (uni->type_op == type_union));
1061 assert(pos >= 0 && pos < get_union_n_members(uni));
1062 return uni->attr.ua.members[pos+1];
1064 void set_union_member (type *uni, int pos, entity *member) {
1065 assert(uni && (uni->type_op == type_union));
1066 assert(pos >= 0 && pos < get_union_n_members(uni));
1067 uni->attr.ua.members[pos+1] = member;
1069 void remove_union_member(type *uni, entity *member) {
1071 assert(uni && (uni->type_op == type_union));
1072 for (i = 1; i < (ARR_LEN (uni->attr.ua.members)); i++)
1073 if (uni->attr.ua.members[i] == member) {
1074 for(; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
1075 uni->attr.ua.members[i] = uni->attr.ua.members[i+1];
1076 ARR_SETLEN(entity*, uni->attr.ua.members, ARR_LEN(uni->attr.ua.members) - 1);
1082 bool is_union_type (type *uni) {
1084 if (uni->type_op == type_union) return 1; else return 0;
1087 /*******************************************************************/
1089 /*******************************************************************/
1092 /* create a new type array -- set dimension sizes independently */
1093 INLINE type *new_type_array (ident *name, int n_dimensions,
1094 type *element_type) {
1097 ir_graph *rem = current_ir_graph;
1098 assert(!is_method_type(element_type));
1100 res = new_type(type_array, NULL, name);
1101 res->attr.aa.n_dimensions = n_dimensions;
1102 res->attr.aa.lower_bound = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
1103 res->attr.aa.upper_bound = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
1104 res->attr.aa.order = (int *) xmalloc (sizeof (int) * n_dimensions);
1106 current_ir_graph = get_const_code_irg();
1107 for (i = 0; i < n_dimensions; i++) {
1108 res->attr.aa.lower_bound[i] = new_Unknown();
1109 res->attr.aa.upper_bound[i] = new_Unknown();
1110 res->attr.aa.order[i] = i;
1112 current_ir_graph = rem;
1114 res->attr.aa.element_type = element_type;
1115 new_entity(res, mangle_u(name, id_from_str("elem_ent", 8)), element_type);
1119 type *new_d_type_array (ident *name, int n_dimensions,
1120 type *element_type, dbg_info* db) {
1121 type *res = new_type_array (name, n_dimensions, element_type);
1122 set_type_dbg_info(res, db);
1126 INLINE void free_array_attrs (type *array) {
1127 assert(array && (array->type_op == type_array));
1128 free(array->attr.aa.lower_bound);
1129 free(array->attr.aa.upper_bound);
1132 /* manipulate private fields of array type */
1133 int get_array_n_dimensions (type *array) {
1134 assert(array && (array->type_op == type_array));
1135 return array->attr.aa.n_dimensions;
1139 set_array_bounds (type *array, int dimension, ir_node * lower_bound,
1140 ir_node * upper_bound) {
1141 assert(array && (array->type_op == type_array));
1142 assert(lower_bound && "lower_bound node may not be NULL.");
1143 assert(upper_bound && "upper_bound node may not be NULL.");
1144 assert(dimension < array->attr.aa.n_dimensions && dimension >= 0);
1145 array->attr.aa.lower_bound[dimension] = lower_bound;
1146 array->attr.aa.upper_bound[dimension] = upper_bound;
1149 set_array_bounds_int (type *array, int dimension, int lower_bound,
1151 ir_graph *rem = current_ir_graph;
1152 current_ir_graph = get_const_code_irg();
1153 set_array_bounds (array, dimension,
1154 new_Const(mode_Iu, new_tarval_from_long (lower_bound, mode_Iu)),
1155 new_Const(mode_Iu, new_tarval_from_long (upper_bound, mode_Iu )));
1156 current_ir_graph = rem;
1159 set_array_lower_bound (type *array, int dimension, ir_node * lower_bound) {
1160 assert(array && (array->type_op == type_array));
1161 assert(lower_bound && "lower_bound node may not be NULL.");
1162 array->attr.aa.lower_bound[dimension] = lower_bound;
1164 void set_array_lower_bound_int (type *array, int dimension, int lower_bound) {
1165 ir_graph *rem = current_ir_graph;
1166 current_ir_graph = get_const_code_irg();
1167 set_array_lower_bound (array, dimension,
1168 new_Const(mode_Iu, new_tarval_from_long (lower_bound, mode_Iu)));
1169 current_ir_graph = rem;
1172 set_array_upper_bound (type *array, int dimension, ir_node * upper_bound) {
1173 assert(array && (array->type_op == type_array));
1174 assert(upper_bound && "upper_bound node may not be NULL.");
1175 array->attr.aa.upper_bound[dimension] = upper_bound;
1177 void set_array_upper_bound_int (type *array, int dimension, int upper_bound) {
1178 ir_graph *rem = current_ir_graph;
1179 current_ir_graph = get_const_code_irg();
1180 set_array_upper_bound (array, dimension,
1181 new_Const(mode_Iu, new_tarval_from_long (upper_bound, mode_Iu)));
1182 current_ir_graph = rem;
1184 int has_array_lower_bound (type *array, int dimension) {
1185 assert(array && (array->type_op == type_array));
1186 return (get_irn_op(array->attr.aa.lower_bound[dimension]) != op_Unknown);
1188 ir_node * get_array_lower_bound (type *array, int dimension) {
1189 assert(array && (array->type_op == type_array));
1190 return array->attr.aa.lower_bound[dimension];
1192 int has_array_upper_bound (type *array, int dimension) {
1193 assert(array && (array->type_op == type_array));
1194 return (get_irn_op(array->attr.aa.upper_bound[dimension]) != op_Unknown);
1196 ir_node * get_array_upper_bound (type *array, int dimension) {
1197 assert(array && (array->type_op == type_array));
1198 return array->attr.aa.upper_bound[dimension];
1201 void set_array_order (type *array, int dimension, int order) {
1202 assert(array && (array->type_op == type_array));
1203 array->attr.aa.order[dimension] = order;
1205 int get_array_order (type *array, int dimension) {
1206 assert(array && (array->type_op == type_array));
1207 return array->attr.aa.order[dimension];
1210 void set_array_element_type (type *array, type *tp) {
1211 assert(array && (array->type_op == type_array));
1212 assert(!is_method_type(tp));
1213 array->attr.aa.element_type = tp;
1215 type *get_array_element_type (type *array) {
1216 assert(array && (array->type_op == type_array));
1217 return array->attr.aa.element_type = skip_tid(array->attr.aa.element_type);
1220 void set_array_element_entity (type *array, entity *ent) {
1221 assert(array && (array->type_op == type_array));
1222 assert((get_entity_type(ent)->type_op != type_method));
1223 array->attr.aa.element_ent = ent;
1224 array->attr.aa.element_type = get_entity_type(ent);
1226 entity *get_array_element_entity (type *array) {
1227 assert(array && (array->type_op == type_array));
1228 return array->attr.aa.element_ent;
1232 bool is_array_type (type *array) {
1234 if (array->type_op == type_array) return 1; else return 0;
1237 /*******************************************************************/
1238 /** TYPE_ENUMERATION **/
1239 /*******************************************************************/
1241 /* create a new type enumeration -- set the enumerators independently */
1242 INLINE type *new_type_enumeration (ident *name, int n_enums) {
1245 res = new_type(type_enumeration, NULL, name);
1246 res->attr.ea.n_enums = n_enums;
1247 res->attr.ea.enumer = (tarval **) xmalloc (sizeof (tarval *) * n_enums);
1248 res->attr.ea.enum_nameid = (ident **) xmalloc (sizeof (ident *) * n_enums);
1249 for (i = 0; i < n_enums; i++) {
1250 res->attr.ea.enumer[i] = NULL;
1251 res->attr.ea.enum_nameid = NULL;
1255 type *new_d_type_enumeration (ident *name, int n_enums, dbg_info* db) {
1256 type *res = new_type_enumeration (name, n_enums);
1257 set_type_dbg_info(res, db);
1261 INLINE void free_enumeration_attrs(type *enumeration) {
1262 assert(enumeration && (enumeration->type_op == type_enumeration));
1263 free(enumeration->attr.ea.enumer);
1264 free(enumeration->attr.ea.enum_nameid);
1267 /* manipulate fields of enumeration type. */
1268 int get_enumeration_n_enums (type *enumeration) {
1269 assert(enumeration && (enumeration->type_op == type_enumeration));
1270 return enumeration->attr.ea.n_enums;
1272 void set_enumeration_enum (type *enumeration, int pos, tarval *con) {
1273 assert(enumeration && (enumeration->type_op == type_enumeration));
1274 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1275 enumeration->attr.ea.enumer[pos] = con;
1277 tarval *get_enumeration_enum (type *enumeration, int pos) {
1278 assert(enumeration && (enumeration->type_op == type_enumeration));
1279 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1280 return enumeration->attr.ea.enumer[pos];
1282 void set_enumeration_nameid (type *enumeration, int pos, ident *id) {
1283 assert(enumeration && (enumeration->type_op == type_enumeration));
1284 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1285 enumeration->attr.ea.enum_nameid[pos] = id;
1287 ident *get_enumeration_nameid (type *enumeration, int pos) {
1288 assert(enumeration && (enumeration->type_op == type_enumeration));
1289 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1290 return enumeration->attr.ea.enum_nameid[pos];
1292 const char *get_enumeration_name(type *enumeration, int pos) {
1293 assert(enumeration && (enumeration->type_op == type_enumeration));
1294 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1295 return get_id_str(enumeration->attr.ea.enum_nameid[pos]);
1299 bool is_enumeration_type (type *enumeration) {
1300 assert(enumeration);
1301 if (enumeration->type_op == type_enumeration) return 1; else return 0;
1304 /*******************************************************************/
1305 /** TYPE_POINTER **/
1306 /*******************************************************************/
1308 /* Create a new type pointer */
1309 INLINE type *new_type_pointer_mode (ident *name, type *points_to, ir_mode *ptr_mode) {
1311 assert(mode_is_reference(ptr_mode));
1312 res = new_type(type_pointer, ptr_mode, name);
1313 res->attr.pa.points_to = points_to;
1314 assert((get_mode_size_bytes(res->mode) != -1) && "unorthodox modes not implemented");
1315 res->size = get_mode_size_bytes(res->mode);
1316 res->state = layout_fixed;
1319 type *new_d_type_pointer (ident *name, type *points_to, ir_mode *ptr_mode, dbg_info* db) {
1320 type *res = new_type_pointer_mode (name, points_to, ptr_mode);
1321 set_type_dbg_info(res, db);
1324 INLINE void free_pointer_attrs (type *pointer) {
1325 assert(pointer && (pointer->type_op == type_pointer));
1327 /* manipulate fields of type_pointer */
1328 void set_pointer_points_to_type (type *pointer, type *tp) {
1329 assert(pointer && (pointer->type_op == type_pointer));
1330 pointer->attr.pa.points_to = tp;
1332 type *get_pointer_points_to_type (type *pointer) {
1333 assert(pointer && (pointer->type_op == type_pointer));
1334 return pointer->attr.pa.points_to = skip_tid(pointer->attr.pa.points_to);
1338 bool is_pointer_type (type *pointer) {
1340 if (pointer->type_op == type_pointer) return 1; else return 0;
1344 /*******************************************************************/
1345 /** TYPE_PRIMITIVE **/
1346 /*******************************************************************/
1348 /* create a new type primitive */
1349 INLINE type *new_type_primitive (ident *name, ir_mode *mode) {
1351 /* @@@ assert( mode_is_data(mode) && (!mode_is_reference(mode))); */
1352 res = new_type(type_primitive, mode, name);
1353 assert((get_mode_size_bytes(mode) != -1) && "unorthodox modes not implemented");
1354 res->size = get_mode_size_bytes(mode);
1355 res->state = layout_fixed;
1358 type *new_d_type_primitive (ident *name, ir_mode *mode, dbg_info* db) {
1359 type *res = new_type_primitive (name, mode);
1360 set_type_dbg_info(res, db);
1363 INLINE void free_primitive_attrs (type *primitive) {
1364 assert(primitive && (primitive->type_op == type_primitive));
1368 bool is_primitive_type (type *primitive) {
1369 assert(primitive && primitive->kind == k_type);
1370 if (primitive->type_op == type_primitive) return 1; else return 0;
1373 /*******************************************************************/
1374 /** common functionality **/
1375 /*******************************************************************/
1378 INLINE int is_atomic_type(type *tp) {
1379 assert(tp && tp->kind == k_type);
1380 return (is_primitive_type(tp) || is_pointer_type(tp) ||
1381 is_enumeration_type(tp));
1385 * Gets the number of elements in a firm compound type.
1387 int get_compound_n_members(type *tp)
1391 if (is_struct_type(tp))
1392 res = get_struct_n_members(tp);
1393 else if (is_class_type(tp))
1394 res = get_class_n_members(tp);
1395 else if (is_union_type(tp))
1396 res = get_union_n_members(tp);
1398 assert(0 && "need struct, union or class for member count");
1404 * Gets the member of a firm compound type at position pos.
1406 entity *get_compound_member(type *tp, int pos)
1410 if (is_struct_type(tp))
1411 res = get_struct_member(tp, pos);
1412 else if (is_class_type(tp))
1413 res = get_class_member(tp, pos);
1414 else if (is_union_type(tp))
1415 res = get_union_member(tp, pos);
1418 assert(0 && "need struct, union or class to get a member");
1426 INLINE int is_compound_type(type *tp) {
1427 assert(tp && tp->kind == k_type);
1428 return (is_class_type(tp) || is_struct_type(tp) ||
1429 is_array_type(tp) || is_union_type(tp));