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. */
160 struct expression_base_t {
161 expression_kind_t kind;
163 source_position_t source_position;
166 struct const_expression_t {
167 expression_base_t base;
170 long double float_value;
175 struct string_literal_expression_t {
176 expression_base_t base;
180 struct wide_string_literal_expression_t {
181 expression_base_t base;
185 struct builtin_symbol_expression_t {
186 expression_base_t base;
190 struct builtin_constant_expression_t {
191 expression_base_t base;
195 struct builtin_prefetch_expression_t {
196 expression_base_t base;
199 expression_t *locality;
202 struct reference_expression_t {
203 expression_base_t base;
205 declaration_t *declaration;
208 struct call_argument_t {
209 expression_t *expression;
210 call_argument_t *next;
213 struct call_expression_t {
214 expression_base_t base;
215 expression_t *function;
216 call_argument_t *arguments;
219 struct unary_expression_t {
220 expression_base_t base;
224 struct binary_expression_t {
225 expression_base_t base;
230 struct select_expression_t {
231 expression_base_t base;
232 expression_t *compound;
235 declaration_t *compound_entry;
238 struct array_access_expression_t {
239 expression_base_t base;
240 expression_t *array_ref;
242 bool flipped; /* index/ref was written in a 5[a] way */
245 struct typeprop_expression_t {
246 expression_base_t base;
248 expression_t *tp_expression;
251 struct designator_t {
253 expression_t *array_access;
257 struct offsetof_expression_t {
258 expression_base_t base;
260 designator_t *designator;
263 struct va_start_expression_t {
264 expression_base_t base;
266 declaration_t *parameter;
269 struct va_arg_expression_t {
270 expression_base_t base;
274 struct conditional_expression_t {
275 expression_base_t base;
276 expression_t *condition;
277 expression_t *true_expression;
278 expression_t *false_expression;
281 struct statement_expression_t {
282 expression_base_t base;
283 statement_t *statement;
286 struct classify_type_expression_t {
287 expression_base_t base;
288 expression_t *type_expression;
292 expression_kind_t kind;
293 expression_base_t base;
294 const_expression_t conste;
295 string_literal_expression_t string;
296 wide_string_literal_expression_t wide_string;
297 builtin_symbol_expression_t builtin_symbol;
298 builtin_constant_expression_t builtin_constant;
299 builtin_prefetch_expression_t builtin_prefetch;
300 reference_expression_t reference;
301 call_expression_t call;
302 unary_expression_t unary;
303 binary_expression_t binary;
304 select_expression_t select;
305 array_access_expression_t array_access;
306 typeprop_expression_t typeprop;
307 offsetof_expression_t offsetofe;
308 va_start_expression_t va_starte;
309 va_arg_expression_t va_arge;
310 conditional_expression_t conditional;
311 statement_expression_t statement;
312 classify_type_expression_t classify_type;
317 STORAGE_CLASS_TYPEDEF,
318 STORAGE_CLASS_EXTERN,
319 STORAGE_CLASS_STATIC,
321 STORAGE_CLASS_REGISTER,
322 STORAGE_CLASS_ENUM_ENTRY,
323 STORAGE_CLASS_THREAD,
324 STORAGE_CLASS_THREAD_EXTERN,
325 STORAGE_CLASS_THREAD_STATIC
326 } storage_class_tag_t;
340 INITIALIZER_WIDE_STRING
341 } initializer_kind_t;
343 struct initializer_base_t {
344 initializer_kind_t kind;
347 struct initializer_value_t {
348 initializer_base_t initializer;
352 struct initializer_list_t {
353 initializer_base_t initializer;
355 initializer_t *initializers[];
358 struct initializer_string_t {
359 initializer_base_t initializer;
363 struct initializer_wide_string_t {
364 initializer_base_t initializer;
365 wide_string_t string;
368 union initializer_t {
369 initializer_kind_t kind;
370 initializer_base_t base;
371 initializer_value_t value;
372 initializer_list_t list;
373 initializer_string_t string;
374 initializer_wide_string_t wide_string;
378 DM_DLLIMPORT = (1 << 0),
379 DM_DLLEXPORT = (1 << 1),
380 DM_THREAD = (1 << 2),
382 DM_FORCEINLINE = (1 << 4),
383 DM_NOTHROW = (1 << 5),
384 DM_NORETURN = (1 << 6),
385 DM_NOINLINE = (1 << 7)
388 typedef unsigned short decl_modifiers_t;
390 struct declaration_t {
391 unsigned char namespc;
392 unsigned char storage_class;
393 decl_modifiers_t modifiers;
394 unsigned int address_taken : 1;
395 unsigned int is_inline : 1;
396 unsigned int used : 1; /**< Set if the declaration is used. */
399 source_position_t source_position;
402 statement_t *statement;
403 initializer_t *initializer;
404 expression_t *enum_value;
407 scope_t *parent_scope;
409 /** next declaration in a scope */
411 /** next declaration with same symbol */
412 declaration_t *symbol_next;
414 /* the following fields are used in ast2firm module */
415 unsigned char declaration_kind;
417 unsigned int value_number;
429 STATEMENT_DECLARATION,
432 STATEMENT_EXPRESSION,
437 STATEMENT_CASE_LABEL,
444 struct statement_base_t {
445 statement_kind_t kind;
447 source_position_t source_position;
450 struct return_statement_t {
451 statement_base_t base;
455 struct compound_statement_t {
456 statement_base_t base;
457 statement_t *statements;
461 struct declaration_statement_t {
462 statement_base_t base;
463 declaration_t *declarations_begin;
464 declaration_t *declarations_end;
467 struct if_statement_t {
468 statement_base_t base;
469 expression_t *condition;
470 statement_t *true_statement;
471 statement_t *false_statement;
474 struct switch_statement_t {
475 statement_base_t base;
476 expression_t *expression;
478 case_label_statement_t *first_case, *last_case;
481 struct goto_statement_t {
482 statement_base_t base;
483 declaration_t *label; /**< The destination label. */
484 goto_statement_t *next; /**< links all goto statements of a function */
487 struct case_label_statement_t {
488 statement_base_t base;
489 expression_t *expression; /**< The case label expression, NULL for default label. */
490 expression_t *end_range; /**< For GNUC case a .. b: the end range expression, NULL else. */
491 statement_t *statement;
492 case_label_statement_t *next; /**< link to the next case label in switch */
495 struct label_statement_t {
496 statement_base_t base;
497 declaration_t *label;
498 statement_t *statement;
499 label_statement_t *next; /**< links all label statements of a function */
502 struct expression_statement_t {
503 statement_base_t base;
504 expression_t *expression;
507 struct while_statement_t {
508 statement_base_t base;
509 expression_t *condition;
513 struct do_while_statement_t {
514 statement_base_t base;
515 expression_t *condition;
519 struct for_statement_t {
520 statement_base_t base;
521 expression_t *initialisation;
522 expression_t *condition;
528 struct asm_constraint_t {
529 string_t constraints;
530 expression_t *expression;
532 asm_constraint_t *next;
535 struct asm_clobber_t {
540 struct asm_statement_t {
541 statement_base_t base;
543 asm_constraint_t *inputs;
544 asm_constraint_t *outputs;
545 asm_clobber_t *clobbers;
550 statement_kind_t kind;
551 statement_base_t base;
552 return_statement_t returns;
553 compound_statement_t compound;
554 declaration_statement_t declaration;
556 switch_statement_t switchs;
557 goto_statement_t gotos;
558 case_label_statement_t case_label;
559 label_statement_t label;
560 expression_statement_t expression;
561 while_statement_t whiles;
562 do_while_statement_t do_while;
563 for_statement_t fors;
564 asm_statement_t asms;
567 struct translation_unit_t {
572 void *_allocate_ast(size_t size)
574 return obstack_alloc(&ast_obstack, size);
577 #define allocate_ast(size) _allocate_ast(size)