2 * This file is part of cparser.
3 * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 #include <libfirm/firm_types.h>
32 extern struct obstack ast_obstack;
39 EXPR_CHARACTER_CONSTANT,
40 EXPR_WIDE_CHARACTER_CONSTANT,
42 EXPR_WIDE_STRING_LITERAL,
43 EXPR_COMPOUND_LITERAL,
55 EXPR_BUILTIN_CONSTANT_P,
56 EXPR_BUILTIN_PREFETCH,
63 EXPR_UNARY_NEGATE = EXPR_UNARY_FIRST,
65 EXPR_UNARY_BITWISE_NEGATE,
67 EXPR_UNARY_DEREFERENCE,
68 EXPR_UNARY_TAKE_ADDRESS,
69 EXPR_UNARY_POSTFIX_INCREMENT,
70 EXPR_UNARY_POSTFIX_DECREMENT,
71 EXPR_UNARY_PREFIX_INCREMENT,
72 EXPR_UNARY_PREFIX_DECREMENT,
74 EXPR_UNARY_CAST_IMPLICIT, /**< compiler generated cast */
75 EXPR_UNARY_ASSUME, /**< MS __assume() */
76 EXPR_UNARY_BITFIELD_EXTRACT,
77 EXPR_UNARY_LAST = EXPR_UNARY_BITFIELD_EXTRACT,
80 EXPR_BINARY_ADD = EXPR_BINARY_FIRST,
88 EXPR_BINARY_LESSEQUAL,
90 EXPR_BINARY_GREATEREQUAL,
91 EXPR_BINARY_BITWISE_AND,
92 EXPR_BINARY_BITWISE_OR,
93 EXPR_BINARY_BITWISE_XOR,
94 EXPR_BINARY_LOGICAL_AND,
95 EXPR_BINARY_LOGICAL_OR,
96 EXPR_BINARY_SHIFTLEFT,
97 EXPR_BINARY_SHIFTRIGHT,
99 EXPR_BINARY_MUL_ASSIGN,
100 EXPR_BINARY_DIV_ASSIGN,
101 EXPR_BINARY_MOD_ASSIGN,
102 EXPR_BINARY_ADD_ASSIGN,
103 EXPR_BINARY_SUB_ASSIGN,
104 EXPR_BINARY_SHIFTLEFT_ASSIGN,
105 EXPR_BINARY_SHIFTRIGHT_ASSIGN,
106 EXPR_BINARY_BITWISE_AND_ASSIGN,
107 EXPR_BINARY_BITWISE_XOR_ASSIGN,
108 EXPR_BINARY_BITWISE_OR_ASSIGN,
111 EXPR_BINARY_BUILTIN_EXPECT,
112 EXPR_BINARY_ISGREATER,
113 EXPR_BINARY_ISGREATEREQUAL,
115 EXPR_BINARY_ISLESSEQUAL,
116 EXPR_BINARY_ISLESSGREATER,
117 EXPR_BINARY_ISUNORDERED,
118 EXPR_BINARY_LAST = EXPR_BINARY_ISUNORDERED,
121 /* convenience macros */
122 #define EXPR_BINARY_CASES \
123 case EXPR_BINARY_ADD: \
124 case EXPR_BINARY_SUB: \
125 case EXPR_BINARY_MUL: \
126 case EXPR_BINARY_DIV: \
127 case EXPR_BINARY_MOD: \
128 case EXPR_BINARY_EQUAL: \
129 case EXPR_BINARY_NOTEQUAL: \
130 case EXPR_BINARY_LESS: \
131 case EXPR_BINARY_LESSEQUAL: \
132 case EXPR_BINARY_GREATER: \
133 case EXPR_BINARY_GREATEREQUAL: \
134 case EXPR_BINARY_BITWISE_AND: \
135 case EXPR_BINARY_BITWISE_OR: \
136 case EXPR_BINARY_BITWISE_XOR: \
137 case EXPR_BINARY_LOGICAL_AND: \
138 case EXPR_BINARY_LOGICAL_OR: \
139 case EXPR_BINARY_SHIFTLEFT: \
140 case EXPR_BINARY_SHIFTRIGHT: \
141 case EXPR_BINARY_ASSIGN: \
142 case EXPR_BINARY_MUL_ASSIGN: \
143 case EXPR_BINARY_DIV_ASSIGN: \
144 case EXPR_BINARY_MOD_ASSIGN: \
145 case EXPR_BINARY_ADD_ASSIGN: \
146 case EXPR_BINARY_SUB_ASSIGN: \
147 case EXPR_BINARY_SHIFTLEFT_ASSIGN: \
148 case EXPR_BINARY_SHIFTRIGHT_ASSIGN: \
149 case EXPR_BINARY_BITWISE_AND_ASSIGN: \
150 case EXPR_BINARY_BITWISE_XOR_ASSIGN: \
151 case EXPR_BINARY_BITWISE_OR_ASSIGN: \
152 case EXPR_BINARY_COMMA: \
153 case EXPR_BINARY_BUILTIN_EXPECT: \
154 case EXPR_BINARY_ISGREATER: \
155 case EXPR_BINARY_ISGREATEREQUAL: \
156 case EXPR_BINARY_ISLESS: \
157 case EXPR_BINARY_ISLESSEQUAL: \
158 case EXPR_BINARY_ISLESSGREATER: \
159 case EXPR_BINARY_ISUNORDERED:
161 #define EXPR_UNARY_CASES \
162 case EXPR_UNARY_NEGATE: \
163 case EXPR_UNARY_PLUS: \
164 case EXPR_UNARY_BITWISE_NEGATE: \
165 case EXPR_UNARY_NOT: \
166 case EXPR_UNARY_DEREFERENCE: \
167 case EXPR_UNARY_TAKE_ADDRESS: \
168 case EXPR_UNARY_POSTFIX_INCREMENT: \
169 case EXPR_UNARY_POSTFIX_DECREMENT: \
170 case EXPR_UNARY_PREFIX_INCREMENT: \
171 case EXPR_UNARY_PREFIX_DECREMENT: \
172 case EXPR_UNARY_CAST: \
173 case EXPR_UNARY_CAST_IMPLICIT: \
174 case EXPR_UNARY_ASSUME: \
175 case EXPR_UNARY_BITFIELD_EXTRACT:
178 declaration_t *declarations; /**< List of declarations in this scope. */
179 declaration_t *last_declaration;
182 struct expression_base_t {
183 expression_kind_t kind;
185 source_position_t source_position;
188 struct const_expression_t {
189 expression_base_t base;
192 long double float_value;
194 wide_string_t wide_character;
198 struct string_literal_expression_t {
199 expression_base_t base;
203 struct wide_string_literal_expression_t {
204 expression_base_t base;
208 struct compound_literal_expression_t {
209 expression_base_t base;
211 initializer_t *initializer;
214 struct builtin_symbol_expression_t {
215 expression_base_t base;
219 struct builtin_constant_expression_t {
220 expression_base_t base;
224 struct builtin_prefetch_expression_t {
225 expression_base_t base;
228 expression_t *locality;
231 struct reference_expression_t {
232 expression_base_t base;
234 declaration_t *declaration;
237 struct call_argument_t {
238 expression_t *expression;
239 call_argument_t *next;
242 struct call_expression_t {
243 expression_base_t base;
244 expression_t *function;
245 call_argument_t *arguments;
248 struct unary_expression_t {
249 expression_base_t base;
253 struct binary_expression_t {
254 expression_base_t base;
259 struct select_expression_t {
260 expression_base_t base;
261 expression_t *compound;
264 declaration_t *compound_entry;
267 struct array_access_expression_t {
268 expression_base_t base;
269 expression_t *array_ref;
271 bool flipped; /* index/ref was written in a 5[a] way */
274 struct typeprop_expression_t {
275 expression_base_t base;
277 expression_t *tp_expression;
280 struct designator_t {
281 source_position_t source_position;
283 expression_t *array_index;
287 struct offsetof_expression_t {
288 expression_base_t base;
290 designator_t *designator;
293 struct va_start_expression_t {
294 expression_base_t base;
296 declaration_t *parameter;
299 struct va_arg_expression_t {
300 expression_base_t base;
304 struct conditional_expression_t {
305 expression_base_t base;
306 expression_t *condition;
307 expression_t *true_expression;
308 expression_t *false_expression;
311 struct statement_expression_t {
312 expression_base_t base;
313 statement_t *statement;
316 struct classify_type_expression_t {
317 expression_base_t base;
318 expression_t *type_expression;
322 expression_kind_t kind;
323 expression_base_t base;
324 const_expression_t conste;
325 string_literal_expression_t string;
326 wide_string_literal_expression_t wide_string;
327 compound_literal_expression_t compound_literal;
328 builtin_symbol_expression_t builtin_symbol;
329 builtin_constant_expression_t builtin_constant;
330 builtin_prefetch_expression_t builtin_prefetch;
331 reference_expression_t reference;
332 call_expression_t call;
333 unary_expression_t unary;
334 binary_expression_t binary;
335 select_expression_t select;
336 array_access_expression_t array_access;
337 typeprop_expression_t typeprop;
338 offsetof_expression_t offsetofe;
339 va_start_expression_t va_starte;
340 va_arg_expression_t va_arge;
341 conditional_expression_t conditional;
342 statement_expression_t statement;
343 classify_type_expression_t classify_type;
348 STORAGE_CLASS_EXTERN,
349 STORAGE_CLASS_STATIC,
350 STORAGE_CLASS_TYPEDEF,
352 STORAGE_CLASS_REGISTER,
353 STORAGE_CLASS_ENUM_ENTRY,
354 STORAGE_CLASS_THREAD,
355 STORAGE_CLASS_THREAD_EXTERN,
356 STORAGE_CLASS_THREAD_STATIC,
357 } storage_class_tag_t;
371 INITIALIZER_WIDE_STRING,
372 INITIALIZER_DESIGNATOR
373 } initializer_kind_t;
375 struct initializer_base_t {
376 initializer_kind_t kind;
379 struct initializer_value_t {
380 initializer_base_t base;
384 struct initializer_list_t {
385 initializer_base_t base;
387 initializer_t *initializers[];
390 struct initializer_string_t {
391 initializer_base_t base;
395 struct initializer_wide_string_t {
396 initializer_base_t base;
397 wide_string_t string;
400 struct initializer_designator_t {
401 initializer_base_t base;
402 designator_t *designator;
405 union initializer_t {
406 initializer_kind_t kind;
407 initializer_base_t base;
408 initializer_value_t value;
409 initializer_list_t list;
410 initializer_string_t string;
411 initializer_wide_string_t wide_string;
412 initializer_designator_t designator;
416 DM_DLLIMPORT = (1 << 0),
417 DM_DLLEXPORT = (1 << 1),
418 DM_THREAD = (1 << 2),
420 DM_FORCEINLINE = (1 << 4),
421 DM_NOTHROW = (1 << 5),
422 DM_NORETURN = (1 << 6),
423 DM_NOINLINE = (1 << 7)
426 typedef unsigned short decl_modifiers_t;
428 struct declaration_t {
429 unsigned char namespc;
430 unsigned char declared_storage_class;
431 unsigned char storage_class;
432 decl_modifiers_t modifiers;
433 unsigned int address_taken : 1;
434 unsigned int is_inline : 1;
435 unsigned int used : 1; /**< Set if the declaration is used. */
438 source_position_t source_position;
441 statement_t *statement;
442 initializer_t *initializer;
443 expression_t *enum_value;
446 scope_t *parent_scope;
448 /** next declaration in a scope */
450 /** next declaration with same symbol */
451 declaration_t *symbol_next;
453 /* the following fields are used in ast2firm module */
454 unsigned char declaration_kind;
456 unsigned int value_number;
469 STATEMENT_DECLARATION,
472 STATEMENT_EXPRESSION,
477 STATEMENT_CASE_LABEL,
484 struct statement_base_t {
485 statement_kind_t kind;
487 source_position_t source_position;
490 struct return_statement_t {
491 statement_base_t base;
495 struct compound_statement_t {
496 statement_base_t base;
497 statement_t *statements;
501 struct declaration_statement_t {
502 statement_base_t base;
503 declaration_t *declarations_begin;
504 declaration_t *declarations_end;
507 struct if_statement_t {
508 statement_base_t base;
509 expression_t *condition;
510 statement_t *true_statement;
511 statement_t *false_statement;
514 struct switch_statement_t {
515 statement_base_t base;
516 expression_t *expression;
518 case_label_statement_t *first_case, *last_case;
521 struct goto_statement_t {
522 statement_base_t base;
523 declaration_t *label; /**< The destination label. */
524 goto_statement_t *next; /**< links all goto statements of a function */
527 struct case_label_statement_t {
528 statement_base_t base;
529 expression_t *expression; /**< The case label expression, NULL for default label. */
530 expression_t *end_range; /**< For GNUC case a .. b: the end range expression, NULL else. */
531 statement_t *statement;
532 case_label_statement_t *next; /**< link to the next case label in switch */
535 struct label_statement_t {
536 statement_base_t base;
537 declaration_t *label;
538 statement_t *statement;
539 label_statement_t *next; /**< links all label statements of a function */
542 struct expression_statement_t {
543 statement_base_t base;
544 expression_t *expression;
547 struct while_statement_t {
548 statement_base_t base;
549 expression_t *condition;
553 struct do_while_statement_t {
554 statement_base_t base;
555 expression_t *condition;
559 struct for_statement_t {
560 statement_base_t base;
561 expression_t *initialisation;
562 expression_t *condition;
568 struct asm_constraint_t {
569 string_t constraints;
570 expression_t *expression;
572 asm_constraint_t *next;
575 struct asm_clobber_t {
580 struct asm_statement_t {
581 statement_base_t base;
583 asm_constraint_t *inputs;
584 asm_constraint_t *outputs;
585 asm_clobber_t *clobbers;
590 statement_kind_t kind;
591 statement_base_t base;
592 return_statement_t returns;
593 compound_statement_t compound;
594 declaration_statement_t declaration;
596 switch_statement_t switchs;
597 goto_statement_t gotos;
598 case_label_statement_t case_label;
599 label_statement_t label;
600 expression_statement_t expression;
601 while_statement_t whiles;
602 do_while_statement_t do_while;
603 for_statement_t fors;
604 asm_statement_t asms;
607 struct translation_unit_t {
612 void *_allocate_ast(size_t size)
614 return obstack_alloc(&ast_obstack, size);
617 #define allocate_ast(size) _allocate_ast(size)