4 #include <libfirm/firm_types.h>
13 extern struct obstack ast_obstack;
21 EXPR_WIDE_STRING_LITERAL,
33 EXPR_BUILTIN_CONSTANT_P,
34 EXPR_BUILTIN_PREFETCH,
41 EXPR_UNARY_NEGATE = EXPR_UNARY_FIRST,
43 EXPR_UNARY_BITWISE_NEGATE,
45 EXPR_UNARY_DEREFERENCE,
46 EXPR_UNARY_TAKE_ADDRESS,
47 EXPR_UNARY_POSTFIX_INCREMENT,
48 EXPR_UNARY_POSTFIX_DECREMENT,
49 EXPR_UNARY_PREFIX_INCREMENT,
50 EXPR_UNARY_PREFIX_DECREMENT,
52 EXPR_UNARY_CAST_IMPLICIT, /**< compiler generated cast */
53 EXPR_UNARY_ASSUME, /**< MS __assume() */
54 EXPR_UNARY_BITFIELD_EXTRACT,
55 EXPR_UNARY_LAST = EXPR_UNARY_BITFIELD_EXTRACT,
58 EXPR_BINARY_ADD = EXPR_BINARY_FIRST,
66 EXPR_BINARY_LESSEQUAL,
68 EXPR_BINARY_GREATEREQUAL,
69 EXPR_BINARY_BITWISE_AND,
70 EXPR_BINARY_BITWISE_OR,
71 EXPR_BINARY_BITWISE_XOR,
72 EXPR_BINARY_LOGICAL_AND,
73 EXPR_BINARY_LOGICAL_OR,
74 EXPR_BINARY_SHIFTLEFT,
75 EXPR_BINARY_SHIFTRIGHT,
77 EXPR_BINARY_MUL_ASSIGN,
78 EXPR_BINARY_DIV_ASSIGN,
79 EXPR_BINARY_MOD_ASSIGN,
80 EXPR_BINARY_ADD_ASSIGN,
81 EXPR_BINARY_SUB_ASSIGN,
82 EXPR_BINARY_SHIFTLEFT_ASSIGN,
83 EXPR_BINARY_SHIFTRIGHT_ASSIGN,
84 EXPR_BINARY_BITWISE_AND_ASSIGN,
85 EXPR_BINARY_BITWISE_XOR_ASSIGN,
86 EXPR_BINARY_BITWISE_OR_ASSIGN,
89 EXPR_BINARY_BUILTIN_EXPECT,
90 EXPR_BINARY_ISGREATER,
91 EXPR_BINARY_ISGREATEREQUAL,
93 EXPR_BINARY_ISLESSEQUAL,
94 EXPR_BINARY_ISLESSGREATER,
95 EXPR_BINARY_ISUNORDERED,
96 EXPR_BINARY_LAST = EXPR_BINARY_ISUNORDERED,
99 /* convenience macros */
100 #define EXPR_BINARY_CASES \
101 case EXPR_BINARY_ADD: \
102 case EXPR_BINARY_SUB: \
103 case EXPR_BINARY_MUL: \
104 case EXPR_BINARY_DIV: \
105 case EXPR_BINARY_MOD: \
106 case EXPR_BINARY_EQUAL: \
107 case EXPR_BINARY_NOTEQUAL: \
108 case EXPR_BINARY_LESS: \
109 case EXPR_BINARY_LESSEQUAL: \
110 case EXPR_BINARY_GREATER: \
111 case EXPR_BINARY_GREATEREQUAL: \
112 case EXPR_BINARY_BITWISE_AND: \
113 case EXPR_BINARY_BITWISE_OR: \
114 case EXPR_BINARY_BITWISE_XOR: \
115 case EXPR_BINARY_LOGICAL_AND: \
116 case EXPR_BINARY_LOGICAL_OR: \
117 case EXPR_BINARY_SHIFTLEFT: \
118 case EXPR_BINARY_SHIFTRIGHT: \
119 case EXPR_BINARY_ASSIGN: \
120 case EXPR_BINARY_MUL_ASSIGN: \
121 case EXPR_BINARY_DIV_ASSIGN: \
122 case EXPR_BINARY_MOD_ASSIGN: \
123 case EXPR_BINARY_ADD_ASSIGN: \
124 case EXPR_BINARY_SUB_ASSIGN: \
125 case EXPR_BINARY_SHIFTLEFT_ASSIGN: \
126 case EXPR_BINARY_SHIFTRIGHT_ASSIGN: \
127 case EXPR_BINARY_BITWISE_AND_ASSIGN: \
128 case EXPR_BINARY_BITWISE_XOR_ASSIGN: \
129 case EXPR_BINARY_BITWISE_OR_ASSIGN: \
130 case EXPR_BINARY_COMMA: \
131 case EXPR_BINARY_BUILTIN_EXPECT: \
132 case EXPR_BINARY_ISGREATER: \
133 case EXPR_BINARY_ISGREATEREQUAL: \
134 case EXPR_BINARY_ISLESS: \
135 case EXPR_BINARY_ISLESSEQUAL: \
136 case EXPR_BINARY_ISLESSGREATER: \
137 case EXPR_BINARY_ISUNORDERED:
139 #define EXPR_UNARY_CASES \
140 case EXPR_UNARY_NEGATE: \
141 case EXPR_UNARY_PLUS: \
142 case EXPR_UNARY_BITWISE_NEGATE: \
143 case EXPR_UNARY_NOT: \
144 case EXPR_UNARY_DEREFERENCE: \
145 case EXPR_UNARY_TAKE_ADDRESS: \
146 case EXPR_UNARY_POSTFIX_INCREMENT: \
147 case EXPR_UNARY_POSTFIX_DECREMENT: \
148 case EXPR_UNARY_PREFIX_INCREMENT: \
149 case EXPR_UNARY_PREFIX_DECREMENT: \
150 case EXPR_UNARY_CAST: \
151 case EXPR_UNARY_CAST_IMPLICIT: \
152 case EXPR_UNARY_ASSUME: \
153 case EXPR_UNARY_BITFIELD_EXTRACT:
156 declaration_t *declarations; /**< List of declarations in this scope. */
159 struct expression_base_t {
160 expression_kind_t kind;
162 source_position_t source_position;
165 struct const_expression_t {
166 expression_base_t base;
169 long double float_value;
173 struct string_literal_expression_t {
174 expression_base_t base;
178 struct wide_string_literal_expression_t {
179 expression_base_t base;
183 struct builtin_symbol_expression_t {
184 expression_base_t base;
188 struct builtin_constant_expression_t {
189 expression_base_t base;
193 struct builtin_prefetch_expression_t {
194 expression_base_t base;
197 expression_t *locality;
200 struct reference_expression_t {
201 expression_base_t base;
203 declaration_t *declaration;
206 struct call_argument_t {
207 expression_t *expression;
208 call_argument_t *next;
211 struct call_expression_t {
212 expression_base_t base;
213 expression_t *function;
214 call_argument_t *arguments;
217 struct unary_expression_t {
218 expression_base_t base;
222 struct binary_expression_t {
223 expression_base_t base;
228 struct select_expression_t {
229 expression_base_t base;
230 expression_t *compound;
233 declaration_t *compound_entry;
236 struct array_access_expression_t {
237 expression_base_t base;
238 expression_t *array_ref;
240 bool flipped; /* index/ref was written in a 5[a] way */
243 struct typeprop_expression_t {
244 expression_base_t base;
246 expression_t *tp_expression;
249 struct designator_t {
251 expression_t *array_access;
255 struct offsetof_expression_t {
256 expression_base_t base;
258 designator_t *designator;
261 struct va_start_expression_t {
262 expression_base_t base;
264 declaration_t *parameter;
267 struct va_arg_expression_t {
268 expression_base_t base;
272 struct conditional_expression_t {
273 expression_base_t base;
274 expression_t *condition;
275 expression_t *true_expression;
276 expression_t *false_expression;
279 struct statement_expression_t {
280 expression_base_t base;
281 statement_t *statement;
284 struct classify_type_expression_t {
285 expression_base_t base;
286 expression_t *type_expression;
290 expression_kind_t kind;
291 expression_base_t base;
292 const_expression_t conste;
293 string_literal_expression_t string;
294 wide_string_literal_expression_t wide_string;
295 builtin_symbol_expression_t builtin_symbol;
296 builtin_constant_expression_t builtin_constant;
297 builtin_prefetch_expression_t builtin_prefetch;
298 reference_expression_t reference;
299 call_expression_t call;
300 unary_expression_t unary;
301 binary_expression_t binary;
302 select_expression_t select;
303 array_access_expression_t array_access;
304 typeprop_expression_t typeprop;
305 offsetof_expression_t offsetofe;
306 va_start_expression_t va_starte;
307 va_arg_expression_t va_arge;
308 conditional_expression_t conditional;
309 statement_expression_t statement;
310 classify_type_expression_t classify_type;
315 STORAGE_CLASS_TYPEDEF,
316 STORAGE_CLASS_EXTERN,
317 STORAGE_CLASS_STATIC,
319 STORAGE_CLASS_REGISTER,
320 STORAGE_CLASS_ENUM_ENTRY,
321 STORAGE_CLASS_THREAD,
322 STORAGE_CLASS_THREAD_EXTERN,
323 STORAGE_CLASS_THREAD_STATIC
324 } storage_class_tag_t;
338 INITIALIZER_WIDE_STRING
339 } initializer_kind_t;
341 struct initializer_base_t {
342 initializer_kind_t kind;
345 struct initializer_value_t {
346 initializer_base_t initializer;
350 struct initializer_list_t {
351 initializer_base_t initializer;
353 initializer_t *initializers[];
356 struct initializer_string_t {
357 initializer_base_t initializer;
361 struct initializer_wide_string_t {
362 initializer_base_t initializer;
363 wide_string_t string;
366 union initializer_t {
367 initializer_kind_t kind;
368 initializer_base_t base;
369 initializer_value_t value;
370 initializer_list_t list;
371 initializer_string_t string;
372 initializer_wide_string_t wide_string;
376 DM_DLLIMPORT = (1 << 0),
377 DM_DLLEXPORT = (1 << 1),
378 DM_THREAD = (1 << 2),
380 DM_FORCEINLINE = (1 << 4),
381 DM_NOTHROW = (1 << 5),
382 DM_NORETURN = (1 << 6),
383 DM_NOINLINE = (1 << 7)
386 typedef unsigned short decl_modifiers_t;
388 struct declaration_t {
389 unsigned char namespc;
390 unsigned char storage_class;
391 decl_modifiers_t modifiers;
392 unsigned int address_taken : 1;
393 unsigned int is_inline : 1;
394 unsigned int used : 1; /**< Set if the declaration is used. */
397 source_position_t source_position;
400 statement_t *statement;
401 initializer_t *initializer;
402 expression_t *enum_value;
405 scope_t *parent_scope;
407 /** next declaration in a scope */
409 /** next declaration with same symbol */
410 declaration_t *symbol_next;
412 /* the following fields are used in ast2firm module */
413 unsigned char declaration_kind;
415 unsigned int value_number;
426 STATEMENT_DECLARATION,
429 STATEMENT_EXPRESSION,
434 STATEMENT_CASE_LABEL,
441 struct statement_base_t {
442 statement_kind_t kind;
444 source_position_t source_position;
447 struct return_statement_t {
448 statement_base_t base;
452 struct compound_statement_t {
453 statement_base_t base;
454 statement_t *statements;
458 struct declaration_statement_t {
459 statement_base_t base;
460 declaration_t *declarations_begin;
461 declaration_t *declarations_end;
464 struct if_statement_t {
465 statement_base_t base;
466 expression_t *condition;
467 statement_t *true_statement;
468 statement_t *false_statement;
471 struct switch_statement_t {
472 statement_base_t base;
473 expression_t *expression;
475 case_label_statement_t *first_case, *last_case;
478 struct goto_statement_t {
479 statement_base_t base;
480 declaration_t *label; /**< The destination label. */
481 goto_statement_t *next; /**< links all goto statements of a function */
484 struct case_label_statement_t {
485 statement_base_t base;
486 expression_t *expression;
487 statement_t *statement;
488 case_label_statement_t *next; /**< link to the next case label in switch */
491 struct label_statement_t {
492 statement_base_t base;
493 declaration_t *label;
494 statement_t *statement;
495 label_statement_t *next; /**< links all label statements of a function */
498 struct expression_statement_t {
499 statement_base_t base;
500 expression_t *expression;
503 struct while_statement_t {
504 statement_base_t base;
505 expression_t *condition;
509 struct do_while_statement_t {
510 statement_base_t base;
511 expression_t *condition;
515 struct for_statement_t {
516 statement_base_t base;
517 expression_t *initialisation;
518 expression_t *condition;
524 struct asm_constraint_t {
525 string_t constraints;
526 expression_t *expression;
528 asm_constraint_t *next;
531 struct asm_clobber_t {
536 struct asm_statement_t {
537 statement_base_t base;
539 asm_constraint_t *inputs;
540 asm_constraint_t *outputs;
541 asm_clobber_t *clobbers;
546 statement_kind_t kind;
547 statement_base_t base;
548 return_statement_t returns;
549 compound_statement_t compound;
550 declaration_statement_t declaration;
552 switch_statement_t switchs;
553 goto_statement_t gotos;
554 case_label_statement_t case_label;
555 label_statement_t label;
556 expression_statement_t expression;
557 while_statement_t whiles;
558 do_while_statement_t do_while;
559 for_statement_t fors;
560 asm_statement_t asms;
563 struct translation_unit_t {
568 void *_allocate_ast(size_t size)
570 return obstack_alloc(&ast_obstack, size);
573 #define allocate_ast(size) _allocate_ast(size)