4 #include <libfirm/firm_types.h>
13 extern struct obstack ast_obstack;
21 EXPR_WIDE_STRING_LITERAL,
38 EXPR_UNARY_NEGATE = EXPR_UNARY_FIRST,
40 EXPR_UNARY_BITWISE_NEGATE,
42 EXPR_UNARY_DEREFERENCE,
43 EXPR_UNARY_TAKE_ADDRESS,
44 EXPR_UNARY_POSTFIX_INCREMENT,
45 EXPR_UNARY_POSTFIX_DECREMENT,
46 EXPR_UNARY_PREFIX_INCREMENT,
47 EXPR_UNARY_PREFIX_DECREMENT,
49 EXPR_UNARY_CAST_IMPLICIT, /* compiler generated cast */
50 EXPR_UNARY_LAST = EXPR_UNARY_CAST_IMPLICIT,
53 EXPR_BINARY_ADD = EXPR_BINARY_FIRST,
61 EXPR_BINARY_LESSEQUAL,
63 EXPR_BINARY_GREATEREQUAL,
64 EXPR_BINARY_BITWISE_AND,
65 EXPR_BINARY_BITWISE_OR,
66 EXPR_BINARY_BITWISE_XOR,
67 EXPR_BINARY_LOGICAL_AND,
68 EXPR_BINARY_LOGICAL_OR,
69 EXPR_BINARY_SHIFTLEFT,
70 EXPR_BINARY_SHIFTRIGHT,
72 EXPR_BINARY_MUL_ASSIGN,
73 EXPR_BINARY_DIV_ASSIGN,
74 EXPR_BINARY_MOD_ASSIGN,
75 EXPR_BINARY_ADD_ASSIGN,
76 EXPR_BINARY_SUB_ASSIGN,
77 EXPR_BINARY_SHIFTLEFT_ASSIGN,
78 EXPR_BINARY_SHIFTRIGHT_ASSIGN,
79 EXPR_BINARY_BITWISE_AND_ASSIGN,
80 EXPR_BINARY_BITWISE_XOR_ASSIGN,
81 EXPR_BINARY_BITWISE_OR_ASSIGN,
84 EXPR_BINARY_ISGREATER,
85 EXPR_BINARY_ISGREATEREQUAL,
87 EXPR_BINARY_ISLESSEQUAL,
88 EXPR_BINARY_ISLESSGREATER,
89 EXPR_BINARY_ISUNORDERED,
90 EXPR_BINARY_LAST = EXPR_BINARY_ISUNORDERED,
93 /* convenience macros */
94 #define EXPR_BINARY_CASES \
95 case EXPR_BINARY_ADD: \
96 case EXPR_BINARY_SUB: \
97 case EXPR_BINARY_MUL: \
98 case EXPR_BINARY_DIV: \
99 case EXPR_BINARY_MOD: \
100 case EXPR_BINARY_EQUAL: \
101 case EXPR_BINARY_NOTEQUAL: \
102 case EXPR_BINARY_LESS: \
103 case EXPR_BINARY_LESSEQUAL: \
104 case EXPR_BINARY_GREATER: \
105 case EXPR_BINARY_GREATEREQUAL: \
106 case EXPR_BINARY_BITWISE_AND: \
107 case EXPR_BINARY_BITWISE_OR: \
108 case EXPR_BINARY_BITWISE_XOR: \
109 case EXPR_BINARY_LOGICAL_AND: \
110 case EXPR_BINARY_LOGICAL_OR: \
111 case EXPR_BINARY_SHIFTLEFT: \
112 case EXPR_BINARY_SHIFTRIGHT: \
113 case EXPR_BINARY_ASSIGN: \
114 case EXPR_BINARY_MUL_ASSIGN: \
115 case EXPR_BINARY_DIV_ASSIGN: \
116 case EXPR_BINARY_MOD_ASSIGN: \
117 case EXPR_BINARY_ADD_ASSIGN: \
118 case EXPR_BINARY_SUB_ASSIGN: \
119 case EXPR_BINARY_SHIFTLEFT_ASSIGN: \
120 case EXPR_BINARY_SHIFTRIGHT_ASSIGN: \
121 case EXPR_BINARY_BITWISE_AND_ASSIGN: \
122 case EXPR_BINARY_BITWISE_XOR_ASSIGN: \
123 case EXPR_BINARY_BITWISE_OR_ASSIGN: \
124 case EXPR_BINARY_COMMA: \
125 case EXPR_BINARY_ISGREATER: \
126 case EXPR_BINARY_ISGREATEREQUAL: \
127 case EXPR_BINARY_ISLESS: \
128 case EXPR_BINARY_ISLESSEQUAL: \
129 case EXPR_BINARY_ISLESSGREATER: \
130 case EXPR_BINARY_ISUNORDERED:
132 #define EXPR_UNARY_CASES \
133 case EXPR_UNARY_NEGATE: \
134 case EXPR_UNARY_PLUS: \
135 case EXPR_UNARY_BITWISE_NEGATE: \
136 case EXPR_UNARY_NOT: \
137 case EXPR_UNARY_DEREFERENCE: \
138 case EXPR_UNARY_TAKE_ADDRESS: \
139 case EXPR_UNARY_POSTFIX_INCREMENT: \
140 case EXPR_UNARY_POSTFIX_DECREMENT: \
141 case EXPR_UNARY_PREFIX_INCREMENT: \
142 case EXPR_UNARY_PREFIX_DECREMENT: \
143 case EXPR_UNARY_CAST: \
144 case EXPR_UNARY_CAST_IMPLICIT:
147 declaration_t *declarations;
150 struct expression_base_t {
151 expression_type_t type;
153 source_position_t source_position;
156 struct const_expression_t {
157 expression_base_t expression;
160 long double float_value;
164 struct string_literal_expression_t {
165 expression_base_t expression;
169 struct wide_string_literal_expression_t {
170 expression_base_t expression;
174 struct builtin_symbol_expression_t {
175 expression_base_t expression;
179 struct reference_expression_t {
180 expression_base_t expression;
182 declaration_t *declaration;
185 struct call_argument_t {
186 expression_t *expression;
187 call_argument_t *next;
190 struct call_expression_t {
191 expression_base_t expression;
192 expression_t *function;
193 call_argument_t *arguments;
196 struct unary_expression_t {
197 expression_base_t expression;
201 struct binary_expression_t {
202 expression_base_t expression;
207 struct select_expression_t {
208 expression_base_t expression;
209 expression_t *compound;
212 declaration_t *compound_entry;
215 struct array_access_expression_t {
216 expression_base_t expression;
217 expression_t *array_ref;
219 bool flipped; /* index/ref was written in a 5[a] way */
222 struct sizeof_expression_t {
223 expression_base_t expression;
225 expression_t *size_expression;
228 struct designator_t {
230 expression_t *array_access;
234 struct offsetof_expression_t {
235 expression_base_t expression;
237 designator_t *designator;
240 struct va_start_expression_t {
241 expression_base_t expression;
243 declaration_t *parameter;
246 struct va_arg_expression_t {
247 expression_base_t expression;
251 struct conditional_expression_t {
252 expression_base_t expression;
253 expression_t *condition;
254 expression_t *true_expression;
255 expression_t *false_expression;
258 struct statement_expression_t {
259 expression_base_t expression;
260 statement_t *statement;
263 struct classify_type_expression_t {
264 expression_base_t expression;
265 expression_t *type_expression;
269 expression_type_t type;
270 expression_base_t base;
271 const_expression_t conste;
272 string_literal_expression_t string;
273 wide_string_literal_expression_t wide_string;
274 builtin_symbol_expression_t builtin_symbol;
275 reference_expression_t reference;
276 call_expression_t call;
277 unary_expression_t unary;
278 binary_expression_t binary;
279 select_expression_t select;
280 array_access_expression_t array_access;
281 sizeof_expression_t sizeofe;
282 offsetof_expression_t offsetofe;
283 va_start_expression_t va_starte;
284 va_arg_expression_t va_arge;
285 conditional_expression_t conditional;
286 statement_expression_t statement;
287 classify_type_expression_t classify_type;
292 STORAGE_CLASS_TYPEDEF,
293 STORAGE_CLASS_EXTERN,
294 STORAGE_CLASS_STATIC,
296 STORAGE_CLASS_REGISTER,
297 STORAGE_CLASS_ENUM_ENTRY,
298 STORAGE_CLASS_THREAD,
299 STORAGE_CLASS_THREAD_EXTERN,
300 STORAGE_CLASS_THREAD_STATIC
301 } storage_class_tag_t;
315 INITIALIZER_WIDE_STRING
316 } initializer_type_t;
318 struct initializer_base_t {
319 initializer_type_t type;
322 struct initializer_value_t {
323 initializer_base_t initializer;
327 struct initializer_list_t {
328 initializer_base_t initializer;
330 initializer_t *initializers[];
333 struct initializer_string_t {
334 initializer_base_t initializer;
338 struct initializer_wide_string_t {
339 initializer_base_t initializer;
340 wide_string_t string;
343 union initializer_t {
344 initializer_type_t type;
345 initializer_base_t base;
346 initializer_value_t value;
347 initializer_list_t list;
348 initializer_string_t string;
349 initializer_wide_string_t wide_string;
353 DM_DLLIMPORT = (1 << 0),
354 DM_DLLEXPORT = (1 << 1),
355 DM_THREAD = (1 << 2),
357 DM_FORCEINLINE = (1 << 4),
358 DM_NOTHROW = (1 << 5),
359 DM_NORETURN = (1 << 6),
360 DM_NOINLINE = (1 << 7)
363 typedef unsigned short decl_modifiers_t;
365 struct declaration_t {
366 unsigned char namespc;
367 unsigned char storage_class;
368 decl_modifiers_t decl_modifiers;
369 unsigned int address_taken : 1;
370 unsigned int is_inline : 1;
373 source_position_t source_position;
376 statement_t *statement;
377 initializer_t *initializer;
378 expression_t *enum_value;
381 context_t *parent_context;
383 /** next declaration in a context */
385 /** next declaration with same symbol */
386 declaration_t *symbol_next;
388 unsigned char declaration_type; /* used in ast2firm module */
390 unsigned int value_number; /* used in ast2firm module */
391 ir_entity *entity; /* used in ast2firm module */
392 ir_node *block; /* used in ast2firm module */
393 tarval *enum_val; /* used in ast2firm module */
401 STATEMENT_DECLARATION,
404 STATEMENT_EXPRESSION,
409 STATEMENT_CASE_LABEL,
416 struct statement_base_t {
417 statement_type_t type;
419 source_position_t source_position;
422 struct return_statement_t {
423 statement_base_t statement;
424 expression_t *return_value;
427 struct compound_statement_t {
428 statement_base_t statement;
429 statement_t *statements;
433 struct declaration_statement_t {
434 statement_base_t statement;
435 declaration_t *declarations_begin;
436 declaration_t *declarations_end;
439 struct if_statement_t {
440 statement_base_t statement;
441 expression_t *condition;
442 statement_t *true_statement;
443 statement_t *false_statement;
446 struct switch_statement_t {
447 statement_base_t statement;
448 expression_t *expression;
452 struct goto_statement_t {
453 statement_base_t statement;
454 declaration_t *label;
457 struct case_label_statement_t {
458 statement_base_t statement;
459 expression_t *expression;
460 statement_t *label_statement;
463 struct label_statement_t {
464 statement_base_t statement;
465 declaration_t *label;
466 statement_t *label_statement;
469 struct expression_statement_t {
470 statement_base_t statement;
471 expression_t *expression;
474 struct while_statement_t {
475 statement_base_t statement;
476 expression_t *condition;
480 struct do_while_statement_t {
481 statement_base_t statement;
482 expression_t *condition;
486 struct for_statement_t {
487 statement_base_t statement;
488 expression_t *initialisation;
489 expression_t *condition;
495 struct asm_constraint_t {
496 const char *constraints;
497 expression_t *expression;
499 asm_constraint_t *next;
502 struct asm_clobber_t {
507 struct asm_statement_t {
508 statement_base_t statement;
509 const char *asm_text;
510 asm_constraint_t *inputs;
511 asm_constraint_t *outputs;
512 asm_clobber_t *clobbers;
517 statement_type_t type;
518 statement_base_t base;
519 return_statement_t returns;
520 compound_statement_t compound;
521 declaration_statement_t declaration;
523 switch_statement_t switchs;
524 goto_statement_t gotos;
525 case_label_statement_t case_label;
526 label_statement_t label;
527 expression_statement_t expression;
528 while_statement_t whiles;
529 do_while_statement_t do_while;
530 for_statement_t fors;
531 asm_statement_t asms;
534 struct translation_unit_t {
539 void *_allocate_ast(size_t size)
541 return obstack_alloc(&ast_obstack, size);
544 #define allocate_ast(size) _allocate_ast(size)