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++; }
95 new_type(tp_op *type_op, ir_mode *mode, ident* name) {
99 assert(type_op != type_id);
100 assert(!id_contains_char(name, ' ') && "type name should not contain spaces");
102 node_size = offsetof (type, attr) + type_op->attr_size;
103 res = (type *) xmalloc (node_size);
104 add_irp_type(res); /* Remember the new type global. */
107 res->type_op = type_op;
110 res->state = layout_undefined;
115 res->nr = get_irp_new_node_nr();
121 void free_type(type *tp) {
122 if ((get_type_tpop(tp) == tpop_none) || (get_type_tpop(tp) == tpop_unknown))
124 /* Remove from list of all types */
126 /* Free the attributes of the type. */
128 /* Free entities automatically allocated with the type */
129 if (is_array_type(tp))
130 free_entity(get_array_element_entity(tp));
131 /* And now the type itself... */
136 void free_type_entities(type *tp) {
137 switch(get_type_tpop_code(tp)) {
138 case tpo_class: { free_class_entities(tp); } break;
139 case tpo_struct: { free_struct_entities(tp); } break;
140 case tpo_method: { free_method_entities(tp); } break;
141 case tpo_union: { free_union_entities(tp); } break;
142 case tpo_array: { free_array_entities(tp); } break;
143 case tpo_enumeration: { free_enumeration_entities(tp); } break;
144 case tpo_pointer: { free_pointer_entities(tp); } break;
145 case tpo_primitive: { free_primitive_entities(tp); } break;
150 void free_type_attrs(type *tp) {
151 switch(get_type_tpop_code(tp)) {
152 case tpo_class: { free_class_attrs(tp); } break;
153 case tpo_struct: { free_struct_attrs(tp); } break;
154 case tpo_method: { free_method_attrs(tp); } break;
155 case tpo_union: { free_union_attrs(tp); } break;
156 case tpo_array: { free_array_attrs(tp); } break;
157 case tpo_enumeration: { free_enumeration_attrs(tp); } break;
158 case tpo_pointer: { free_pointer_attrs(tp); } break;
159 case tpo_primitive: { free_primitive_attrs(tp); } break;
164 /* set/get the link field */
165 void *get_type_link(type *tp)
167 assert(tp && tp->kind == k_type);
171 void set_type_link(type *tp, void *l)
173 assert(tp && tp->kind == k_type);
177 tp_op* get_type_tpop(type *tp) {
178 assert(tp && tp->kind == k_type);
182 ident* get_type_tpop_nameid(type *tp) {
183 assert(tp && tp->kind == k_type);
184 return tp->type_op->name;
187 const char* get_type_tpop_name(type *tp) {
188 assert(tp && tp->kind == k_type);
189 return get_id_str(tp->type_op->name);
192 tp_opcode get_type_tpop_code(type *tp) {
193 assert(tp && tp->kind == k_type);
194 return tp->type_op->code;
197 ir_mode* get_type_mode(type *tp) {
198 assert(tp && tp->kind == k_type);
202 void set_type_mode(type *tp, ir_mode* m) {
203 assert(tp && tp->kind == k_type);
205 assert(((tp->type_op != type_primitive) || mode_is_data(m)) &&
206 /* Modes of primitives must be data */
207 ((tp->type_op != type_enumeration) || mode_is_int(m)) &&
208 /* Modes of enumerations must be integers */
209 ((tp->type_op != type_pointer) || mode_is_reference(m)) );
210 /* Modes of pointers must be references. */
212 if ((tp->type_op == type_primitive) ||
213 (tp->type_op == type_enumeration) ||
214 (tp->type_op == type_pointer) ) {
215 /* For pointer, primitive and enumeration size depends on the mode. */
216 assert((get_mode_size_bytes(m) != -1) && "unorthodox modes not implemented");
217 tp->size = get_mode_size_bytes(m);
222 ident* get_type_ident(type *tp) {
223 assert(tp && tp->kind == k_type);
227 void set_type_ident(type *tp, ident* id) {
228 assert(tp && tp->kind == k_type);
232 /* Outputs a unique number for this node */
234 get_type_nr(type *tp) {
243 const char* get_type_name(type *tp) {
244 assert(tp && tp->kind == k_type);
245 return (get_id_str(tp->name));
248 int get_type_size(type *tp) {
249 assert(tp && tp->kind == k_type);
254 set_type_size(type *tp, int size) {
255 assert(tp && tp->kind == k_type);
256 /* For pointer enumeration and primitive size depends on the mode.
257 Methods don't have a size. */
258 if ((tp->type_op != type_pointer) && (tp->type_op != type_primitive) &&
259 (tp->type_op != type_enumeration) && (tp->type_op != type_method))
264 get_type_state(type *tp) {
265 assert(tp && tp->kind == k_type);
270 set_type_state(type *tp, type_state state) {
271 assert(tp && tp->kind == k_type);
273 if ((tp->type_op == type_pointer) || (tp->type_op == type_primitive) ||
274 (tp->type_op == type_method))
277 /* Just a correctness check: */
278 if (state == layout_fixed) {
280 switch (get_type_tpop_code(tp)) {
283 assert(get_type_size(tp) > -1);
284 if (tp != get_glob_type())
285 for (i = 0; i < get_class_n_members(tp); i++) {
286 if (get_entity_offset(get_class_member(tp, i)) <= -1)
287 { DDMT(tp); DDME(get_class_member(tp, i)); }
288 assert(get_entity_offset(get_class_member(tp, i)) > -1);
289 assert(is_method_type(get_entity_type(get_class_member(tp, i))) ||
290 (get_entity_allocation(get_class_member(tp, i)) == allocation_automatic));
295 assert(get_type_size(tp) > -1);
296 for (i = 0; i < get_struct_n_members(tp); i++) {
297 assert(get_entity_offset(get_struct_member(tp, i)) > -1);
298 assert((get_entity_allocation(get_struct_member(tp, i)) == allocation_automatic));
307 Assure that only innermost dimension is dynamic? */
309 case tpo_enumeration:
311 assert(get_type_mode != NULL);
312 for (i = 0; i < get_enumeration_n_enums(tp); i++)
313 assert(get_enumeration_enum(tp, i) != NULL);
321 unsigned long get_type_visited(type *tp) {
322 assert(tp && tp->kind == k_type);
326 void set_type_visited(type *tp, unsigned long num) {
327 assert(tp && tp->kind == k_type);
330 /* Sets visited field in type to type_visited. */
331 void mark_type_visited(type *tp) {
332 assert(tp && tp->kind == k_type);
333 assert(tp->visit < type_visited);
334 tp->visit = type_visited;
336 /* @@@ name clash with master flag
337 bool type_visited(type *tp) {
338 assert(tp && tp->kind == k_type);
339 return tp->visit >= type_visited;
341 bool type_not_visited(type *tp) {
342 assert(tp && tp->kind == k_type);
343 return tp->visit < type_visited;
347 int is_type (void *thing) {
349 if (get_kind(thing) == k_type)
356 bool equal_type(type *typ1, type *typ2) {
361 if (typ1 == typ2) return true;
363 if ((get_type_tpop_code(typ1) != get_type_tpop_code(typ2)) ||
364 (get_type_ident(typ1) != get_type_ident(typ2)) ||
365 (get_type_mode(typ1) != get_type_mode(typ2)) ||
366 (get_type_state(typ1) != get_type_state(typ2)))
368 if ((get_type_state(typ1) == layout_fixed) &&
369 (get_type_size(typ1) != get_type_size(typ2)))
372 switch(get_type_tpop_code(typ1)) {
374 if (get_class_n_members(typ1) != get_class_n_members(typ2)) return false;
375 if (get_class_n_subtypes(typ1) != get_class_n_subtypes(typ2)) return false;
376 if (get_class_n_supertypes(typ1) != get_class_n_supertypes(typ2)) return false;
377 if (get_class_peculiarity(typ1) != get_class_peculiarity(typ2)) return false;
378 /** Compare the members **/
379 m = alloca(sizeof(entity *) * get_class_n_members(typ1));
380 memset(m, 0, sizeof(entity *) * get_class_n_members(typ1));
381 /* First sort the members of typ2 */
382 for (i = 0; i < get_class_n_members(typ1); i++) {
383 entity *e1 = get_class_member(typ1, i);
384 for (j = 0; j < get_class_n_members(typ2); j++) {
385 entity *e2 = get_class_member(typ2, j);
386 if (get_entity_name(e1) == get_entity_name(e2))
390 for (i = 0; i < get_class_n_members(typ1); i++) {
391 if (!m[i] || /* Found no counterpart */
392 !equal_entity(get_class_member(typ1, i), m[i]))
395 /** Compare the supertypes **/
396 t = alloca(sizeof(entity *) * get_class_n_supertypes(typ1));
397 memset(t, 0, sizeof(entity *) * get_class_n_supertypes(typ1));
398 /* First sort the supertypes of typ2 */
399 for (i = 0; i < get_class_n_supertypes(typ1); i++) {
400 type *t1 = get_class_supertype(typ1, i);
401 for (j = 0; j < get_class_n_supertypes(typ2); j++) {
402 type *t2 = get_class_supertype(typ2, j);
403 if (get_type_ident(t2) == get_type_ident(t1))
407 for (i = 0; i < get_class_n_supertypes(typ1); i++) {
408 if (!t[i] || /* Found no counterpart */
409 get_class_supertype(typ1, i) != t[i])
414 if (get_struct_n_members(typ1) != get_struct_n_members(typ2)) return false;
415 m = alloca(sizeof(entity *) * get_struct_n_members(typ1));
416 memset(m, 0, sizeof(entity *) * get_struct_n_members(typ1));
417 /* First sort the members of lt */
418 for (i = 0; i < get_struct_n_members(typ1); i++) {
419 entity *e1 = get_struct_member(typ1, i);
420 for (j = 0; j < get_struct_n_members(typ2); j++) {
421 entity *e2 = get_struct_member(typ2, j);
422 if (get_entity_name(e1) == get_entity_name(e2))
426 for (i = 0; i < get_struct_n_members(typ1); i++) {
427 if (!m[i] || /* Found no counterpart */
428 !equal_entity(get_struct_member(typ1, i), m[i]))
433 if (get_method_variadicity(typ1) != get_method_variadicity(typ2)) return false;
434 if (get_method_n_params(typ1) != get_method_n_params(typ2)) return false;
435 if (get_method_n_ress(typ1) != get_method_n_ress(typ2)) return false;
436 for (i = 0; i < get_method_n_params(typ1); i++) {
437 if (!equal_type(get_method_param_type(typ1, i), get_method_param_type(typ2, i)))
440 for (i = 0; i < get_method_n_ress(typ1); i++) {
441 if (!equal_type(get_method_res_type(typ1, i), get_method_res_type(typ2, i)))
446 if (get_union_n_members(typ1) != get_union_n_members(typ2)) return false;
447 m = alloca(sizeof(entity *) * get_union_n_members(typ1));
448 memset(m, 0, sizeof(entity *) * get_union_n_members(typ1));
449 /* First sort the members of lt */
450 for (i = 0; i < get_union_n_members(typ1); i++) {
451 entity *e1 = get_union_member(typ1, i);
452 for (j = 0; j < get_union_n_members(typ2); j++) {
453 entity *e2 = get_union_member(typ2, j);
454 if (get_entity_name(e1) == get_entity_name(e2))
458 for (i = 0; i < get_union_n_members(typ1); i++) {
459 if (!m[i] || /* Found no counterpart */
460 !equal_entity(get_union_member(typ1, i), m[i]))
465 if (get_array_n_dimensions(typ1) != get_array_n_dimensions(typ2))
467 if (!equal_type(get_array_element_type(typ1), get_array_element_type(typ2)))
469 for(i = 0; i < get_array_n_dimensions(typ1); i++) {
470 if (get_array_lower_bound(typ1, i) != get_array_lower_bound(typ2, i) ||
471 get_array_upper_bound(typ1, i) != get_array_upper_bound(typ2, i))
473 if (get_array_order(typ1, i) != get_array_order(typ2, i))
474 assert(0 && "type compare with different dimension orders not implemented");
477 case tpo_enumeration: {
478 assert(0 && "enumerations not implemented");
481 if (get_pointer_points_to_type(typ1) != get_pointer_points_to_type(typ2))
484 case tpo_primitive: {
491 bool smaller_type (type *st, type *lt) {
495 if (st == lt) return true;
497 if (get_type_tpop_code(st) != get_type_tpop_code(lt))
500 switch(get_type_tpop_code(st)) {
502 return is_subclass_of(st, lt);
505 if (get_struct_n_members(st) != get_struct_n_members(lt)) return false;
506 m = alloca(sizeof(entity *) * get_struct_n_members(st));
507 memset(m, 0, sizeof(entity *) * get_struct_n_members(st));
508 /* First sort the members of lt */
509 for (i = 0; i < get_struct_n_members(st); i++) {
510 entity *se = get_struct_member(st, i);
511 for (j = 0; j < get_struct_n_members(lt); j++) {
512 entity *le = get_struct_member(lt, j);
513 if (get_entity_name(le) == get_entity_name(se))
517 for (i = 0; i < get_struct_n_members(st); i++) {
518 if (!m[i] || /* Found no counterpart */
519 !smaller_type(get_entity_type(get_struct_member(st, i)),
520 get_entity_type(m[i])))
525 if (get_method_variadicity(st) != get_method_variadicity(lt)) return false;
526 if (get_method_n_params(st) != get_method_n_params(lt)) return false;
527 if (get_method_n_ress(st) != get_method_n_ress(lt)) return false;
528 for (i = 0; i < get_method_n_params(st); i++) {
529 if (!smaller_type(get_method_param_type(st, i), get_method_param_type(lt, i)))
532 for (i = 0; i < get_method_n_ress(st); i++) {
533 if (!smaller_type(get_method_res_type(st, i), get_method_res_type(lt, i)))
538 if (get_union_n_members(st) != get_union_n_members(lt)) return false;
539 m = alloca(sizeof(entity *) * get_union_n_members(st));
540 memset(m, 0, sizeof(entity *) * get_union_n_members(st));
541 /* First sort the members of lt */
542 for (i = 0; i < get_union_n_members(st); i++) {
543 entity *se = get_union_member(st, i);
544 for (j = 0; j < get_union_n_members(lt); j++) {
545 entity *le = get_union_member(lt, j);
546 if (get_entity_name(le) == get_entity_name(se))
550 for (i = 0; i < get_union_n_members(st); i++) {
551 if (!m[i] || /* Found no counterpart */
552 !smaller_type(get_entity_type(get_union_member(st, i)),
553 get_entity_type(m[i])))
558 type *set, *let; /* small/large elt. type */
559 if (get_array_n_dimensions(st) != get_array_n_dimensions(lt))
561 set = get_array_element_type(st);
562 let = get_array_element_type(lt);
564 /* If the elt types are different, set must be convertible
565 to let, and they must have the same size so that address
566 computations work out. To have a size the layout must
568 if ((get_type_state(set) != layout_fixed) ||
569 (get_type_state(let) != layout_fixed))
571 if (!smaller_type(set, let) ||
572 get_type_size(set) != get_type_size(let))
575 for(i = 0; i < get_array_n_dimensions(st); i++) {
576 if (get_array_lower_bound(lt, i))
577 if(get_array_lower_bound(st, i) != get_array_lower_bound(lt, i))
579 if (get_array_upper_bound(lt, i))
580 if(get_array_upper_bound(st, i) != get_array_upper_bound(lt, i))
584 case tpo_enumeration: {
585 assert(0 && "enumerations not implemented");
588 if (!smaller_type(get_pointer_points_to_type(st),
589 get_pointer_points_to_type(lt)))
592 case tpo_primitive: {
593 if (!smaller_mode(get_type_mode(st), get_type_mode(lt)))
601 /*******************************************************************/
603 /*******************************************************************/
605 /* create a new class type */
606 INLINE type *new_type_class (ident *name) {
609 res = new_type(type_class, NULL, name);
611 res->attr.ca.members = NEW_ARR_F (entity *, 1);
612 res->attr.ca.subtypes = NEW_ARR_F (type *, 1);
613 res->attr.ca.supertypes = NEW_ARR_F (type *, 1);
614 res->attr.ca.peculiarity = peculiarity_existent;
615 res->attr.ca.dfn = 0;
619 type *new_d_type_class (ident *name, dbg_info* db) {
620 type *res = new_type_class (name);
621 set_type_dbg_info(res, db);
625 INLINE void free_class_entities(type *clss) {
627 assert(clss && (clss->type_op == type_class));
628 for (i = get_class_n_members(clss)-1; i >= 0; --i)
629 free_entity(get_class_member(clss, i));
632 INLINE void free_class_attrs(type *clss) {
633 assert(clss && (clss->type_op == type_class));
634 DEL_ARR_F(clss->attr.ca.members);
635 DEL_ARR_F(clss->attr.ca.subtypes);
636 DEL_ARR_F(clss->attr.ca.supertypes);
639 /* manipulate private fields of class type */
640 void add_class_member (type *clss, entity *member) {
641 assert(clss && (clss->type_op == type_class));
642 ARR_APP1 (entity *, clss->attr.ca.members, member);
644 int get_class_n_members (type *clss) {
645 assert(clss && (clss->type_op == type_class));
646 return (ARR_LEN (clss->attr.ca.members))-1;
648 int get_class_member_index(type *clss, entity *mem) {
650 assert(clss && (clss->type_op == type_class));
651 for (i = 0; i < get_class_n_members(clss); i++)
652 if (get_class_member(clss, i) == mem)
656 entity *get_class_member (type *clss, int pos) {
657 assert(clss && (clss->type_op == type_class));
658 assert(pos >= 0 && pos < get_class_n_members(clss));
659 return clss->attr.ca.members[pos+1];
661 void set_class_member (type *clss, entity *member, int pos) {
662 assert(clss && (clss->type_op == type_class));
663 assert(pos >= 0 && pos < get_class_n_members(clss));
664 clss->attr.ca.members[pos+1] = member;
666 void set_class_members (type *clss, entity **members, int arity) {
668 assert(clss && (clss->type_op == type_class));
669 DEL_ARR_F(clss->attr.ca.members);
670 clss->attr.ca.members = NEW_ARR_F (entity *, 1);
671 for (i = 0; i < arity; i++) {
672 set_entity_owner(members[i], clss);
673 ARR_APP1 (entity *, clss->attr.ca.members, members[i]);
676 void remove_class_member(type *clss, entity *member) {
678 assert(clss && (clss->type_op == type_class));
679 for (i = 1; i < (ARR_LEN (clss->attr.ca.members)); i++) {
680 if (clss->attr.ca.members[i] == member) {
681 for(; i < (ARR_LEN (clss->attr.ca.members)) - 1; i++)
682 clss->attr.ca.members[i] = clss->attr.ca.members[i + 1];
683 ARR_SETLEN(entity*, clss->attr.ca.members, ARR_LEN(clss->attr.ca.members) - 1);
689 void add_class_subtype (type *clss, type *subtype) {
691 assert(clss && (clss->type_op == type_class));
692 ARR_APP1 (type *, clss->attr.ca.subtypes, subtype);
693 for (i = 0; i < get_class_n_supertypes(subtype); i++)
694 if (get_class_supertype(subtype, i) == clss)
695 /* Class already registered */
697 ARR_APP1 (type *, subtype->attr.ca.supertypes, clss);
699 int get_class_n_subtypes (type *clss) {
700 assert(clss && (clss->type_op == type_class));
701 return (ARR_LEN (clss->attr.ca.subtypes))-1;
703 type *get_class_subtype (type *clss, int pos) {
704 assert(clss && (clss->type_op == type_class));
705 assert(pos >= 0 && pos < get_class_n_subtypes(clss));
706 return clss->attr.ca.subtypes[pos+1] = skip_tid(clss->attr.ca.subtypes[pos+1]);
708 void set_class_subtype (type *clss, type *subtype, int pos) {
709 assert(clss && (clss->type_op == type_class));
710 assert(pos >= 0 && pos < get_class_n_subtypes(clss));
711 clss->attr.ca.subtypes[pos+1] = subtype;
713 void remove_class_subtype(type *clss, type *subtype) {
715 assert(clss && (clss->type_op == type_class));
716 for (i = 1; i < (ARR_LEN (clss->attr.ca.subtypes)); i++)
717 if (clss->attr.ca.subtypes[i] == subtype) {
718 for(; i < (ARR_LEN (clss->attr.ca.subtypes))-1; i++)
719 clss->attr.ca.subtypes[i] = clss->attr.ca.subtypes[i+1];
720 ARR_SETLEN(entity*, clss->attr.ca.subtypes, ARR_LEN(clss->attr.ca.subtypes) - 1);
725 void add_class_supertype (type *clss, type *supertype) {
727 assert(clss && (clss->type_op == type_class));
728 assert(supertype && (supertype -> type_op == type_class));
729 ARR_APP1 (type *, clss->attr.ca.supertypes, supertype);
730 for (i = 0; i < get_class_n_subtypes(supertype); i++)
731 if (get_class_subtype(supertype, i) == clss)
732 /* Class already registered */
734 ARR_APP1 (type *, supertype->attr.ca.subtypes, clss);
736 int get_class_n_supertypes (type *clss) {
737 assert(clss && (clss->type_op == type_class));
738 return (ARR_LEN (clss->attr.ca.supertypes))-1;
740 int get_class_supertype_index(type *clss, type *super_clss) {
742 assert(clss && (clss->type_op == type_class));
743 assert(super_clss && (super_clss->type_op == type_class));
744 for (i = 0; i < get_class_n_supertypes(clss); i++)
745 if (get_class_supertype(clss, i) == super_clss)
749 type *get_class_supertype (type *clss, int pos) {
750 assert(clss && (clss->type_op == type_class));
751 assert(pos >= 0 && pos < get_class_n_supertypes(clss));
752 return clss->attr.ca.supertypes[pos+1] = skip_tid(clss->attr.ca.supertypes[pos+1]);
754 void set_class_supertype (type *clss, type *supertype, int pos) {
755 assert(clss && (clss->type_op == type_class));
756 assert(pos >= 0 && pos < get_class_n_supertypes(clss));
757 clss->attr.ca.supertypes[pos+1] = supertype;
759 void remove_class_supertype(type *clss, type *supertype) {
761 assert(clss && (clss->type_op == type_class));
762 for (i = 1; i < (ARR_LEN (clss->attr.ca.supertypes)); i++)
763 if (clss->attr.ca.supertypes[i] == supertype) {
764 for(; i < (ARR_LEN (clss->attr.ca.supertypes))-1; i++)
765 clss->attr.ca.supertypes[i] = clss->attr.ca.supertypes[i+1];
766 ARR_SETLEN(entity*, clss->attr.ca.supertypes, ARR_LEN(clss->attr.ca.supertypes) - 1);
771 char *get_peculiarity_string(peculiarity p) {
772 if (p == peculiarity_description)
773 return "peculiarity_description";
774 if (p == peculiarity_inherited)
775 return "peculiarity_inherited";
776 return "peculiarity_existent";
779 INLINE peculiarity get_class_peculiarity (type *clss) {
780 assert(clss && (clss->type_op == type_class));
781 return clss->attr.ca.peculiarity;
783 INLINE void set_class_peculiarity (type *clss, peculiarity pec) {
784 assert(clss && (clss->type_op == type_class));
785 assert(pec != peculiarity_inherited); /* There is no inheritance of types in libFirm. */
786 clss->attr.ca.peculiarity = pec;
789 void set_class_dfn (type *clss, int dfn)
791 clss->attr.ca.dfn = dfn;
794 int get_class_dfn (type *clss)
796 return (clss->attr.ca.dfn);
800 bool is_class_type(type *clss) {
802 if (clss->type_op == type_class) return 1; else return 0;
805 bool is_subclass_of(type *low, type *high) {
807 assert(is_class_type(low) && is_class_type(high));
808 if (low == high) return true;
809 /* depth first search from high downwards. */
810 for (i = 0; i < get_class_n_subtypes(high); i++) {
811 if (low == get_class_subtype(high, i))
813 if (is_subclass_of(low, get_class_subtype(high, i)))
819 /*******************************************************************/
821 /*******************************************************************/
823 /* create a new type struct */
824 INLINE type *new_type_struct (ident *name) {
826 res = new_type(type_struct, NULL, name);
827 res->attr.sa.members = NEW_ARR_F (entity *, 1);
830 type *new_d_type_struct (ident *name, dbg_info* db) {
831 type *res = new_type_struct (name);
832 set_type_dbg_info(res, db);
835 INLINE void free_struct_entities (type *strct) {
837 assert(strct && (strct->type_op == type_struct));
838 for (i = get_struct_n_members(strct)-1; i >= 0; --i)
839 free_entity(get_struct_member(strct, i));
841 INLINE void free_struct_attrs (type *strct) {
842 assert(strct && (strct->type_op == type_struct));
843 DEL_ARR_F(strct->attr.sa.members);
846 /* manipulate private fields of struct */
847 int get_struct_n_members (type *strct) {
848 assert(strct && (strct->type_op == type_struct));
849 return (ARR_LEN (strct->attr.sa.members))-1;
851 void add_struct_member (type *strct, entity *member) {
852 assert(strct && (strct->type_op == type_struct));
853 assert(get_type_tpop(get_entity_type(member)) != type_method);
854 /* @@@ lowerfirm geht nicht durch */
855 ARR_APP1 (entity *, strct->attr.sa.members, member);
857 entity *get_struct_member (type *strct, int pos) {
858 assert(strct && (strct->type_op == type_struct));
859 assert(pos >= 0 && pos < get_struct_n_members(strct));
860 return strct->attr.sa.members[pos+1];
862 void set_struct_member (type *strct, int pos, entity *member) {
863 assert(strct && (strct->type_op == type_struct));
864 assert(pos >= 0 && pos < get_struct_n_members(strct));
865 assert(get_entity_type(member)->type_op != type_method);/* @@@ lowerfirm !!*/
866 strct->attr.sa.members[pos+1] = member;
868 void remove_struct_member(type *strct, entity *member) {
870 assert(strct && (strct->type_op == type_struct));
871 for (i = 1; i < (ARR_LEN (strct->attr.sa.members)); i++)
872 if (strct->attr.sa.members[i] == member) {
873 for(; i < (ARR_LEN (strct->attr.sa.members))-1; i++)
874 strct->attr.sa.members[i] = strct->attr.sa.members[i+1];
875 ARR_SETLEN(entity*, strct->attr.sa.members, ARR_LEN(strct->attr.sa.members) - 1);
881 bool is_struct_type(type *strct) {
883 if (strct->type_op == type_struct) return 1; else return 0;
886 /*******************************************************************/
888 /*******************************************************************/
890 /* Lazy construction of value argument / result representation. */
892 build_value_type(ident *name, int len, type **tps) {
894 type *res = new_type_struct(name);
895 /* Remove type from type list. Must be treated differently than other types. */
896 remove_irp_type_from_list(res);
897 for (i = 0; i < len; i++) {
898 type *elt_type = res; /* use res as default if corresponding type is not yet set. */
899 if (tps[i]) elt_type = tps[i];
900 new_entity(res, mangle_u(name, get_type_ident(elt_type)), elt_type);
905 /* Create a new method type.
906 N_param is the number of parameters, n_res the number of results. */
907 INLINE type *new_type_method (ident *name, int n_param, int n_res) {
909 res = new_type(type_method, mode_P_mach, name);
910 res->state = layout_fixed;
911 assert((get_mode_size_bytes(mode_P_mach) != -1) && "unorthodox modes not implemented");
912 res->size = get_mode_size_bytes(mode_P_mach);
913 res->attr.ma.n_params = n_param;
914 res->attr.ma.param_type = (type **) xmalloc (sizeof (type *) * n_param);
915 res->attr.ma.value_params = NULL;
916 res->attr.ma.n_res = n_res;
917 res->attr.ma.res_type = (type **) xmalloc (sizeof (type *) * n_res);
918 res->attr.ma.value_ress = NULL;
919 res->attr.ma.variadicity = variadicity_non_variadic;
924 type *new_d_type_method (ident *name, int n_param, int n_res, dbg_info* db) {
925 type *res = new_type_method (name, n_param, n_res);
926 set_type_dbg_info(res, db);
930 INLINE void free_method_entities(type *method) {
931 assert(method && (method->type_op == type_method));
933 /* Attention: also frees entities in value parameter subtypes! */
934 INLINE void free_method_attrs(type *method) {
935 assert(method && (method->type_op == type_method));
936 free(method->attr.ma.param_type);
937 free(method->attr.ma.res_type);
938 if (method->attr.ma.value_params) {
939 free_type_entities(method->attr.ma.value_params);
940 free_type(method->attr.ma.value_params);
942 if (method->attr.ma.value_ress) {
943 free_type_entities(method->attr.ma.value_ress);
944 free_type(method->attr.ma.value_ress);
948 /* manipulate private fields of method. */
949 int get_method_n_params (type *method) {
950 assert(method && (method->type_op == type_method));
951 return method->attr.ma.n_params;
953 type *get_method_param_type(type *method, int pos) {
955 assert(method && (method->type_op == type_method));
956 assert(pos >= 0 && pos < get_method_n_params(method));
957 res = method->attr.ma.param_type[pos];
958 assert(res != NULL && "empty method param type");
959 return method->attr.ma.param_type[pos] = skip_tid(res);
961 void set_method_param_type(type *method, int pos, type* tp) {
962 assert(method && (method->type_op == type_method));
963 assert(pos >= 0 && pos < get_method_n_params(method));
964 method->attr.ma.param_type[pos] = tp;
965 /* If information constructed set pass-by-value representation. */
966 if (method->attr.ma.value_params) {
967 assert(get_method_n_params(method) == get_struct_n_members(method->attr.ma.value_params));
968 set_entity_type(get_struct_member(method->attr.ma.value_params, pos), tp);
971 /* Returns an entity that represents the copied value argument. Only necessary
972 for compounds passed by value. */
973 entity *get_method_value_param_ent(type *method, int pos) {
974 assert(method && (method->type_op == type_method));
975 assert(pos >= 0 && pos < get_method_n_params(method));
976 if (!method->attr.ma.value_params)
977 method->attr.ma.value_params
978 = build_value_type(mangle_u(get_type_ident(method), value_params_suffix),
979 get_method_n_params(method), method->attr.ma.param_type);
980 assert((get_entity_type(get_struct_member(method->attr.ma.value_params, pos))
981 != method->attr.ma.value_params)
982 && "param type not yet set");
983 return get_struct_member(method->attr.ma.value_params, pos);
986 type *get_method_value_res_type(type *method) {
987 assert(method && (method->type_op == type_method));
988 return method->attr.ma.value_params;
992 int get_method_n_ress (type *method) {
993 assert(method && (method->type_op == type_method));
994 return method->attr.ma.n_res;
996 type *get_method_res_type(type *method, int pos) {
998 assert(method && (method->type_op == type_method));
999 assert(pos >= 0 && pos < get_method_n_ress(method));
1000 res = method->attr.ma.res_type[pos];
1001 assert(res != NULL && "empty method return type");
1002 return method->attr.ma.res_type[pos] = skip_tid(res);
1004 void set_method_res_type(type *method, int pos, type* tp) {
1005 assert(method && (method->type_op == type_method));
1006 assert(pos >= 0 && pos < get_method_n_ress(method));
1007 /* set the result type */
1008 method->attr.ma.res_type[pos] = tp;
1009 /* If information constructed set pass-by-value representation. */
1010 if (method->attr.ma.value_ress) {
1011 assert(get_method_n_ress(method) == get_struct_n_members(method->attr.ma.value_ress));
1012 set_entity_type(get_struct_member(method->attr.ma.value_ress, pos), tp);
1015 /* Returns an entity that represents the copied value result. Only necessary
1016 for compounds passed by value. */
1017 entity *get_method_value_res_ent(type *method, int pos) {
1018 assert(method && (method->type_op == type_method));
1019 assert(pos >= 0 && pos < get_method_n_ress(method));
1020 if (!method->attr.ma.value_ress)
1021 method->attr.ma.value_ress
1022 = build_value_type(mangle_u(get_type_ident(method), value_ress_suffix),
1023 get_method_n_ress(method), method->attr.ma.res_type);
1024 assert((get_entity_type(get_struct_member(method->attr.ma.value_ress, pos)) != method->attr.ma.value_ress)
1025 && "result type not yet set");
1026 return get_struct_member(method->attr.ma.value_ress, pos);
1029 /* Returns the null-terminated name of this variadicity. */
1030 const char *get_variadicity_name(variadicity vari)
1032 #define X(a) case a: return #a
1034 X(variadicity_non_variadic);
1035 X(variadicity_variadic);
1042 variadicity get_method_variadicity(type *method)
1044 assert(method && (method->type_op == type_method));
1045 return method->attr.ma.variadicity;
1048 void set_method_variadicity(type *method, variadicity vari)
1050 assert(method && (method->type_op == type_method));
1051 method->attr.ma.variadicity = vari;
1055 bool is_method_type (type *method) {
1057 if (method->type_op == type_method) return 1; else return 0;
1060 /*******************************************************************/
1062 /*******************************************************************/
1064 /* create a new type uni */
1065 INLINE type *new_type_union (ident *name) {
1067 res = new_type(type_union, NULL, name);
1068 /*res->attr.ua.unioned_type = (type **) xmalloc (sizeof (type *) * n_types);
1069 res->attr.ua.delim_names = (ident **) xmalloc (sizeof (ident *) * n_types); */
1070 res->attr.ua.members = NEW_ARR_F (entity *, 1);
1073 type *new_d_type_union (ident *name, dbg_info* db) {
1074 type *res = new_type_union (name);
1075 set_type_dbg_info(res, db);
1078 INLINE void free_union_entities (type *uni) {
1080 assert(uni && (uni->type_op == type_union));
1081 for (i = get_union_n_members(uni)-1; i >= 0; --i)
1082 free_entity(get_union_member(uni, i));
1084 INLINE void free_union_attrs (type *uni) {
1085 assert(uni && (uni->type_op == type_union));
1086 DEL_ARR_F(uni->attr.ua.members);
1088 /* manipulate private fields of union */
1090 int get_union_n_types (type *uni) {
1091 assert(uni && (uni->type_op == type_union));
1092 return uni->attr.ua.n_types;
1094 type *get_union_unioned_type (type *uni, int pos) {
1095 assert(uni && (uni->type_op == type_union));
1096 assert(pos >= 0 && pos < get_union_n_types(uni));
1097 return uni->attr.ua.unioned_type[pos] = skip_tid(uni->attr.ua.unioned_type[pos]);
1099 void set_union_unioned_type (type *uni, int pos, type *tp) {
1100 assert(uni && (uni->type_op == type_union));
1101 assert(pos >= 0 && pos < get_union_n_types(uni));
1102 uni->attr.ua.unioned_type[pos] = tp;
1104 ident *get_union_delim_nameid (type *uni, int pos) {
1105 assert(uni && (uni->type_op == type_union));
1106 assert(pos >= 0 && pos < get_union_n_types(uni));
1107 return uni->attr.ua.delim_names[pos];
1109 const char *get_union_delim_name (type *uni, int pos) {
1110 assert(uni && (uni->type_op == type_union));
1111 assert(pos >= 0 && pos < get_union_n_types(uni));
1112 return get_id_str(uni->attr.ua.delim_names[pos]);
1114 void set_union_delim_nameid (type *uni, int pos, ident *id) {
1115 assert(uni && (uni->type_op == type_union));
1116 assert(pos >= 0 && pos < get_union_n_types(uni));
1117 uni->attr.ua.delim_names[pos] = id;
1120 int get_union_n_members (type *uni) {
1121 assert(uni && (uni->type_op == type_union));
1122 return (ARR_LEN (uni->attr.ua.members))-1;
1124 void add_union_member (type *uni, entity *member) {
1125 assert(uni && (uni->type_op == type_union));
1126 ARR_APP1 (entity *, uni->attr.ua.members, member);
1128 entity *get_union_member (type *uni, int pos) {
1129 assert(uni && (uni->type_op == type_union));
1130 assert(pos >= 0 && pos < get_union_n_members(uni));
1131 return uni->attr.ua.members[pos+1];
1133 void set_union_member (type *uni, int pos, entity *member) {
1134 assert(uni && (uni->type_op == type_union));
1135 assert(pos >= 0 && pos < get_union_n_members(uni));
1136 uni->attr.ua.members[pos+1] = member;
1138 void remove_union_member(type *uni, entity *member) {
1140 assert(uni && (uni->type_op == type_union));
1141 for (i = 1; i < (ARR_LEN (uni->attr.ua.members)); i++)
1142 if (uni->attr.ua.members[i] == member) {
1143 for(; i < (ARR_LEN (uni->attr.ua.members))-1; i++)
1144 uni->attr.ua.members[i] = uni->attr.ua.members[i+1];
1145 ARR_SETLEN(entity*, uni->attr.ua.members, ARR_LEN(uni->attr.ua.members) - 1);
1151 bool is_union_type (type *uni) {
1153 if (uni->type_op == type_union) return 1; else return 0;
1156 /*******************************************************************/
1158 /*******************************************************************/
1161 /* create a new type array -- set dimension sizes independently */
1162 INLINE type *new_type_array (ident *name, int n_dimensions,
1163 type *element_type) {
1166 ir_graph *rem = current_ir_graph;
1167 assert(!is_method_type(element_type));
1169 res = new_type(type_array, NULL, name);
1170 res->attr.aa.n_dimensions = n_dimensions;
1171 res->attr.aa.lower_bound = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
1172 res->attr.aa.upper_bound = (ir_node **) xmalloc (sizeof (ir_node *) * n_dimensions);
1173 res->attr.aa.order = (int *) xmalloc (sizeof (int) * n_dimensions);
1175 current_ir_graph = get_const_code_irg();
1176 for (i = 0; i < n_dimensions; i++) {
1177 res->attr.aa.lower_bound[i] = new_Unknown(mode_Iu);
1178 res->attr.aa.upper_bound[i] = new_Unknown(mode_Iu);
1179 res->attr.aa.order[i] = i;
1181 current_ir_graph = rem;
1183 res->attr.aa.element_type = element_type;
1184 new_entity(res, mangle_u(name, id_from_str("elem_ent", 8)), element_type);
1188 type *new_d_type_array (ident *name, int n_dimensions,
1189 type *element_type, dbg_info* db) {
1190 type *res = new_type_array (name, n_dimensions, element_type);
1191 set_type_dbg_info(res, db);
1195 INLINE void free_array_entities (type *array) {
1196 assert(array && (array->type_op == type_array));
1198 INLINE void free_array_attrs (type *array) {
1199 assert(array && (array->type_op == type_array));
1200 free(array->attr.aa.lower_bound);
1201 free(array->attr.aa.upper_bound);
1204 /* manipulate private fields of array type */
1205 int get_array_n_dimensions (type *array) {
1206 assert(array && (array->type_op == type_array));
1207 return array->attr.aa.n_dimensions;
1211 set_array_bounds (type *array, int dimension, ir_node * lower_bound,
1212 ir_node * upper_bound) {
1213 assert(array && (array->type_op == type_array));
1214 assert(lower_bound && "lower_bound node may not be NULL.");
1215 assert(upper_bound && "upper_bound node may not be NULL.");
1216 assert(dimension < array->attr.aa.n_dimensions && dimension >= 0);
1217 array->attr.aa.lower_bound[dimension] = lower_bound;
1218 array->attr.aa.upper_bound[dimension] = upper_bound;
1221 set_array_bounds_int (type *array, int dimension, int lower_bound,
1223 ir_graph *rem = current_ir_graph;
1224 current_ir_graph = get_const_code_irg();
1225 set_array_bounds (array, dimension,
1226 new_Const(mode_Iu, new_tarval_from_long (lower_bound, mode_Iu)),
1227 new_Const(mode_Iu, new_tarval_from_long (upper_bound, mode_Iu )));
1228 current_ir_graph = rem;
1231 set_array_lower_bound (type *array, int dimension, ir_node * lower_bound) {
1232 assert(array && (array->type_op == type_array));
1233 assert(lower_bound && "lower_bound node may not be NULL.");
1234 array->attr.aa.lower_bound[dimension] = lower_bound;
1236 void set_array_lower_bound_int (type *array, int dimension, int lower_bound) {
1237 ir_graph *rem = current_ir_graph;
1238 current_ir_graph = get_const_code_irg();
1239 set_array_lower_bound (array, dimension,
1240 new_Const(mode_Iu, new_tarval_from_long (lower_bound, mode_Iu)));
1241 current_ir_graph = rem;
1244 set_array_upper_bound (type *array, int dimension, ir_node * upper_bound) {
1245 assert(array && (array->type_op == type_array));
1246 assert(upper_bound && "upper_bound node may not be NULL.");
1247 array->attr.aa.upper_bound[dimension] = upper_bound;
1249 void set_array_upper_bound_int (type *array, int dimension, int upper_bound) {
1250 ir_graph *rem = current_ir_graph;
1251 current_ir_graph = get_const_code_irg();
1252 set_array_upper_bound (array, dimension,
1253 new_Const(mode_Iu, new_tarval_from_long (upper_bound, mode_Iu)));
1254 current_ir_graph = rem;
1256 int has_array_lower_bound (type *array, int dimension) {
1257 assert(array && (array->type_op == type_array));
1258 return (get_irn_op(array->attr.aa.lower_bound[dimension]) != op_Unknown);
1260 ir_node * get_array_lower_bound (type *array, int dimension) {
1261 assert(array && (array->type_op == type_array));
1262 return array->attr.aa.lower_bound[dimension];
1264 int has_array_upper_bound (type *array, int dimension) {
1265 assert(array && (array->type_op == type_array));
1266 return (get_irn_op(array->attr.aa.upper_bound[dimension]) != op_Unknown);
1268 ir_node * get_array_upper_bound (type *array, int dimension) {
1269 assert(array && (array->type_op == type_array));
1270 return array->attr.aa.upper_bound[dimension];
1273 void set_array_order (type *array, int dimension, int order) {
1274 assert(array && (array->type_op == type_array));
1275 array->attr.aa.order[dimension] = order;
1277 int get_array_order (type *array, int dimension) {
1278 assert(array && (array->type_op == type_array));
1279 return array->attr.aa.order[dimension];
1282 void set_array_element_type (type *array, type *tp) {
1283 assert(array && (array->type_op == type_array));
1284 assert(!is_method_type(tp));
1285 array->attr.aa.element_type = tp;
1287 type *get_array_element_type (type *array) {
1288 assert(array && (array->type_op == type_array));
1289 return array->attr.aa.element_type = skip_tid(array->attr.aa.element_type);
1292 void set_array_element_entity (type *array, entity *ent) {
1293 assert(array && (array->type_op == type_array));
1294 assert((get_entity_type(ent)->type_op != type_method));
1295 array->attr.aa.element_ent = ent;
1296 array->attr.aa.element_type = get_entity_type(ent);
1298 entity *get_array_element_entity (type *array) {
1299 assert(array && (array->type_op == type_array));
1300 return array->attr.aa.element_ent;
1304 bool is_array_type (type *array) {
1306 if (array->type_op == type_array) return 1; else return 0;
1309 /*******************************************************************/
1310 /** TYPE_ENUMERATION **/
1311 /*******************************************************************/
1313 /* create a new type enumeration -- set the enumerators independently */
1314 INLINE type *new_type_enumeration (ident *name, int n_enums) {
1317 res = new_type(type_enumeration, NULL, name);
1318 res->attr.ea.n_enums = n_enums;
1319 res->attr.ea.enumer = (tarval **) xmalloc (sizeof (tarval *) * n_enums);
1320 res->attr.ea.enum_nameid = (ident **) xmalloc (sizeof (ident *) * n_enums);
1321 for (i = 0; i < n_enums; i++) {
1322 res->attr.ea.enumer[i] = NULL;
1323 res->attr.ea.enum_nameid = NULL;
1327 type *new_d_type_enumeration (ident *name, int n_enums, dbg_info* db) {
1328 type *res = new_type_enumeration (name, n_enums);
1329 set_type_dbg_info(res, db);
1333 INLINE void free_enumeration_entities(type *enumeration) {
1334 assert(enumeration && (enumeration->type_op == type_enumeration));
1336 INLINE void free_enumeration_attrs(type *enumeration) {
1337 assert(enumeration && (enumeration->type_op == type_enumeration));
1338 free(enumeration->attr.ea.enumer);
1339 free(enumeration->attr.ea.enum_nameid);
1342 /* manipulate fields of enumeration type. */
1343 int get_enumeration_n_enums (type *enumeration) {
1344 assert(enumeration && (enumeration->type_op == type_enumeration));
1345 return enumeration->attr.ea.n_enums;
1347 void set_enumeration_enum (type *enumeration, int pos, tarval *con) {
1348 assert(enumeration && (enumeration->type_op == type_enumeration));
1349 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1350 enumeration->attr.ea.enumer[pos] = con;
1352 tarval *get_enumeration_enum (type *enumeration, int pos) {
1353 assert(enumeration && (enumeration->type_op == type_enumeration));
1354 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1355 return enumeration->attr.ea.enumer[pos];
1357 void set_enumeration_nameid (type *enumeration, int pos, ident *id) {
1358 assert(enumeration && (enumeration->type_op == type_enumeration));
1359 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1360 enumeration->attr.ea.enum_nameid[pos] = id;
1362 ident *get_enumeration_nameid (type *enumeration, int pos) {
1363 assert(enumeration && (enumeration->type_op == type_enumeration));
1364 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1365 return enumeration->attr.ea.enum_nameid[pos];
1367 const char *get_enumeration_name(type *enumeration, int pos) {
1368 assert(enumeration && (enumeration->type_op == type_enumeration));
1369 assert(pos >= 0 && pos < get_enumeration_n_enums(enumeration));
1370 return get_id_str(enumeration->attr.ea.enum_nameid[pos]);
1374 bool is_enumeration_type (type *enumeration) {
1375 assert(enumeration);
1376 if (enumeration->type_op == type_enumeration) return 1; else return 0;
1379 /*******************************************************************/
1380 /** TYPE_POINTER **/
1381 /*******************************************************************/
1383 /* Create a new type pointer */
1384 INLINE type *new_type_pointer_mode (ident *name, type *points_to, ir_mode *ptr_mode) {
1386 assert(mode_is_reference(ptr_mode));
1387 res = new_type(type_pointer, ptr_mode, name);
1388 res->attr.pa.points_to = points_to;
1389 assert((get_mode_size_bytes(res->mode) != -1) && "unorthodox modes not implemented");
1390 res->size = get_mode_size_bytes(res->mode);
1391 res->state = layout_fixed;
1394 type *new_d_type_pointer (ident *name, type *points_to, ir_mode *ptr_mode, dbg_info* db) {
1395 type *res = new_type_pointer_mode (name, points_to, ptr_mode);
1396 set_type_dbg_info(res, db);
1399 INLINE void free_pointer_entities (type *pointer) {
1400 assert(pointer && (pointer->type_op == type_pointer));
1402 INLINE void free_pointer_attrs (type *pointer) {
1403 assert(pointer && (pointer->type_op == type_pointer));
1405 /* manipulate fields of type_pointer */
1406 void set_pointer_points_to_type (type *pointer, type *tp) {
1407 assert(pointer && (pointer->type_op == type_pointer));
1408 pointer->attr.pa.points_to = tp;
1410 type *get_pointer_points_to_type (type *pointer) {
1411 assert(pointer && (pointer->type_op == type_pointer));
1412 return pointer->attr.pa.points_to = skip_tid(pointer->attr.pa.points_to);
1416 bool is_pointer_type (type *pointer) {
1418 if (pointer->type_op == type_pointer) return 1; else return 0;
1421 /* Returns the first pointer type that has as points_to tp.
1422 * Not efficient: O(#types).
1423 * If not found returns unknown_type. */
1424 type *find_pointer_type_to_type (type *tp) {
1426 for (i = 0; i < get_irp_n_types(); ++i) {
1427 type *found = get_irp_type(i);
1428 if (is_pointer_type(found) && get_pointer_points_to_type(found) == tp)
1431 return unknown_type;
1436 /*******************************************************************/
1437 /** TYPE_PRIMITIVE **/
1438 /*******************************************************************/
1440 /* create a new type primitive */
1441 INLINE type *new_type_primitive (ident *name, ir_mode *mode) {
1443 /* @@@ assert( mode_is_data(mode) && (!mode_is_reference(mode))); */
1444 res = new_type(type_primitive, mode, name);
1445 assert((get_mode_size_bytes(mode) != -1) && "unorthodox modes not implemented");
1446 res->size = get_mode_size_bytes(mode);
1447 res->state = layout_fixed;
1450 type *new_d_type_primitive (ident *name, ir_mode *mode, dbg_info* db) {
1451 type *res = new_type_primitive (name, mode);
1452 set_type_dbg_info(res, db);
1455 INLINE void free_primitive_entities (type *primitive) {
1456 assert(primitive && (primitive->type_op == type_primitive));
1458 INLINE void free_primitive_attrs (type *primitive) {
1459 assert(primitive && (primitive->type_op == type_primitive));
1463 bool is_primitive_type (type *primitive) {
1464 assert(primitive && primitive->kind == k_type);
1465 if (primitive->type_op == type_primitive) return 1; else return 0;
1468 /*******************************************************************/
1469 /** common functionality **/
1470 /*******************************************************************/
1473 INLINE int is_atomic_type(type *tp) {
1474 assert(tp && tp->kind == k_type);
1475 return (is_primitive_type(tp) || is_pointer_type(tp) ||
1476 is_enumeration_type(tp));
1480 * Gets the number of elements in a firm compound type.
1482 int get_compound_n_members(type *tp)
1486 if (is_struct_type(tp))
1487 res = get_struct_n_members(tp);
1488 else if (is_class_type(tp))
1489 res = get_class_n_members(tp);
1490 else if (is_union_type(tp))
1491 res = get_union_n_members(tp);
1493 assert(0 && "need struct, union or class for member count");
1499 * Gets the member of a firm compound type at position pos.
1501 entity *get_compound_member(type *tp, int pos)
1505 if (is_struct_type(tp))
1506 res = get_struct_member(tp, pos);
1507 else if (is_class_type(tp))
1508 res = get_class_member(tp, pos);
1509 else if (is_union_type(tp))
1510 res = get_union_member(tp, pos);
1513 assert(0 && "need struct, union or class to get a member");
1521 INLINE int is_compound_type(type *tp) {
1522 assert(tp && tp->kind == k_type);
1523 return (is_class_type(tp) || is_struct_type(tp) ||
1524 is_array_type(tp) || is_union_type(tp));