4 #include <libfirm/firm_types.h>
13 extern struct obstack ast_obstack;
22 EXPR_WIDE_STRING_LITERAL,
23 EXPR_COMPOUND_LITERAL,
35 EXPR_BUILTIN_CONSTANT_P,
36 EXPR_BUILTIN_PREFETCH,
43 EXPR_UNARY_NEGATE = EXPR_UNARY_FIRST,
45 EXPR_UNARY_BITWISE_NEGATE,
47 EXPR_UNARY_DEREFERENCE,
48 EXPR_UNARY_TAKE_ADDRESS,
49 EXPR_UNARY_POSTFIX_INCREMENT,
50 EXPR_UNARY_POSTFIX_DECREMENT,
51 EXPR_UNARY_PREFIX_INCREMENT,
52 EXPR_UNARY_PREFIX_DECREMENT,
54 EXPR_UNARY_CAST_IMPLICIT, /**< compiler generated cast */
55 EXPR_UNARY_ASSUME, /**< MS __assume() */
56 EXPR_UNARY_BITFIELD_EXTRACT,
57 EXPR_UNARY_LAST = EXPR_UNARY_BITFIELD_EXTRACT,
60 EXPR_BINARY_ADD = EXPR_BINARY_FIRST,
68 EXPR_BINARY_LESSEQUAL,
70 EXPR_BINARY_GREATEREQUAL,
71 EXPR_BINARY_BITWISE_AND,
72 EXPR_BINARY_BITWISE_OR,
73 EXPR_BINARY_BITWISE_XOR,
74 EXPR_BINARY_LOGICAL_AND,
75 EXPR_BINARY_LOGICAL_OR,
76 EXPR_BINARY_SHIFTLEFT,
77 EXPR_BINARY_SHIFTRIGHT,
79 EXPR_BINARY_MUL_ASSIGN,
80 EXPR_BINARY_DIV_ASSIGN,
81 EXPR_BINARY_MOD_ASSIGN,
82 EXPR_BINARY_ADD_ASSIGN,
83 EXPR_BINARY_SUB_ASSIGN,
84 EXPR_BINARY_SHIFTLEFT_ASSIGN,
85 EXPR_BINARY_SHIFTRIGHT_ASSIGN,
86 EXPR_BINARY_BITWISE_AND_ASSIGN,
87 EXPR_BINARY_BITWISE_XOR_ASSIGN,
88 EXPR_BINARY_BITWISE_OR_ASSIGN,
91 EXPR_BINARY_BUILTIN_EXPECT,
92 EXPR_BINARY_ISGREATER,
93 EXPR_BINARY_ISGREATEREQUAL,
95 EXPR_BINARY_ISLESSEQUAL,
96 EXPR_BINARY_ISLESSGREATER,
97 EXPR_BINARY_ISUNORDERED,
98 EXPR_BINARY_LAST = EXPR_BINARY_ISUNORDERED,
101 /* convenience macros */
102 #define EXPR_BINARY_CASES \
103 case EXPR_BINARY_ADD: \
104 case EXPR_BINARY_SUB: \
105 case EXPR_BINARY_MUL: \
106 case EXPR_BINARY_DIV: \
107 case EXPR_BINARY_MOD: \
108 case EXPR_BINARY_EQUAL: \
109 case EXPR_BINARY_NOTEQUAL: \
110 case EXPR_BINARY_LESS: \
111 case EXPR_BINARY_LESSEQUAL: \
112 case EXPR_BINARY_GREATER: \
113 case EXPR_BINARY_GREATEREQUAL: \
114 case EXPR_BINARY_BITWISE_AND: \
115 case EXPR_BINARY_BITWISE_OR: \
116 case EXPR_BINARY_BITWISE_XOR: \
117 case EXPR_BINARY_LOGICAL_AND: \
118 case EXPR_BINARY_LOGICAL_OR: \
119 case EXPR_BINARY_SHIFTLEFT: \
120 case EXPR_BINARY_SHIFTRIGHT: \
121 case EXPR_BINARY_ASSIGN: \
122 case EXPR_BINARY_MUL_ASSIGN: \
123 case EXPR_BINARY_DIV_ASSIGN: \
124 case EXPR_BINARY_MOD_ASSIGN: \
125 case EXPR_BINARY_ADD_ASSIGN: \
126 case EXPR_BINARY_SUB_ASSIGN: \
127 case EXPR_BINARY_SHIFTLEFT_ASSIGN: \
128 case EXPR_BINARY_SHIFTRIGHT_ASSIGN: \
129 case EXPR_BINARY_BITWISE_AND_ASSIGN: \
130 case EXPR_BINARY_BITWISE_XOR_ASSIGN: \
131 case EXPR_BINARY_BITWISE_OR_ASSIGN: \
132 case EXPR_BINARY_COMMA: \
133 case EXPR_BINARY_BUILTIN_EXPECT: \
134 case EXPR_BINARY_ISGREATER: \
135 case EXPR_BINARY_ISGREATEREQUAL: \
136 case EXPR_BINARY_ISLESS: \
137 case EXPR_BINARY_ISLESSEQUAL: \
138 case EXPR_BINARY_ISLESSGREATER: \
139 case EXPR_BINARY_ISUNORDERED:
141 #define EXPR_UNARY_CASES \
142 case EXPR_UNARY_NEGATE: \
143 case EXPR_UNARY_PLUS: \
144 case EXPR_UNARY_BITWISE_NEGATE: \
145 case EXPR_UNARY_NOT: \
146 case EXPR_UNARY_DEREFERENCE: \
147 case EXPR_UNARY_TAKE_ADDRESS: \
148 case EXPR_UNARY_POSTFIX_INCREMENT: \
149 case EXPR_UNARY_POSTFIX_DECREMENT: \
150 case EXPR_UNARY_PREFIX_INCREMENT: \
151 case EXPR_UNARY_PREFIX_DECREMENT: \
152 case EXPR_UNARY_CAST: \
153 case EXPR_UNARY_CAST_IMPLICIT: \
154 case EXPR_UNARY_ASSUME: \
155 case EXPR_UNARY_BITFIELD_EXTRACT:
158 declaration_t *declarations; /**< List of declarations in this scope. */
159 declaration_t *last_declaration;
162 struct expression_base_t {
163 expression_kind_t kind;
165 source_position_t source_position;
168 struct const_expression_t {
169 expression_base_t base;
172 long double float_value;
177 struct string_literal_expression_t {
178 expression_base_t base;
182 struct wide_string_literal_expression_t {
183 expression_base_t base;
187 struct compound_literal_expression_t {
188 expression_base_t base;
190 initializer_t *initializer;
193 struct builtin_symbol_expression_t {
194 expression_base_t base;
198 struct builtin_constant_expression_t {
199 expression_base_t base;
203 struct builtin_prefetch_expression_t {
204 expression_base_t base;
207 expression_t *locality;
210 struct reference_expression_t {
211 expression_base_t base;
213 declaration_t *declaration;
216 struct call_argument_t {
217 expression_t *expression;
218 call_argument_t *next;
221 struct call_expression_t {
222 expression_base_t base;
223 expression_t *function;
224 call_argument_t *arguments;
227 struct unary_expression_t {
228 expression_base_t base;
232 struct binary_expression_t {
233 expression_base_t base;
238 struct select_expression_t {
239 expression_base_t base;
240 expression_t *compound;
243 declaration_t *compound_entry;
246 struct array_access_expression_t {
247 expression_base_t base;
248 expression_t *array_ref;
250 bool flipped; /* index/ref was written in a 5[a] way */
253 struct typeprop_expression_t {
254 expression_base_t base;
256 expression_t *tp_expression;
259 struct designator_t {
260 source_position_t source_position;
262 expression_t *array_index;
266 struct offsetof_expression_t {
267 expression_base_t base;
269 designator_t *designator;
272 struct va_start_expression_t {
273 expression_base_t base;
275 declaration_t *parameter;
278 struct va_arg_expression_t {
279 expression_base_t base;
283 struct conditional_expression_t {
284 expression_base_t base;
285 expression_t *condition;
286 expression_t *true_expression;
287 expression_t *false_expression;
290 struct statement_expression_t {
291 expression_base_t base;
292 statement_t *statement;
295 struct classify_type_expression_t {
296 expression_base_t base;
297 expression_t *type_expression;
301 expression_kind_t kind;
302 expression_base_t base;
303 const_expression_t conste;
304 string_literal_expression_t string;
305 wide_string_literal_expression_t wide_string;
306 compound_literal_expression_t compound_literal;
307 builtin_symbol_expression_t builtin_symbol;
308 builtin_constant_expression_t builtin_constant;
309 builtin_prefetch_expression_t builtin_prefetch;
310 reference_expression_t reference;
311 call_expression_t call;
312 unary_expression_t unary;
313 binary_expression_t binary;
314 select_expression_t select;
315 array_access_expression_t array_access;
316 typeprop_expression_t typeprop;
317 offsetof_expression_t offsetofe;
318 va_start_expression_t va_starte;
319 va_arg_expression_t va_arge;
320 conditional_expression_t conditional;
321 statement_expression_t statement;
322 classify_type_expression_t classify_type;
327 STORAGE_CLASS_TYPEDEF,
328 STORAGE_CLASS_EXTERN,
329 STORAGE_CLASS_STATIC,
331 STORAGE_CLASS_REGISTER,
332 STORAGE_CLASS_ENUM_ENTRY,
333 STORAGE_CLASS_THREAD,
334 STORAGE_CLASS_THREAD_EXTERN,
335 STORAGE_CLASS_THREAD_STATIC
336 } storage_class_tag_t;
350 INITIALIZER_WIDE_STRING,
351 INITIALIZER_DESIGNATOR
352 } initializer_kind_t;
354 struct initializer_base_t {
355 initializer_kind_t kind;
358 struct initializer_value_t {
359 initializer_base_t base;
363 struct initializer_list_t {
364 initializer_base_t base;
366 initializer_t *initializers[];
369 struct initializer_string_t {
370 initializer_base_t base;
374 struct initializer_wide_string_t {
375 initializer_base_t base;
376 wide_string_t string;
379 struct initializer_designator_t {
380 initializer_base_t base;
381 designator_t *designator;
384 union initializer_t {
385 initializer_kind_t kind;
386 initializer_base_t base;
387 initializer_value_t value;
388 initializer_list_t list;
389 initializer_string_t string;
390 initializer_wide_string_t wide_string;
391 initializer_designator_t designator;
395 DM_DLLIMPORT = (1 << 0),
396 DM_DLLEXPORT = (1 << 1),
397 DM_THREAD = (1 << 2),
399 DM_FORCEINLINE = (1 << 4),
400 DM_NOTHROW = (1 << 5),
401 DM_NORETURN = (1 << 6),
402 DM_NOINLINE = (1 << 7)
405 typedef unsigned short decl_modifiers_t;
407 struct declaration_t {
408 unsigned char namespc;
409 unsigned char storage_class;
410 decl_modifiers_t modifiers;
411 unsigned int address_taken : 1;
412 unsigned int is_inline : 1;
413 unsigned int used : 1; /**< Set if the declaration is used. */
416 source_position_t source_position;
419 statement_t *statement;
420 initializer_t *initializer;
421 expression_t *enum_value;
424 scope_t *parent_scope;
426 /** next declaration in a scope */
428 /** next declaration with same symbol */
429 declaration_t *symbol_next;
431 /* the following fields are used in ast2firm module */
432 unsigned char declaration_kind;
434 unsigned int value_number;
446 STATEMENT_DECLARATION,
449 STATEMENT_EXPRESSION,
454 STATEMENT_CASE_LABEL,
461 struct statement_base_t {
462 statement_kind_t kind;
464 source_position_t source_position;
467 struct return_statement_t {
468 statement_base_t base;
472 struct compound_statement_t {
473 statement_base_t base;
474 statement_t *statements;
478 struct declaration_statement_t {
479 statement_base_t base;
480 declaration_t *declarations_begin;
481 declaration_t *declarations_end;
484 struct if_statement_t {
485 statement_base_t base;
486 expression_t *condition;
487 statement_t *true_statement;
488 statement_t *false_statement;
491 struct switch_statement_t {
492 statement_base_t base;
493 expression_t *expression;
495 case_label_statement_t *first_case, *last_case;
498 struct goto_statement_t {
499 statement_base_t base;
500 declaration_t *label; /**< The destination label. */
501 goto_statement_t *next; /**< links all goto statements of a function */
504 struct case_label_statement_t {
505 statement_base_t base;
506 expression_t *expression; /**< The case label expression, NULL for default label. */
507 expression_t *end_range; /**< For GNUC case a .. b: the end range expression, NULL else. */
508 statement_t *statement;
509 case_label_statement_t *next; /**< link to the next case label in switch */
512 struct label_statement_t {
513 statement_base_t base;
514 declaration_t *label;
515 statement_t *statement;
516 label_statement_t *next; /**< links all label statements of a function */
519 struct expression_statement_t {
520 statement_base_t base;
521 expression_t *expression;
524 struct while_statement_t {
525 statement_base_t base;
526 expression_t *condition;
530 struct do_while_statement_t {
531 statement_base_t base;
532 expression_t *condition;
536 struct for_statement_t {
537 statement_base_t base;
538 expression_t *initialisation;
539 expression_t *condition;
545 struct asm_constraint_t {
546 string_t constraints;
547 expression_t *expression;
549 asm_constraint_t *next;
552 struct asm_clobber_t {
557 struct asm_statement_t {
558 statement_base_t base;
560 asm_constraint_t *inputs;
561 asm_constraint_t *outputs;
562 asm_clobber_t *clobbers;
567 statement_kind_t kind;
568 statement_base_t base;
569 return_statement_t returns;
570 compound_statement_t compound;
571 declaration_statement_t declaration;
573 switch_statement_t switchs;
574 goto_statement_t gotos;
575 case_label_statement_t case_label;
576 label_statement_t label;
577 expression_statement_t expression;
578 while_statement_t whiles;
579 do_while_statement_t do_while;
580 for_statement_t fors;
581 asm_statement_t asms;
584 struct translation_unit_t {
589 void *_allocate_ast(size_t size)
591 return obstack_alloc(&ast_obstack, size);
594 #define allocate_ast(size) _allocate_ast(size)