2 * This file is part of cparser.
3 * Copyright (C) 2007-2008 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 extern struct obstack *type_obst;
36 typedef enum type_kind_t {
57 type_qualifiers_t qualifiers;
59 /* cached ast2firm infos */
63 struct atomic_type_t {
65 atomic_type_kind_t akind;
68 struct complex_type_t {
70 atomic_type_kind_t akind;
73 struct imaginary_type_t {
75 atomic_type_kind_t akind;
78 struct builtin_type_t {
84 struct pointer_type_t {
87 variable_t *base_variable; /**< Microsoft __based() extension: base variable or NULL. */
90 struct reference_type_t {
98 expression_t *size_expression;
101 ir_node *size_node; /**< used by ast2firm phase */
103 bool is_static : 1; /**< a [static] type */
104 bool is_variable : 1; /**< a [*] type */
105 bool has_implicit_size : 1;
106 bool size_constant : 1; /**< size expression is constant */
107 bool is_vla : 1; /**< it's a variable length array */
111 * An entry in the parameter list of a function type.
113 struct function_parameter_t {
114 type_t *type; /**< The parameter type. */
115 function_parameter_t *next; /**< Points to the next type in the parameter list.*/
118 /** Linkage specifications. */
119 typedef enum linkage_kind_t {
121 LINKAGE_C, /**< C linkage. */
122 LINKAGE_CXX /**< C++ linkage. */
125 /** Calling conventions. */
126 typedef enum cc_kind_t {
127 CC_DEFAULT, /**< default calling convention. */
128 CC_CDECL, /**< cdecl calling convention. */
129 CC_STDCALL, /**< stdcall calling convention. */
130 CC_FASTCALL, /**< fastcall calling convention. */
131 CC_THISCALL /**< thiscall calling convention. */
137 struct function_type_t {
139 type_t *return_type; /**< The return type. */
140 function_parameter_t *parameters; /**< A list of the parameter types. */
141 linkage_kind_t linkage;
142 cc_kind_t calling_convention; /**< The specified calling convention. */
143 decl_modifiers_t modifiers;
145 bool unspecified_parameters : 1;
146 bool kr_style_parameters : 1;
150 struct compound_type_t {
152 bool packed : 1; /**< Set if packed was specified. */
153 /** the declaration of the compound type, the scope of the declaration
154 * contains the compound entries. */
155 compound_t *compound;
160 atomic_type_kind_t akind; /**< underlying atomic type */
161 /** the enum entity. You can find the enum entries by walking the
162 * enum->base.next list until you don't find ENTITY_ENUM_VALUE entities
167 struct typedef_type_t {
170 type_t *resolved_type;
173 struct typeof_type_t {
175 expression_t *expression;
177 type_t *resolved_type;
180 struct bitfield_type_t {
183 expression_t *size_expression; /**< The expression for the bit size. */
184 il_size_t bit_size; /**< Size of this bitfield in bits. */
190 atomic_type_t atomic;
191 complex_type_t complex;
192 imaginary_type_t imaginary;
193 builtin_type_t builtin;
194 pointer_type_t pointer;
195 reference_type_t reference;
197 function_type_t function;
198 compound_type_t compound;
200 typedef_type_t typedeft;
201 bitfield_type_t bitfield;
202 typeof_type_t typeoft;
205 /** The default calling convention for functions. */
206 extern cc_kind_t default_calling_convention;
208 type_t *make_atomic_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
209 type_t *make_complex_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
210 type_t *make_imaginary_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
211 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
212 type_t *make_reference_type(type_t *refers_to);
213 type_t *make_based_pointer_type(type_t *points_to,
214 type_qualifiers_t qualifiers, variable_t *variable);
215 type_t *make_array_type(type_t *element_type, size_t size,
216 type_qualifiers_t qualifiers);
218 type_t *duplicate_type(const type_t *type);
219 type_t *identify_new_type(type_t *type);
221 static inline bool is_typeref(const type_t *type)
223 return type->kind == TYPE_TYPEDEF || type->kind == TYPE_TYPEOF;
226 static inline bool is_type_atomic(const type_t *type, atomic_type_kind_t atype)
228 assert(!is_typeref(type));
230 if(type->kind != TYPE_ATOMIC)
232 const atomic_type_t *atomic_type = &type->atomic;
234 return atomic_type->akind == atype;
237 static inline bool is_type_pointer(const type_t *type)
239 assert(!is_typeref(type));
240 return type->kind == TYPE_POINTER;
243 static inline bool is_type_reference(const type_t *type)
245 assert(!is_typeref(type));
246 return type->kind == TYPE_REFERENCE;
249 static inline bool is_type_array(const type_t *type)
251 assert(!is_typeref(type));
252 return type->kind == TYPE_ARRAY;
255 static inline bool is_type_function(const type_t *type)
257 assert(!is_typeref(type));
258 return type->kind == TYPE_FUNCTION;
261 static inline bool is_type_union(const type_t *type)
263 assert(!is_typeref(type));
264 return type->kind == TYPE_COMPOUND_UNION;
267 static inline bool is_type_struct(const type_t *type)
269 assert(!is_typeref(type));
270 return type->kind == TYPE_COMPOUND_STRUCT;
273 static inline bool is_type_builtin(const type_t *type)
275 assert(!is_typeref(type));
276 return type->kind == TYPE_BUILTIN;
279 static inline bool is_type_compound(const type_t *type)
281 assert(!is_typeref(type));
282 return type->kind == TYPE_COMPOUND_STRUCT
283 || type->kind == TYPE_COMPOUND_UNION;
286 static inline bool is_type_valid(const type_t *type)
288 assert(!is_typeref(type));
289 return type->kind != TYPE_ERROR;