2 * This file is part of cparser.
3 * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
14 /** Type used to express sizes. */
15 typedef unsigned long il_size_t;
16 typedef unsigned char il_alignment_t;
18 /* note that the constant values represent the rank of the types as defined
20 typedef enum atomic_type_kind_t {
23 ATOMIC_TYPE_WCHAR_T, /* only used in C++, in C code wchar_t is a pp-macro */
34 ATOMIC_TYPE_ULONGLONG,
37 ATOMIC_TYPE_LONG_DOUBLE,
39 ATOMIC_TYPE_LAST = ATOMIC_TYPE_LONG_DOUBLE
42 typedef enum atomic_type_flag_t {
43 ATOMIC_TYPE_FLAG_NONE = 0,
44 ATOMIC_TYPE_FLAG_SIGNED = 1 << 0,
45 ATOMIC_TYPE_FLAG_INTEGER = 1 << 1,
46 ATOMIC_TYPE_FLAG_FLOAT = 1 << 2,
47 ATOMIC_TYPE_FLAG_ARITHMETIC = 1 << 3,
50 typedef enum type_qualifier_t {
51 TYPE_QUALIFIER_NONE = 0,
52 TYPE_QUALIFIER_CONST = 1 << 0,
53 TYPE_QUALIFIER_RESTRICT = 1 << 1,
54 TYPE_QUALIFIER_VOLATILE = 1 << 2,
55 /* microsoft extended qualifiers */
56 TYPE_QUALIFIER_W64 = 1 << 3,
57 TYPE_QUALIFIER_PTR32 = 1 << 4,
58 TYPE_QUALIFIER_PTR64 = 1 << 5,
59 TYPE_QUALIFIER_SPTR = 1 << 6,
60 TYPE_QUALIFIER_UPTR = 1 << 7,
62 typedef unsigned short type_qualifiers_t;
64 typedef struct type_base_t type_base_t;
65 typedef struct atomic_type_t atomic_type_t;
66 typedef struct pointer_type_t pointer_type_t;
67 typedef struct reference_type_t reference_type_t;
68 typedef struct function_parameter_t function_parameter_t;
69 typedef struct function_type_t function_type_t;
70 typedef struct compound_type_t compound_type_t;
71 typedef struct enum_type_t enum_type_t;
72 typedef struct builtin_type_t builtin_type_t;
73 typedef struct array_type_t array_type_t;
74 typedef struct typedef_type_t typedef_type_t;
75 typedef struct bitfield_type_t bitfield_type_t;
76 typedef struct typeof_type_t typeof_type_t;
77 typedef union type_t type_t;
80 * Initializes the type system. Attempts to set some defaults on the atomic
81 * types based on a given machine size.
82 * These type properties are not final but you should adapt them to your system
83 * as your architecture and operating systems application binary interface (ABI)
86 void init_types(unsigned machine_size);
87 void exit_types(void);
92 * @param type The type.
94 void print_type(const type_t *type);
97 * prints a human readable form of @p type. prints an abstract typename
100 void print_type_ext(const type_t *type, const symbol_t *symbol,
101 const scope_t *parameters);
103 typedef enum QualifierSeparators {
105 QUAL_SEP_START = 1U << 0,
106 QUAL_SEP_END = 1U << 1
107 } QualifierSeparators;
109 void print_type_qualifiers(type_qualifiers_t qualifiers, QualifierSeparators);
112 * Prints an enum definition.
114 * @param declaration The enum's type declaration.
116 void print_enum_definition(const enum_t *enume);
119 * Print the compound part of a compound type.
121 void print_compound_definition(const compound_t *compound);
123 void inc_type_visited(void);
126 * Returns true if the given type is an integer type.
128 * @param type The type to check.
129 * @return True if type is an integer type.
131 bool is_type_integer(const type_t *type);
134 * Returns true if the given type is an enum type.
136 * @param type The type to check.
137 * @return True if type is an enum type.
139 bool is_type_enum(const type_t *type);
142 * Returns true if the given type is a signed type.
144 * @param type The type to check.
145 * @return True if type is a signed type.
147 bool is_type_signed(const type_t *type);
150 * Returns true if the given type is a floating point type.
152 * @param type The type to check.
153 * @return True if type is a floating point type.
155 bool is_type_float(const type_t *type);
158 * Returns true if the given type is a complex type.
160 * @param type The type to check.
161 * @return True if type is a complex type.
163 bool is_type_complex(const type_t *type);
166 * Returns true if the given type is an integer or float type.
168 * @param type The type to check.
169 * @return True if type is an integer or float type.
171 bool is_type_real(const type_t *type);
174 * Returns true if the type is an arithmetic type (§6.2.5 clause 18)
176 * @param type The type to check.
177 * @return True if type represents an arithmetic type.
179 bool is_type_arithmetic(const type_t *type);
182 * Returns true if the type is a scalar type (§6.2.5 clause 21)
184 * @param type The type to check.
185 * @return True if type represents a scalar type.
187 bool is_type_scalar(const type_t *type);
190 * Check if a given type is incomplete.
192 * @param type The type to check.
193 * @return True if the given type is incomplete (i.e. just forward).
195 bool is_type_incomplete(const type_t *type);
197 bool is_type_object(const type_t *type);
200 * Check if two types are compatible.
202 bool types_compatible(const type_t *type1, const type_t *type2);
205 * Returns the unqualified type of a given type.
207 * @param type The type.
208 * @returns The unqualified type.
210 type_t *get_unqualified_type(type_t *type);
212 type_t *get_qualified_type(type_t*, type_qualifiers_t);
213 type_t *skip_typeref(type_t *type);
216 * Return the type qualifier set of a type. If skip_array_type
217 * is true, skip all array types.
219 type_qualifiers_t get_type_qualifier(const type_t *type, bool skip_array_type);
222 * returns size of an atomic type kind in bytes
224 unsigned get_atomic_type_size(atomic_type_kind_t kind);
227 * returns alignment of an atomic type kind in bytes
229 unsigned get_atomic_type_alignment(atomic_type_kind_t kind);
231 unsigned get_type_alignment(type_t *type);
232 unsigned get_type_size(type_t *type);
233 decl_modifiers_t get_type_modifiers(const type_t *type);
236 * returns flags of an atomic type kind
238 unsigned get_atomic_type_flags(atomic_type_kind_t kind);
241 * Find the atomic type kind representing a given size (signed).
243 atomic_type_kind_t find_signed_int_atomic_type_kind_for_size(unsigned size);
246 * Find the atomic type kind representing a given size (unsigned).
248 atomic_type_kind_t find_unsigned_int_atomic_type_kind_for_size(unsigned size);
250 const char *get_atomic_kind_name(atomic_type_kind_t kind);
253 * Finish the construction of a struct type by calculating its size, offsets,
256 void layout_struct_type(compound_type_t *type);
259 * Finish the construction of an union type by calculating
260 * its size and alignment.
262 void layout_union_type(compound_type_t *type);