get rid of some fields in ast_t: outer_fkt_jmp, is_outer_ref, is_parameter
[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         scope_t       *parent;            /**< points to the parent scope. */
193         unsigned      depth;              /**< while parsing, the depth of this scope in the scope stack. */
194 };
195
196 struct expression_base_t {
197         expression_kind_t   kind;
198         type_t             *type;
199         source_position_t   source_position;
200 #ifndef NDEBUG
201         bool                transformed;
202 #endif
203 };
204
205 struct const_expression_t {
206         expression_base_t  base;
207         union {
208                 long long      int_value;
209                 long double    float_value;
210                 string_t       character;
211                 wide_string_t  wide_character;
212         } v;
213         bool               is_ms_noop;  /**< True, if this constant is the result
214                                              of an microsoft __noop operator */
215 };
216
217 struct string_literal_expression_t {
218         expression_base_t  base;
219         string_t           value;
220 };
221
222 struct funcname_expression_t {
223         expression_base_t  base;
224         funcname_kind_t    kind;
225         string_t           value;     /**< the value once assigned. */
226 };
227
228 struct wide_string_literal_expression_t {
229         expression_base_t  base;
230         wide_string_t      value;
231 };
232
233 struct compound_literal_expression_t {
234         expression_base_t  base;
235         type_t            *type;
236         initializer_t     *initializer;
237 };
238
239 struct builtin_symbol_expression_t {
240         expression_base_t  base;
241         symbol_t          *symbol;
242 };
243
244 struct builtin_constant_expression_t {
245         expression_base_t  base;
246         expression_t      *value;
247 };
248
249 struct builtin_prefetch_expression_t {
250         expression_base_t  base;
251         expression_t      *adr;
252         expression_t      *rw;
253         expression_t      *locality;
254 };
255
256 struct reference_expression_t {
257         expression_base_t  base;
258         declaration_t     *declaration;
259 };
260
261 struct call_argument_t {
262         expression_t    *expression;
263         call_argument_t *next;
264 };
265
266 struct call_expression_t {
267         expression_base_t  base;
268         expression_t      *function;
269         call_argument_t   *arguments;
270 };
271
272 struct unary_expression_t {
273         expression_base_t  base;
274         expression_t      *value;
275 };
276
277 struct binary_expression_t {
278         expression_base_t  base;
279         expression_t      *left;
280         expression_t      *right;
281 };
282
283 struct select_expression_t {
284         expression_base_t  base;
285         expression_t      *compound;
286         declaration_t     *compound_entry;
287 };
288
289 struct array_access_expression_t {
290         expression_base_t  base;
291         expression_t      *array_ref;
292         expression_t      *index;
293         bool               flipped; /**< index/ref was written in a 5[a] way */
294 };
295
296 struct typeprop_expression_t {
297         expression_base_t  base;
298         type_t            *type;
299         expression_t      *tp_expression;
300 };
301
302 struct designator_t {
303         source_position_t  source_position;
304         symbol_t          *symbol;
305         expression_t      *array_index;
306         designator_t      *next;
307 };
308
309 struct offsetof_expression_t {
310         expression_base_t  base;
311         type_t            *type;
312         designator_t      *designator;
313 };
314
315 struct va_start_expression_t {
316         expression_base_t  base;
317         expression_t      *ap;
318         declaration_t     *parameter;
319 };
320
321 struct va_arg_expression_t {
322         expression_base_t  base;
323         expression_t      *ap;
324 };
325
326 struct conditional_expression_t {
327         expression_base_t  base;
328         expression_t      *condition;
329         expression_t      *true_expression;
330         expression_t      *false_expression;
331 };
332
333 struct statement_expression_t {
334         expression_base_t  base;
335         statement_t       *statement;
336 };
337
338 struct classify_type_expression_t {
339         expression_base_t  base;
340         expression_t      *type_expression;
341 };
342
343 struct label_address_expression_t {
344         expression_base_t  base;
345         declaration_t     *declaration;
346 };
347
348 union expression_t {
349         expression_kind_t                kind;
350         expression_base_t                base;
351         const_expression_t               conste;
352         funcname_expression_t            funcname;
353         string_literal_expression_t      string;
354         wide_string_literal_expression_t wide_string;
355         compound_literal_expression_t    compound_literal;
356         builtin_symbol_expression_t      builtin_symbol;
357         builtin_constant_expression_t    builtin_constant;
358         builtin_prefetch_expression_t    builtin_prefetch;
359         reference_expression_t           reference;
360         call_expression_t                call;
361         unary_expression_t               unary;
362         binary_expression_t              binary;
363         select_expression_t              select;
364         array_access_expression_t        array_access;
365         typeprop_expression_t            typeprop;
366         offsetof_expression_t            offsetofe;
367         va_start_expression_t            va_starte;
368         va_arg_expression_t              va_arge;
369         conditional_expression_t         conditional;
370         statement_expression_t           statement;
371         classify_type_expression_t       classify_type;
372         label_address_expression_t       label_address;
373 };
374
375 typedef enum storage_class_tag_t {
376         STORAGE_CLASS_NONE,
377         STORAGE_CLASS_EXTERN,
378         STORAGE_CLASS_STATIC,
379         STORAGE_CLASS_TYPEDEF,
380         STORAGE_CLASS_AUTO,
381         STORAGE_CLASS_REGISTER,
382         STORAGE_CLASS_ENUM_ENTRY,
383         STORAGE_CLASS_THREAD,
384         STORAGE_CLASS_THREAD_EXTERN,
385         STORAGE_CLASS_THREAD_STATIC,
386 } storage_class_tag_t;
387
388 typedef enum namespace_t {
389         NAMESPACE_NORMAL,
390         NAMESPACE_STRUCT,
391         NAMESPACE_UNION,
392         NAMESPACE_ENUM,
393         NAMESPACE_LABEL,
394         NAMESPACE_LOCAL_LABEL
395 } namespace_t;
396
397 typedef enum initializer_kind_t {
398         INITIALIZER_VALUE,
399         INITIALIZER_LIST,
400         INITIALIZER_STRING,
401         INITIALIZER_WIDE_STRING,
402         INITIALIZER_DESIGNATOR
403 } initializer_kind_t;
404
405 struct initializer_base_t {
406         initializer_kind_t kind;
407 };
408
409 struct initializer_value_t {
410         initializer_base_t  base;
411         expression_t       *value;
412 };
413
414 struct initializer_list_t {
415         initializer_base_t  base;
416         size_t              len;
417         initializer_t      *initializers[];
418 };
419
420 struct initializer_string_t {
421         initializer_base_t base;
422         string_t           string;
423 };
424
425 struct initializer_wide_string_t {
426         initializer_base_t  base;
427         wide_string_t       string;
428 };
429
430 struct initializer_designator_t {
431         initializer_base_t  base;
432         designator_t       *designator;
433 };
434
435 union initializer_t {
436         initializer_kind_t        kind;
437         initializer_base_t        base;
438         initializer_value_t       value;
439         initializer_list_t        list;
440         initializer_string_t      string;
441         initializer_wide_string_t wide_string;
442         initializer_designator_t  designator;
443 };
444
445 /**
446  * GNU attributes.
447  */
448 typedef enum gnu_attribute_kind_t {
449         GNU_AK_CONST,
450         GNU_AK_VOLATILE,
451         GNU_AK_CDECL,
452         GNU_AK_STDCALL,
453         GNU_AK_FASTCALL,
454         GNU_AK_DEPRECATED,
455         GNU_AK_NOINLINE,
456         GNU_AK_NORETURN,
457         GNU_AK_NAKED,
458         GNU_AK_PURE,
459         GNU_AK_ALWAYS_INLINE,
460         GNU_AK_MALLOC,
461         GNU_AK_WEAK,
462         GNU_AK_CONSTRUCTOR,
463         GNU_AK_DESTRUCTOR,
464         GNU_AK_NOTHROW,
465         GNU_AK_TRANSPARENT_UNION,
466         GNU_AK_COMMON,
467         GNU_AK_NOCOMMON,
468         GNU_AK_PACKED,
469         GNU_AK_SHARED,
470         GNU_AK_NOTSHARED,
471         GNU_AK_USED,
472         GNU_AK_UNUSED,
473         GNU_AK_NO_INSTRUMENT_FUNCTION,
474         GNU_AK_WARN_UNUSED_RESULT,
475         GNU_AK_LONGCALL,
476         GNU_AK_SHORTCALL,
477         GNU_AK_LONG_CALL,
478         GNU_AK_SHORT_CALL,
479         GNU_AK_FUNCTION_VECTOR,
480         GNU_AK_INTERRUPT,
481         GNU_AK_INTERRUPT_HANDLER,
482         GNU_AK_NMI_HANDLER,
483         GNU_AK_NESTING,
484         GNU_AK_NEAR,
485         GNU_AK_FAR,
486         GNU_AK_SIGNAL,
487         GNU_AK_EIGTHBIT_DATA,
488         GNU_AK_TINY_DATA,
489         GNU_AK_SAVEALL,
490         GNU_AK_FLATTEN,
491         GNU_AK_SSEREGPARM,
492         GNU_AK_EXTERNALLY_VISIBLE,
493         GNU_AK_RETURN_TWICE,
494         GNU_AK_MAY_ALIAS,
495         GNU_AK_MS_STRUCT,
496         GNU_AK_GCC_STRUCT,
497         GNU_AK_DLLIMPORT,
498         GNU_AK_DLLEXPORT,
499         GNU_AK_ALIGNED,
500         GNU_AK_ALIAS,
501         GNU_AK_SECTION,
502         GNU_AK_FORMAT,
503         GNU_AK_FORMAT_ARG,
504         GNU_AK_WEAKREF,
505         GNU_AK_NONNULL,
506         GNU_AK_TLS_MODEL,
507         GNU_AK_VISIBILITY,
508         GNU_AK_REGPARM,
509         GNU_AK_MODEL,
510         GNU_AK_MODE,
511         GNU_AK_TRAP_EXIT,
512         GNU_AK_SP_SWITCH,
513         GNU_AK_SENTINEL,
514         GNU_AK_LAST
515 } gnu_attribute_kind_t;
516
517 /**
518  * Extended microsoft modifier.
519  */
520 typedef enum decl_modifier_t {
521         DM_DLLIMPORT         = 1 <<  0,
522         DM_DLLEXPORT         = 1 <<  1,
523         DM_THREAD            = 1 <<  2,
524         DM_NAKED             = 1 <<  3,
525         DM_MICROSOFT_INLINE  = 1 <<  4,
526         DM_FORCEINLINE       = 1 <<  5,
527         DM_SELECTANY         = 1 <<  6,
528         DM_NOTHROW           = 1 <<  7,
529         DM_NOVTABLE          = 1 <<  8,
530         DM_NORETURN          = 1 <<  9,
531         DM_NOINLINE          = 1 << 10,
532         DM_RESTRICT          = 1 << 11,
533         DM_NOALIAS           = 1 << 12,
534         DM_PACKED            = 1 << 13,
535         DM_TRANSPARENT_UNION = 1 << 14,
536         DM_CONST             = 1 << 15,
537         DM_PURE              = 1 << 16,
538         DM_CONSTRUCTOR       = 1 << 17,
539         DM_DESTRUCTOR        = 1 << 18,
540         DM_UNUSED            = 1 << 19,
541         DM_USED              = 1 << 20,
542         DM_CDECL             = 1 << 21,
543         DM_FASTCALL          = 1 << 22,
544         DM_STDCALL           = 1 << 23,
545         DM_THISCALL          = 1 << 24,
546         DM_DEPRECATED        = 1 << 25
547 } decl_modifier_t;
548
549 typedef unsigned decl_modifiers_t;
550
551 struct declaration_t {
552         unsigned char       namespc;
553         unsigned char       declared_storage_class;
554         unsigned char       storage_class;
555         unsigned char       alignment;          /**< Alignment of the declaration, 0 for default. */
556         decl_modifiers_t    modifiers;          /**< modifiers. */
557         const char         *deprecated_string;  /**< MS deprecated string if any. */
558         symbol_t           *get_property_sym;   /**< MS get property. */
559         symbol_t           *put_property_sym;   /**< MS put property. */
560         unsigned int        address_taken : 1;  /**< Set if the address of this declaration was taken. */
561         unsigned int        is_inline     : 1;
562         unsigned int        used          : 1;  /**< Set if the declaration is used. */
563         unsigned int        read          : 1;
564         unsigned int        implicit      : 1;  /**< Set for implicit (not found in source code) declarations. */
565         unsigned int        need_closure  : 1;  /**< Inner function needs closure. */
566         unsigned int        goto_to_outer : 1;  /**< Inner function has goto to outer function. */
567         type_t             *type;
568         il_size_t           offset;             /**< The offset of this member inside a compound. */
569         symbol_t           *symbol;
570         source_position_t   source_position;
571         union {
572                 bool            complete;           /**< used to indicate whether struct/union types are already defined or if just the name is declared */
573                 statement_t    *statement;
574                 initializer_t  *initializer;
575                 expression_t   *enum_value;
576         } init;
577         scope_t             scope;              /**< The scope that this declaration opens. */
578         scope_t            *parent_scope;       /**< The parent scope where this declaration lives. */
579
580         /** next declaration in a scope */
581         declaration_t      *next;
582         /** next declaration with same symbol */
583         declaration_t      *symbol_next;
584
585         /* the following fields are used in ast2firm module */
586         unsigned char       declaration_kind;
587         union {
588                 unsigned int  value_number;
589                 ir_entity    *entity;
590                 ir_node      *block;
591                 ir_node      *vla_base;
592                 tarval       *enum_val;
593                 ir_type      *irtype;
594         } v;
595 };
596
597 typedef enum statement_kind_t {
598         STATEMENT_INVALID,
599         STATEMENT_EMPTY,
600         STATEMENT_COMPOUND,
601         STATEMENT_RETURN,
602         STATEMENT_DECLARATION,
603         STATEMENT_IF,
604         STATEMENT_SWITCH,
605         STATEMENT_EXPRESSION,
606         STATEMENT_CONTINUE,
607         STATEMENT_BREAK,
608         STATEMENT_GOTO,
609         STATEMENT_LABEL,
610         STATEMENT_CASE_LABEL,
611         STATEMENT_WHILE,
612         STATEMENT_DO_WHILE,
613         STATEMENT_FOR,
614         STATEMENT_ASM,
615         STATEMENT_MS_TRY,          /**< MS __try/__finally or __try/__except */
616         STATEMENT_LEAVE            /**< MS __leave */
617 } statement_kind_t;
618
619 struct statement_base_t {
620         statement_kind_t   kind;
621         statement_t       *next;
622         source_position_t  source_position;
623         statement_t       *parent;
624         bool               reachable;
625 #ifndef NDEBUG
626         bool               transformed;
627 #endif
628 };
629
630 struct invalid_statement_t {
631         statement_base_t  base;
632 };
633
634 struct empty_statement_t {
635         statement_base_t  base;
636 };
637
638 struct return_statement_t {
639         statement_base_t  base;
640         expression_t     *value;
641 };
642
643 struct compound_statement_t {
644         statement_base_t  base;
645         statement_t      *statements;
646         scope_t           scope;
647 };
648
649 struct declaration_statement_t {
650         statement_base_t  base;
651         declaration_t    *declarations_begin;
652         declaration_t    *declarations_end;
653 };
654
655 struct if_statement_t {
656         statement_base_t  base;
657         expression_t     *condition;
658         statement_t      *true_statement;
659         statement_t      *false_statement;
660 };
661
662 struct switch_statement_t {
663         statement_base_t        base;
664         expression_t           *expression;
665         statement_t            *body;
666         case_label_statement_t *first_case, *last_case;  /**< List of all cases, including default. */
667         case_label_statement_t *default_label;           /**< The default label if existent. */
668         unsigned long           default_proj_nr;         /**< The Proj-number for the default Proj. */
669 };
670
671 struct goto_statement_t {
672         statement_base_t  base;
673         declaration_t    *label;         /**< The destination label. */
674         expression_t     *expression;    /**< The expression for an assigned goto. */
675         goto_statement_t *next;          /**< links all goto statements of a function */
676 };
677
678 struct case_label_statement_t {
679         statement_base_t        base;
680         expression_t           *expression;    /**< The case label expression, NULL for default label. */
681         expression_t           *end_range;     /**< For GNUC case a .. b: the end range expression, NULL else. */
682         case_label_statement_t *next;          /**< link to the next case label in switch */
683         statement_t            *statement;
684         long                   first_case;     /**< The folded value of expression. */
685         long                   last_case;      /**< The folded value of end_range. */
686         bool                   is_bad;         /**< If set marked as bad to suppress warnings. */
687         bool                   is_empty_range; /**< If set marked this as an empty range. */
688 };
689
690 struct label_statement_t {
691         statement_base_t   base;
692         declaration_t     *label;
693         statement_t       *statement;
694         label_statement_t *next;    /**< links all label statements of a function */
695 };
696
697 struct expression_statement_t {
698         statement_base_t  base;
699         expression_t     *expression;
700 };
701
702 struct while_statement_t {
703         statement_base_t  base;
704         expression_t     *condition;
705         statement_t      *body;
706 };
707
708 struct do_while_statement_t {
709         statement_base_t  base;
710         expression_t     *condition;
711         statement_t      *body;
712 };
713
714 struct for_statement_t {
715         statement_base_t  base;
716         expression_t     *initialisation;
717         expression_t     *condition;
718         expression_t     *step;
719         statement_t      *body;
720         scope_t           scope;
721         bool              condition_reachable:1;
722         bool              step_reachable:1;
723 };
724
725 struct asm_argument_t {
726         string_t        constraints;
727         expression_t   *expression;
728         symbol_t       *symbol;
729         asm_argument_t *next;
730 };
731
732 struct asm_clobber_t {
733         string_t       clobber;
734         asm_clobber_t *next;
735 };
736
737 struct asm_statement_t {
738         statement_base_t base;
739         string_t         asm_text;
740         asm_argument_t  *inputs;
741         asm_argument_t  *outputs;
742         asm_clobber_t   *clobbers;
743         bool             is_volatile;
744 };
745
746 struct ms_try_statement_t {
747         statement_base_t  base;
748         statement_t      *try_statement;
749         expression_t     *except_expression; /**< non-null for except, NULL for finally */
750         statement_t      *final_statement;
751 };
752
753 struct leave_statement_t {
754         statement_base_t  base;
755 };
756
757 union statement_t {
758         statement_kind_t         kind;
759         statement_base_t         base;
760         return_statement_t       returns;
761         compound_statement_t     compound;
762         declaration_statement_t  declaration;
763         if_statement_t           ifs;
764         switch_statement_t       switchs;
765         goto_statement_t         gotos;
766         case_label_statement_t   case_label;
767         label_statement_t        label;
768         expression_statement_t   expression;
769         while_statement_t        whiles;
770         do_while_statement_t     do_while;
771         for_statement_t          fors;
772         asm_statement_t          asms;
773         ms_try_statement_t       ms_try;
774         leave_statement_t        leave;
775 };
776
777 struct translation_unit_t {
778         scope_t      scope;
779         statement_t *global_asm;
780 };
781
782 static inline
783 void *_allocate_ast(size_t size)
784 {
785         return obstack_alloc(&ast_obstack, size);
786 }
787
788 static inline
789 bool is_invalid_expression(expression_t *expression)
790 {
791         return expression->base.kind == EXPR_INVALID;
792 }
793
794 static inline
795 bool is_invalid_statement(statement_t *statement)
796 {
797         return statement->base.kind == STATEMENT_INVALID;
798 }
799
800
801 #define allocate_ast(size)                 _allocate_ast(size)
802
803 #endif