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 {
101 unsigned is_static : 1;
102 unsigned is_variable : 1;
103 unsigned has_implicit_size : 1;
106 struct function_parameter_t {
108 function_parameter_t *next;
111 struct function_type_t {
114 function_parameter_t *parameters;
115 unsigned variadic : 1;
116 unsigned unspecified_parameters : 1;
117 unsigned kr_style_parameters : 1;
120 struct compound_type_t {
122 /** the declaration of the compound type, the scope of the declaration
123 * contains the compound entries. */
124 declaration_t *declaration;
129 /** the declaration of the enum type. You can find the enum entries by
130 * walking the declaration->next list until you don't find
131 * STORAGE_CLASS_ENUM_ENTRY declarations anymore */
132 declaration_t *declaration;
135 struct typedef_type_t {
137 declaration_t *declaration;
138 type_t *resolved_type;
141 struct typeof_type_t {
143 expression_t *expression;
145 type_t *resolved_type;
148 struct bitfield_type_t {
157 atomic_type_t atomic;
158 builtin_type_t builtin;
159 pointer_type_t pointer;
161 function_type_t function;
162 compound_type_t compound;
164 typedef_type_t typedeft;
165 bitfield_type_t bitfield;
166 typeof_type_t typeoft;
169 type_t *make_atomic_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
170 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
172 type_t *duplicate_type(const type_t *type);
174 static inline bool is_typeref(const type_t *type)
176 return type->kind == TYPE_TYPEDEF || type->kind == TYPE_TYPEOF;
179 static inline bool is_type_atomic(const type_t *type, atomic_type_kind_t atype)
181 assert(!is_typeref(type));
183 if(type->kind != TYPE_ATOMIC)
185 const atomic_type_t *atomic_type = &type->atomic;
187 return atomic_type->akind == atype;
190 static inline bool is_type_pointer(const type_t *type)
192 assert(!is_typeref(type));
193 return type->kind == TYPE_POINTER;
196 static inline bool is_type_array(const type_t *type)
198 assert(!is_typeref(type));
199 return type->kind == TYPE_ARRAY;
202 static inline bool is_type_function(const type_t *type)
204 assert(!is_typeref(type));
205 return type->kind == TYPE_FUNCTION;
208 static inline bool is_type_compound(const type_t *type)
210 assert(!is_typeref(type));
211 return type->kind == TYPE_COMPOUND_STRUCT
212 || type->kind == TYPE_COMPOUND_UNION;
215 static inline bool is_type_valid(const type_t *type)
217 return type->kind != TYPE_ERROR;