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 * A scope containing declarations.
181 declaration_t *declarations; /**< List of declarations in this scope. */
182 declaration_t *last_declaration; /**< last declaration in this scope. */
185 struct expression_base_t {
186 expression_kind_t kind;
188 source_position_t source_position;
191 struct const_expression_t {
192 expression_base_t base;
195 long double float_value;
197 wide_string_t wide_character;
201 struct string_literal_expression_t {
202 expression_base_t base;
206 struct wide_string_literal_expression_t {
207 expression_base_t base;
211 struct compound_literal_expression_t {
212 expression_base_t base;
214 initializer_t *initializer;
217 struct builtin_symbol_expression_t {
218 expression_base_t base;
222 struct builtin_constant_expression_t {
223 expression_base_t base;
227 struct builtin_prefetch_expression_t {
228 expression_base_t base;
231 expression_t *locality;
234 struct reference_expression_t {
235 expression_base_t base;
237 declaration_t *declaration;
240 struct call_argument_t {
241 expression_t *expression;
242 call_argument_t *next;
245 struct call_expression_t {
246 expression_base_t base;
247 expression_t *function;
248 call_argument_t *arguments;
251 struct unary_expression_t {
252 expression_base_t base;
256 struct binary_expression_t {
257 expression_base_t base;
262 struct select_expression_t {
263 expression_base_t base;
264 expression_t *compound;
267 declaration_t *compound_entry;
270 struct array_access_expression_t {
271 expression_base_t base;
272 expression_t *array_ref;
274 bool flipped; /* index/ref was written in a 5[a] way */
277 struct typeprop_expression_t {
278 expression_base_t base;
280 expression_t *tp_expression;
283 struct designator_t {
284 source_position_t source_position;
286 expression_t *array_index;
290 struct offsetof_expression_t {
291 expression_base_t base;
293 designator_t *designator;
296 struct va_start_expression_t {
297 expression_base_t base;
299 declaration_t *parameter;
302 struct va_arg_expression_t {
303 expression_base_t base;
307 struct conditional_expression_t {
308 expression_base_t base;
309 expression_t *condition;
310 expression_t *true_expression;
311 expression_t *false_expression;
314 struct statement_expression_t {
315 expression_base_t base;
316 statement_t *statement;
319 struct classify_type_expression_t {
320 expression_base_t base;
321 expression_t *type_expression;
325 expression_kind_t kind;
326 expression_base_t base;
327 const_expression_t conste;
328 string_literal_expression_t string;
329 wide_string_literal_expression_t wide_string;
330 compound_literal_expression_t compound_literal;
331 builtin_symbol_expression_t builtin_symbol;
332 builtin_constant_expression_t builtin_constant;
333 builtin_prefetch_expression_t builtin_prefetch;
334 reference_expression_t reference;
335 call_expression_t call;
336 unary_expression_t unary;
337 binary_expression_t binary;
338 select_expression_t select;
339 array_access_expression_t array_access;
340 typeprop_expression_t typeprop;
341 offsetof_expression_t offsetofe;
342 va_start_expression_t va_starte;
343 va_arg_expression_t va_arge;
344 conditional_expression_t conditional;
345 statement_expression_t statement;
346 classify_type_expression_t classify_type;
351 STORAGE_CLASS_EXTERN,
352 STORAGE_CLASS_STATIC,
353 STORAGE_CLASS_TYPEDEF,
355 STORAGE_CLASS_REGISTER,
356 STORAGE_CLASS_ENUM_ENTRY,
357 STORAGE_CLASS_THREAD,
358 STORAGE_CLASS_THREAD_EXTERN,
359 STORAGE_CLASS_THREAD_STATIC,
360 } storage_class_tag_t;
374 INITIALIZER_WIDE_STRING,
375 INITIALIZER_DESIGNATOR
376 } initializer_kind_t;
378 struct initializer_base_t {
379 initializer_kind_t kind;
382 struct initializer_value_t {
383 initializer_base_t base;
387 struct initializer_list_t {
388 initializer_base_t base;
390 initializer_t *initializers[];
393 struct initializer_string_t {
394 initializer_base_t base;
398 struct initializer_wide_string_t {
399 initializer_base_t base;
400 wide_string_t string;
403 struct initializer_designator_t {
404 initializer_base_t base;
405 designator_t *designator;
408 union initializer_t {
409 initializer_kind_t kind;
410 initializer_base_t base;
411 initializer_value_t value;
412 initializer_list_t list;
413 initializer_string_t string;
414 initializer_wide_string_t wide_string;
415 initializer_designator_t designator;
419 * Extended microsoft modifier.
422 DM_DLLIMPORT = (1 << 0),
423 DM_DLLEXPORT = (1 << 1),
424 DM_THREAD = (1 << 2),
426 DM_MICROSOFT_INLINE = (1 << 4),
427 DM_FORCEINLINE = (1 << 5),
428 DM_SELECTANY = (1 << 6),
429 DM_NOTHROW = (1 << 7),
430 DM_NOVTABLE = (1 << 8),
431 DM_NORETURN = (1 << 9),
432 DM_NOINLINE = (1 << 10),
433 DM_DEPRECATED = (1 << 11)
436 typedef unsigned short decl_modifiers_t;
438 struct declaration_t {
439 unsigned char namespc;
440 unsigned char declared_storage_class;
441 unsigned char storage_class;
442 unsigned char alignment; /**< Alignmnet of the declaration, 0 for default. */
443 decl_modifiers_t modifiers; /**< MS __declspec modifiers. */
444 const char *deprecated_string; /**< MS deprecated string if any. */
445 symbol_t *get_property_sym; /**< MS get property. */
446 symbol_t *put_property_sym; /**< MS put property. */
447 unsigned int address_taken : 1;
448 unsigned int is_inline : 1;
449 unsigned int used : 1; /**< Set if the declaration is used. */
452 source_position_t source_position;
455 statement_t *statement;
456 initializer_t *initializer;
457 expression_t *enum_value;
459 scope_t scope; /**< The scope that this declaration opens. */
460 scope_t *parent_scope; /**< The parant scope where this declaration lives. */
462 /** next declaration in a scope */
464 /** next declaration with same symbol */
465 declaration_t *symbol_next;
467 /* the following fields are used in ast2firm module */
468 unsigned char declaration_kind;
470 unsigned int value_number;
483 STATEMENT_DECLARATION,
486 STATEMENT_EXPRESSION,
491 STATEMENT_CASE_LABEL,
498 struct statement_base_t {
499 statement_kind_t kind;
501 source_position_t source_position;
504 struct return_statement_t {
505 statement_base_t base;
509 struct compound_statement_t {
510 statement_base_t base;
511 statement_t *statements;
515 struct declaration_statement_t {
516 statement_base_t base;
517 declaration_t *declarations_begin;
518 declaration_t *declarations_end;
521 struct if_statement_t {
522 statement_base_t base;
523 expression_t *condition;
524 statement_t *true_statement;
525 statement_t *false_statement;
528 struct switch_statement_t {
529 statement_base_t base;
530 expression_t *expression;
532 case_label_statement_t *first_case, *last_case;
535 struct goto_statement_t {
536 statement_base_t base;
537 declaration_t *label; /**< The destination label. */
538 goto_statement_t *next; /**< links all goto statements of a function */
541 struct case_label_statement_t {
542 statement_base_t base;
543 expression_t *expression; /**< The case label expression, NULL for default label. */
544 expression_t *end_range; /**< For GNUC case a .. b: the end range expression, NULL else. */
545 statement_t *statement;
546 case_label_statement_t *next; /**< link to the next case label in switch */
549 struct label_statement_t {
550 statement_base_t base;
551 declaration_t *label;
552 statement_t *statement;
553 label_statement_t *next; /**< links all label statements of a function */
556 struct expression_statement_t {
557 statement_base_t base;
558 expression_t *expression;
561 struct while_statement_t {
562 statement_base_t base;
563 expression_t *condition;
567 struct do_while_statement_t {
568 statement_base_t base;
569 expression_t *condition;
573 struct for_statement_t {
574 statement_base_t base;
575 expression_t *initialisation;
576 expression_t *condition;
582 struct asm_constraint_t {
583 string_t constraints;
584 expression_t *expression;
586 asm_constraint_t *next;
589 struct asm_clobber_t {
594 struct asm_statement_t {
595 statement_base_t base;
597 asm_constraint_t *inputs;
598 asm_constraint_t *outputs;
599 asm_clobber_t *clobbers;
604 statement_kind_t kind;
605 statement_base_t base;
606 return_statement_t returns;
607 compound_statement_t compound;
608 declaration_statement_t declaration;
610 switch_statement_t switchs;
611 goto_statement_t gotos;
612 case_label_statement_t case_label;
613 label_statement_t label;
614 expression_statement_t expression;
615 while_statement_t whiles;
616 do_while_statement_t do_while;
617 for_statement_t fors;
618 asm_statement_t asms;
621 struct translation_unit_t {
626 void *_allocate_ast(size_t size)
628 return obstack_alloc(&ast_obstack, size);
631 #define allocate_ast(size) _allocate_ast(size)