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