declaration_t -> entity_t
[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.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 /**
232  * A scope containing declarations.
233  */
234 struct scope_t {
235         entity_t *entities;     /**< List of declarations in this scope. */
236         entity_t *last_entity;  /**< last declaration in this scope. */
237         scope_t  *parent;       /**< points to the parent scope. */
238         unsigned  depth;        /**< while parsing, the depth of this scope in the scope stack. */
239 };
240
241 struct expression_base_t {
242         expression_kind_t   kind;
243         type_t             *type;
244         source_position_t   source_position;
245 #ifndef NDEBUG
246         bool                transformed;
247 #endif
248 };
249
250 struct const_expression_t {
251         expression_base_t  base;
252         union {
253                 long long      int_value;
254                 long double    float_value;
255                 string_t       character;
256                 wide_string_t  wide_character;
257         } v;
258         bool               is_ms_noop;  /**< True, if this constant is the result
259                                              of an microsoft __noop operator */
260 };
261
262 struct string_literal_expression_t {
263         expression_base_t  base;
264         string_t           value;
265 };
266
267 struct funcname_expression_t {
268         expression_base_t  base;
269         funcname_kind_t    kind;
270         string_t           value;     /**< the value once assigned. */
271 };
272
273 struct wide_string_literal_expression_t {
274         expression_base_t  base;
275         wide_string_t      value;
276 };
277
278 struct compound_literal_expression_t {
279         expression_base_t  base;
280         type_t            *type;
281         initializer_t     *initializer;
282 };
283
284 struct builtin_symbol_expression_t {
285         expression_base_t  base;
286         symbol_t          *symbol;
287 };
288
289 struct builtin_constant_expression_t {
290         expression_base_t  base;
291         expression_t      *value;
292 };
293
294 struct builtin_prefetch_expression_t {
295         expression_base_t  base;
296         expression_t      *adr;
297         expression_t      *rw;
298         expression_t      *locality;
299 };
300
301 struct reference_expression_t {
302         expression_base_t  base;
303         entity_t          *entity;
304 };
305
306 struct call_argument_t {
307         expression_t    *expression;
308         call_argument_t *next;
309 };
310
311 struct call_expression_t {
312         expression_base_t  base;
313         expression_t      *function;
314         call_argument_t   *arguments;
315 };
316
317 struct unary_expression_t {
318         expression_base_t  base;
319         expression_t      *value;
320 };
321
322 struct binary_expression_t {
323         expression_base_t  base;
324         expression_t      *left;
325         expression_t      *right;
326 };
327
328 struct select_expression_t {
329         expression_base_t  base;
330         expression_t      *compound;
331         entity_t          *compound_entry;
332 };
333
334 struct array_access_expression_t {
335         expression_base_t  base;
336         expression_t      *array_ref;
337         expression_t      *index;
338         bool               flipped; /**< index/ref was written in a 5[a] way */
339 };
340
341 struct typeprop_expression_t {
342         expression_base_t  base;
343         type_t            *type;
344         expression_t      *tp_expression;
345 };
346
347 struct designator_t {
348         source_position_t  source_position;
349         symbol_t          *symbol;
350         expression_t      *array_index;
351         designator_t      *next;
352 };
353
354 struct offsetof_expression_t {
355         expression_base_t  base;
356         type_t            *type;
357         designator_t      *designator;
358 };
359
360 struct va_start_expression_t {
361         expression_base_t  base;
362         expression_t      *ap;
363         variable_t        *parameter;
364 };
365
366 struct va_arg_expression_t {
367         expression_base_t  base;
368         expression_t      *ap;
369 };
370
371 struct conditional_expression_t {
372         expression_base_t  base;
373         expression_t      *condition;
374         expression_t      *true_expression;
375         expression_t      *false_expression;
376 };
377
378 struct statement_expression_t {
379         expression_base_t  base;
380         statement_t       *statement;
381 };
382
383 struct classify_type_expression_t {
384         expression_base_t  base;
385         expression_t      *type_expression;
386 };
387
388 struct label_address_expression_t {
389         expression_base_t  base;
390         label_t           *label;
391 };
392
393 union expression_t {
394         expression_kind_t                kind;
395         expression_base_t                base;
396         const_expression_t               conste;
397         funcname_expression_t            funcname;
398         string_literal_expression_t      string;
399         wide_string_literal_expression_t wide_string;
400         compound_literal_expression_t    compound_literal;
401         builtin_symbol_expression_t      builtin_symbol;
402         builtin_constant_expression_t    builtin_constant;
403         builtin_prefetch_expression_t    builtin_prefetch;
404         reference_expression_t           reference;
405         call_expression_t                call;
406         unary_expression_t               unary;
407         binary_expression_t              binary;
408         select_expression_t              select;
409         array_access_expression_t        array_access;
410         typeprop_expression_t            typeprop;
411         offsetof_expression_t            offsetofe;
412         va_start_expression_t            va_starte;
413         va_arg_expression_t              va_arge;
414         conditional_expression_t         conditional;
415         statement_expression_t           statement;
416         classify_type_expression_t       classify_type;
417         label_address_expression_t       label_address;
418 };
419
420 typedef enum initializer_kind_t {
421         INITIALIZER_VALUE,
422         INITIALIZER_LIST,
423         INITIALIZER_STRING,
424         INITIALIZER_WIDE_STRING,
425         INITIALIZER_DESIGNATOR
426 } initializer_kind_t;
427
428 struct initializer_base_t {
429         initializer_kind_t kind;
430 };
431
432 struct initializer_value_t {
433         initializer_base_t  base;
434         expression_t       *value;
435 };
436
437 struct initializer_list_t {
438         initializer_base_t  base;
439         size_t              len;
440         initializer_t      *initializers[];
441 };
442
443 struct initializer_string_t {
444         initializer_base_t base;
445         string_t           string;
446 };
447
448 struct initializer_wide_string_t {
449         initializer_base_t  base;
450         wide_string_t       string;
451 };
452
453 struct initializer_designator_t {
454         initializer_base_t  base;
455         designator_t       *designator;
456 };
457
458 union initializer_t {
459         initializer_kind_t        kind;
460         initializer_base_t        base;
461         initializer_value_t       value;
462         initializer_list_t        list;
463         initializer_string_t      string;
464         initializer_wide_string_t wide_string;
465         initializer_designator_t  designator;
466 };
467
468 /**
469  * GNU attributes.
470  */
471 typedef enum gnu_attribute_kind_t {
472         GNU_AK_CONST,
473         GNU_AK_VOLATILE,
474         GNU_AK_CDECL,
475         GNU_AK_STDCALL,
476         GNU_AK_FASTCALL,
477         GNU_AK_DEPRECATED,
478         GNU_AK_NOINLINE,
479         GNU_AK_NORETURN,
480         GNU_AK_NAKED,
481         GNU_AK_PURE,
482         GNU_AK_ALWAYS_INLINE,
483         GNU_AK_MALLOC,
484         GNU_AK_WEAK,
485         GNU_AK_CONSTRUCTOR,
486         GNU_AK_DESTRUCTOR,
487         GNU_AK_NOTHROW,
488         GNU_AK_TRANSPARENT_UNION,
489         GNU_AK_COMMON,
490         GNU_AK_NOCOMMON,
491         GNU_AK_PACKED,
492         GNU_AK_SHARED,
493         GNU_AK_NOTSHARED,
494         GNU_AK_USED,
495         GNU_AK_UNUSED,
496         GNU_AK_NO_INSTRUMENT_FUNCTION,
497         GNU_AK_WARN_UNUSED_RESULT,
498         GNU_AK_LONGCALL,
499         GNU_AK_SHORTCALL,
500         GNU_AK_LONG_CALL,
501         GNU_AK_SHORT_CALL,
502         GNU_AK_FUNCTION_VECTOR,
503         GNU_AK_INTERRUPT,
504         GNU_AK_INTERRUPT_HANDLER,
505         GNU_AK_NMI_HANDLER,
506         GNU_AK_NESTING,
507         GNU_AK_NEAR,
508         GNU_AK_FAR,
509         GNU_AK_SIGNAL,
510         GNU_AK_EIGTHBIT_DATA,
511         GNU_AK_TINY_DATA,
512         GNU_AK_SAVEALL,
513         GNU_AK_FLATTEN,
514         GNU_AK_SSEREGPARM,
515         GNU_AK_EXTERNALLY_VISIBLE,
516         GNU_AK_RETURN_TWICE,
517         GNU_AK_MAY_ALIAS,
518         GNU_AK_MS_STRUCT,
519         GNU_AK_GCC_STRUCT,
520         GNU_AK_DLLIMPORT,
521         GNU_AK_DLLEXPORT,
522         GNU_AK_ALIGNED,
523         GNU_AK_ALIAS,
524         GNU_AK_SECTION,
525         GNU_AK_FORMAT,
526         GNU_AK_FORMAT_ARG,
527         GNU_AK_WEAKREF,
528         GNU_AK_NONNULL,
529         GNU_AK_TLS_MODEL,
530         GNU_AK_VISIBILITY,
531         GNU_AK_REGPARM,
532         GNU_AK_MODEL,
533         GNU_AK_MODE,
534         GNU_AK_TRAP_EXIT,
535         GNU_AK_SP_SWITCH,
536         GNU_AK_SENTINEL,
537         GNU_AK_LAST
538 } gnu_attribute_kind_t;
539
540 typedef enum statement_kind_t {
541         STATEMENT_INVALID,
542         STATEMENT_EMPTY,
543         STATEMENT_COMPOUND,
544         STATEMENT_RETURN,
545         STATEMENT_DECLARATION,
546         STATEMENT_LOCAL_LABEL,
547         STATEMENT_IF,
548         STATEMENT_SWITCH,
549         STATEMENT_EXPRESSION,
550         STATEMENT_CONTINUE,
551         STATEMENT_BREAK,
552         STATEMENT_GOTO,
553         STATEMENT_LABEL,
554         STATEMENT_CASE_LABEL,
555         STATEMENT_WHILE,
556         STATEMENT_DO_WHILE,
557         STATEMENT_FOR,
558         STATEMENT_ASM,
559         STATEMENT_MS_TRY,          /**< MS __try/__finally or __try/__except */
560         STATEMENT_LEAVE            /**< MS __leave */
561 } statement_kind_t;
562
563 struct statement_base_t {
564         statement_kind_t   kind;
565         statement_t       *next;
566         source_position_t  source_position;
567         statement_t       *parent;
568         bool               reachable;
569 #ifndef NDEBUG
570         bool               transformed;
571 #endif
572 };
573
574 struct invalid_statement_t {
575         statement_base_t  base;
576 };
577
578 struct empty_statement_t {
579         statement_base_t  base;
580 };
581
582 struct return_statement_t {
583         statement_base_t  base;
584         expression_t     *value;
585 };
586
587 struct compound_statement_t {
588         statement_base_t  base;
589         statement_t      *statements;
590         scope_t           scope;
591 };
592
593 struct declaration_statement_t {
594         statement_base_t  base;
595         entity_t         *declarations_begin;
596         entity_t         *declarations_end;
597 };
598
599 struct local_label_statement_t {
600         statement_base_t  base;
601         entity_t         *labels_begin;
602         entity_t         *labels_end;
603 };
604
605 struct if_statement_t {
606         statement_base_t  base;
607         expression_t     *condition;
608         statement_t      *true_statement;
609         statement_t      *false_statement;
610 };
611
612 struct switch_statement_t {
613         statement_base_t        base;
614         expression_t           *expression;
615         statement_t            *body;
616         case_label_statement_t *first_case, *last_case;  /**< List of all cases, including default. */
617         case_label_statement_t *default_label;           /**< The default label if existent. */
618         unsigned long           default_proj_nr;         /**< The Proj-number for the default Proj. */
619 };
620
621 struct goto_statement_t {
622         statement_base_t  base;
623         label_t          *label;         /**< The destination label. */
624         expression_t     *expression;    /**< The expression for an assigned goto. */
625         goto_statement_t *next;          /**< links all goto statements of a function */
626 };
627
628 struct case_label_statement_t {
629         statement_base_t        base;
630         expression_t           *expression;    /**< The case label expression, NULL for default label. */
631         expression_t           *end_range;     /**< For GNUC case a .. b: the end range expression, NULL else. */
632         case_label_statement_t *next;          /**< link to the next case label in switch */
633         statement_t            *statement;
634         long                   first_case;     /**< The folded value of expression. */
635         long                   last_case;      /**< The folded value of end_range. */
636         bool                   is_bad;         /**< If set marked as bad to suppress warnings. */
637         bool                   is_empty_range; /**< If set marked this as an empty range. */
638 };
639
640 struct label_statement_t {
641         statement_base_t   base;
642         label_t           *label;
643         statement_t       *statement;
644         label_statement_t *next;    /**< links all label statements of a function */
645 };
646
647 struct expression_statement_t {
648         statement_base_t  base;
649         expression_t     *expression;
650 };
651
652 struct while_statement_t {
653         statement_base_t  base;
654         expression_t     *condition;
655         statement_t      *body;
656 };
657
658 struct do_while_statement_t {
659         statement_base_t  base;
660         expression_t     *condition;
661         statement_t      *body;
662 };
663
664 struct for_statement_t {
665         statement_base_t  base;
666         expression_t     *initialisation;
667         expression_t     *condition;
668         expression_t     *step;
669         statement_t      *body;
670         scope_t           scope;
671         bool              condition_reachable:1;
672         bool              step_reachable:1;
673 };
674
675 struct asm_argument_t {
676         string_t        constraints;
677         expression_t   *expression;
678         symbol_t       *symbol;
679         asm_argument_t *next;
680 };
681
682 struct asm_clobber_t {
683         string_t       clobber;
684         asm_clobber_t *next;
685 };
686
687 struct asm_statement_t {
688         statement_base_t base;
689         string_t         asm_text;
690         asm_argument_t  *inputs;
691         asm_argument_t  *outputs;
692         asm_clobber_t   *clobbers;
693         bool             is_volatile;
694 };
695
696 struct ms_try_statement_t {
697         statement_base_t  base;
698         statement_t      *try_statement;
699         expression_t     *except_expression; /**< non-null for except, NULL for finally */
700         statement_t      *final_statement;
701 };
702
703 struct leave_statement_t {
704         statement_base_t  base;
705 };
706
707 union statement_t {
708         statement_kind_t         kind;
709         statement_base_t         base;
710         return_statement_t       returns;
711         compound_statement_t     compound;
712         declaration_statement_t  declaration;
713         local_label_statement_t  local_label;
714         if_statement_t           ifs;
715         switch_statement_t       switchs;
716         goto_statement_t         gotos;
717         case_label_statement_t   case_label;
718         label_statement_t        label;
719         expression_statement_t   expression;
720         while_statement_t        whiles;
721         do_while_statement_t     do_while;
722         for_statement_t          fors;
723         asm_statement_t          asms;
724         ms_try_statement_t       ms_try;
725         leave_statement_t        leave;
726 };
727
728 struct translation_unit_t {
729         scope_t      scope;
730         statement_t *global_asm;
731 };
732
733 static inline
734 void *_allocate_ast(size_t size)
735 {
736         return obstack_alloc(&ast_obstack, size);
737 }
738
739 static inline
740 bool is_invalid_expression(expression_t *expression)
741 {
742         return expression->base.kind == EXPR_INVALID;
743 }
744
745 static inline
746 bool is_invalid_statement(statement_t *statement)
747 {
748         return statement->base.kind == STATEMENT_INVALID;
749 }
750
751
752 #define allocate_ast(size)                 _allocate_ast(size)
753
754 #endif