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