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;
53 TYPE_QUALIFIER_NONE = 0,
54 TYPE_QUALIFIER_CONST = 1 << 0,
55 TYPE_QUALIFIER_RESTRICT = 1 << 1,
56 TYPE_QUALIFIER_VOLATILE = 1 << 2,
57 /* microsoft extended qualifiers */
58 TYPE_QUALIFIER_W64 = 1 << 3,
59 TYPE_QUALIFIER_PTR32 = 1 << 4,
60 TYPE_QUALIFIER_PTR64 = 1 << 5,
61 TYPE_QUALIFIER_SPTR = 1 << 6,
62 TYPE_QUALIFIER_UPTR = 1 << 7,
65 typedef unsigned int type_qualifiers_t;
69 type_qualifiers_t qualifiers;
70 unsigned char alignment; /**< The extra alignment of the type, 0 for default. */
71 source_position_t source_position;
76 struct atomic_type_t {
78 atomic_type_kind_t akind;
81 struct builtin_type_t {
87 struct pointer_type_t {
95 expression_t *size_expression;
98 ir_node *size_node; /**< used by ast2firm phase */
100 unsigned is_static : 1; /**< a [static] type */
101 unsigned is_variable : 1; /**< a [*] type */
102 unsigned has_implicit_size : 1;
103 unsigned size_constant : 1; /**< size expression is constant */
104 unsigned is_vla : 1; /**< it's a variable length array */
107 struct function_parameter_t {
109 function_parameter_t *next;
112 struct function_type_t {
115 function_parameter_t *parameters;
116 unsigned variadic : 1;
117 unsigned unspecified_parameters : 1;
118 unsigned kr_style_parameters : 1;
121 struct compound_type_t {
123 /** the declaration of the compound type, the scope of the declaration
124 * contains the compound entries. */
125 declaration_t *declaration;
130 /** the declaration of the enum type. You can find the enum entries by
131 * walking the declaration->next list until you don't find
132 * STORAGE_CLASS_ENUM_ENTRY declarations anymore */
133 declaration_t *declaration;
136 struct typedef_type_t {
138 declaration_t *declaration;
139 type_t *resolved_type;
142 struct typeof_type_t {
144 expression_t *expression;
146 type_t *resolved_type;
149 struct bitfield_type_t {
158 atomic_type_t atomic;
159 builtin_type_t builtin;
160 pointer_type_t pointer;
162 function_type_t function;
163 compound_type_t compound;
165 typedef_type_t typedeft;
166 bitfield_type_t bitfield;
167 typeof_type_t typeoft;
170 type_t *make_atomic_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
171 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
172 type_t *make_array_type(type_t *element_type, size_t size,
173 type_qualifiers_t qualifiers);
175 type_t *duplicate_type(const type_t *type);
177 static inline bool is_typeref(const type_t *type)
179 return type->kind == TYPE_TYPEDEF || type->kind == TYPE_TYPEOF;
182 static inline bool is_type_atomic(const type_t *type, atomic_type_kind_t atype)
184 assert(!is_typeref(type));
186 if(type->kind != TYPE_ATOMIC)
188 const atomic_type_t *atomic_type = &type->atomic;
190 return atomic_type->akind == atype;
193 static inline bool is_type_pointer(const type_t *type)
195 assert(!is_typeref(type));
196 return type->kind == TYPE_POINTER;
199 static inline bool is_type_array(const type_t *type)
201 assert(!is_typeref(type));
202 return type->kind == TYPE_ARRAY;
205 static inline bool is_type_function(const type_t *type)
207 assert(!is_typeref(type));
208 return type->kind == TYPE_FUNCTION;
211 static inline bool is_type_union(const type_t *type)
213 assert(!is_typeref(type));
214 return type->kind == TYPE_COMPOUND_UNION;
217 static inline bool is_type_struct(const type_t *type)
219 assert(!is_typeref(type));
220 return type->kind == TYPE_COMPOUND_STRUCT;
223 static inline bool is_type_builtin(const type_t *type)
225 assert(!is_typeref(type));
226 return type->kind == TYPE_BUILTIN;
229 static inline bool is_type_compound(const type_t *type)
231 assert(!is_typeref(type));
232 return type->kind == TYPE_COMPOUND_STRUCT
233 || type->kind == TYPE_COMPOUND_UNION;
236 static inline bool is_type_valid(const type_t *type)
238 return type->kind != TYPE_ERROR;