2 * This file is part of cparser.
3 * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
13 /** Type used to express sizes. */
14 typedef unsigned long il_size_t;
15 typedef unsigned char il_alignment_t;
17 /* note that the constant values represent the rank of the types as defined
19 typedef enum atomic_type_kind_t {
22 ATOMIC_TYPE_WCHAR_T, /* only used in C++, in C code wchar_t is a pp-macro */
33 ATOMIC_TYPE_ULONGLONG,
36 ATOMIC_TYPE_LONG_DOUBLE,
38 ATOMIC_TYPE_LAST = ATOMIC_TYPE_LONG_DOUBLE
41 typedef enum atomic_type_flag_t {
42 ATOMIC_TYPE_FLAG_NONE = 0,
43 ATOMIC_TYPE_FLAG_SIGNED = 1 << 0,
44 ATOMIC_TYPE_FLAG_INTEGER = 1 << 1,
45 ATOMIC_TYPE_FLAG_FLOAT = 1 << 2,
46 ATOMIC_TYPE_FLAG_ARITHMETIC = 1 << 3,
49 typedef enum type_qualifier_t {
50 TYPE_QUALIFIER_NONE = 0,
51 TYPE_QUALIFIER_CONST = 1 << 0,
52 TYPE_QUALIFIER_RESTRICT = 1 << 1,
53 TYPE_QUALIFIER_VOLATILE = 1 << 2,
54 /* microsoft extended qualifiers */
55 TYPE_QUALIFIER_W64 = 1 << 3,
56 TYPE_QUALIFIER_PTR32 = 1 << 4,
57 TYPE_QUALIFIER_PTR64 = 1 << 5,
58 TYPE_QUALIFIER_SPTR = 1 << 6,
59 TYPE_QUALIFIER_UPTR = 1 << 7,
61 typedef unsigned short type_qualifiers_t;
63 typedef struct type_base_t type_base_t;
64 typedef struct atomic_type_t atomic_type_t;
65 typedef struct pointer_type_t pointer_type_t;
66 typedef struct reference_type_t reference_type_t;
67 typedef struct function_parameter_t function_parameter_t;
68 typedef struct function_type_t function_type_t;
69 typedef struct compound_type_t compound_type_t;
70 typedef struct enum_type_t enum_type_t;
71 typedef struct builtin_type_t builtin_type_t;
72 typedef struct array_type_t array_type_t;
73 typedef struct typedef_type_t typedef_type_t;
74 typedef struct bitfield_type_t bitfield_type_t;
75 typedef struct typeof_type_t typeof_type_t;
76 typedef union type_t type_t;
79 * Initializes the type system. Attempts to set some defaults on the atomic
80 * types based on a given machine size.
81 * These type properties are not final but you should adapt them to your system
82 * as your architecture and operating systems application binary interface (ABI)
85 void init_types(unsigned machine_size);
86 void exit_types(void);
91 * @param type The type.
93 void print_type(const type_t *type);
96 * prints a human readable form of @p type. prints an abstract typename
99 void print_type_ext(const type_t *type, const symbol_t *symbol,
100 const scope_t *parameters);
102 typedef enum QualifierSeparators {
104 QUAL_SEP_START = 1U << 0,
105 QUAL_SEP_END = 1U << 1
106 } QualifierSeparators;
108 void print_type_qualifiers(type_qualifiers_t qualifiers, QualifierSeparators);
111 * Prints an enum definition.
113 * @param declaration The enum's type declaration.
115 void print_enum_definition(const enum_t *enume);
118 * Print the compound part of a compound type.
120 void print_compound_definition(const compound_t *compound);
122 void inc_type_visited(void);
125 * Returns true if the given type is an integer type.
127 * @param type The type to check.
128 * @return True if type is an integer type.
130 bool is_type_integer(const type_t *type);
133 * Returns true if the given type is an enum type.
135 * @param type The type to check.
136 * @return True if type is an enum type.
138 bool is_type_enum(const type_t *type);
141 * Returns true if the given type is a signed type.
143 * @param type The type to check.
144 * @return True if type is a signed type.
146 bool is_type_signed(const type_t *type);
149 * Returns true if the given type is a floating point type.
151 * @param type The type to check.
152 * @return True if type is a floating point type.
154 bool is_type_float(const type_t *type);
157 * Returns true if the given type is a complex type.
159 * @param type The type to check.
160 * @return True if type is a complex type.
162 bool is_type_complex(const type_t *type);
165 * Returns true if the given type is an integer or float type.
167 * @param type The type to check.
168 * @return True if type is an integer or float type.
170 bool is_type_real(const type_t *type);
173 * Returns true if the type is an arithmetic type (§6.2.5 clause 18)
175 * @param type The type to check.
176 * @return True if type represents an arithmetic type.
178 bool is_type_arithmetic(const type_t *type);
181 * Returns true if the type is a scalar type (§6.2.5 clause 21)
183 * @param type The type to check.
184 * @return True if type represents a scalar type.
186 bool is_type_scalar(const type_t *type);
189 * Check if a given type is incomplete.
191 * @param type The type to check.
192 * @return True if the given type is incomplete (i.e. just forward).
194 bool is_type_incomplete(const type_t *type);
196 bool is_type_object(const type_t *type);
199 * Check if two types are compatible.
201 bool types_compatible(const type_t *type1, const type_t *type2);
204 * Returns the unqualified type of a given type.
206 * @param type The type.
207 * @returns The unqualified type.
209 type_t *get_unqualified_type(type_t *type);
211 type_t *get_qualified_type(type_t*, type_qualifiers_t);
212 type_t *skip_typeref(type_t *type);
215 * Return the type qualifier set of a type. If skip_array_type
216 * is true, skip all array types.
218 type_qualifiers_t get_type_qualifier(const type_t *type, bool skip_array_type);
221 * returns size of an atomic type kind in bytes
223 unsigned get_atomic_type_size(atomic_type_kind_t kind);
226 * returns alignment of an atomic type kind in bytes
228 unsigned get_atomic_type_alignment(atomic_type_kind_t kind);
230 unsigned get_type_alignment(type_t *type);
231 unsigned get_type_size(type_t *type);
232 decl_modifiers_t get_type_modifiers(const type_t *type);
235 * returns flags of an atomic type kind
237 unsigned get_atomic_type_flags(atomic_type_kind_t kind);
240 * Find the atomic type kind representing a given size (signed).
242 atomic_type_kind_t find_signed_int_atomic_type_kind_for_size(unsigned size);
245 * Find the atomic type kind representing a given size (unsigned).
247 atomic_type_kind_t find_unsigned_int_atomic_type_kind_for_size(unsigned size);
249 const char *get_atomic_kind_name(atomic_type_kind_t kind);
252 * Finish the construction of a struct type by calculating its size, offsets,
255 void layout_struct_type(compound_type_t *type);
258 * Finish the construction of an union type by calculating
259 * its size and alignment.
261 void layout_union_type(compound_type_t *type);