7 #include <libfirm/firm_types.h>
15 extern struct obstack *type_obst;
33 /* note that the constant values represent the rank of the types as defined
36 ATOMIC_TYPE_INVALID = 0,
48 ATOMIC_TYPE_ULONGLONG,
51 ATOMIC_TYPE_LONG_DOUBLE,
53 #ifdef PROVIDE_COMPLEX
54 ATOMIC_TYPE_FLOAT_COMPLEX,
55 ATOMIC_TYPE_DOUBLE_COMPLEX,
56 ATOMIC_TYPE_LONG_DOUBLE_COMPLEX,
57 ATOMIC_TYPE_FLOAT_IMAGINARY,
58 ATOMIC_TYPE_DOUBLE_IMAGINARY,
59 ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY,
65 TYPE_QUALIFIER_NONE = 0,
66 TYPE_QUALIFIER_CONST = 1 << 0,
67 TYPE_QUALIFIER_RESTRICT = 1 << 1,
68 TYPE_QUALIFIER_VOLATILE = 1 << 2,
71 typedef unsigned int type_qualifiers_t;
75 type_qualifiers_t qualifiers;
76 source_position_t source_position;
81 struct atomic_type_t {
83 atomic_type_kind_t akind;
86 struct builtin_type_t {
92 struct pointer_type_t {
100 expression_t *size_expression;
103 ir_node *size_node; /**< used by ast2firm phase */
105 unsigned is_static : 1; /**< a [static] type */
106 unsigned is_variable : 1; /**< a [*] type */
107 unsigned has_implicit_size : 1;
108 unsigned size_constant : 1; /**< size expression is constant */
109 unsigned is_vla : 1; /**< it's a variable length array */
112 struct function_parameter_t {
114 function_parameter_t *next;
117 struct function_type_t {
120 function_parameter_t *parameters;
121 unsigned variadic : 1;
122 unsigned unspecified_parameters : 1;
123 unsigned kr_style_parameters : 1;
126 struct compound_type_t {
128 /** the declaration of the compound type, the scope of the declaration
129 * contains the compound entries. */
130 declaration_t *declaration;
135 /** the declaration of the enum type. You can find the enum entries by
136 * walking the declaration->next list until you don't find
137 * STORAGE_CLASS_ENUM_ENTRY declarations anymore */
138 declaration_t *declaration;
141 struct typedef_type_t {
143 declaration_t *declaration;
144 type_t *resolved_type;
147 struct typeof_type_t {
149 expression_t *expression;
151 type_t *resolved_type;
154 struct bitfield_type_t {
163 atomic_type_t atomic;
164 builtin_type_t builtin;
165 pointer_type_t pointer;
167 function_type_t function;
168 compound_type_t compound;
170 typedef_type_t typedeft;
171 bitfield_type_t bitfield;
172 typeof_type_t typeoft;
175 type_t *make_atomic_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
176 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
177 type_t *make_array_type(type_t *element_type, size_t size,
178 type_qualifiers_t qualifiers);
180 type_t *duplicate_type(const type_t *type);
182 static inline bool is_typeref(const type_t *type)
184 return type->kind == TYPE_TYPEDEF || type->kind == TYPE_TYPEOF;
187 static inline bool is_type_atomic(const type_t *type, atomic_type_kind_t atype)
189 assert(!is_typeref(type));
191 if(type->kind != TYPE_ATOMIC)
193 const atomic_type_t *atomic_type = &type->atomic;
195 return atomic_type->akind == atype;
198 static inline bool is_type_pointer(const type_t *type)
200 assert(!is_typeref(type));
201 return type->kind == TYPE_POINTER;
204 static inline bool is_type_array(const type_t *type)
206 assert(!is_typeref(type));
207 return type->kind == TYPE_ARRAY;
210 static inline bool is_type_function(const type_t *type)
212 assert(!is_typeref(type));
213 return type->kind == TYPE_FUNCTION;
216 static inline bool is_type_union(const type_t *type)
218 assert(!is_typeref(type));
219 return type->kind == TYPE_COMPOUND_UNION;
222 static inline bool is_type_struct(const type_t *type)
224 assert(!is_typeref(type));
225 return type->kind == TYPE_COMPOUND_STRUCT;
228 static inline bool is_type_builtin(const type_t *type)
230 assert(!is_typeref(type));
231 return type->kind == TYPE_BUILTIN;
234 static inline bool is_type_compound(const type_t *type)
236 assert(!is_typeref(type));
237 return type->kind == TYPE_COMPOUND_STRUCT
238 || type->kind == TYPE_COMPOUND_UNION;
241 static inline bool is_type_valid(const type_t *type)
243 return type->kind != TYPE_ERROR;