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