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;
55 TYPE_QUALIFIER_NONE = 0,
56 TYPE_QUALIFIER_CONST = 1 << 0,
57 TYPE_QUALIFIER_RESTRICT = 1 << 1,
58 TYPE_QUALIFIER_VOLATILE = 1 << 2,
59 /* microsoft extended qualifiers */
60 TYPE_QUALIFIER_W64 = 1 << 3,
61 TYPE_QUALIFIER_PTR32 = 1 << 4,
62 TYPE_QUALIFIER_PTR64 = 1 << 5,
63 TYPE_QUALIFIER_SPTR = 1 << 6,
64 TYPE_QUALIFIER_UPTR = 1 << 7,
67 typedef unsigned int type_qualifiers_t;
71 type_qualifiers_t qualifiers;
72 unsigned char alignment; /**< The extra alignment of the type, 0 for default. */
73 source_position_t source_position;
78 struct atomic_type_t {
80 atomic_type_kind_t akind;
83 struct complex_type_t {
85 atomic_type_kind_t akind;
88 struct imaginary_type_t {
90 atomic_type_kind_t akind;
93 struct builtin_type_t {
99 struct pointer_type_t {
104 struct array_type_t {
106 type_t *element_type;
107 expression_t *size_expression;
110 ir_node *size_node; /**< used by ast2firm phase */
112 unsigned is_static : 1; /**< a [static] type */
113 unsigned is_variable : 1; /**< a [*] type */
114 unsigned has_implicit_size : 1;
115 unsigned size_constant : 1; /**< size expression is constant */
116 unsigned is_vla : 1; /**< it's a variable length array */
119 struct function_parameter_t {
121 function_parameter_t *next;
124 struct function_type_t {
127 function_parameter_t *parameters;
128 unsigned variadic : 1;
129 unsigned unspecified_parameters : 1;
130 unsigned kr_style_parameters : 1;
133 struct compound_type_t {
135 /** the declaration of the compound type, the scope of the declaration
136 * contains the compound entries. */
137 declaration_t *declaration;
142 /** the declaration of the enum type. You can find the enum entries by
143 * walking the declaration->next list until you don't find
144 * STORAGE_CLASS_ENUM_ENTRY declarations anymore */
145 declaration_t *declaration;
148 struct typedef_type_t {
150 declaration_t *declaration;
151 type_t *resolved_type;
154 struct typeof_type_t {
156 expression_t *expression;
158 type_t *resolved_type;
161 struct bitfield_type_t {
170 atomic_type_t atomic;
171 complex_type_t complex;
172 imaginary_type_t imaginary;
173 builtin_type_t builtin;
174 pointer_type_t pointer;
176 function_type_t function;
177 compound_type_t compound;
179 typedef_type_t typedeft;
180 bitfield_type_t bitfield;
181 typeof_type_t typeoft;
184 type_t *make_atomic_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
185 type_t *make_complex_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
186 type_t *make_imaginary_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
187 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
188 type_t *make_array_type(type_t *element_type, size_t size,
189 type_qualifiers_t qualifiers);
191 type_t *duplicate_type(const type_t *type);
193 static inline bool is_typeref(const type_t *type)
195 return type->kind == TYPE_TYPEDEF || type->kind == TYPE_TYPEOF;
198 static inline bool is_type_atomic(const type_t *type, atomic_type_kind_t atype)
200 assert(!is_typeref(type));
202 if(type->kind != TYPE_ATOMIC)
204 const atomic_type_t *atomic_type = &type->atomic;
206 return atomic_type->akind == atype;
209 static inline bool is_type_pointer(const type_t *type)
211 assert(!is_typeref(type));
212 return type->kind == TYPE_POINTER;
215 static inline bool is_type_array(const type_t *type)
217 assert(!is_typeref(type));
218 return type->kind == TYPE_ARRAY;
221 static inline bool is_type_function(const type_t *type)
223 assert(!is_typeref(type));
224 return type->kind == TYPE_FUNCTION;
227 static inline bool is_type_union(const type_t *type)
229 assert(!is_typeref(type));
230 return type->kind == TYPE_COMPOUND_UNION;
233 static inline bool is_type_struct(const type_t *type)
235 assert(!is_typeref(type));
236 return type->kind == TYPE_COMPOUND_STRUCT;
239 static inline bool is_type_builtin(const type_t *type)
241 assert(!is_typeref(type));
242 return type->kind == TYPE_BUILTIN;
245 static inline bool is_type_compound(const type_t *type)
247 assert(!is_typeref(type));
248 return type->kind == TYPE_COMPOUND_STRUCT
249 || type->kind == TYPE_COMPOUND_UNION;
252 static inline bool is_type_valid(const type_t *type)
254 return type->kind != TYPE_ERROR;