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_ASSUME, /**< MS __assume() */
51 EXPR_UNARY_LAST = EXPR_UNARY_ASSUME,
54 EXPR_BINARY_ADD = EXPR_BINARY_FIRST,
62 EXPR_BINARY_LESSEQUAL,
64 EXPR_BINARY_GREATEREQUAL,
65 EXPR_BINARY_BITWISE_AND,
66 EXPR_BINARY_BITWISE_OR,
67 EXPR_BINARY_BITWISE_XOR,
68 EXPR_BINARY_LOGICAL_AND,
69 EXPR_BINARY_LOGICAL_OR,
70 EXPR_BINARY_SHIFTLEFT,
71 EXPR_BINARY_SHIFTRIGHT,
73 EXPR_BINARY_MUL_ASSIGN,
74 EXPR_BINARY_DIV_ASSIGN,
75 EXPR_BINARY_MOD_ASSIGN,
76 EXPR_BINARY_ADD_ASSIGN,
77 EXPR_BINARY_SUB_ASSIGN,
78 EXPR_BINARY_SHIFTLEFT_ASSIGN,
79 EXPR_BINARY_SHIFTRIGHT_ASSIGN,
80 EXPR_BINARY_BITWISE_AND_ASSIGN,
81 EXPR_BINARY_BITWISE_XOR_ASSIGN,
82 EXPR_BINARY_BITWISE_OR_ASSIGN,
85 EXPR_BINARY_BUILTIN_EXPECT,
86 EXPR_BINARY_ISGREATER,
87 EXPR_BINARY_ISGREATEREQUAL,
89 EXPR_BINARY_ISLESSEQUAL,
90 EXPR_BINARY_ISLESSGREATER,
91 EXPR_BINARY_ISUNORDERED,
92 EXPR_BINARY_LAST = EXPR_BINARY_ISUNORDERED,
95 /* convenience macros */
96 #define EXPR_BINARY_CASES \
97 case EXPR_BINARY_ADD: \
98 case EXPR_BINARY_SUB: \
99 case EXPR_BINARY_MUL: \
100 case EXPR_BINARY_DIV: \
101 case EXPR_BINARY_MOD: \
102 case EXPR_BINARY_EQUAL: \
103 case EXPR_BINARY_NOTEQUAL: \
104 case EXPR_BINARY_LESS: \
105 case EXPR_BINARY_LESSEQUAL: \
106 case EXPR_BINARY_GREATER: \
107 case EXPR_BINARY_GREATEREQUAL: \
108 case EXPR_BINARY_BITWISE_AND: \
109 case EXPR_BINARY_BITWISE_OR: \
110 case EXPR_BINARY_BITWISE_XOR: \
111 case EXPR_BINARY_LOGICAL_AND: \
112 case EXPR_BINARY_LOGICAL_OR: \
113 case EXPR_BINARY_SHIFTLEFT: \
114 case EXPR_BINARY_SHIFTRIGHT: \
115 case EXPR_BINARY_ASSIGN: \
116 case EXPR_BINARY_MUL_ASSIGN: \
117 case EXPR_BINARY_DIV_ASSIGN: \
118 case EXPR_BINARY_MOD_ASSIGN: \
119 case EXPR_BINARY_ADD_ASSIGN: \
120 case EXPR_BINARY_SUB_ASSIGN: \
121 case EXPR_BINARY_SHIFTLEFT_ASSIGN: \
122 case EXPR_BINARY_SHIFTRIGHT_ASSIGN: \
123 case EXPR_BINARY_BITWISE_AND_ASSIGN: \
124 case EXPR_BINARY_BITWISE_XOR_ASSIGN: \
125 case EXPR_BINARY_BITWISE_OR_ASSIGN: \
126 case EXPR_BINARY_COMMA: \
127 case EXPR_BINARY_BUILTIN_EXPECT: \
128 case EXPR_BINARY_ISGREATER: \
129 case EXPR_BINARY_ISGREATEREQUAL: \
130 case EXPR_BINARY_ISLESS: \
131 case EXPR_BINARY_ISLESSEQUAL: \
132 case EXPR_BINARY_ISLESSGREATER: \
133 case EXPR_BINARY_ISUNORDERED:
135 #define EXPR_UNARY_CASES \
136 case EXPR_UNARY_NEGATE: \
137 case EXPR_UNARY_PLUS: \
138 case EXPR_UNARY_BITWISE_NEGATE: \
139 case EXPR_UNARY_NOT: \
140 case EXPR_UNARY_DEREFERENCE: \
141 case EXPR_UNARY_TAKE_ADDRESS: \
142 case EXPR_UNARY_POSTFIX_INCREMENT: \
143 case EXPR_UNARY_POSTFIX_DECREMENT: \
144 case EXPR_UNARY_PREFIX_INCREMENT: \
145 case EXPR_UNARY_PREFIX_DECREMENT: \
146 case EXPR_UNARY_CAST: \
147 case EXPR_UNARY_CAST_IMPLICIT: \
148 case EXPR_UNARY_ASSUME:
151 declaration_t *declarations;
154 struct expression_base_t {
155 expression_kind_t kind;
157 source_position_t source_position;
160 struct const_expression_t {
161 expression_base_t expression;
164 long double float_value;
168 struct string_literal_expression_t {
169 expression_base_t expression;
173 struct wide_string_literal_expression_t {
174 expression_base_t expression;
178 struct builtin_symbol_expression_t {
179 expression_base_t expression;
183 struct reference_expression_t {
184 expression_base_t expression;
186 declaration_t *declaration;
189 struct call_argument_t {
190 expression_t *expression;
191 call_argument_t *next;
194 struct call_expression_t {
195 expression_base_t expression;
196 expression_t *function;
197 call_argument_t *arguments;
200 struct unary_expression_t {
201 expression_base_t expression;
205 struct binary_expression_t {
206 expression_base_t expression;
211 struct select_expression_t {
212 expression_base_t expression;
213 expression_t *compound;
216 declaration_t *compound_entry;
219 struct array_access_expression_t {
220 expression_base_t expression;
221 expression_t *array_ref;
223 bool flipped; /* index/ref was written in a 5[a] way */
226 struct sizeof_expression_t {
227 expression_base_t expression;
229 expression_t *size_expression;
232 struct designator_t {
234 expression_t *array_access;
238 struct offsetof_expression_t {
239 expression_base_t expression;
241 designator_t *designator;
244 struct va_start_expression_t {
245 expression_base_t expression;
247 declaration_t *parameter;
250 struct va_arg_expression_t {
251 expression_base_t expression;
255 struct conditional_expression_t {
256 expression_base_t expression;
257 expression_t *condition;
258 expression_t *true_expression;
259 expression_t *false_expression;
262 struct statement_expression_t {
263 expression_base_t expression;
264 statement_t *statement;
267 struct classify_type_expression_t {
268 expression_base_t expression;
269 expression_t *type_expression;
273 expression_kind_t kind;
274 expression_base_t base;
275 const_expression_t conste;
276 string_literal_expression_t string;
277 wide_string_literal_expression_t wide_string;
278 builtin_symbol_expression_t builtin_symbol;
279 reference_expression_t reference;
280 call_expression_t call;
281 unary_expression_t unary;
282 binary_expression_t binary;
283 select_expression_t select;
284 array_access_expression_t array_access;
285 sizeof_expression_t sizeofe;
286 offsetof_expression_t offsetofe;
287 va_start_expression_t va_starte;
288 va_arg_expression_t va_arge;
289 conditional_expression_t conditional;
290 statement_expression_t statement;
291 classify_type_expression_t classify_type;
296 STORAGE_CLASS_TYPEDEF,
297 STORAGE_CLASS_EXTERN,
298 STORAGE_CLASS_STATIC,
300 STORAGE_CLASS_REGISTER,
301 STORAGE_CLASS_ENUM_ENTRY,
302 STORAGE_CLASS_THREAD,
303 STORAGE_CLASS_THREAD_EXTERN,
304 STORAGE_CLASS_THREAD_STATIC
305 } storage_class_tag_t;
319 INITIALIZER_WIDE_STRING
320 } initializer_kind_t;
322 struct initializer_base_t {
323 initializer_kind_t kind;
326 struct initializer_value_t {
327 initializer_base_t initializer;
331 struct initializer_list_t {
332 initializer_base_t initializer;
334 initializer_t *initializers[];
337 struct initializer_string_t {
338 initializer_base_t initializer;
342 struct initializer_wide_string_t {
343 initializer_base_t initializer;
344 wide_string_t string;
347 union initializer_t {
348 initializer_kind_t kind;
349 initializer_base_t base;
350 initializer_value_t value;
351 initializer_list_t list;
352 initializer_string_t string;
353 initializer_wide_string_t wide_string;
357 DM_DLLIMPORT = (1 << 0),
358 DM_DLLEXPORT = (1 << 1),
359 DM_THREAD = (1 << 2),
361 DM_FORCEINLINE = (1 << 4),
362 DM_NOTHROW = (1 << 5),
363 DM_NORETURN = (1 << 6),
364 DM_NOINLINE = (1 << 7)
367 typedef unsigned short decl_modifiers_t;
369 struct declaration_t {
370 unsigned char namespc;
371 unsigned char storage_class;
372 decl_modifiers_t decl_modifiers;
373 unsigned int address_taken : 1;
374 unsigned int is_inline : 1;
377 source_position_t source_position;
380 statement_t *statement;
381 initializer_t *initializer;
382 expression_t *enum_value;
385 context_t *parent_context;
387 /** next declaration in a context */
389 /** next declaration with same symbol */
390 declaration_t *symbol_next;
392 /* the following fields are used in ast2firm module */
393 unsigned char declaration_type;
395 unsigned int value_number;
406 STATEMENT_DECLARATION,
409 STATEMENT_EXPRESSION,
414 STATEMENT_CASE_LABEL,
421 struct statement_base_t {
422 statement_kind_t kind;
424 source_position_t source_position;
427 struct return_statement_t {
428 statement_base_t statement;
429 expression_t *return_value;
432 struct compound_statement_t {
433 statement_base_t statement;
434 statement_t *statements;
438 struct declaration_statement_t {
439 statement_base_t statement;
440 declaration_t *declarations_begin;
441 declaration_t *declarations_end;
444 struct if_statement_t {
445 statement_base_t statement;
446 expression_t *condition;
447 statement_t *true_statement;
448 statement_t *false_statement;
451 struct switch_statement_t {
452 statement_base_t statement;
453 expression_t *expression;
457 struct goto_statement_t {
458 statement_base_t statement;
459 declaration_t *label;
462 struct case_label_statement_t {
463 statement_base_t statement;
464 expression_t *expression;
465 statement_t *label_statement;
468 struct label_statement_t {
469 statement_base_t statement;
470 declaration_t *label;
471 statement_t *label_statement;
474 struct expression_statement_t {
475 statement_base_t statement;
476 expression_t *expression;
479 struct while_statement_t {
480 statement_base_t statement;
481 expression_t *condition;
485 struct do_while_statement_t {
486 statement_base_t statement;
487 expression_t *condition;
491 struct for_statement_t {
492 statement_base_t statement;
493 expression_t *initialisation;
494 expression_t *condition;
500 struct asm_constraint_t {
501 const char *constraints;
502 expression_t *expression;
504 asm_constraint_t *next;
507 struct asm_clobber_t {
512 struct asm_statement_t {
513 statement_base_t statement;
514 const char *asm_text;
515 asm_constraint_t *inputs;
516 asm_constraint_t *outputs;
517 asm_clobber_t *clobbers;
522 statement_kind_t kind;
523 statement_base_t base;
524 return_statement_t returns;
525 compound_statement_t compound;
526 declaration_statement_t declaration;
528 switch_statement_t switchs;
529 goto_statement_t gotos;
530 case_label_statement_t case_label;
531 label_statement_t label;
532 expression_statement_t expression;
533 while_statement_t whiles;
534 do_while_statement_t do_while;
535 for_statement_t fors;
536 asm_statement_t asms;
539 struct translation_unit_t {
544 void *_allocate_ast(size_t size)
546 return obstack_alloc(&ast_obstack, size);
549 #define allocate_ast(size) _allocate_ast(size)