7 #include <libfirm/firm_types.h>
15 extern struct obstack *type_obst;
32 /* note that the constant values represent the rank of the types as defined
35 ATOMIC_TYPE_INVALID = 0,
47 ATOMIC_TYPE_ULONGLONG,
50 ATOMIC_TYPE_LONG_DOUBLE,
52 #ifdef PROVIDE_COMPLEX
53 ATOMIC_TYPE_FLOAT_COMPLEX,
54 ATOMIC_TYPE_DOUBLE_COMPLEX,
55 ATOMIC_TYPE_LONG_DOUBLE_COMPLEX,
56 ATOMIC_TYPE_FLOAT_IMAGINARY,
57 ATOMIC_TYPE_DOUBLE_IMAGINARY,
58 ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY,
64 TYPE_QUALIFIER_NONE = 0,
65 TYPE_QUALIFIER_CONST = 1 << 0,
66 TYPE_QUALIFIER_RESTRICT = 1 << 1,
67 TYPE_QUALIFIER_VOLATILE = 1 << 2,
70 typedef unsigned int type_qualifiers_t;
74 type_qualifiers_t qualifiers;
79 struct atomic_type_t {
81 atomic_type_kind_t akind;
84 struct builtin_type_t {
90 struct pointer_type_t {
103 struct function_parameter_t {
105 function_parameter_t *next;
108 struct function_type_t {
111 function_parameter_t *parameters;
112 unsigned variadic : 1;
113 unsigned unspecified_parameters : 1;
114 unsigned kr_style_parameters : 1;
117 struct compound_type_t {
119 /** the declaration of the compound type, its context field
120 * contains the compound entries. */
121 declaration_t *declaration;
126 /** the declaration of the enum type. You can find the enum entries by
127 * walking the declaration->next list until you don't find
128 * STORAGE_CLASS_ENUM_ENTRY declarations anymore */
129 declaration_t *declaration;
132 struct typedef_type_t {
134 declaration_t *declaration;
135 type_t *resolved_type;
138 struct typeof_type_t {
140 expression_t *expression;
142 type_t *resolved_type;
145 struct bitfield_type_t {
154 atomic_type_t atomic;
155 builtin_type_t builtin;
156 pointer_type_t pointer;
158 function_type_t function;
159 compound_type_t compound;
161 typedef_type_t typedeft;
162 bitfield_type_t bitfield;
163 typeof_type_t typeoft;
166 type_t *make_atomic_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
167 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
169 type_t *duplicate_type(type_t *type);
171 static inline bool is_typeref(const type_t *type)
173 return type->kind == TYPE_TYPEDEF || type->kind == TYPE_TYPEOF;
176 static inline bool is_type_atomic(const type_t *type, atomic_type_kind_t atype)
178 assert(!is_typeref(type));
180 if(type->kind != TYPE_ATOMIC)
182 const atomic_type_t *atomic_type = &type->atomic;
184 return atomic_type->akind == atype;
187 static inline bool is_type_pointer(const type_t *type)
189 assert(!is_typeref(type));
190 return type->kind == TYPE_POINTER;
193 static inline bool is_type_array(const type_t *type)
195 assert(!is_typeref(type));
196 return type->kind == TYPE_ARRAY;
199 static inline bool is_type_function(const type_t *type)
201 assert(!is_typeref(type));
202 return type->kind == TYPE_FUNCTION;
205 static inline bool is_type_compound(const type_t *type)
207 assert(!is_typeref(type));
208 return type->kind == TYPE_COMPOUND_STRUCT
209 || type->kind == TYPE_COMPOUND_UNION;