s/true/false/, fix a typo: a function definition with () means no parameters, not...
[cparser] / ast_t.h
diff --git a/ast_t.h b/ast_t.h
index 50d0b6d..6a61564 100644 (file)
--- a/ast_t.h
+++ b/ast_t.h
@@ -2,6 +2,7 @@
 #define AST_T_H
 
 #include <libfirm/firm_types.h>
+#include <assert.h>
 
 #include "ast.h"
 #include "symbol.h"
@@ -32,40 +33,40 @@ typedef enum {
        EXPR_OFFSETOF,
        EXPR_VA_ARG,
        EXPR_STATEMENT
-} expresion_type_t;
+} expression_type_t;
 
 struct context_t {
        declaration_t   *declarations;
 };
 
-struct expression_t {
-       expresion_type_t   type;
-       type_t            *datatype;
-       source_position_t  source_position;
+struct expression_base_t {
+       expression_type_t   type;
+       type_t             *datatype;
+       source_position_t   source_position;
 };
 
-struct const_t {
-       expression_t  expression;
+struct const_expression_t {
+       expression_base_t  expression;
        union {
                long long   int_value;
                long double float_value;
        } v;
 };
 
-struct string_literal_t {
-       expression_t  expression;
-       const char   *value;
+struct string_literal_expression_t {
+       expression_base_t  expression;
+       const char        *value;
 };
 
 struct builtin_symbol_expression_t {
-       expression_t  expression;
-       symbol_t     *symbol;
+       expression_base_t  expression;
+       symbol_t          *symbol;
 };
 
 struct reference_expression_t {
-       expression_  expression;
-       symbol_t      *symbol;
-       declaration_t *declaration;
+       expression_base_t  expression;
+       symbol_t          *symbol;
+       declaration_t     *declaration;
 };
 
 struct call_argument_t {
@@ -74,9 +75,9 @@ struct call_argument_t {
 };
 
 struct call_expression_t {
-       expression_t     expression;
-       expression_t    *function;
-       call_argument_t *arguments;
+       expression_base_t  expression;
+       expression_t      *function;
+       call_argument_t   *arguments;
 };
 
 typedef enum {
@@ -95,7 +96,7 @@ typedef enum {
 } unary_expression_type_t;
 
 struct unary_expression_t {
-       expression_t             expression;
+       expression_base_t        expression;
        unary_expression_type_t  type;
        expression_t            *value;
 };
@@ -135,30 +136,31 @@ typedef enum {
 } binary_expression_type_t;
 
 struct binary_expression_t {
-       expression_t              expression;
+       expression_base_t         expression;
        binary_expression_type_t  type;
        expression_t             *left;
        expression_t             *right;
 };
 
 struct select_expression_t {
-       expression_  expression;
-       expression_t  *compound;
-       symbol_t      *symbol;
+       expression_base_t  expression;
+       expression_t      *compound;
+       symbol_t          *symbol;
 
-       declaration_t *compound_entry;
+       declaration_t     *compound_entry;
 };
 
 struct array_access_expression_t {
-       expression_t  expression;
-       expression_t *array_ref;
-       expression_t *index;
+       expression_base_t  expression;
+       expression_t      *array_ref;
+       expression_t      *index;
+       bool               flipped; /* index/ref was written in a 5[a] way */
 };
 
 struct sizeof_expression_t {
-       expression_t  expression;
-       type_t       *type;
-       expression_t *size_expression;
+       expression_base_t  expression;
+       type_t            *type;
+       expression_t      *size_expression;
 };
 
 struct designator_t {
@@ -168,32 +170,52 @@ struct designator_t {
 };
 
 struct offsetof_expression_t {
-       expression_t  expression;
-       type_t       *type;
-       designator_t *designator;
+       expression_base_t  expression;
+       type_t            *type;
+       designator_t      *designator;
 };
 
 struct va_arg_expression_t {
-       expression_t  expression;
-       expression_t *arg;
-       type_t       *type;
+       expression_base_t  expression;
+       expression_t      *arg;
+       type_t            *type;
 };
 
 struct conditional_expression_t {
-       expression_t  expression;
-       expression_t *condition;
-       expression_t *true_expression;
-       expression_t *false_expression;
+       expression_base_t  expression;
+       expression_t      *condition;
+       expression_t      *true_expression;
+       expression_t      *false_expression;
 };
 
 struct statement_expression_t {
-       expression_t  expression;
-       statement_t  *statement;
+       expression_base_t  expression;
+       statement_t       *statement;
 };
 
 struct classify_type_expression_t {
-       expression_t  expression;
-       expression_t *type_expression;
+       expression_base_t  expression;
+       expression_t      *type_expression;
+};
+
+union expression_t {
+       expression_type_t            type;
+       expression_base_t            base;
+       const_expression_t           conste;
+       string_literal_expression_t  string;
+       builtin_symbol_expression_t  builtin_symbol;
+       reference_expression_t       reference;
+       call_expression_t            call;
+       unary_expression_t           unary;
+       binary_expression_t          binary;
+       select_expression_t          select;
+       array_access_expression_t    array_access;
+       sizeof_expression_t          sizeofe;
+       offsetof_expression_t        offsetofe;
+       va_arg_expression_t          va_arge;
+       conditional_expression_t     conditional;
+       statement_expression_t       statement;
+       classify_type_expression_t   classify_type;
 };
 
 typedef enum {
@@ -203,36 +225,53 @@ typedef enum {
        STORAGE_CLASS_STATIC,
        STORAGE_CLASS_AUTO,
        STORAGE_CLASS_REGISTER,
-       STORAGE_CLASS_ENUM_ENTRY
-} storage_class_t;
+       STORAGE_CLASS_ENUM_ENTRY,
+       STORAGE_CLASS_THREAD,
+       STORAGE_CLASS_THREAD_EXTERN,
+       STORAGE_CLASS_THREAD_STATIC
+} storage_class_tag_t;
 
 typedef enum {
        NAMESPACE_NORMAL,
        NAMESPACE_STRUCT,
        NAMESPACE_UNION,
        NAMESPACE_ENUM,
-       NAMESPACE_LABEL
+       NAMESPACE_LABEL,
 } namespace_t;
 
 typedef enum {
        INITIALIZER_VALUE,
        INITIALIZER_LIST,
-       INITIALIZER_STRING
+       INITIALIZER_STRING,
+       INITIALIZER_COUNT
 } initializer_type_t;
 
-struct initializer_t {
-       initializer_type_t  type;
-       union {
-               /* if type == INITIALIZER_VALUE */
-               expression_t *value;
-               /* if type == INITIALIZER_LIST */
-               struct {
-                       size_t         len;
-                       initializer_t *initializers[1];
-               } list;
-               /* if type == INITIALIZER_STRING */
-               const char    *string;
-       } v;
+struct initializer_base_t {
+       initializer_type_t type;
+};
+
+struct initializer_value_t {
+       initializer_base_t  initializer;
+       expression_t       *value;
+};
+
+struct initializer_list_t {
+       initializer_base_t  initializer;
+       size_t              len;
+       initializer_t      *initializers[];
+};
+
+struct initializer_string_t {
+       initializer_base_t  initializer;
+       const char         *string;
+};
+
+union initializer_t {
+       initializer_type_t   type;
+       initializer_base_t   base;
+       initializer_value_t  value;
+       initializer_list_t   list;
+       initializer_string_t string;
 };
 
 struct declaration_t {
@@ -262,6 +301,7 @@ struct declaration_t {
                unsigned int    value_number;     /* used in ast2firm module */
                ir_entity      *entity;           /* used in ast2firm module */
                ir_node        *block;            /* used in ast2firm module */
+               tarval         *enum_val;         /* used in ast2firm module */
        } v;
 };
 
@@ -283,62 +323,100 @@ typedef enum {
        STATEMENT_FOR
 } statement_type_t;
 
-struct statement_t {
+struct statement_base_t {
        statement_type_t   type;
        statement_t       *next;
        source_position_t  source_position;
-       union {
-               /* if type == STATEMENT_COMPOUND */
-               struct {
-                       statement_t *statements;
-                       context_t    context;
-               } compound_stmt;
-               /* if type == STATEMENT_RETURN */
-               expression_t *return_value;
-               /* if type == STATEMENT_DECLARATION */
-               struct {
-                       declaration_t *begin;
-                       declaration_t *end;
-               } declaration_stmt;
-               /* if type == STATEMENT_IF */
-               struct {
-                       expression_t *condition;
-                       statement_t  *true_statement;
-                       statement_t  *false_statement;
-               } if_stmt;
-               /* if type == STATEMENT_SWITCH */
-               struct {
-                       expression_t *expression;
-                       statement_t  *body;
-               } switch_stmt;
-               /* if type == STATEMENT_EXPRESSION */
-               expression_t *expression;
-               /* if type == STATEMENT_GOTO */
-               declaration_t *goto_label;
-               /* if type == STATEMENT_LABEL */
-               struct {
-                       declaration_t *label;
-                       statement_t   *label_statement;
-               } label_stmt;
-               /* if type == STATEMENT_CASE_LABEL */
-               struct {
-                       expression_t *expression;
-                       statement_t  *label_statement;
-               } case_label_stmt;
-               /* if type == STATEMENT_WHILE or STATEMENT_DO_WHILE */
-               struct {
-                       expression_t *condition;
-                       statement_t  *body;
-               } while_stmt;
-               /* if type == STATEMENT_FOR */
-               struct {
-                       expression_t  *initialisation;
-                       expression_t  *condition;
-                       expression_t  *step;
-                       statement_t   *body;
-                       context_t      context;
-               } for_stmt;
-       } v;
+};
+
+struct return_statement_t {
+       statement_base_t  statement;
+       expression_t     *return_value;
+};
+
+struct compound_statement_t {
+       statement_base_t  statement;
+       statement_t      *statements;
+       context_t         context;
+};
+
+struct declaration_statement_t {
+       statement_base_t  statement;
+       declaration_t    *declarations_begin;
+       declaration_t    *declarations_end;
+};
+
+struct if_statement_t {
+       statement_base_t  statement;
+       expression_t     *condition;
+       statement_t      *true_statement;
+       statement_t      *false_statement;
+};
+
+struct switch_statement_t {
+       statement_base_t  statement;
+       expression_t     *expression;
+       statement_t      *body;
+};
+
+struct goto_statement_t {
+       statement_base_t  statement;
+       declaration_t    *label;
+};
+
+struct case_label_statement_t {
+       statement_base_t  statement;
+       expression_t     *expression;
+       statement_t      *label_statement;
+};
+
+struct label_statement_t {
+       statement_base_t  statement;
+       declaration_t    *label;
+       statement_t      *label_statement;
+};
+
+struct expression_statement_t {
+       statement_base_t  statement;
+       expression_t     *expression;
+};
+
+struct while_statement_t {
+       statement_base_t  statement;
+       expression_t     *condition;
+       statement_t      *body;
+};
+
+struct do_while_statement_t {
+       statement_base_t  statement;
+       expression_t     *condition;
+       statement_t      *body;
+};
+
+struct for_statement_t {
+       statement_base_t  statement;
+       expression_t     *initialisation;
+       expression_t     *condition;
+       expression_t     *step;
+       statement_t      *body;
+       context_t         context;
+};
+
+union statement_t {
+       statement_type_t         type;
+       statement_base_t         base;
+       return_statement_t       returns;
+       compound_statement_t     compound;
+       declaration_statement_t  declaration;
+       if_statement_t           ifs;
+       switch_statement_t       switchs;
+       goto_statement_t         gotos;
+       case_label_statement_t   case_label;
+       label_statement_t        label;
+       expression_statement_t   expression;
+       while_statement_t        whiles;
+       do_while_statement_t     do_while;
+       for_statement_t          fors;
 };
 
 struct translation_unit_t {