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;
80 struct atomic_type_t {
82 atomic_type_kind_t akind;
85 struct builtin_type_t {
91 struct pointer_type_t {
100 unsigned is_static : 1;
101 unsigned is_variable : 1;
102 unsigned has_implicit_size : 1;
105 struct function_parameter_t {
107 function_parameter_t *next;
110 struct function_type_t {
113 function_parameter_t *parameters;
114 unsigned variadic : 1;
115 unsigned unspecified_parameters : 1;
116 unsigned kr_style_parameters : 1;
119 struct compound_type_t {
121 /** the declaration of the compound type, the scope of the declaration
122 * contains the compound entries. */
123 declaration_t *declaration;
128 /** the declaration of the enum type. You can find the enum entries by
129 * walking the declaration->next list until you don't find
130 * STORAGE_CLASS_ENUM_ENTRY declarations anymore */
131 declaration_t *declaration;
134 struct typedef_type_t {
136 declaration_t *declaration;
137 type_t *resolved_type;
140 struct typeof_type_t {
142 expression_t *expression;
144 type_t *resolved_type;
147 struct bitfield_type_t {
156 atomic_type_t atomic;
157 builtin_type_t builtin;
158 pointer_type_t pointer;
160 function_type_t function;
161 compound_type_t compound;
163 typedef_type_t typedeft;
164 bitfield_type_t bitfield;
165 typeof_type_t typeoft;
168 type_t *make_atomic_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
169 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
171 type_t *duplicate_type(const type_t *type);
173 static inline bool is_typeref(const type_t *type)
175 return type->kind == TYPE_TYPEDEF || type->kind == TYPE_TYPEOF;
178 static inline bool is_type_atomic(const type_t *type, atomic_type_kind_t atype)
180 assert(!is_typeref(type));
182 if(type->kind != TYPE_ATOMIC)
184 const atomic_type_t *atomic_type = &type->atomic;
186 return atomic_type->akind == atype;
189 static inline bool is_type_pointer(const type_t *type)
191 assert(!is_typeref(type));
192 return type->kind == TYPE_POINTER;
195 static inline bool is_type_array(const type_t *type)
197 assert(!is_typeref(type));
198 return type->kind == TYPE_ARRAY;
201 static inline bool is_type_function(const type_t *type)
203 assert(!is_typeref(type));
204 return type->kind == TYPE_FUNCTION;
207 static inline bool is_type_compound(const type_t *type)
209 assert(!is_typeref(type));
210 return type->kind == TYPE_COMPOUND_STRUCT
211 || type->kind == TYPE_COMPOUND_UNION;
214 static inline bool is_type_valid(const type_t *type)
216 return type->kind != TYPE_ERROR;