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,
59 typedef unsigned int type_qualifiers_t;
63 type_qualifiers_t qualifiers;
64 unsigned char alignment; /**< The extra alignment of the type, 0 for default. */
65 source_position_t source_position;
70 struct atomic_type_t {
72 atomic_type_kind_t akind;
75 struct builtin_type_t {
81 struct pointer_type_t {
89 expression_t *size_expression;
92 ir_node *size_node; /**< used by ast2firm phase */
94 unsigned is_static : 1; /**< a [static] type */
95 unsigned is_variable : 1; /**< a [*] type */
96 unsigned has_implicit_size : 1;
97 unsigned size_constant : 1; /**< size expression is constant */
98 unsigned is_vla : 1; /**< it's a variable length array */
101 struct function_parameter_t {
103 function_parameter_t *next;
106 struct function_type_t {
109 function_parameter_t *parameters;
110 unsigned variadic : 1;
111 unsigned unspecified_parameters : 1;
112 unsigned kr_style_parameters : 1;
115 struct compound_type_t {
117 /** the declaration of the compound type, the scope of the declaration
118 * contains the compound entries. */
119 declaration_t *declaration;
124 /** the declaration of the enum type. You can find the enum entries by
125 * walking the declaration->next list until you don't find
126 * STORAGE_CLASS_ENUM_ENTRY declarations anymore */
127 declaration_t *declaration;
130 struct typedef_type_t {
132 declaration_t *declaration;
133 type_t *resolved_type;
136 struct typeof_type_t {
138 expression_t *expression;
140 type_t *resolved_type;
143 struct bitfield_type_t {
152 atomic_type_t atomic;
153 builtin_type_t builtin;
154 pointer_type_t pointer;
156 function_type_t function;
157 compound_type_t compound;
159 typedef_type_t typedeft;
160 bitfield_type_t bitfield;
161 typeof_type_t typeoft;
164 type_t *make_atomic_type(atomic_type_kind_t type, type_qualifiers_t qualifiers);
165 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
166 type_t *make_array_type(type_t *element_type, size_t size,
167 type_qualifiers_t qualifiers);
169 type_t *duplicate_type(const type_t *type);
171 static inline bool is_typeref(const type_t *type)
173 return type->kind == TYPE_TYPEDEF || type->kind == TYPE_TYPEOF;
176 static inline bool is_type_atomic(const type_t *type, atomic_type_kind_t atype)
178 assert(!is_typeref(type));
180 if(type->kind != TYPE_ATOMIC)
182 const atomic_type_t *atomic_type = &type->atomic;
184 return atomic_type->akind == atype;
187 static inline bool is_type_pointer(const type_t *type)
189 assert(!is_typeref(type));
190 return type->kind == TYPE_POINTER;
193 static inline bool is_type_array(const type_t *type)
195 assert(!is_typeref(type));
196 return type->kind == TYPE_ARRAY;
199 static inline bool is_type_function(const type_t *type)
201 assert(!is_typeref(type));
202 return type->kind == TYPE_FUNCTION;
205 static inline bool is_type_union(const type_t *type)
207 assert(!is_typeref(type));
208 return type->kind == TYPE_COMPOUND_UNION;
211 static inline bool is_type_struct(const type_t *type)
213 assert(!is_typeref(type));
214 return type->kind == TYPE_COMPOUND_STRUCT;
217 static inline bool is_type_builtin(const type_t *type)
219 assert(!is_typeref(type));
220 return type->kind == TYPE_BUILTIN;
223 static inline bool is_type_compound(const type_t *type)
225 assert(!is_typeref(type));
226 return type->kind == TYPE_COMPOUND_STRUCT
227 || type->kind == TYPE_COMPOUND_UNION;
230 static inline bool is_type_valid(const type_t *type)
232 return type->kind != TYPE_ERROR;