2 * This file is part of cparser.
3 * Copyright (C) 2007-2009 Matthias Braun <matze@braunis.de>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include <libfirm/firm_types.h>
34 typedef enum type_kind_t {
52 type_qualifiers_t qualifiers;
54 /* cached ast2firm infos */
58 struct atomic_type_t {
60 atomic_type_kind_t akind;
63 struct complex_type_t {
65 atomic_type_kind_t akind;
68 struct imaginary_type_t {
70 atomic_type_kind_t akind;
73 struct pointer_type_t {
76 variable_t *base_variable; /**< Microsoft __based() extension: base variable or NULL. */
79 struct reference_type_t {
87 expression_t *size_expression;
90 ir_node *size_node; /**< used by ast2firm phase */
92 bool is_static : 1; /**< a [static] type */
93 bool is_variable : 1; /**< a [*] type */
94 bool has_implicit_size : 1;
95 bool size_constant : 1; /**< size expression is constant */
96 bool is_vla : 1; /**< it's a variable length array */
100 * An entry in the parameter list of a function type.
102 struct function_parameter_t {
103 type_t *type; /**< The parameter type. */
104 function_parameter_t *next; /**< Points to the next type in the parameter list.*/
107 /** Linkage specifications. */
108 typedef enum linkage_kind_t {
110 LINKAGE_C, /**< C linkage. */
111 LINKAGE_CXX /**< C++ linkage. */
114 /** Calling conventions. */
115 typedef enum cc_kind_t {
116 CC_DEFAULT, /**< default calling convention. */
117 CC_CDECL, /**< cdecl calling convention. */
118 CC_STDCALL, /**< stdcall calling convention. */
119 CC_FASTCALL, /**< fastcall calling convention. */
120 CC_THISCALL /**< thiscall calling convention. */
126 struct function_type_t {
128 type_t *return_type; /**< The return type. */
129 function_parameter_t *parameters; /**< A list of the parameter types. */
130 linkage_kind_t linkage;
131 cc_kind_t calling_convention; /**< The specified calling convention. */
132 decl_modifiers_t modifiers;
134 bool unspecified_parameters : 1;
135 bool kr_style_parameters : 1;
138 struct compound_type_t {
140 bool packed : 1; /**< Set if packed was specified. */
141 /** the declaration of the compound type, the scope of the declaration
142 * contains the compound entries. */
143 compound_t *compound;
148 atomic_type_kind_t akind; /**< underlying atomic type */
149 /** the enum entity. You can find the enum entries by walking the
150 * enum->base.next list until you don't find ENTITY_ENUM_VALUE entities
155 struct typedef_type_t {
158 type_t *resolved_type;
161 struct typeof_type_t {
163 expression_t *expression;
165 type_t *resolved_type;
171 atomic_type_t atomic;
172 complex_type_t complex;
173 imaginary_type_t imaginary;
174 pointer_type_t pointer;
175 reference_type_t reference;
177 function_type_t function;
178 compound_type_t compound;
180 typedef_type_t typedeft;
181 typeof_type_t typeoft;
184 typedef struct atomic_type_properties_t atomic_type_properties_t;
185 struct atomic_type_properties_t {
186 unsigned size; /**< type size in bytes */
187 unsigned alignment; /**< type alignment in bytes */
188 /** some ABIs are broken and require an alignment different from the
189 * recommended/best alignment inside structs. Fixing ABIs is difficult
190 * so people rather stick with the wrong values for compatibility.
191 * (double type on x86 System V ABI)
193 unsigned struct_alignment;
194 unsigned flags; /**< type flags from atomic_type_flag_t */
197 extern atomic_type_properties_t atomic_type_properties[ATOMIC_TYPE_LAST+1];
198 extern atomic_type_properties_t pointer_properties;
200 /** The default calling convention for functions. */
201 extern cc_kind_t default_calling_convention;
203 type_t *make_atomic_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
204 type_t *make_complex_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
205 type_t *make_imaginary_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
206 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
207 type_t *make_reference_type(type_t *refers_to);
208 type_t *make_based_pointer_type(type_t *points_to,
209 type_qualifiers_t qualifiers, variable_t *variable);
210 type_t *make_array_type(type_t *element_type, size_t size,
211 type_qualifiers_t qualifiers);
212 function_parameter_t *allocate_parameter(type_t*);
214 type_t *duplicate_type(const type_t *type);
215 type_t *identify_new_type(type_t *type);
217 static inline bool is_typeref(const type_t *type)
219 return type->kind == TYPE_TYPEDEF || type->kind == TYPE_TYPEOF;
222 static inline bool is_type_atomic(const type_t *type, atomic_type_kind_t atype)
224 assert(!is_typeref(type));
226 if(type->kind != TYPE_ATOMIC)
228 const atomic_type_t *atomic_type = &type->atomic;
230 return atomic_type->akind == atype;
233 static inline bool is_type_pointer(const type_t *type)
235 assert(!is_typeref(type));
236 return type->kind == TYPE_POINTER;
239 static inline bool is_type_reference(const type_t *type)
241 assert(!is_typeref(type));
242 return type->kind == TYPE_REFERENCE;
245 static inline bool is_type_array(const type_t *type)
247 assert(!is_typeref(type));
248 return type->kind == TYPE_ARRAY;
251 static inline bool is_type_function(const type_t *type)
253 assert(!is_typeref(type));
254 return type->kind == TYPE_FUNCTION;
257 static inline bool is_type_union(const type_t *type)
259 assert(!is_typeref(type));
260 return type->kind == TYPE_COMPOUND_UNION;
263 static inline bool is_type_struct(const type_t *type)
265 assert(!is_typeref(type));
266 return type->kind == TYPE_COMPOUND_STRUCT;
269 static inline bool is_type_compound(const type_t *type)
271 assert(!is_typeref(type));
272 return type->kind == TYPE_COMPOUND_STRUCT
273 || type->kind == TYPE_COMPOUND_UNION;
276 static inline bool is_type_valid(const type_t *type)
278 assert(!is_typeref(type));
279 return type->kind != TYPE_ERROR;
283 * Allocate a type node of given kind and initialize all
286 * @param kind type kind to allocate
288 type_t *allocate_type_zero(type_kind_t kind);
291 * Creates a return_type (func)(void) function type if not
294 * @param return_type the return type
296 type_t *make_function_0_type(type_t *return_type);
299 * Creates a return_type (func)(argument_type) function type if not
302 * @param return_type the return type
303 * @param argument_type the argument type
305 type_t *make_function_1_type(type_t *return_type, type_t *argument_type1);
309 * Creates a return_type (func)(argument_type1,argument_type2) function type
310 * if not already exists.
312 type_t *make_function_2_type(type_t *return_type, type_t *argument_type1,
313 type_t *argument_type2);
316 * Creates a return_type (func)(argument_type, ...) function type if not
319 * @param return_type the return type
320 * @param argument_type the argument type
322 type_t *make_function_1_type_variadic(type_t *return_type, type_t *argument_type);
325 * Create a function type with n parameters
327 type_t *make_function_type(type_t *return_type, int n_types,
328 type_t *const *argument_types,
329 decl_modifiers_t modifiers);