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_LAST = EXPR_UNARY_ASSUME,
57 EXPR_BINARY_ADD = EXPR_BINARY_FIRST,
65 EXPR_BINARY_LESSEQUAL,
67 EXPR_BINARY_GREATEREQUAL,
68 EXPR_BINARY_BITWISE_AND,
69 EXPR_BINARY_BITWISE_OR,
70 EXPR_BINARY_BITWISE_XOR,
71 EXPR_BINARY_LOGICAL_AND,
72 EXPR_BINARY_LOGICAL_OR,
73 EXPR_BINARY_SHIFTLEFT,
74 EXPR_BINARY_SHIFTRIGHT,
76 EXPR_BINARY_MUL_ASSIGN,
77 EXPR_BINARY_DIV_ASSIGN,
78 EXPR_BINARY_MOD_ASSIGN,
79 EXPR_BINARY_ADD_ASSIGN,
80 EXPR_BINARY_SUB_ASSIGN,
81 EXPR_BINARY_SHIFTLEFT_ASSIGN,
82 EXPR_BINARY_SHIFTRIGHT_ASSIGN,
83 EXPR_BINARY_BITWISE_AND_ASSIGN,
84 EXPR_BINARY_BITWISE_XOR_ASSIGN,
85 EXPR_BINARY_BITWISE_OR_ASSIGN,
88 EXPR_BINARY_BUILTIN_EXPECT,
89 EXPR_BINARY_ISGREATER,
90 EXPR_BINARY_ISGREATEREQUAL,
92 EXPR_BINARY_ISLESSEQUAL,
93 EXPR_BINARY_ISLESSGREATER,
94 EXPR_BINARY_ISUNORDERED,
95 EXPR_BINARY_LAST = EXPR_BINARY_ISUNORDERED,
98 /* convenience macros */
99 #define EXPR_BINARY_CASES \
100 case EXPR_BINARY_ADD: \
101 case EXPR_BINARY_SUB: \
102 case EXPR_BINARY_MUL: \
103 case EXPR_BINARY_DIV: \
104 case EXPR_BINARY_MOD: \
105 case EXPR_BINARY_EQUAL: \
106 case EXPR_BINARY_NOTEQUAL: \
107 case EXPR_BINARY_LESS: \
108 case EXPR_BINARY_LESSEQUAL: \
109 case EXPR_BINARY_GREATER: \
110 case EXPR_BINARY_GREATEREQUAL: \
111 case EXPR_BINARY_BITWISE_AND: \
112 case EXPR_BINARY_BITWISE_OR: \
113 case EXPR_BINARY_BITWISE_XOR: \
114 case EXPR_BINARY_LOGICAL_AND: \
115 case EXPR_BINARY_LOGICAL_OR: \
116 case EXPR_BINARY_SHIFTLEFT: \
117 case EXPR_BINARY_SHIFTRIGHT: \
118 case EXPR_BINARY_ASSIGN: \
119 case EXPR_BINARY_MUL_ASSIGN: \
120 case EXPR_BINARY_DIV_ASSIGN: \
121 case EXPR_BINARY_MOD_ASSIGN: \
122 case EXPR_BINARY_ADD_ASSIGN: \
123 case EXPR_BINARY_SUB_ASSIGN: \
124 case EXPR_BINARY_SHIFTLEFT_ASSIGN: \
125 case EXPR_BINARY_SHIFTRIGHT_ASSIGN: \
126 case EXPR_BINARY_BITWISE_AND_ASSIGN: \
127 case EXPR_BINARY_BITWISE_XOR_ASSIGN: \
128 case EXPR_BINARY_BITWISE_OR_ASSIGN: \
129 case EXPR_BINARY_COMMA: \
130 case EXPR_BINARY_BUILTIN_EXPECT: \
131 case EXPR_BINARY_ISGREATER: \
132 case EXPR_BINARY_ISGREATEREQUAL: \
133 case EXPR_BINARY_ISLESS: \
134 case EXPR_BINARY_ISLESSEQUAL: \
135 case EXPR_BINARY_ISLESSGREATER: \
136 case EXPR_BINARY_ISUNORDERED:
138 #define EXPR_UNARY_CASES \
139 case EXPR_UNARY_NEGATE: \
140 case EXPR_UNARY_PLUS: \
141 case EXPR_UNARY_BITWISE_NEGATE: \
142 case EXPR_UNARY_NOT: \
143 case EXPR_UNARY_DEREFERENCE: \
144 case EXPR_UNARY_TAKE_ADDRESS: \
145 case EXPR_UNARY_POSTFIX_INCREMENT: \
146 case EXPR_UNARY_POSTFIX_DECREMENT: \
147 case EXPR_UNARY_PREFIX_INCREMENT: \
148 case EXPR_UNARY_PREFIX_DECREMENT: \
149 case EXPR_UNARY_CAST: \
150 case EXPR_UNARY_CAST_IMPLICIT: \
151 case EXPR_UNARY_ASSUME:
154 declaration_t *declarations; /**< List of declarations in this context. */
157 struct expression_base_t {
158 expression_kind_t kind;
160 source_position_t source_position;
163 struct const_expression_t {
164 expression_base_t expression;
167 long double float_value;
171 struct string_literal_expression_t {
172 expression_base_t expression;
176 struct wide_string_literal_expression_t {
177 expression_base_t expression;
181 struct builtin_symbol_expression_t {
182 expression_base_t expression;
186 struct builtin_constant_expression_t {
187 expression_base_t expression;
191 struct builtin_prefetch_expression_t {
192 expression_base_t expression;
195 expression_t *locality;
198 struct reference_expression_t {
199 expression_base_t expression;
201 declaration_t *declaration;
204 struct call_argument_t {
205 expression_t *expression;
206 call_argument_t *next;
209 struct call_expression_t {
210 expression_base_t expression;
211 expression_t *function;
212 call_argument_t *arguments;
215 struct unary_expression_t {
216 expression_base_t expression;
220 struct binary_expression_t {
221 expression_base_t expression;
226 struct select_expression_t {
227 expression_base_t expression;
228 expression_t *compound;
231 declaration_t *compound_entry;
234 struct array_access_expression_t {
235 expression_base_t expression;
236 expression_t *array_ref;
238 bool flipped; /* index/ref was written in a 5[a] way */
241 struct sizeof_expression_t {
242 expression_base_t expression;
244 expression_t *size_expression;
247 struct alignof_expression_t {
248 expression_base_t expression;
252 struct designator_t {
254 expression_t *array_access;
258 struct offsetof_expression_t {
259 expression_base_t expression;
261 designator_t *designator;
264 struct va_start_expression_t {
265 expression_base_t expression;
267 declaration_t *parameter;
270 struct va_arg_expression_t {
271 expression_base_t expression;
275 struct conditional_expression_t {
276 expression_base_t expression;
277 expression_t *condition;
278 expression_t *true_expression;
279 expression_t *false_expression;
282 struct statement_expression_t {
283 expression_base_t expression;
284 statement_t *statement;
287 struct classify_type_expression_t {
288 expression_base_t expression;
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 sizeof_expression_t sizeofe;
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;
314 alignof_expression_t alignofe;
319 STORAGE_CLASS_TYPEDEF,
320 STORAGE_CLASS_EXTERN,
321 STORAGE_CLASS_STATIC,
323 STORAGE_CLASS_REGISTER,
324 STORAGE_CLASS_ENUM_ENTRY,
325 STORAGE_CLASS_THREAD,
326 STORAGE_CLASS_THREAD_EXTERN,
327 STORAGE_CLASS_THREAD_STATIC
328 } storage_class_tag_t;
342 INITIALIZER_WIDE_STRING
343 } initializer_kind_t;
345 struct initializer_base_t {
346 initializer_kind_t kind;
349 struct initializer_value_t {
350 initializer_base_t initializer;
354 struct initializer_list_t {
355 initializer_base_t initializer;
357 initializer_t *initializers[];
360 struct initializer_string_t {
361 initializer_base_t initializer;
365 struct initializer_wide_string_t {
366 initializer_base_t initializer;
367 wide_string_t string;
370 union initializer_t {
371 initializer_kind_t kind;
372 initializer_base_t base;
373 initializer_value_t value;
374 initializer_list_t list;
375 initializer_string_t string;
376 initializer_wide_string_t wide_string;
380 DM_DLLIMPORT = (1 << 0),
381 DM_DLLEXPORT = (1 << 1),
382 DM_THREAD = (1 << 2),
384 DM_FORCEINLINE = (1 << 4),
385 DM_NOTHROW = (1 << 5),
386 DM_NORETURN = (1 << 6),
387 DM_NOINLINE = (1 << 7)
390 typedef unsigned short decl_modifiers_t;
392 struct declaration_t {
393 unsigned char namespc;
394 unsigned char storage_class;
395 decl_modifiers_t decl_modifiers;
396 unsigned int address_taken : 1;
397 unsigned int is_inline : 1;
400 source_position_t source_position;
403 statement_t *statement;
404 initializer_t *initializer;
405 expression_t *enum_value;
408 context_t *parent_context;
410 /** next declaration in a context */
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;
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 statement;
452 expression_t *return_value;
455 struct compound_statement_t {
456 statement_base_t statement;
457 statement_t *statements;
461 struct declaration_statement_t {
462 statement_base_t statement;
463 declaration_t *declarations_begin;
464 declaration_t *declarations_end;
467 struct if_statement_t {
468 statement_base_t statement;
469 expression_t *condition;
470 statement_t *true_statement;
471 statement_t *false_statement;
474 struct switch_statement_t {
475 statement_base_t statement;
476 expression_t *expression;
480 struct goto_statement_t {
481 statement_base_t statement;
482 declaration_t *label;
485 struct case_label_statement_t {
486 statement_base_t statement;
487 expression_t *expression;
488 statement_t *label_statement;
491 struct label_statement_t {
492 statement_base_t statement;
493 declaration_t *label;
494 statement_t *label_statement;
497 struct expression_statement_t {
498 statement_base_t statement;
499 expression_t *expression;
502 struct while_statement_t {
503 statement_base_t statement;
504 expression_t *condition;
508 struct do_while_statement_t {
509 statement_base_t statement;
510 expression_t *condition;
514 struct for_statement_t {
515 statement_base_t statement;
516 expression_t *initialisation;
517 expression_t *condition;
523 struct asm_constraint_t {
524 const char *constraints;
525 expression_t *expression;
527 asm_constraint_t *next;
530 struct asm_clobber_t {
535 struct asm_statement_t {
536 statement_base_t statement;
537 const char *asm_text;
538 asm_constraint_t *inputs;
539 asm_constraint_t *outputs;
540 asm_clobber_t *clobbers;
545 statement_kind_t kind;
546 statement_base_t base;
547 return_statement_t returns;
548 compound_statement_t compound;
549 declaration_statement_t declaration;
551 switch_statement_t switchs;
552 goto_statement_t gotos;
553 case_label_statement_t case_label;
554 label_statement_t label;
555 expression_statement_t expression;
556 while_statement_t whiles;
557 do_while_statement_t do_while;
558 for_statement_t fors;
559 asm_statement_t asms;
562 struct translation_unit_t {
567 void *_allocate_ast(size_t size)
569 return obstack_alloc(&ast_obstack, size);
572 #define allocate_ast(size) _allocate_ast(size)