4 #include <libfirm/firm_types.h>
13 extern struct obstack ast_obstack;
22 EXPR_WIDE_STRING_LITERAL,
34 EXPR_BUILTIN_CONSTANT_P,
35 EXPR_BUILTIN_PREFETCH,
42 EXPR_UNARY_NEGATE = EXPR_UNARY_FIRST,
44 EXPR_UNARY_BITWISE_NEGATE,
46 EXPR_UNARY_DEREFERENCE,
47 EXPR_UNARY_TAKE_ADDRESS,
48 EXPR_UNARY_POSTFIX_INCREMENT,
49 EXPR_UNARY_POSTFIX_DECREMENT,
50 EXPR_UNARY_PREFIX_INCREMENT,
51 EXPR_UNARY_PREFIX_DECREMENT,
53 EXPR_UNARY_CAST_IMPLICIT, /**< compiler generated cast */
54 EXPR_UNARY_ASSUME, /**< MS __assume() */
55 EXPR_UNARY_BITFIELD_EXTRACT,
56 EXPR_UNARY_LAST = EXPR_UNARY_BITFIELD_EXTRACT,
59 EXPR_BINARY_ADD = EXPR_BINARY_FIRST,
67 EXPR_BINARY_LESSEQUAL,
69 EXPR_BINARY_GREATEREQUAL,
70 EXPR_BINARY_BITWISE_AND,
71 EXPR_BINARY_BITWISE_OR,
72 EXPR_BINARY_BITWISE_XOR,
73 EXPR_BINARY_LOGICAL_AND,
74 EXPR_BINARY_LOGICAL_OR,
75 EXPR_BINARY_SHIFTLEFT,
76 EXPR_BINARY_SHIFTRIGHT,
78 EXPR_BINARY_MUL_ASSIGN,
79 EXPR_BINARY_DIV_ASSIGN,
80 EXPR_BINARY_MOD_ASSIGN,
81 EXPR_BINARY_ADD_ASSIGN,
82 EXPR_BINARY_SUB_ASSIGN,
83 EXPR_BINARY_SHIFTLEFT_ASSIGN,
84 EXPR_BINARY_SHIFTRIGHT_ASSIGN,
85 EXPR_BINARY_BITWISE_AND_ASSIGN,
86 EXPR_BINARY_BITWISE_XOR_ASSIGN,
87 EXPR_BINARY_BITWISE_OR_ASSIGN,
90 EXPR_BINARY_BUILTIN_EXPECT,
91 EXPR_BINARY_ISGREATER,
92 EXPR_BINARY_ISGREATEREQUAL,
94 EXPR_BINARY_ISLESSEQUAL,
95 EXPR_BINARY_ISLESSGREATER,
96 EXPR_BINARY_ISUNORDERED,
97 EXPR_BINARY_LAST = EXPR_BINARY_ISUNORDERED,
100 /* convenience macros */
101 #define EXPR_BINARY_CASES \
102 case EXPR_BINARY_ADD: \
103 case EXPR_BINARY_SUB: \
104 case EXPR_BINARY_MUL: \
105 case EXPR_BINARY_DIV: \
106 case EXPR_BINARY_MOD: \
107 case EXPR_BINARY_EQUAL: \
108 case EXPR_BINARY_NOTEQUAL: \
109 case EXPR_BINARY_LESS: \
110 case EXPR_BINARY_LESSEQUAL: \
111 case EXPR_BINARY_GREATER: \
112 case EXPR_BINARY_GREATEREQUAL: \
113 case EXPR_BINARY_BITWISE_AND: \
114 case EXPR_BINARY_BITWISE_OR: \
115 case EXPR_BINARY_BITWISE_XOR: \
116 case EXPR_BINARY_LOGICAL_AND: \
117 case EXPR_BINARY_LOGICAL_OR: \
118 case EXPR_BINARY_SHIFTLEFT: \
119 case EXPR_BINARY_SHIFTRIGHT: \
120 case EXPR_BINARY_ASSIGN: \
121 case EXPR_BINARY_MUL_ASSIGN: \
122 case EXPR_BINARY_DIV_ASSIGN: \
123 case EXPR_BINARY_MOD_ASSIGN: \
124 case EXPR_BINARY_ADD_ASSIGN: \
125 case EXPR_BINARY_SUB_ASSIGN: \
126 case EXPR_BINARY_SHIFTLEFT_ASSIGN: \
127 case EXPR_BINARY_SHIFTRIGHT_ASSIGN: \
128 case EXPR_BINARY_BITWISE_AND_ASSIGN: \
129 case EXPR_BINARY_BITWISE_XOR_ASSIGN: \
130 case EXPR_BINARY_BITWISE_OR_ASSIGN: \
131 case EXPR_BINARY_COMMA: \
132 case EXPR_BINARY_BUILTIN_EXPECT: \
133 case EXPR_BINARY_ISGREATER: \
134 case EXPR_BINARY_ISGREATEREQUAL: \
135 case EXPR_BINARY_ISLESS: \
136 case EXPR_BINARY_ISLESSEQUAL: \
137 case EXPR_BINARY_ISLESSGREATER: \
138 case EXPR_BINARY_ISUNORDERED:
140 #define EXPR_UNARY_CASES \
141 case EXPR_UNARY_NEGATE: \
142 case EXPR_UNARY_PLUS: \
143 case EXPR_UNARY_BITWISE_NEGATE: \
144 case EXPR_UNARY_NOT: \
145 case EXPR_UNARY_DEREFERENCE: \
146 case EXPR_UNARY_TAKE_ADDRESS: \
147 case EXPR_UNARY_POSTFIX_INCREMENT: \
148 case EXPR_UNARY_POSTFIX_DECREMENT: \
149 case EXPR_UNARY_PREFIX_INCREMENT: \
150 case EXPR_UNARY_PREFIX_DECREMENT: \
151 case EXPR_UNARY_CAST: \
152 case EXPR_UNARY_CAST_IMPLICIT: \
153 case EXPR_UNARY_ASSUME: \
154 case EXPR_UNARY_BITFIELD_EXTRACT:
157 declaration_t *declarations; /**< List of declarations in this scope. */
158 declaration_t *last_declaration;
161 struct expression_base_t {
162 expression_kind_t kind;
164 source_position_t source_position;
167 struct const_expression_t {
168 expression_base_t base;
171 long double float_value;
176 struct string_literal_expression_t {
177 expression_base_t base;
181 struct wide_string_literal_expression_t {
182 expression_base_t base;
186 struct builtin_symbol_expression_t {
187 expression_base_t base;
191 struct builtin_constant_expression_t {
192 expression_base_t base;
196 struct builtin_prefetch_expression_t {
197 expression_base_t base;
200 expression_t *locality;
203 struct reference_expression_t {
204 expression_base_t base;
206 declaration_t *declaration;
209 struct call_argument_t {
210 expression_t *expression;
211 call_argument_t *next;
214 struct call_expression_t {
215 expression_base_t base;
216 expression_t *function;
217 call_argument_t *arguments;
220 struct unary_expression_t {
221 expression_base_t base;
225 struct binary_expression_t {
226 expression_base_t base;
231 struct select_expression_t {
232 expression_base_t base;
233 expression_t *compound;
236 declaration_t *compound_entry;
239 struct array_access_expression_t {
240 expression_base_t base;
241 expression_t *array_ref;
243 bool flipped; /* index/ref was written in a 5[a] way */
246 struct typeprop_expression_t {
247 expression_base_t base;
249 expression_t *tp_expression;
252 struct designator_t {
254 expression_t *array_access;
258 struct offsetof_expression_t {
259 expression_base_t base;
261 designator_t *designator;
264 struct va_start_expression_t {
265 expression_base_t base;
267 declaration_t *parameter;
270 struct va_arg_expression_t {
271 expression_base_t base;
275 struct conditional_expression_t {
276 expression_base_t base;
277 expression_t *condition;
278 expression_t *true_expression;
279 expression_t *false_expression;
282 struct statement_expression_t {
283 expression_base_t base;
284 statement_t *statement;
287 struct classify_type_expression_t {
288 expression_base_t base;
289 expression_t *type_expression;
293 expression_kind_t kind;
294 expression_base_t base;
295 const_expression_t conste;
296 string_literal_expression_t string;
297 wide_string_literal_expression_t wide_string;
298 builtin_symbol_expression_t builtin_symbol;
299 builtin_constant_expression_t builtin_constant;
300 builtin_prefetch_expression_t builtin_prefetch;
301 reference_expression_t reference;
302 call_expression_t call;
303 unary_expression_t unary;
304 binary_expression_t binary;
305 select_expression_t select;
306 array_access_expression_t array_access;
307 typeprop_expression_t typeprop;
308 offsetof_expression_t offsetofe;
309 va_start_expression_t va_starte;
310 va_arg_expression_t va_arge;
311 conditional_expression_t conditional;
312 statement_expression_t statement;
313 classify_type_expression_t classify_type;
318 STORAGE_CLASS_TYPEDEF,
319 STORAGE_CLASS_EXTERN,
320 STORAGE_CLASS_STATIC,
322 STORAGE_CLASS_REGISTER,
323 STORAGE_CLASS_ENUM_ENTRY,
324 STORAGE_CLASS_THREAD,
325 STORAGE_CLASS_THREAD_EXTERN,
326 STORAGE_CLASS_THREAD_STATIC
327 } storage_class_tag_t;
341 INITIALIZER_WIDE_STRING
342 } initializer_kind_t;
344 struct initializer_base_t {
345 initializer_kind_t kind;
348 struct initializer_value_t {
349 initializer_base_t initializer;
353 struct initializer_list_t {
354 initializer_base_t initializer;
356 initializer_t *initializers[];
359 struct initializer_string_t {
360 initializer_base_t initializer;
364 struct initializer_wide_string_t {
365 initializer_base_t initializer;
366 wide_string_t string;
369 union initializer_t {
370 initializer_kind_t kind;
371 initializer_base_t base;
372 initializer_value_t value;
373 initializer_list_t list;
374 initializer_string_t string;
375 initializer_wide_string_t wide_string;
379 DM_DLLIMPORT = (1 << 0),
380 DM_DLLEXPORT = (1 << 1),
381 DM_THREAD = (1 << 2),
383 DM_FORCEINLINE = (1 << 4),
384 DM_NOTHROW = (1 << 5),
385 DM_NORETURN = (1 << 6),
386 DM_NOINLINE = (1 << 7)
389 typedef unsigned short decl_modifiers_t;
391 struct declaration_t {
392 unsigned char namespc;
393 unsigned char storage_class;
394 decl_modifiers_t modifiers;
395 unsigned int address_taken : 1;
396 unsigned int is_inline : 1;
397 unsigned int used : 1; /**< Set if the declaration is used. */
400 source_position_t source_position;
403 statement_t *statement;
404 initializer_t *initializer;
405 expression_t *enum_value;
408 scope_t *parent_scope;
410 /** next declaration in a scope */
412 /** next declaration with same symbol */
413 declaration_t *symbol_next;
415 /* the following fields are used in ast2firm module */
416 unsigned char declaration_kind;
418 unsigned int value_number;
430 STATEMENT_DECLARATION,
433 STATEMENT_EXPRESSION,
438 STATEMENT_CASE_LABEL,
445 struct statement_base_t {
446 statement_kind_t kind;
448 source_position_t source_position;
451 struct return_statement_t {
452 statement_base_t base;
456 struct compound_statement_t {
457 statement_base_t base;
458 statement_t *statements;
462 struct declaration_statement_t {
463 statement_base_t base;
464 declaration_t *declarations_begin;
465 declaration_t *declarations_end;
468 struct if_statement_t {
469 statement_base_t base;
470 expression_t *condition;
471 statement_t *true_statement;
472 statement_t *false_statement;
475 struct switch_statement_t {
476 statement_base_t base;
477 expression_t *expression;
479 case_label_statement_t *first_case, *last_case;
482 struct goto_statement_t {
483 statement_base_t base;
484 declaration_t *label; /**< The destination label. */
485 goto_statement_t *next; /**< links all goto statements of a function */
488 struct case_label_statement_t {
489 statement_base_t base;
490 expression_t *expression; /**< The case label expression, NULL for default label. */
491 expression_t *end_range; /**< For GNUC case a .. b: the end range expression, NULL else. */
492 statement_t *statement;
493 case_label_statement_t *next; /**< link to the next case label in switch */
496 struct label_statement_t {
497 statement_base_t base;
498 declaration_t *label;
499 statement_t *statement;
500 label_statement_t *next; /**< links all label statements of a function */
503 struct expression_statement_t {
504 statement_base_t base;
505 expression_t *expression;
508 struct while_statement_t {
509 statement_base_t base;
510 expression_t *condition;
514 struct do_while_statement_t {
515 statement_base_t base;
516 expression_t *condition;
520 struct for_statement_t {
521 statement_base_t base;
522 expression_t *initialisation;
523 expression_t *condition;
529 struct asm_constraint_t {
530 string_t constraints;
531 expression_t *expression;
533 asm_constraint_t *next;
536 struct asm_clobber_t {
541 struct asm_statement_t {
542 statement_base_t base;
544 asm_constraint_t *inputs;
545 asm_constraint_t *outputs;
546 asm_clobber_t *clobbers;
551 statement_kind_t kind;
552 statement_base_t base;
553 return_statement_t returns;
554 compound_statement_t compound;
555 declaration_statement_t declaration;
557 switch_statement_t switchs;
558 goto_statement_t gotos;
559 case_label_statement_t case_label;
560 label_statement_t label;
561 expression_statement_t expression;
562 while_statement_t whiles;
563 do_while_statement_t do_while;
564 for_statement_t fors;
565 asm_statement_t asms;
568 struct translation_unit_t {
573 void *_allocate_ast(size_t size)
575 return obstack_alloc(&ast_obstack, size);
578 #define allocate_ast(size) _allocate_ast(size)