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 unsigned char alignment; /**< The extra alignment of the type, 0 for default. */
96 source_position_t source_position;
101 struct atomic_type_t {
103 atomic_type_kind_t akind;
106 struct builtin_type_t {
112 struct pointer_type_t {
117 struct array_type_t {
119 type_t *element_type;
120 expression_t *size_expression;
123 ir_node *size_node; /**< used by ast2firm phase */
125 unsigned is_static : 1; /**< a [static] type */
126 unsigned is_variable : 1; /**< a [*] type */
127 unsigned has_implicit_size : 1;
128 unsigned size_constant : 1; /**< size expression is constant */
129 unsigned is_vla : 1; /**< it's a variable length array */
132 struct function_parameter_t {
134 function_parameter_t *next;
137 struct function_type_t {
140 function_parameter_t *parameters;
141 unsigned variadic : 1;
142 unsigned unspecified_parameters : 1;
143 unsigned kr_style_parameters : 1;
146 struct compound_type_t {
148 /** the declaration of the compound type, the scope of the declaration
149 * contains the compound entries. */
150 declaration_t *declaration;
155 /** the declaration of the enum type. You can find the enum entries by
156 * walking the declaration->next list until you don't find
157 * STORAGE_CLASS_ENUM_ENTRY declarations anymore */
158 declaration_t *declaration;
161 struct typedef_type_t {
163 declaration_t *declaration;
164 type_t *resolved_type;
167 struct typeof_type_t {
169 expression_t *expression;
171 type_t *resolved_type;
174 struct bitfield_type_t {
183 atomic_type_t atomic;
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_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
197 type_t *make_array_type(type_t *element_type, size_t size,
198 type_qualifiers_t qualifiers);
200 type_t *duplicate_type(const type_t *type);
202 static inline bool is_typeref(const type_t *type)
204 return type->kind == TYPE_TYPEDEF || type->kind == TYPE_TYPEOF;
207 static inline bool is_type_atomic(const type_t *type, atomic_type_kind_t atype)
209 assert(!is_typeref(type));
211 if(type->kind != TYPE_ATOMIC)
213 const atomic_type_t *atomic_type = &type->atomic;
215 return atomic_type->akind == atype;
218 static inline bool is_type_pointer(const type_t *type)
220 assert(!is_typeref(type));
221 return type->kind == TYPE_POINTER;
224 static inline bool is_type_array(const type_t *type)
226 assert(!is_typeref(type));
227 return type->kind == TYPE_ARRAY;
230 static inline bool is_type_function(const type_t *type)
232 assert(!is_typeref(type));
233 return type->kind == TYPE_FUNCTION;
236 static inline bool is_type_union(const type_t *type)
238 assert(!is_typeref(type));
239 return type->kind == TYPE_COMPOUND_UNION;
242 static inline bool is_type_struct(const type_t *type)
244 assert(!is_typeref(type));
245 return type->kind == TYPE_COMPOUND_STRUCT;
248 static inline bool is_type_builtin(const type_t *type)
250 assert(!is_typeref(type));
251 return type->kind == TYPE_BUILTIN;
254 static inline bool is_type_compound(const type_t *type)
256 assert(!is_typeref(type));
257 return type->kind == TYPE_COMPOUND_STRUCT
258 || type->kind == TYPE_COMPOUND_UNION;
261 static inline bool is_type_valid(const type_t *type)
263 return type->kind != TYPE_ERROR;