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;
52 /* note that the constant values represent the rank of the types as defined
55 ATOMIC_TYPE_INVALID = 0,
67 ATOMIC_TYPE_ULONGLONG,
70 ATOMIC_TYPE_LONG_DOUBLE,
72 #ifdef PROVIDE_COMPLEX
73 ATOMIC_TYPE_FLOAT_COMPLEX,
74 ATOMIC_TYPE_DOUBLE_COMPLEX,
75 ATOMIC_TYPE_LONG_DOUBLE_COMPLEX,
76 ATOMIC_TYPE_FLOAT_IMAGINARY,
77 ATOMIC_TYPE_DOUBLE_IMAGINARY,
78 ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY,
84 TYPE_QUALIFIER_NONE = 0,
85 TYPE_QUALIFIER_CONST = 1 << 0,
86 TYPE_QUALIFIER_RESTRICT = 1 << 1,
87 TYPE_QUALIFIER_VOLATILE = 1 << 2,
90 typedef unsigned int type_qualifiers_t;
94 type_qualifiers_t qualifiers;
95 source_position_t source_position;
100 struct atomic_type_t {
102 atomic_type_kind_t akind;
105 struct builtin_type_t {
111 struct pointer_type_t {
116 struct array_type_t {
118 type_t *element_type;
119 expression_t *size_expression;
122 ir_node *size_node; /**< used by ast2firm phase */
124 unsigned is_static : 1; /**< a [static] type */
125 unsigned is_variable : 1; /**< a [*] type */
126 unsigned has_implicit_size : 1;
127 unsigned size_constant : 1; /**< size expression is constant */
128 unsigned is_vla : 1; /**< it's a variable length array */
131 struct function_parameter_t {
133 function_parameter_t *next;
136 struct function_type_t {
139 function_parameter_t *parameters;
140 unsigned variadic : 1;
141 unsigned unspecified_parameters : 1;
142 unsigned kr_style_parameters : 1;
145 struct compound_type_t {
147 /** the declaration of the compound type, the scope of the declaration
148 * contains the compound entries. */
149 declaration_t *declaration;
154 /** the declaration of the enum type. You can find the enum entries by
155 * walking the declaration->next list until you don't find
156 * STORAGE_CLASS_ENUM_ENTRY declarations anymore */
157 declaration_t *declaration;
160 struct typedef_type_t {
162 declaration_t *declaration;
163 type_t *resolved_type;
166 struct typeof_type_t {
168 expression_t *expression;
170 type_t *resolved_type;
173 struct bitfield_type_t {
182 atomic_type_t atomic;
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_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
196 type_t *make_array_type(type_t *element_type, size_t size,
197 type_qualifiers_t qualifiers);
199 type_t *duplicate_type(const type_t *type);
201 static inline bool is_typeref(const type_t *type)
203 return type->kind == TYPE_TYPEDEF || type->kind == TYPE_TYPEOF;
206 static inline bool is_type_atomic(const type_t *type, atomic_type_kind_t atype)
208 assert(!is_typeref(type));
210 if(type->kind != TYPE_ATOMIC)
212 const atomic_type_t *atomic_type = &type->atomic;
214 return atomic_type->akind == atype;
217 static inline bool is_type_pointer(const type_t *type)
219 assert(!is_typeref(type));
220 return type->kind == TYPE_POINTER;
223 static inline bool is_type_array(const type_t *type)
225 assert(!is_typeref(type));
226 return type->kind == TYPE_ARRAY;
229 static inline bool is_type_function(const type_t *type)
231 assert(!is_typeref(type));
232 return type->kind == TYPE_FUNCTION;
235 static inline bool is_type_union(const type_t *type)
237 assert(!is_typeref(type));
238 return type->kind == TYPE_COMPOUND_UNION;
241 static inline bool is_type_struct(const type_t *type)
243 assert(!is_typeref(type));
244 return type->kind == TYPE_COMPOUND_STRUCT;
247 static inline bool is_type_builtin(const type_t *type)
249 assert(!is_typeref(type));
250 return type->kind == TYPE_BUILTIN;
253 static inline bool is_type_compound(const type_t *type)
255 assert(!is_typeref(type));
256 return type->kind == TYPE_COMPOUND_STRUCT
257 || type->kind == TYPE_COMPOUND_UNION;
260 static inline bool is_type_valid(const type_t *type)
262 return type->kind != TYPE_ERROR;