change back union stuff and expriment with new union mode for initializers
[cparser] / type_t.h
1 #ifndef TYPE_T_H
2 #define TYPE_T_H
3
4 #include <stdbool.h>
5
6 #include <libfirm/firm_types.h>
7
8 #include "type.h"
9 #include "symbol.h"
10 #include "token_t.h"
11 #include "ast_t.h"
12 #include "adt/obst.h"
13
14 struct obstack *type_obst;
15
16 typedef enum {
17         TYPE_INVALID,
18         TYPE_ATOMIC,
19         TYPE_COMPOUND_STRUCT,
20         TYPE_COMPOUND_UNION,
21         TYPE_ENUM,
22         TYPE_FUNCTION,
23         TYPE_POINTER,
24         TYPE_ARRAY,
25         TYPE_BUILTIN,
26         TYPE_TYPEDEF,
27         TYPE_TYPEOF
28 } type_type_t;
29
30 /* note that the constant values represent the rank of the types as defined
31  * in ยง 6.3.1 */
32 typedef enum {
33         ATOMIC_TYPE_INVALID = 0,
34         ATOMIC_TYPE_VOID,
35         ATOMIC_TYPE_CHAR,
36         ATOMIC_TYPE_SCHAR,
37         ATOMIC_TYPE_UCHAR,
38         ATOMIC_TYPE_SHORT,
39         ATOMIC_TYPE_USHORT,
40         ATOMIC_TYPE_INT,
41         ATOMIC_TYPE_UINT,
42         ATOMIC_TYPE_LONG,
43         ATOMIC_TYPE_ULONG,
44         ATOMIC_TYPE_LONGLONG,
45         ATOMIC_TYPE_ULONGLONG,
46         ATOMIC_TYPE_FLOAT,
47         ATOMIC_TYPE_DOUBLE,
48         ATOMIC_TYPE_LONG_DOUBLE,
49         ATOMIC_TYPE_BOOL,
50 #ifdef PROVIDE_COMPLEX
51         ATOMIC_TYPE_FLOAT_COMPLEX,
52         ATOMIC_TYPE_DOUBLE_COMPLEX,
53         ATOMIC_TYPE_LONG_DOUBLE_COMPLEX,
54         ATOMIC_TYPE_FLOAT_IMAGINARY,
55         ATOMIC_TYPE_DOUBLE_IMAGINARY,
56         ATOMIC_TYPE_LONG_DOUBLE_IMAGINARY,
57 #endif
58 } atomic_type_type_t;
59
60 typedef enum {
61         TYPE_QUALIFIER_NONE     = 0,
62         TYPE_QUALIFIER_CONST    = 1 << 0,
63         TYPE_QUALIFIER_RESTRICT = 1 << 1,
64         TYPE_QUALIFIER_VOLATILE = 1 << 2,
65 } type_qualifier_t;
66
67 typedef unsigned int type_qualifiers_t;
68
69 struct type_t {
70         type_type_t       type;
71         type_qualifiers_t qualifiers;
72
73         ir_type          *firm_type;
74 };
75
76 struct atomic_type_t {
77         type_t              type;
78         atomic_type_type_t  atype;
79 };
80
81 struct builtin_type_t {
82         type_t    type;
83         symbol_t *symbol;
84         type_t   *real_type;
85 };
86
87 struct pointer_type_t {
88         type_t   type;
89         type_t  *points_to;
90 };
91
92 struct array_type_t {
93         type_t        type;
94         type_t       *element_type;
95         bool          is_static;
96         bool          is_variable;
97         expression_t *size;
98 };
99
100 struct function_parameter_t {
101         type_t               *type;
102         function_parameter_t *next;
103 };
104
105 struct function_type_t {
106         type_t                type;
107         type_t               *result_type;
108         function_parameter_t *parameters;
109         bool                  variadic;
110         bool                  unspecified_parameters;
111 };
112
113 struct compound_type_t {
114         type_t         type;
115         /** the declaration of the compound type, its context field
116          * contains the compound entries. */
117         declaration_t *declaration;
118 };
119
120 struct enum_type_t {
121         type_t         type;
122         /** the declaration of the enum type. You can find the enum entries by
123          * walking the declaration->next list until you don't find
124          * STORAGE_CLASS_ENUM_ENTRY declarations anymore */
125         declaration_t *declaration;
126 };
127
128 struct typedef_type_t {
129         type_t         type;
130         declaration_t *declaration;
131         type_t        *resolved_type;
132 };
133
134 struct typeof_type_t {
135         type_t        type;
136         expression_t *expression;
137         type_t       *typeof_type;
138         type_t       *resolved_type;
139 };
140
141 type_t *make_atomic_type(atomic_type_type_t type, type_qualifiers_t qualifiers);
142 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers);
143
144 #endif