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 {
54 typedef enum type_modifier_t {
55 TYPE_MODIFIER_NONE = 0,
56 TYPE_MODIFIER_TRANSPARENT_UNION = 1 << 0,
58 typedef unsigned short type_modifiers_t;
62 il_size_t size; /**< The size of this type. */
63 type_qualifiers_t qualifiers;
64 type_modifiers_t modifiers;
65 il_alignment_t alignment; /**< The extra alignment of the type, 0 for default. */
70 struct atomic_type_t {
72 atomic_type_kind_t akind;
75 struct complex_type_t {
77 atomic_type_kind_t akind;
80 struct imaginary_type_t {
82 atomic_type_kind_t akind;
85 struct builtin_type_t {
91 struct pointer_type_t {
99 expression_t *size_expression;
102 ir_node *size_node; /**< used by ast2firm phase */
104 bool is_static : 1; /**< a [static] type */
105 bool is_variable : 1; /**< a [*] type */
106 bool has_implicit_size : 1;
107 bool size_constant : 1; /**< size expression is constant */
108 bool is_vla : 1; /**< it's a variable length array */
112 * An entry in the parameter list of a function type.
114 struct function_parameter_t {
115 type_t *type; /**< The parameter type. */
116 function_parameter_t *next; /**< Points to the next type inthe parameter list.*/
119 /** Calling conventions. */
120 typedef enum cc_kind_t {
121 CC_DEFAULT, /**< default calling convention. */
122 CC_CDECL, /**< cdecl calling convention. */
123 CC_STDCALL, /**< stdcall calling convention. */
124 CC_FASTCALL, /**< fastcall calling convention. */
125 CC_THISCALL /**< thiscall calling convention. */
131 struct function_type_t {
133 type_t *return_type; /**< The return type. */
134 function_parameter_t *parameters; /**< A list of the parameter types. */
135 cc_kind_t calling_convention; /**< The specified calling convention. */
137 bool unspecified_parameters : 1;
138 bool kr_style_parameters : 1;
141 struct compound_type_t {
143 bool packed : 1; /**< Set if packed was specified. */
144 /** the declaration of the compound type, the scope of the declaration
145 * contains the compound entries. */
146 compound_t *compound;
151 /** the enum entity. You can find the enum entries by walking the
152 * enum->base.next list until you don't find ENTITY_ENUM_VALUE entities
157 struct typedef_type_t {
160 type_t *resolved_type;
163 struct typeof_type_t {
165 expression_t *expression;
167 type_t *resolved_type;
170 struct bitfield_type_t {
173 expression_t *size_expression; /**< The expression for the bit size. */
174 il_size_t bit_size; /**< Size of this bitfield in bits. */
180 atomic_type_t atomic;
181 complex_type_t complex;
182 imaginary_type_t imaginary;
183 builtin_type_t builtin;
184 pointer_type_t pointer;
186 function_type_t function;
187 compound_type_t compound;
189 typedef_type_t typedeft;
190 bitfield_type_t bitfield;
191 typeof_type_t typeoft;
194 type_t *make_atomic_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
195 type_t *make_complex_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
196 type_t *make_imaginary_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
197 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
198 type_t *make_array_type(type_t *element_type, size_t size,
199 type_qualifiers_t qualifiers);
201 type_t *duplicate_type(const type_t *type);
203 static inline bool is_typeref(const type_t *type)
205 return type->kind == TYPE_TYPEDEF || type->kind == TYPE_TYPEOF;
208 static inline bool is_type_atomic(const type_t *type, atomic_type_kind_t atype)
210 assert(!is_typeref(type));
212 if(type->kind != TYPE_ATOMIC)
214 const atomic_type_t *atomic_type = &type->atomic;
216 return atomic_type->akind == atype;
219 static inline bool is_type_pointer(const type_t *type)
221 assert(!is_typeref(type));
222 return type->kind == TYPE_POINTER;
225 static inline bool is_type_array(const type_t *type)
227 assert(!is_typeref(type));
228 return type->kind == TYPE_ARRAY;
231 static inline bool is_type_function(const type_t *type)
233 assert(!is_typeref(type));
234 return type->kind == TYPE_FUNCTION;
237 static inline bool is_type_union(const type_t *type)
239 assert(!is_typeref(type));
240 return type->kind == TYPE_COMPOUND_UNION;
243 static inline bool is_type_struct(const type_t *type)
245 assert(!is_typeref(type));
246 return type->kind == TYPE_COMPOUND_STRUCT;
249 static inline bool is_type_builtin(const type_t *type)
251 assert(!is_typeref(type));
252 return type->kind == TYPE_BUILTIN;
255 static inline bool is_type_compound(const type_t *type)
257 assert(!is_typeref(type));
258 return type->kind == TYPE_COMPOUND_STRUCT
259 || type->kind == TYPE_COMPOUND_UNION;
262 static inline bool is_type_valid(const type_t *type)
264 assert(!is_typeref(type));
265 return type->kind != TYPE_ERROR;