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