More work for C++ mode:
[cparser] / ast_t.h
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
4  *
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.
9  *
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.
14  *
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
18  * 02111-1307, USA.
19  */
20 #ifndef AST_T_H
21 #define AST_T_H
22
23 #include <libfirm/firm_types.h>
24 #include <assert.h>
25
26 #include "ast.h"
27 #include "symbol.h"
28 #include "token_t.h"
29 #include "type.h"
30 #include "entity_t.h"
31 #include "adt/obst.h"
32
33 /** The AST obstack contains all data that must stay in the AST. */
34 extern struct obstack ast_obstack;
35
36 /**
37  * Operator precedence classes
38  */
39 typedef enum precedence_t {
40         PREC_BOTTOM,
41         PREC_EXPRESSION,     /* ,                                  left to right */
42         PREC_ASSIGNMENT,     /* = += -= *= /= %= <<= >>= &= ^= |=  right to left */
43         PREC_CONDITIONAL,    /* ?:                                 right to left */
44         PREC_LOGICAL_OR,     /* ||                                 left to right */
45         PREC_LOGICAL_AND,    /* &&                                 left to right */
46         PREC_OR,             /* |                                  left to right */
47         PREC_XOR,            /* ^                                  left to right */
48         PREC_AND,            /* &                                  left to right */
49         PREC_EQUALITY,       /* == !=                              left to right */
50         PREC_RELATIONAL,     /* < <= > >=                          left to right */
51         PREC_SHIFT,          /* << >>                              left to right */
52         PREC_ADDITIVE,       /* + -                                left to right */
53         PREC_MULTIPLICATIVE, /* * / %                              left to right */
54         PREC_CAST,           /* (type)                             right to left */
55         PREC_UNARY,          /* ! ~ ++ -- + - * & sizeof           right to left */
56         PREC_POSTFIX,        /* () [] -> .                         left to right */
57         PREC_PRIMARY,
58         PREC_TOP
59 } precedence_t;
60
61 /**
62  * Expression kinds.
63  */
64 typedef enum expression_kind_t {
65         EXPR_UNKNOWN = 0,
66         EXPR_INVALID,
67         EXPR_REFERENCE,
68         EXPR_REFERENCE_ENUM_VALUE,
69         EXPR_CONST,
70         EXPR_CHARACTER_CONSTANT,
71         EXPR_WIDE_CHARACTER_CONSTANT,
72         EXPR_STRING_LITERAL,
73         EXPR_WIDE_STRING_LITERAL,
74         EXPR_COMPOUND_LITERAL,
75         EXPR_CALL,
76         EXPR_CONDITIONAL,
77         EXPR_SELECT,
78         EXPR_ARRAY_ACCESS,
79         EXPR_SIZEOF,
80         EXPR_CLASSIFY_TYPE,
81         EXPR_ALIGNOF,
82
83         EXPR_FUNCNAME,
84         EXPR_BUILTIN_SYMBOL,
85         EXPR_BUILTIN_CONSTANT_P,
86         EXPR_BUILTIN_PREFETCH,
87         EXPR_OFFSETOF,
88         EXPR_VA_START,
89         EXPR_VA_ARG,
90         EXPR_STATEMENT,
91         EXPR_LABEL_ADDRESS, /**< GCC extension &&label operator */
92
93         EXPR_UNARY_FIRST,
94         EXPR_UNARY_NEGATE = EXPR_UNARY_FIRST,
95         EXPR_UNARY_PLUS,
96         EXPR_UNARY_BITWISE_NEGATE,
97         EXPR_UNARY_NOT,
98         EXPR_UNARY_DEREFERENCE,
99         EXPR_UNARY_TAKE_ADDRESS,
100         EXPR_UNARY_POSTFIX_INCREMENT,
101         EXPR_UNARY_POSTFIX_DECREMENT,
102         EXPR_UNARY_PREFIX_INCREMENT,
103         EXPR_UNARY_PREFIX_DECREMENT,
104         EXPR_UNARY_CAST,
105         EXPR_UNARY_CAST_IMPLICIT, /**< compiler generated cast */
106         EXPR_UNARY_ASSUME,        /**< MS __assume() */
107         EXPR_UNARY_DELETE,
108         EXPR_UNARY_DELETE_ARRAY,
109         EXPR_UNARY_THROW,
110         EXPR_UNARY_LAST = EXPR_UNARY_THROW,
111
112         EXPR_BINARY_FIRST,
113         EXPR_BINARY_ADD = EXPR_BINARY_FIRST,
114         EXPR_BINARY_SUB,
115         EXPR_BINARY_MUL,
116         EXPR_BINARY_DIV,
117         EXPR_BINARY_MOD,
118         EXPR_BINARY_EQUAL,
119         EXPR_BINARY_NOTEQUAL,
120         EXPR_BINARY_LESS,
121         EXPR_BINARY_LESSEQUAL,
122         EXPR_BINARY_GREATER,
123         EXPR_BINARY_GREATEREQUAL,
124         EXPR_BINARY_BITWISE_AND,
125         EXPR_BINARY_BITWISE_OR,
126         EXPR_BINARY_BITWISE_XOR,
127         EXPR_BINARY_LOGICAL_AND,
128         EXPR_BINARY_LOGICAL_OR,
129         EXPR_BINARY_SHIFTLEFT,
130         EXPR_BINARY_SHIFTRIGHT,
131         EXPR_BINARY_ASSIGN,
132         EXPR_BINARY_MUL_ASSIGN,
133         EXPR_BINARY_DIV_ASSIGN,
134         EXPR_BINARY_MOD_ASSIGN,
135         EXPR_BINARY_ADD_ASSIGN,
136         EXPR_BINARY_SUB_ASSIGN,
137         EXPR_BINARY_SHIFTLEFT_ASSIGN,
138         EXPR_BINARY_SHIFTRIGHT_ASSIGN,
139         EXPR_BINARY_BITWISE_AND_ASSIGN,
140         EXPR_BINARY_BITWISE_XOR_ASSIGN,
141         EXPR_BINARY_BITWISE_OR_ASSIGN,
142         EXPR_BINARY_COMMA,
143
144         EXPR_BINARY_BUILTIN_EXPECT,
145         EXPR_BINARY_ISGREATER,
146         EXPR_BINARY_ISGREATEREQUAL,
147         EXPR_BINARY_ISLESS,
148         EXPR_BINARY_ISLESSEQUAL,
149         EXPR_BINARY_ISLESSGREATER,
150         EXPR_BINARY_ISUNORDERED,
151         EXPR_BINARY_LAST = EXPR_BINARY_ISUNORDERED,
152 } expression_kind_t;
153
154 typedef enum funcname_kind_t {
155         FUNCNAME_FUNCTION,           /**< C99 __func__, older __FUNCTION__ */
156         FUNCNAME_PRETTY_FUNCTION,    /**< GNUC __PRETTY_FUNCTION__ */
157         FUNCNAME_FUNCSIG,            /**< MS __FUNCSIG__ */
158         FUNCNAME_FUNCDNAME           /**< MS __FUNCDNAME__ */
159 } funcname_kind_t;
160
161 /* convenience macros */
162 #define EXPR_BINARY_CASES                  \
163         case EXPR_BINARY_ADD:                  \
164         case EXPR_BINARY_SUB:                  \
165         case EXPR_BINARY_MUL:                  \
166         case EXPR_BINARY_DIV:                  \
167         case EXPR_BINARY_MOD:                  \
168         case EXPR_BINARY_EQUAL:                \
169         case EXPR_BINARY_NOTEQUAL:             \
170         case EXPR_BINARY_LESS:                 \
171         case EXPR_BINARY_LESSEQUAL:            \
172         case EXPR_BINARY_GREATER:              \
173         case EXPR_BINARY_GREATEREQUAL:         \
174         case EXPR_BINARY_BITWISE_AND:          \
175         case EXPR_BINARY_BITWISE_OR:           \
176         case EXPR_BINARY_BITWISE_XOR:          \
177         case EXPR_BINARY_LOGICAL_AND:          \
178         case EXPR_BINARY_LOGICAL_OR:           \
179         case EXPR_BINARY_SHIFTLEFT:            \
180         case EXPR_BINARY_SHIFTRIGHT:           \
181         case EXPR_BINARY_ASSIGN:               \
182         case EXPR_BINARY_MUL_ASSIGN:           \
183         case EXPR_BINARY_DIV_ASSIGN:           \
184         case EXPR_BINARY_MOD_ASSIGN:           \
185         case EXPR_BINARY_ADD_ASSIGN:           \
186         case EXPR_BINARY_SUB_ASSIGN:           \
187         case EXPR_BINARY_SHIFTLEFT_ASSIGN:     \
188         case EXPR_BINARY_SHIFTRIGHT_ASSIGN:    \
189         case EXPR_BINARY_BITWISE_AND_ASSIGN:   \
190         case EXPR_BINARY_BITWISE_XOR_ASSIGN:   \
191         case EXPR_BINARY_BITWISE_OR_ASSIGN:    \
192         case EXPR_BINARY_COMMA:                \
193         case EXPR_BINARY_BUILTIN_EXPECT:       \
194         case EXPR_BINARY_ISGREATER:            \
195         case EXPR_BINARY_ISGREATEREQUAL:       \
196         case EXPR_BINARY_ISLESS:               \
197         case EXPR_BINARY_ISLESSEQUAL:          \
198         case EXPR_BINARY_ISLESSGREATER:        \
199         case EXPR_BINARY_ISUNORDERED:
200
201 /**
202  * unary expression with mandatory operand
203  */
204 #define EXPR_UNARY_CASES_MANDATORY         \
205         case EXPR_UNARY_NEGATE:                \
206         case EXPR_UNARY_PLUS:                  \
207         case EXPR_UNARY_BITWISE_NEGATE:        \
208         case EXPR_UNARY_NOT:                   \
209         case EXPR_UNARY_DEREFERENCE:           \
210         case EXPR_UNARY_TAKE_ADDRESS:          \
211         case EXPR_UNARY_POSTFIX_INCREMENT:     \
212         case EXPR_UNARY_POSTFIX_DECREMENT:     \
213         case EXPR_UNARY_PREFIX_INCREMENT:      \
214         case EXPR_UNARY_PREFIX_DECREMENT:      \
215         case EXPR_UNARY_CAST:                  \
216         case EXPR_UNARY_CAST_IMPLICIT:         \
217         case EXPR_UNARY_ASSUME:                \
218         case EXPR_UNARY_DELETE:                \
219         case EXPR_UNARY_DELETE_ARRAY:
220
221 /**
222  * unary expression with optinal operand
223  */
224 #define EXPR_UNARY_CASES_OPTIONAL \
225         case EXPR_UNARY_THROW:        \
226
227 #define EXPR_UNARY_CASES       \
228         EXPR_UNARY_CASES_MANDATORY \
229         EXPR_UNARY_CASES_OPTIONAL
230
231 struct expression_base_t {
232         expression_kind_t   kind;
233         type_t             *type;
234         source_position_t   source_position;
235 #ifndef NDEBUG
236         bool                transformed;
237 #endif
238 };
239
240 struct const_expression_t {
241         expression_base_t  base;
242         union {
243                 long long      int_value;
244                 long double    float_value;
245                 string_t       character;
246                 wide_string_t  wide_character;
247         } v;
248         bool               is_ms_noop;  /**< True, if this constant is the result
249                                              of an microsoft __noop operator */
250 };
251
252 struct string_literal_expression_t {
253         expression_base_t  base;
254         string_t           value;
255 };
256
257 struct funcname_expression_t {
258         expression_base_t  base;
259         funcname_kind_t    kind;
260         string_t           value;     /**< the value once assigned. */
261 };
262
263 struct wide_string_literal_expression_t {
264         expression_base_t  base;
265         wide_string_t      value;
266 };
267
268 struct compound_literal_expression_t {
269         expression_base_t  base;
270         type_t            *type;
271         initializer_t     *initializer;
272 };
273
274 struct builtin_symbol_expression_t {
275         expression_base_t  base;
276         symbol_t          *symbol;
277 };
278
279 struct builtin_constant_expression_t {
280         expression_base_t  base;
281         expression_t      *value;
282 };
283
284 struct builtin_prefetch_expression_t {
285         expression_base_t  base;
286         expression_t      *adr;
287         expression_t      *rw;
288         expression_t      *locality;
289 };
290
291 struct reference_expression_t {
292         expression_base_t  base;
293         entity_t          *entity;
294 };
295
296 struct call_argument_t {
297         expression_t    *expression;
298         call_argument_t *next;
299 };
300
301 struct call_expression_t {
302         expression_base_t  base;
303         expression_t      *function;
304         call_argument_t   *arguments;
305 };
306
307 struct unary_expression_t {
308         expression_base_t  base;
309         expression_t      *value;
310 };
311
312 struct binary_expression_t {
313         expression_base_t  base;
314         expression_t      *left;
315         expression_t      *right;
316 };
317
318 struct select_expression_t {
319         expression_base_t  base;
320         expression_t      *compound;
321         entity_t          *compound_entry;
322 };
323
324 struct array_access_expression_t {
325         expression_base_t  base;
326         expression_t      *array_ref;
327         expression_t      *index;
328         bool               flipped; /**< index/ref was written in a 5[a] way */
329 };
330
331 struct typeprop_expression_t {
332         expression_base_t  base;
333         type_t            *type;
334         expression_t      *tp_expression;
335 };
336
337 struct designator_t {
338         source_position_t  source_position;
339         symbol_t          *symbol;
340         expression_t      *array_index;
341         designator_t      *next;
342 };
343
344 struct offsetof_expression_t {
345         expression_base_t  base;
346         type_t            *type;
347         designator_t      *designator;
348 };
349
350 struct va_start_expression_t {
351         expression_base_t  base;
352         expression_t      *ap;
353         variable_t        *parameter;
354 };
355
356 struct va_arg_expression_t {
357         expression_base_t  base;
358         expression_t      *ap;
359 };
360
361 struct conditional_expression_t {
362         expression_base_t  base;
363         expression_t      *condition;
364         expression_t      *true_expression;
365         expression_t      *false_expression;
366 };
367
368 struct statement_expression_t {
369         expression_base_t  base;
370         statement_t       *statement;
371 };
372
373 struct classify_type_expression_t {
374         expression_base_t  base;
375         expression_t      *type_expression;
376 };
377
378 struct label_address_expression_t {
379         expression_base_t  base;
380         label_t           *label;
381 };
382
383 union expression_t {
384         expression_kind_t                kind;
385         expression_base_t                base;
386         const_expression_t               conste;
387         funcname_expression_t            funcname;
388         string_literal_expression_t      string;
389         wide_string_literal_expression_t wide_string;
390         compound_literal_expression_t    compound_literal;
391         builtin_symbol_expression_t      builtin_symbol;
392         builtin_constant_expression_t    builtin_constant;
393         builtin_prefetch_expression_t    builtin_prefetch;
394         reference_expression_t           reference;
395         call_expression_t                call;
396         unary_expression_t               unary;
397         binary_expression_t              binary;
398         select_expression_t              select;
399         array_access_expression_t        array_access;
400         typeprop_expression_t            typeprop;
401         offsetof_expression_t            offsetofe;
402         va_start_expression_t            va_starte;
403         va_arg_expression_t              va_arge;
404         conditional_expression_t         conditional;
405         statement_expression_t           statement;
406         classify_type_expression_t       classify_type;
407         label_address_expression_t       label_address;
408 };
409
410 typedef enum initializer_kind_t {
411         INITIALIZER_VALUE,
412         INITIALIZER_LIST,
413         INITIALIZER_STRING,
414         INITIALIZER_WIDE_STRING,
415         INITIALIZER_DESIGNATOR
416 } initializer_kind_t;
417
418 struct initializer_base_t {
419         initializer_kind_t kind;
420 };
421
422 struct initializer_value_t {
423         initializer_base_t  base;
424         expression_t       *value;
425 };
426
427 struct initializer_list_t {
428         initializer_base_t  base;
429         size_t              len;
430         initializer_t      *initializers[];
431 };
432
433 struct initializer_string_t {
434         initializer_base_t base;
435         string_t           string;
436 };
437
438 struct initializer_wide_string_t {
439         initializer_base_t  base;
440         wide_string_t       string;
441 };
442
443 struct initializer_designator_t {
444         initializer_base_t  base;
445         designator_t       *designator;
446 };
447
448 union initializer_t {
449         initializer_kind_t        kind;
450         initializer_base_t        base;
451         initializer_value_t       value;
452         initializer_list_t        list;
453         initializer_string_t      string;
454         initializer_wide_string_t wide_string;
455         initializer_designator_t  designator;
456 };
457
458 /**
459  * GNU attributes.
460  */
461 typedef enum gnu_attribute_kind_t {
462         GNU_AK_CONST,
463         GNU_AK_VOLATILE,
464         GNU_AK_CDECL,
465         GNU_AK_STDCALL,
466         GNU_AK_FASTCALL,
467         GNU_AK_DEPRECATED,
468         GNU_AK_NOINLINE,
469         GNU_AK_NORETURN,
470         GNU_AK_NAKED,
471         GNU_AK_PURE,
472         GNU_AK_ALWAYS_INLINE,
473         GNU_AK_MALLOC,
474         GNU_AK_WEAK,
475         GNU_AK_CONSTRUCTOR,
476         GNU_AK_DESTRUCTOR,
477         GNU_AK_NOTHROW,
478         GNU_AK_TRANSPARENT_UNION,
479         GNU_AK_COMMON,
480         GNU_AK_NOCOMMON,
481         GNU_AK_PACKED,
482         GNU_AK_SHARED,
483         GNU_AK_NOTSHARED,
484         GNU_AK_USED,
485         GNU_AK_UNUSED,
486         GNU_AK_NO_INSTRUMENT_FUNCTION,
487         GNU_AK_WARN_UNUSED_RESULT,
488         GNU_AK_LONGCALL,
489         GNU_AK_SHORTCALL,
490         GNU_AK_LONG_CALL,
491         GNU_AK_SHORT_CALL,
492         GNU_AK_FUNCTION_VECTOR,
493         GNU_AK_INTERRUPT,
494         GNU_AK_INTERRUPT_HANDLER,
495         GNU_AK_NMI_HANDLER,
496         GNU_AK_NESTING,
497         GNU_AK_NEAR,
498         GNU_AK_FAR,
499         GNU_AK_SIGNAL,
500         GNU_AK_EIGTHBIT_DATA,
501         GNU_AK_TINY_DATA,
502         GNU_AK_SAVEALL,
503         GNU_AK_FLATTEN,
504         GNU_AK_SSEREGPARM,
505         GNU_AK_EXTERNALLY_VISIBLE,
506         GNU_AK_RETURN_TWICE,
507         GNU_AK_MAY_ALIAS,
508         GNU_AK_MS_STRUCT,
509         GNU_AK_GCC_STRUCT,
510         GNU_AK_DLLIMPORT,
511         GNU_AK_DLLEXPORT,
512         GNU_AK_ALIGNED,
513         GNU_AK_ALIAS,
514         GNU_AK_SECTION,
515         GNU_AK_FORMAT,
516         GNU_AK_FORMAT_ARG,
517         GNU_AK_WEAKREF,
518         GNU_AK_NONNULL,
519         GNU_AK_TLS_MODEL,
520         GNU_AK_VISIBILITY,
521         GNU_AK_REGPARM,
522         GNU_AK_MODEL,
523         GNU_AK_MODE,
524         GNU_AK_TRAP_EXIT,
525         GNU_AK_SP_SWITCH,
526         GNU_AK_SENTINEL,
527         GNU_AK_LAST
528 } gnu_attribute_kind_t;
529
530 typedef enum statement_kind_t {
531         STATEMENT_INVALID,
532         STATEMENT_EMPTY,
533         STATEMENT_COMPOUND,
534         STATEMENT_RETURN,
535         STATEMENT_DECLARATION,
536         STATEMENT_LOCAL_LABEL,
537         STATEMENT_IF,
538         STATEMENT_SWITCH,
539         STATEMENT_EXPRESSION,
540         STATEMENT_CONTINUE,
541         STATEMENT_BREAK,
542         STATEMENT_GOTO,
543         STATEMENT_LABEL,
544         STATEMENT_CASE_LABEL,
545         STATEMENT_WHILE,
546         STATEMENT_DO_WHILE,
547         STATEMENT_FOR,
548         STATEMENT_ASM,
549         STATEMENT_MS_TRY,          /**< MS __try/__finally or __try/__except */
550         STATEMENT_LEAVE            /**< MS __leave */
551 } statement_kind_t;
552
553 struct statement_base_t {
554         statement_kind_t   kind;
555         statement_t       *next;
556         source_position_t  source_position;
557         statement_t       *parent;
558         bool               reachable;
559 #ifndef NDEBUG
560         bool               transformed;
561 #endif
562 };
563
564 struct invalid_statement_t {
565         statement_base_t  base;
566 };
567
568 struct empty_statement_t {
569         statement_base_t  base;
570 };
571
572 struct return_statement_t {
573         statement_base_t  base;
574         expression_t     *value;
575 };
576
577 struct compound_statement_t {
578         statement_base_t  base;
579         statement_t      *statements;
580         scope_t           scope;
581 };
582
583 struct declaration_statement_t {
584         statement_base_t  base;
585         entity_t         *declarations_begin;
586         entity_t         *declarations_end;
587 };
588
589 struct local_label_statement_t {
590         statement_base_t  base;
591         entity_t         *labels_begin;
592         entity_t         *labels_end;
593 };
594
595 struct if_statement_t {
596         statement_base_t  base;
597         expression_t     *condition;
598         statement_t      *true_statement;
599         statement_t      *false_statement;
600 };
601
602 struct switch_statement_t {
603         statement_base_t        base;
604         expression_t           *expression;
605         statement_t            *body;
606         case_label_statement_t *first_case, *last_case;  /**< List of all cases, including default. */
607         case_label_statement_t *default_label;           /**< The default label if existent. */
608         unsigned long           default_proj_nr;         /**< The Proj-number for the default Proj. */
609 };
610
611 struct goto_statement_t {
612         statement_base_t  base;
613         label_t          *label;         /**< The destination label. */
614         expression_t     *expression;    /**< The expression for an assigned goto. */
615         goto_statement_t *next;          /**< links all goto statements of a function */
616 };
617
618 struct case_label_statement_t {
619         statement_base_t        base;
620         expression_t           *expression;    /**< The case label expression, NULL for default label. */
621         expression_t           *end_range;     /**< For GNUC case a .. b: the end range expression, NULL else. */
622         case_label_statement_t *next;          /**< link to the next case label in switch */
623         statement_t            *statement;
624         long                   first_case;     /**< The folded value of expression. */
625         long                   last_case;      /**< The folded value of end_range. */
626         bool                   is_bad;         /**< If set marked as bad to suppress warnings. */
627         bool                   is_empty_range; /**< If set marked this as an empty range. */
628 };
629
630 struct label_statement_t {
631         statement_base_t   base;
632         label_t           *label;
633         statement_t       *statement;
634         label_statement_t *next;    /**< links all label statements of a function */
635 };
636
637 struct expression_statement_t {
638         statement_base_t  base;
639         expression_t     *expression;
640 };
641
642 struct while_statement_t {
643         statement_base_t  base;
644         expression_t     *condition;
645         statement_t      *body;
646 };
647
648 struct do_while_statement_t {
649         statement_base_t  base;
650         expression_t     *condition;
651         statement_t      *body;
652 };
653
654 struct for_statement_t {
655         statement_base_t  base;
656         expression_t     *initialisation;
657         expression_t     *condition;
658         expression_t     *step;
659         statement_t      *body;
660         scope_t           scope;
661         bool              condition_reachable:1;
662         bool              step_reachable:1;
663 };
664
665 struct asm_argument_t {
666         string_t        constraints;
667         expression_t   *expression;
668         symbol_t       *symbol;
669         asm_argument_t *next;
670 };
671
672 struct asm_clobber_t {
673         string_t       clobber;
674         asm_clobber_t *next;
675 };
676
677 struct asm_statement_t {
678         statement_base_t base;
679         string_t         asm_text;
680         asm_argument_t  *inputs;
681         asm_argument_t  *outputs;
682         asm_clobber_t   *clobbers;
683         bool             is_volatile;
684 };
685
686 struct ms_try_statement_t {
687         statement_base_t  base;
688         statement_t      *try_statement;
689         expression_t     *except_expression; /**< non-null for except, NULL for finally */
690         statement_t      *final_statement;
691 };
692
693 struct leave_statement_t {
694         statement_base_t  base;
695 };
696
697 union statement_t {
698         statement_kind_t         kind;
699         statement_base_t         base;
700         return_statement_t       returns;
701         compound_statement_t     compound;
702         declaration_statement_t  declaration;
703         local_label_statement_t  local_label;
704         if_statement_t           ifs;
705         switch_statement_t       switchs;
706         goto_statement_t         gotos;
707         case_label_statement_t   case_label;
708         label_statement_t        label;
709         expression_statement_t   expression;
710         while_statement_t        whiles;
711         do_while_statement_t     do_while;
712         for_statement_t          fors;
713         asm_statement_t          asms;
714         ms_try_statement_t       ms_try;
715         leave_statement_t        leave;
716 };
717
718 struct translation_unit_t {
719         scope_t      scope;
720         statement_t *global_asm;
721 };
722
723 static inline
724 void *_allocate_ast(size_t size)
725 {
726         return obstack_alloc(&ast_obstack, size);
727 }
728
729 static inline
730 bool is_invalid_expression(expression_t *expression)
731 {
732         return expression->base.kind == EXPR_INVALID;
733 }
734
735 static inline
736 bool is_invalid_statement(statement_t *statement)
737 {
738         return statement->base.kind == STATEMENT_INVALID;
739 }
740
741
742 #define allocate_ast(size)                 _allocate_ast(size)
743
744 #endif