2 * This file is part of cparser.
3 * Copyright (C) 2007-2009 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
28 /** Type used to express sizes. */
29 typedef unsigned long il_size_t;
30 typedef unsigned char il_alignment_t;
32 /* note that the constant values represent the rank of the types as defined
34 typedef enum atomic_type_kind_t {
35 ATOMIC_TYPE_INVALID = 0,
49 ATOMIC_TYPE_ULONGLONG,
52 ATOMIC_TYPE_LONG_DOUBLE,
54 ATOMIC_TYPE_LAST = ATOMIC_TYPE_LONG_DOUBLE
57 typedef enum atomic_type_flag_t {
58 ATOMIC_TYPE_FLAG_NONE = 0,
59 ATOMIC_TYPE_FLAG_SIGNED = 1 << 0,
60 ATOMIC_TYPE_FLAG_INTEGER = 1 << 1,
61 ATOMIC_TYPE_FLAG_FLOAT = 1 << 2,
62 ATOMIC_TYPE_FLAG_ARITHMETIC = 1 << 3,
63 ATOMIC_TYPE_FLAG_COMPLEX = 1 << 4,
66 typedef enum type_qualifier_t {
67 TYPE_QUALIFIER_NONE = 0,
68 TYPE_QUALIFIER_CONST = 1 << 0,
69 TYPE_QUALIFIER_RESTRICT = 1 << 1,
70 TYPE_QUALIFIER_VOLATILE = 1 << 2,
71 /* microsoft extended qualifiers */
72 TYPE_QUALIFIER_W64 = 1 << 3,
73 TYPE_QUALIFIER_PTR32 = 1 << 4,
74 TYPE_QUALIFIER_PTR64 = 1 << 5,
75 TYPE_QUALIFIER_SPTR = 1 << 6,
76 TYPE_QUALIFIER_UPTR = 1 << 7,
78 typedef unsigned short type_qualifiers_t;
80 typedef struct type_base_t type_base_t;
81 typedef struct atomic_type_t atomic_type_t;
82 typedef struct complex_type_t complex_type_t;
83 typedef struct imaginary_type_t imaginary_type_t;
84 typedef struct pointer_type_t pointer_type_t;
85 typedef struct reference_type_t reference_type_t;
86 typedef struct function_parameter_t function_parameter_t;
87 typedef struct function_type_t function_type_t;
88 typedef struct compound_type_t compound_type_t;
89 typedef struct enum_type_t enum_type_t;
90 typedef struct builtin_type_t builtin_type_t;
91 typedef struct array_type_t array_type_t;
92 typedef struct typedef_type_t typedef_type_t;
93 typedef struct bitfield_type_t bitfield_type_t;
94 typedef struct typeof_type_t typeof_type_t;
95 typedef union type_t type_t;
98 * Initializes the type system. Attempts to set some defaults on the atomic
99 * types based on a given machine size.
100 * These type properties are not final but you should adapt them to your system
101 * as your architecture and operating systems application binary interface (ABI)
104 void init_types(unsigned machine_size);
105 void exit_types(void);
110 * @param type The type.
112 void print_type(const type_t *type);
115 * prints a human readable form of @p type. prints an abstract typename
118 void print_type_ext(const type_t *type, const symbol_t *symbol,
119 const scope_t *parameters);
121 typedef enum QualifierSeparators {
123 QUAL_SEP_START = 1U << 0,
124 QUAL_SEP_END = 1U << 1
125 } QualifierSeparators;
127 void print_type_qualifiers(type_qualifiers_t qualifiers, QualifierSeparators);
130 * Prints an enum definition.
132 * @param declaration The enum's type declaration.
134 void print_enum_definition(const enum_t *enume);
137 * Print the compound part of a compound type.
139 void print_compound_definition(const compound_t *compound);
141 void inc_type_visited(void);
144 * Returns true if the given type is an integer type.
146 * @param type The type to check.
147 * @return True if type is an integer type.
149 bool is_type_integer(const type_t *type);
152 * Returns true if the given type is an enum type.
154 * @param type The type to check.
155 * @return True if type is an enum type.
157 bool is_type_enum(const type_t *type);
160 * Returns true if the given type is a signed type.
162 * @param type The type to check.
163 * @return True if type is a signed type.
165 bool is_type_signed(const type_t *type);
168 * Returns true if the given type is a floating point type.
170 * @param type The type to check.
171 * @return True if type is a floating point type.
173 bool is_type_float(const type_t *type);
176 * Returns true if the given type is a complex type.
178 * @param type The type to check.
179 * @return True if type is a complex type.
181 bool is_type_complex(const type_t *type);
184 * Returns true if the given type is an integer or float type.
186 * @param type The type to check.
187 * @return True if type is an integer or float type.
189 bool is_type_real(const type_t *type);
192 * Returns true if the type is an arithmetic type (§6.2.5 clause 18)
194 * @param type The type to check.
195 * @return True if type represents an arithmetic type.
197 bool is_type_arithmetic(const type_t *type);
200 * Returns true if the type is a scalar type (§6.2.5 clause 21)
202 * @param type The type to check.
203 * @return True if type represents a scalar type.
205 bool is_type_scalar(const type_t *type);
208 * Check if a given type is incomplete.
210 * @param type The type to check.
211 * @return True if the given type is incomplete (ie. just forward).
213 bool is_type_incomplete(const type_t *type);
215 bool is_type_object(const type_t *type);
218 * Check if two types are compatible.
220 bool types_compatible(const type_t *type1, const type_t *type2);
223 * Returns the unqualified type of a given type.
225 * @param type The type.
226 * @returns The unqualified type.
228 type_t *get_unqualified_type(type_t *type);
230 type_t *get_qualified_type(type_t*, type_qualifiers_t);
231 type_t *skip_typeref(type_t *type);
234 * Return the type qualifier set of a type. If skip_array_type
235 * is true, skip all array types.
237 type_qualifiers_t get_type_qualifier(const type_t *type, bool skip_array_type);
240 * returns size of an atomic type kind in bytes
242 unsigned get_atomic_type_size(atomic_type_kind_t kind);
245 * returns alignment of an atomic type kind in bytes
247 unsigned get_atomic_type_alignment(atomic_type_kind_t kind);
249 unsigned get_type_alignment(type_t *type);
250 unsigned get_type_size(type_t *type);
251 decl_modifiers_t get_type_modifiers(const type_t *type);
254 * returns flags of an atomic type kind
256 unsigned get_atomic_type_flags(atomic_type_kind_t kind);
259 * Find the atomic type kind representing a given size (signed).
261 atomic_type_kind_t find_signed_int_atomic_type_kind_for_size(unsigned size);
264 * Find the atomic type kind representing a given size (unsigned).
266 atomic_type_kind_t find_unsigned_int_atomic_type_kind_for_size(unsigned size);
268 const char *get_atomic_kind_name(atomic_type_kind_t kind);
271 * Finish the construction of a struct type by calculating its size, offsets,
274 void layout_struct_type(compound_type_t *type);
277 * Finish the construction of an union type by calculating
278 * its size and alignment.
280 void layout_union_type(compound_type_t *type);