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 source_position_t source_position;
63 il_size_t size; /**< The size of this type. */
64 type_qualifiers_t qualifiers;
65 type_modifiers_t modifiers;
66 il_alignment_t alignment; /**< The extra alignment of the type, 0 for default. */
71 struct atomic_type_t {
73 atomic_type_kind_t akind;
76 struct complex_type_t {
78 atomic_type_kind_t akind;
81 struct imaginary_type_t {
83 atomic_type_kind_t akind;
86 struct builtin_type_t {
92 struct pointer_type_t {
100 expression_t *size_expression;
103 ir_node *size_node; /**< used by ast2firm phase */
105 unsigned is_static : 1; /**< a [static] type */
106 unsigned is_variable : 1; /**< a [*] type */
107 unsigned has_implicit_size : 1;
108 unsigned size_constant : 1; /**< size expression is constant */
109 unsigned is_vla : 1; /**< it's a variable length array */
113 * An entry in the parameter list of a function type.
115 struct function_parameter_t {
116 type_t *type; /**< The parameter type. */
117 function_parameter_t *next; /**< Points to the next type inthe parameter list.*/
120 /** Calling conventions. */
121 typedef enum cc_kind_t {
122 CC_DEFAULT, /**< default calling convention. */
123 CC_CDECL, /**< cdecl calling convention. */
124 CC_STDCALL, /**< stdcall calling convention. */
125 CC_FASTCALL, /**< fastcall calling convention. */
126 CC_THISCALL /**< thiscall calling convention. */
132 struct function_type_t {
134 type_t *return_type; /**< The return type. */
135 function_parameter_t *parameters; /**< A list of the parameter types. */
136 cc_kind_t calling_convention; /**< The specified calling convention. */
137 unsigned variadic : 1;
138 unsigned unspecified_parameters : 1;
139 unsigned kr_style_parameters : 1;
142 struct compound_type_t {
144 unsigned packed:1; /** Set if packed was specified. */
145 /** the declaration of the compound type, the scope of the declaration
146 * contains the compound entries. */
147 declaration_t *declaration;
152 /** the declaration of the enum type. You can find the enum entries by
153 * walking the declaration->next list until you don't find
154 * STORAGE_CLASS_ENUM_ENTRY declarations anymore */
155 declaration_t *declaration;
158 struct typedef_type_t {
160 declaration_t *declaration;
161 type_t *resolved_type;
164 struct typeof_type_t {
166 expression_t *expression;
168 type_t *resolved_type;
171 struct bitfield_type_t {
174 expression_t *size_expression; /**< The expression for the bit size. */
175 il_size_t bit_size; /**< Size of this bitfield in bits. */
181 atomic_type_t atomic;
182 complex_type_t complex;
183 imaginary_type_t imaginary;
184 builtin_type_t builtin;
185 pointer_type_t pointer;
187 function_type_t function;
188 compound_type_t compound;
190 typedef_type_t typedeft;
191 bitfield_type_t bitfield;
192 typeof_type_t typeoft;
195 type_t *make_atomic_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
196 type_t *make_complex_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
197 type_t *make_imaginary_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
198 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
199 type_t *make_array_type(type_t *element_type, size_t size,
200 type_qualifiers_t qualifiers);
202 type_t *duplicate_type(const type_t *type);
204 static inline bool is_typeref(const type_t *type)
206 return type->kind == TYPE_TYPEDEF || type->kind == TYPE_TYPEOF;
209 static inline bool is_type_atomic(const type_t *type, atomic_type_kind_t atype)
211 assert(!is_typeref(type));
213 if(type->kind != TYPE_ATOMIC)
215 const atomic_type_t *atomic_type = &type->atomic;
217 return atomic_type->akind == atype;
220 static inline bool is_type_pointer(const type_t *type)
222 assert(!is_typeref(type));
223 return type->kind == TYPE_POINTER;
226 static inline bool is_type_array(const type_t *type)
228 assert(!is_typeref(type));
229 return type->kind == TYPE_ARRAY;
232 static inline bool is_type_function(const type_t *type)
234 assert(!is_typeref(type));
235 return type->kind == TYPE_FUNCTION;
238 static inline bool is_type_union(const type_t *type)
240 assert(!is_typeref(type));
241 return type->kind == TYPE_COMPOUND_UNION;
244 static inline bool is_type_struct(const type_t *type)
246 assert(!is_typeref(type));
247 return type->kind == TYPE_COMPOUND_STRUCT;
250 static inline bool is_type_builtin(const type_t *type)
252 assert(!is_typeref(type));
253 return type->kind == TYPE_BUILTIN;
256 static inline bool is_type_compound(const type_t *type)
258 assert(!is_typeref(type));
259 return type->kind == TYPE_COMPOUND_STRUCT
260 || type->kind == TYPE_COMPOUND_UNION;
263 static inline bool is_type_valid(const type_t *type)
265 return type->kind != TYPE_ERROR;