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