introduce type_qualifiers_t type and remove a lot of warnings
[cparser] / ast_t.h
1 #ifndef AST_T_H
2 #define AST_T_H
3
4 #include <libfirm/firm_types.h>
5
6 #include "ast.h"
7 #include "symbol.h"
8 #include "token_t.h"
9 #include "type.h"
10 #include "adt/obst.h"
11
12 extern struct obstack ast_obstack;
13
14 typedef enum {
15         EXPR_UNKNOWN = 0,
16         EXPR_INVALID,
17         EXPR_REFERENCE,
18         EXPR_CONST,
19         EXPR_STRING_LITERAL,
20         EXPR_CALL,
21         EXPR_UNARY,
22         EXPR_BINARY,
23         EXPR_CONDITIONAL,
24         EXPR_SELECT,
25         EXPR_ARRAY_ACCESS,
26         EXPR_SIZEOF,
27         EXPR_CLASSIFY_TYPE,
28
29         EXPR_FUNCTION,
30         EXPR_PRETTY_FUNCTION,
31         EXPR_BUILTIN_SYMBOL,
32         EXPR_OFFSETOF,
33         EXPR_VA_ARG,
34         EXPR_STATEMENT
35 } expresion_type_t;
36
37 struct context_t {
38         declaration_t   *declarations;
39 };
40
41 struct expression_t {
42         expresion_type_t   type;
43         type_t            *datatype;
44         source_position_t  source_position;
45 };
46
47 struct const_t {
48         expression_t  expression;
49         union {
50                 long long   int_value;
51                 long double float_value;
52         } v;
53 };
54
55 struct string_literal_t {
56         expression_t  expression;
57         const char   *value;
58 };
59
60 struct builtin_symbol_expression_t {
61         expression_t  expression;
62         symbol_t     *symbol;
63 };
64
65 struct reference_expression_t {
66         expression_t   expression;
67         symbol_t      *symbol;
68         declaration_t *declaration;
69 };
70
71 struct call_argument_t {
72         expression_t    *expression;
73         call_argument_t *next;
74 };
75
76 struct call_expression_t {
77         expression_t     expression;
78         expression_t    *function;
79         call_argument_t *arguments;
80 };
81
82 typedef enum {
83         UNEXPR_INVALID = 0,
84         UNEXPR_NEGATE,
85         UNEXPR_PLUS,
86         UNEXPR_BITWISE_NEGATE,
87         UNEXPR_NOT,
88         UNEXPR_DEREFERENCE,
89         UNEXPR_TAKE_ADDRESS,
90         UNEXPR_POSTFIX_INCREMENT,
91         UNEXPR_POSTFIX_DECREMENT,
92         UNEXPR_PREFIX_INCREMENT,
93         UNEXPR_PREFIX_DECREMENT,
94         UNEXPR_CAST
95 } unary_expression_type_t;
96
97 struct unary_expression_t {
98         expression_t             expression;
99         unary_expression_type_t  type;
100         expression_t            *value;
101 };
102
103 typedef enum {
104         BINEXPR_INVALID = 0,
105         BINEXPR_ADD,
106         BINEXPR_SUB,
107         BINEXPR_MUL,
108         BINEXPR_DIV,
109         BINEXPR_MOD,
110         BINEXPR_EQUAL,
111         BINEXPR_NOTEQUAL,
112         BINEXPR_LESS,
113         BINEXPR_LESSEQUAL,
114         BINEXPR_GREATER,
115         BINEXPR_GREATEREQUAL,
116         BINEXPR_BITWISE_AND,
117         BINEXPR_BITWISE_OR,
118         BINEXPR_BITWISE_XOR,
119         BINEXPR_LOGICAL_AND,
120         BINEXPR_LOGICAL_OR,
121         BINEXPR_SHIFTLEFT,
122         BINEXPR_SHIFTRIGHT,
123         BINEXPR_ASSIGN,
124         BINEXPR_MUL_ASSIGN,
125         BINEXPR_DIV_ASSIGN,
126         BINEXPR_MOD_ASSIGN,
127         BINEXPR_ADD_ASSIGN,
128         BINEXPR_SUB_ASSIGN,
129         BINEXPR_SHIFTLEFT_ASSIGN,
130         BINEXPR_SHIFTRIGHT_ASSIGN,
131         BINEXPR_BITWISE_AND_ASSIGN,
132         BINEXPR_BITWISE_XOR_ASSIGN,
133         BINEXPR_BITWISE_OR_ASSIGN,
134         BINEXPR_COMMA
135 } binary_expression_type_t;
136
137 struct binary_expression_t {
138         expression_t              expression;
139         binary_expression_type_t  type;
140         expression_t             *left;
141         expression_t             *right;
142 };
143
144 struct select_expression_t {
145         expression_t   expression;
146         expression_t  *compound;
147         symbol_t      *symbol;
148
149         declaration_t *compound_entry;
150 };
151
152 struct array_access_expression_t {
153         expression_t  expression;
154         expression_t *array_ref;
155         expression_t *index;
156 };
157
158 struct sizeof_expression_t {
159         expression_t  expression;
160         type_t       *type;
161         expression_t *size_expression;
162 };
163
164 struct designator_t {
165         symbol_t     *symbol;
166         expression_t *array_access;
167         designator_t *next;
168 };
169
170 struct offsetof_expression_t {
171         expression_t  expression;
172         type_t       *type;
173         designator_t *designator;
174 };
175
176 struct va_arg_expression_t {
177         expression_t  expression;
178         expression_t *arg;
179         type_t       *type;
180 };
181
182 struct conditional_expression_t {
183         expression_t  expression;
184         expression_t *condition;
185         expression_t *true_expression;
186         expression_t *false_expression;
187 };
188
189 struct statement_expression_t {
190         expression_t  expression;
191         statement_t  *statement;
192 };
193
194 struct classify_type_expression_t {
195         expression_t  expression;
196         expression_t *type_expression;
197 };
198
199 typedef enum {
200         STORAGE_CLASS_NONE,
201         STORAGE_CLASS_TYPEDEF,
202         STORAGE_CLASS_EXTERN,
203         STORAGE_CLASS_STATIC,
204         STORAGE_CLASS_AUTO,
205         STORAGE_CLASS_REGISTER,
206         STORAGE_CLASS_ENUM_ENTRY
207 } storage_class_t;
208
209 typedef enum {
210         NAMESPACE_NORMAL,
211         NAMESPACE_STRUCT,
212         NAMESPACE_UNION,
213         NAMESPACE_ENUM,
214         NAMESPACE_LABEL
215 } namespace_t;
216
217 typedef enum {
218         INITIALIZER_VALUE,
219         INITIALIZER_LIST,
220         INITIALIZER_STRING
221 } initializer_type_t;
222
223 struct initializer_t {
224         initializer_type_t  type;
225         union {
226                 /* if type == INITIALIZER_VALUE */
227                 expression_t *value;
228                 /* if type == INITIALIZER_LIST */
229                 struct {
230                         size_t         len;
231                         initializer_t *initializers[];
232                 } list;
233                 /* if type == INITIALIZER_STRING */
234                 const char    *string;
235         } v;
236 };
237
238 struct declaration_t {
239         unsigned char       namespc;
240         unsigned char       storage_class;
241         unsigned int        address_taken : 1;
242         unsigned int        is_inline     : 1;
243         type_t             *type;
244         symbol_t           *symbol;
245         source_position_t   source_position;
246         union {
247                 bool            is_defined;
248                 statement_t    *statement;
249                 initializer_t  *initializer;
250                 expression_t   *enum_value;
251         } init;
252         context_t           context;
253         context_t          *parent_context;
254
255         /** next declaration in a context */
256         declaration_t      *next;
257         /** next declaration with same symbol */
258         declaration_t      *symbol_next;
259
260         unsigned char       declaration_type; /* used in ast2firm module */
261         union {
262                 unsigned int    value_number;     /* used in ast2firm module */
263                 ir_entity      *entity;           /* used in ast2firm module */
264                 ir_node        *block;            /* used in ast2firm module */
265         } v;
266 };
267
268 typedef enum {
269         STATEMENT_INVALID,
270         STATEMENT_COMPOUND,
271         STATEMENT_RETURN,
272         STATEMENT_DECLARATION,
273         STATEMENT_IF,
274         STATEMENT_SWITCH,
275         STATEMENT_EXPRESSION,
276         STATEMENT_CONTINUE,
277         STATEMENT_BREAK,
278         STATEMENT_GOTO,
279         STATEMENT_LABEL,
280         STATEMENT_CASE_LABEL,
281         STATEMENT_WHILE,
282         STATEMENT_DO_WHILE,
283         STATEMENT_FOR
284 } statement_type_t;
285
286 struct statement_t {
287         statement_type_t   type;
288         statement_t       *next;
289         source_position_t  source_position;
290         union {
291                 /* if type == STATEMENT_COMPOUND */
292                 struct {
293                         statement_t *statements;
294                         context_t    context;
295                 } compound_stmt;
296                 /* if type == STATEMENT_RETURN */
297                 expression_t *return_value;
298                 /* if type == STATEMENT_DECLARATION */
299                 struct {
300                         declaration_t *begin;
301                         declaration_t *end;
302                 } declaration_stmt;
303                 /* if type == STATEMENT_IF */
304                 struct {
305                         expression_t *condition;
306                         statement_t  *true_statement;
307                         statement_t  *false_statement;
308                 } if_stmt;
309                 /* if type == STATEMENT_SWITCH */
310                 struct {
311                         expression_t *expression;
312                         statement_t  *body;
313                 } switch_stmt;
314                 /* if type == STATEMENT_EXPRESSION */
315                 expression_t *expression;
316                 /* if type == STATEMENT_GOTO */
317                 declaration_t *goto_label;
318                 /* if type == STATEMENT_LABEL */
319                 struct {
320                         declaration_t *label;
321                         statement_t   *label_statement;
322                 } label_stmt;
323                 /* if type == STATEMENT_CASE_LABEL */
324                 struct {
325                         expression_t *expression;
326                         statement_t  *label_statement;
327                 } case_label_stmt;
328                 /* if type == STATEMENT_WHILE or STATEMENT_DO_WHILE */
329                 struct {
330                         expression_t *condition;
331                         statement_t  *body;
332                 } while_stmt;
333                 /* if type == STATEMENT_FOR */
334                 struct {
335                         expression_t  *initialisation;
336                         expression_t  *condition;
337                         expression_t  *step;
338                         statement_t   *body;
339                         context_t      context;
340                 } for_stmt;
341         } v;
342 };
343
344 struct translation_unit_t {
345         context_t context;
346 };
347
348 static inline
349 void *_allocate_ast(size_t size)
350 {
351         return obstack_alloc(&ast_obstack, size);
352 }
353
354 #define allocate_ast(size)                 _allocate_ast(size)
355
356 #endif