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