change back union stuff and expriment with new union mode for initializers
authorMatthias Braun <matze@braunis.de>
Mon, 26 Nov 2007 16:49:22 +0000 (16:49 +0000)
committerMatthias Braun <matze@braunis.de>
Mon, 26 Nov 2007 16:49:22 +0000 (16:49 +0000)
[r18537]

ast.c
ast.h
ast2firm.c
ast_t.h
parser.c
type.c
type.h
type_hash.c
type_t.h
write_fluffy.c

diff --git a/ast.c b/ast.c
index 9bc088f..984df78 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -299,12 +299,12 @@ void print_expression(const expression_t *expression)
        }
 }
 
-static void print_compound_statement(const statement_t *block)
+static void print_compound_statement(const compound_statement_t *block)
 {
        fputs("{\n", out);
        indent++;
 
-       statement_t *statement = block->v.compound_stmt.statements;
+       statement_t *statement = block->statements;
        while(statement != NULL) {
                print_indent();
                print_statement(statement);
@@ -316,78 +316,79 @@ static void print_compound_statement(const statement_t *block)
        fputs("}\n", out);
 }
 
-static void print_return_statement(const statement_t *statement)
+static void print_return_statement(const return_statement_t *statement)
 {
        fprintf(out, "return ");
-       if(statement->v.return_value != NULL)
-               print_expression(statement->v.return_value);
+       if(statement->return_value != NULL)
+               print_expression(statement->return_value);
        fputs(";\n", out);
 }
 
-static void print_expression_statement(const statement_t *statement)
+static void print_expression_statement(const expression_statement_t *statement)
 {
-       print_expression(statement->v.expression);
+       print_expression(statement->expression);
        fputs(";\n", out);
 }
 
-static void print_goto_statement(const statement_t *statement)
+static void print_goto_statement(const goto_statement_t *statement)
 {
        fprintf(out, "goto ");
-       fputs(statement->v.goto_label->symbol->string, out);
-       fprintf(stderr, "(%p)", (void*) statement->v.goto_label);
+       fputs(statement->label->symbol->string, out);
+       fprintf(stderr, "(%p)", (void*) statement->label);
        fputs(";\n", out);
 }
 
-static void print_label_statement(const statement_t *statement)
+static void print_label_statement(const label_statement_t *statement)
 {
-       fprintf(stderr, "(%p)", (void*) statement->v.label_stmt.label);
-       fprintf(out, "%s:\n", statement->v.label_stmt.label->symbol->string);
-       if(statement->v.label_stmt.label_statement != NULL) {
-               print_statement(statement->v.label_stmt.label_statement);
+       fprintf(stderr, "(%p)", (void*) statement->label);
+       fprintf(out, "%s:\n", statement->label->symbol->string);
+       if(statement->label_statement != NULL) {
+               print_statement(statement->label_statement);
        }
 }
 
-static void print_if_statement(const statement_t *statement)
+static void print_if_statement(const if_statement_t *statement)
 {
        fputs("if(", out);
-       print_expression(statement->v.if_stmt.condition);
+       print_expression(statement->condition);
        fputs(") ", out);
-       if(statement->v.if_stmt.true_statement != NULL) {
-               print_statement(statement->v.if_stmt.true_statement);
+       if(statement->true_statement != NULL) {
+               print_statement(statement->true_statement);
        }
 
-       if(statement->v.if_stmt.false_statement != NULL) {
+       if(statement->false_statement != NULL) {
                print_indent();
                fputs("else ", out);
-               print_statement(statement->v.if_stmt.false_statement);
+               print_statement(statement->false_statement);
        }
 }
 
-static void print_switch_statement(const statement_t *statement)
+static void print_switch_statement(const switch_statement_t *statement)
 {
        fputs("switch(", out);
-       print_expression(statement->v.switch_stmt.expression);
+       print_expression(statement->expression);
        fputs(") ", out);
-       print_statement(statement->v.switch_stmt.body);
+       print_statement(statement->body);
 }
 
-static void print_case_label(const statement_t *statement)
+static void print_case_label(const case_label_statement_t *statement)
 {
-       if(statement->v.case_label_stmt.expression == NULL) {
+       if(statement->expression == NULL) {
                fputs("default:\n", out);
        } else {
                fputs("case ", out);
-               print_expression(statement->v.case_label_stmt.expression);
+               print_expression(statement->expression);
                fputs(":\n", out);
        }
-       print_statement(statement->v.case_label_stmt.label_statement);
+       print_statement(statement->label_statement);
 }
 
-static void print_declaration_statement(const statement_t *statement)
+static void print_declaration_statement(
+               const declaration_statement_t *statement)
 {
        int first = 1;
-       declaration_t *declaration = statement->v.declaration_stmt.begin;
-       for( ; declaration != statement->v.declaration_stmt.end->next;
+       declaration_t *declaration = statement->declarations_begin;
+       for( ; declaration != statement->declarations_end->next;
               declaration = declaration->next) {
                if(!first) {
                        print_indent();
@@ -399,68 +400,68 @@ static void print_declaration_statement(const statement_t *statement)
        }
 }
 
-static void print_while_statement(const statement_t *statement)
+static void print_while_statement(const while_statement_t *statement)
 {
        fputs("while(", out);
-       print_expression(statement->v.while_stmt.condition);
+       print_expression(statement->condition);
        fputs(") ", out);
-       print_statement(statement->v.while_stmt.body);
+       print_statement(statement->body);
 }
 
-static void print_do_while_statement(const statement_t *statement)
+static void print_do_while_statement(const do_while_statement_t *statement)
 {
        fputs("do ", out);
-       print_statement(statement->v.while_stmt.body);
+       print_statement(statement->body);
        print_indent();
        fputs("while(", out);
-       print_expression(statement->v.while_stmt.condition);
+       print_expression(statement->condition);
        fputs(");\n", out);
 }
 
-static void print_for_statement(const statement_t *statement)
+static void print_for_statement(const for_statement_t *statement)
 {
        fputs("for(", out);
-       if(statement->v.for_stmt.context.declarations != NULL) {
-               assert(statement->v.for_stmt.initialisation == NULL);
-               print_declaration(statement->v.for_stmt.context.declarations);
-               if(statement->v.for_stmt.context.declarations->next != NULL) {
+       if(statement->context.declarations != NULL) {
+               assert(statement->initialisation == NULL);
+               print_declaration(statement->context.declarations);
+               if(statement->context.declarations->next != NULL) {
                        panic("multiple declarations in for statement not supported yet");
                }
                fputc(' ', out);
        } else {
-               if(statement->v.for_stmt.initialisation) {
-                       print_expression(statement->v.for_stmt.initialisation);
+               if(statement->initialisation) {
+                       print_expression(statement->initialisation);
                }
                fputs("; ", out);
        }
-       if(statement->v.for_stmt.condition != NULL) {
-               print_expression(statement->v.for_stmt.condition);
+       if(statement->condition != NULL) {
+               print_expression(statement->condition);
        }
        fputs("; ", out);
-       if(statement->v.for_stmt.step != NULL) {
-               print_expression(statement->v.for_stmt.step);
+       if(statement->step != NULL) {
+               print_expression(statement->step);
        }
        fputs(")", out);
-       print_statement(statement->v.for_stmt.body);
+       print_statement(statement->body);
 }
 
 void print_statement(const statement_t *statement)
 {
        switch(statement->type) {
        case STATEMENT_COMPOUND:
-               print_compound_statement(statement);
+               print_compound_statement((const compound_statement_t*) statement);
                break;
        case STATEMENT_RETURN:
-               print_return_statement(statement);
+               print_return_statement((const return_statement_t*) statement);
                break;
        case STATEMENT_EXPRESSION:
-               print_expression_statement(statement);
+               print_expression_statement((const expression_statement_t*) statement);
                break;
        case STATEMENT_LABEL:
-               print_label_statement(statement);
+               print_label_statement((const label_statement_t*) statement);
                break;
        case STATEMENT_GOTO:
-               print_goto_statement(statement);
+               print_goto_statement((const goto_statement_t*) statement);
                break;
        case STATEMENT_CONTINUE:
                fputs("continue;\n", out);
@@ -469,25 +470,25 @@ void print_statement(const statement_t *statement)
                fputs("break;\n", out);
                break;
        case STATEMENT_IF:
-               print_if_statement(statement);
+               print_if_statement((const if_statement_t*) statement);
                break;
        case STATEMENT_SWITCH:
-               print_switch_statement(statement);
+               print_switch_statement((const switch_statement_t*) statement);
                break;
        case STATEMENT_CASE_LABEL:
-               print_case_label(statement);
+               print_case_label((const case_label_statement_t*) statement);
                break;
        case STATEMENT_DECLARATION:
-               print_declaration_statement(statement);
+               print_declaration_statement((const declaration_statement_t*) statement);
                break;
        case STATEMENT_WHILE:
-               print_while_statement(statement);
+               print_while_statement((const while_statement_t*) statement);
                break;
        case STATEMENT_DO_WHILE:
-               print_do_while_statement(statement);
+               print_do_while_statement((const do_while_statement_t*) statement);
                break;
        case STATEMENT_FOR:
-               print_for_statement(statement);
+               print_for_statement((const for_statement_t*) statement);
                break;
        case STATEMENT_INVALID:
                fprintf(out, "*invalid statement*");
@@ -512,18 +513,20 @@ static void print_storage_class(storage_class_t storage_class)
 void print_initializer(const initializer_t *initializer)
 {
        if(initializer->type == INITIALIZER_VALUE) {
-               print_expression(initializer->v.value);
+               const initializer_value_t *value = &initializer->value;
+               print_expression(value->value);
                return;
        }
 
        assert(initializer->type == INITIALIZER_LIST);
        fputs("{ ", out);
+       const initializer_list_t *list = &initializer->list;
 
-       for(size_t i = 0 ; i < initializer->v.list.len; ++i) {
+       for(size_t i = 0 ; i < list->len; ++i) {
                if(i > 0) {
                        fputs(", ", out);
                }
-               print_initializer(initializer->v.list.initializers[i]);
+               print_initializer(list->initializers[i]);
        }
        fputs("}", out);
 }
diff --git a/ast.h b/ast.h
index 76c0b21..410c774 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -28,10 +28,27 @@ typedef struct va_arg_expression_t          va_arg_expression_t;
 typedef struct builtin_symbol_expression_t  builtin_symbol_expression_t;
 typedef struct classify_type_expression_t   classify_type_expression_t;
 
-typedef struct initializer_t                initializer_t;
+typedef struct initializer_base_t           initializer_base_t;
+typedef struct initializer_list_t           initializer_list_t;
+typedef struct initializer_value_t          initializer_value_t;
+typedef struct initializer_string_t         initializer_string_t;
+typedef union  initializer_t                initializer_t;
+
 typedef struct declaration_t                declaration_t;
 
 typedef struct statement_t                  statement_t;
+typedef struct compound_statement_t         compound_statement_t;
+typedef struct return_statement_t           return_statement_t;
+typedef struct if_statement_t               if_statement_t;
+typedef struct switch_statement_t           switch_statement_t;
+typedef struct declaration_statement_t      declaration_statement_t;
+typedef struct expression_statement_t       expression_statement_t;
+typedef struct goto_statement_t             goto_statement_t;
+typedef struct label_statement_t            label_statement_t;
+typedef struct case_label_statement_t       case_label_statement_t;
+typedef struct while_statement_t            while_statement_t;
+typedef struct do_while_statement_t         do_while_statement_t;
+typedef struct for_statement_t              for_statement_t;
 
 typedef struct translation_unit_t           translation_unit_t;
 
index b7b31c4..e025e3e 100644 (file)
@@ -119,9 +119,9 @@ static ident *unique_ident(const char *tag)
        return new_id_from_str(buf);
 }
 
-static ir_mode *get_atomic_mode(const type_t* atomic_type)
+static ir_mode *get_atomic_mode(const atomic_type_t* atomic_type)
 {
-       switch(atomic_type->v.atomic_type.atype) {
+       switch(atomic_type->atype) {
        case ATOMIC_TYPE_SCHAR:
        case ATOMIC_TYPE_CHAR:
                return mode_Bs;
@@ -173,9 +173,9 @@ static ir_mode *get_atomic_mode(const type_t* atomic_type)
 
 static unsigned get_type_size(type_t *type);
 
-static unsigned get_atomic_type_size(const type_t *type)
+static unsigned get_atomic_type_size(const atomic_type_t *type)
 {
-       switch(type->v.atomic_type.atype) {
+       switch(type->atype) {
        case ATOMIC_TYPE_CHAR:
        case ATOMIC_TYPE_SCHAR:
        case ATOMIC_TYPE_UCHAR:
@@ -210,15 +210,15 @@ static unsigned get_atomic_type_size(const type_t *type)
        panic("Trying to determine size of invalid atomic type");
 }
 
-static unsigned get_compound_type_size(type_t *type)
+static unsigned get_compound_type_size(compound_type_t *type)
 {
-       ir_type *irtype = get_ir_type(type);
+       ir_type *irtype = get_ir_type(&type->type);
        return get_type_size_bytes(irtype);
 }
 
-static unsigned get_array_type_size(type_t *type)
+static unsigned get_array_type_size(array_type_t *type)
 {
-       ir_type *irtype = get_ir_type(type);
+       ir_type *irtype = get_ir_type(&type->type);
        return get_type_size_bytes(irtype);
 }
 
@@ -228,19 +228,19 @@ static unsigned get_type_size(type_t *type)
 
        switch(type->type) {
        case TYPE_ATOMIC:
-               return get_atomic_type_size(type);
+               return get_atomic_type_size((const atomic_type_t*) type);
        case TYPE_ENUM:
                return get_mode_size_bytes(mode_Is);
        case TYPE_COMPOUND_UNION:
        case TYPE_COMPOUND_STRUCT:
-               return get_compound_type_size(type);
+               return get_compound_type_size((compound_type_t*) type);
        case TYPE_FUNCTION:
                /* just a pointer to the function */
                return get_mode_size_bytes(mode_P_code);
        case TYPE_POINTER:
                return get_mode_size_bytes(mode_P_data);
        case TYPE_ARRAY:
-               return get_array_type_size(type);
+               return get_array_type_size((array_type_t*) type);
        case TYPE_BUILTIN:
        case TYPE_TYPEDEF:
        case TYPE_TYPEOF:
@@ -250,11 +250,11 @@ static unsigned get_type_size(type_t *type)
        panic("Trying to determine size of invalid type");
 }
 
-static unsigned count_parameters(const type_t *type)
+static unsigned count_parameters(const function_type_t *function_type)
 {
        unsigned count = 0;
 
-       function_parameter_t *parameter = type->v.function_type.parameters;
+       function_parameter_t *parameter = function_type->parameters;
        for ( ; parameter != NULL; parameter = parameter->next) {
                ++count;
        }
@@ -267,7 +267,7 @@ static unsigned count_parameters(const type_t *type)
 
 static long fold_constant(const expression_t *expression);
 
-static ir_type *create_atomic_type(const type_t *type)
+static ir_type *create_atomic_type(const atomic_type_t *type)
 {
        ir_mode *mode   = get_atomic_mode(type);
        ident   *id     = get_mode_ident(mode);
@@ -276,12 +276,12 @@ static ir_type *create_atomic_type(const type_t *type)
        return irtype;
 }
 
-static ir_type *create_method_type(const type_t *type)
+static ir_type *create_method_type(const function_type_t *function_type)
 {
-       type_t  *result_type  = type->v.function_type.result_type;
+       type_t  *result_type  = function_type->result_type;
 
        ident   *id           = unique_ident("functiontype");
-       int      n_parameters = count_parameters(type);
+       int      n_parameters = count_parameters(function_type);
        int      n_results    = result_type == type_void ? 0 : 1;
        ir_type *irtype       = new_type_method(id, n_parameters, n_results);
 
@@ -290,7 +290,7 @@ static ir_type *create_method_type(const type_t *type)
                set_method_res_type(irtype, 0, restype);
        }
 
-       function_parameter_t *parameter = type->v.function_type.parameters;
+       function_parameter_t *parameter = function_type->parameters;
        int                   n         = 0;
        for( ; parameter != NULL; parameter = parameter->next) {
                ir_type *p_irtype = get_ir_type(parameter->type);
@@ -298,16 +298,16 @@ static ir_type *create_method_type(const type_t *type)
                ++n;
        }
 
-       if(type->v.function_type.variadic || type->v.function_type.unspecified_parameters) {
+       if(function_type->variadic || function_type->unspecified_parameters) {
                set_method_variadicity(irtype, variadicity_variadic);
        }
 
        return irtype;
 }
 
-static ir_type *create_pointer_type(type_t *type)
+static ir_type *create_pointer_type(pointer_type_t *type)
 {
-       type_t  *points_to = type->v.pointer_type.points_to;
+       type_t  *points_to = type->points_to;
        ir_type *ir_points_to;
        /* Avoid endless recursion if the points_to type contains this poiner type
         * again (might be a struct). We therefore first create a void* pointer
@@ -315,7 +315,7 @@ static ir_type *create_pointer_type(type_t *type)
         */
        ir_type *ir_type = new_type_pointer(unique_ident("pointer"),
                                            ir_type_void, mode_P_data);
-       type->firm_type  = ir_type;
+       type->type.firm_type  = ir_type;
 
        ir_points_to = get_ir_type(points_to);
        set_pointer_points_to_type(ir_type, ir_points_to);
@@ -323,16 +323,16 @@ static ir_type *create_pointer_type(type_t *type)
        return ir_type;
 }
 
-static ir_type *create_array_type(type_t *type)
+static ir_type *create_array_type(array_type_t *type)
 {
-       type_t  *element_type    = type->v.array_type.element_type;
+       type_t  *element_type    = type->element_type;
        ir_type *ir_element_type = get_ir_type(element_type);
 
        ident   *id      = unique_ident("array");
        ir_type *ir_type = new_type_array(id, 1, ir_element_type);
 
-       if(type->v.array_type.size != NULL) {
-               int n_elements = fold_constant(type->v.array_type.size);
+       if(type->size != NULL) {
+               int n_elements = fold_constant(type->size);
 
                set_array_bounds_int(ir_type, 0, 0, n_elements);
 
@@ -351,9 +351,9 @@ static ir_type *create_array_type(type_t *type)
 
 #define INVALID_TYPE ((ir_type_ptr)-1)
 
-static ir_type *create_struct_type(type_t *type)
+static ir_type *create_struct_type(compound_type_t *type)
 {
-       symbol_t *symbol = type->v.compound_type.declaration->symbol;
+       symbol_t *symbol = type->declaration->symbol;
        ident    *id;
        if(symbol != NULL) {
                id = unique_ident(symbol->string);
@@ -362,11 +362,11 @@ static ir_type *create_struct_type(type_t *type)
        }
        ir_type *ir_type = new_type_struct(id);
 
-       type->firm_type = ir_type;
+       type->type.firm_type = ir_type;
 
        int align_all = 1;
        int offset    = 0;
-       declaration_t *entry = type->v.compound_type.declaration->context.declarations;
+       declaration_t *entry = type->declaration->context.declarations;
        for( ; entry != NULL; entry = entry->next) {
                if(entry->namespc != NAMESPACE_NORMAL)
                        continue;
@@ -404,9 +404,9 @@ static ir_type *create_struct_type(type_t *type)
        return ir_type;
 }
 
-static ir_type *create_union_type(type_t *type)
+static ir_type *create_union_type(compound_type_t *type)
 {
-       declaration_t *declaration = type->v.compound_type.declaration;
+       declaration_t *declaration = type->declaration;
        symbol_t      *symbol      = declaration->symbol;
        ident         *id;
        if(symbol != NULL) {
@@ -416,7 +416,7 @@ static ir_type *create_union_type(type_t *type)
        }
        ir_type  *ir_type = new_type_union(id);
 
-       type->firm_type = ir_type;
+       type->type.firm_type = ir_type;
 
        int align_all = 1;
        int size      = 0;
@@ -458,22 +458,22 @@ static ir_type *create_union_type(type_t *type)
 static ir_node *expression_to_firm(const expression_t *expression);
 static inline ir_mode *get_ir_mode(type_t *type);
 
-static ir_type *create_enum_type(type_t *const type)
+static ir_type *create_enum_type(enum_type_t *const type)
 {
-       type->firm_type = ir_type_int;
+       type->type.firm_type = ir_type_int;
 
-       ir_mode *const mode    = get_ir_mode(type);
+       ir_mode *const mode    = get_ir_mode((type_t*) type);
        tarval  *const one     = get_mode_one(mode);
        tarval  *      tv_next = get_tarval_null(mode);
 
-       for (declaration_t *decl = type->v.enum_type.declaration;;) {
-               decl = decl->next;
-               if (decl == NULL || decl->storage_class != STORAGE_CLASS_ENUM_ENTRY)
+       declaration_t *declaration = type->declaration->next;
+       for (; declaration != NULL; declaration = declaration->next) {
+               if (declaration->storage_class != STORAGE_CLASS_ENUM_ENTRY)
                        break;
 
-               decl->declaration_type = DECLARATION_TYPE_ENUM_ENTRY;
+               declaration->declaration_type = DECLARATION_TYPE_ENUM_ENTRY;
 
-               expression_t *const init = decl->init.enum_value;
+               expression_t *const init = declaration->init.enum_value;
                if (init != NULL) {
                        ir_node *const cnst = expression_to_firm(init);
                        if (!is_Const(cnst)) {
@@ -481,7 +481,7 @@ static ir_type *create_enum_type(type_t *const type)
                        }
                        tv_next = get_Const_tarval(cnst);
                }
-               decl->v.enum_val = tv_next;
+               declaration->v.enum_val = tv_next;
                tv_next = tarval_add(tv_next, one);
        }
 
@@ -502,25 +502,25 @@ static ir_type *get_ir_type(type_t *type)
        ir_type *firm_type = NULL;
        switch(type->type) {
        case TYPE_ATOMIC:
-               firm_type = create_atomic_type(type);
+               firm_type = create_atomic_type((atomic_type_t*) type);
                break;
        case TYPE_FUNCTION:
-               firm_type = create_method_type(type);
+               firm_type = create_method_type((function_type_t*) type);
                break;
        case TYPE_POINTER:
-               firm_type = create_pointer_type(type);
+               firm_type = create_pointer_type((pointer_type_t*) type);
                break;
        case TYPE_ARRAY:
-               firm_type = create_array_type(type);
+               firm_type = create_array_type((array_type_t*) type);
                break;
        case TYPE_COMPOUND_STRUCT:
-               firm_type = create_struct_type(type);
+               firm_type = create_struct_type((compound_type_t*) type);
                break;
        case TYPE_COMPOUND_UNION:
-               firm_type = create_union_type(type);
+               firm_type = create_union_type((compound_type_t*) type);
                break;
        case TYPE_ENUM:
-               firm_type = create_enum_type(type);
+               firm_type = create_enum_type((enum_type_t*) type);
                break;
        case TYPE_BUILTIN:
        case TYPE_TYPEOF:
@@ -799,14 +799,14 @@ static ir_node *call_expression_to_firm(const call_expression_t *call)
        }
        ir_node       *callee   = expression_to_firm(function);
 
-       type_t *type;
+       function_type_t *function_type;
        if (function->datatype->type == TYPE_POINTER) {
-               type_t *const ptr_type = function->datatype;
-               assert(ptr_type->v.pointer_type.points_to->type == TYPE_FUNCTION);
-               type = ptr_type->v.pointer_type.points_to;
+               pointer_type_t *const ptr_type = (pointer_type_t*)function->datatype;
+               assert(ptr_type->points_to->type == TYPE_FUNCTION);
+               function_type = (function_type_t*)ptr_type->points_to;
        } else {
                assert(function->datatype->type == TYPE_FUNCTION);
-               type = function->datatype;
+               function_type = (function_type_t*)function->datatype;
        }
 
        int              n_parameters = 0;
@@ -815,9 +815,9 @@ static ir_node *call_expression_to_firm(const call_expression_t *call)
                ++n_parameters;
        }
 
-       ir_type *ir_method_type  = get_ir_type((type_t*) type);
+       ir_type *ir_method_type  = get_ir_type((type_t*) function_type);
        ir_type *new_method_type = NULL;
-       if(type->v.function_type.variadic || type->v.function_type.unspecified_parameters) {
+       if(function_type->variadic || function_type->unspecified_parameters) {
                /* we need to construct a new method type matching the call
                 * arguments... */
                int n_res       = get_method_n_ress(ir_method_type);
@@ -861,7 +861,7 @@ static ir_node *call_expression_to_firm(const call_expression_t *call)
        ir_node  *mem   = new_d_Proj(dbgi, node, mode_M, pn_Call_M_regular);
        set_store(mem);
 
-       type_t  *result_type = type->v.function_type.result_type;
+       type_t  *result_type = function_type->result_type;
        ir_node *result      = NULL;
        if(result_type != type_void) {
                ir_mode *mode    = get_ir_mode(result_type);
@@ -873,7 +873,7 @@ static ir_node *call_expression_to_firm(const call_expression_t *call)
 }
 
 static void statement_to_firm(statement_t *statement);
-static ir_node *compound_statement_to_firm(statement_t *compound);
+static ir_node *compound_statement_to_firm(compound_statement_t *compound);
 
 static ir_node *expression_to_addr(const expression_t *expression);
 static void create_condition_evaluation(const expression_t *expression,
@@ -931,7 +931,8 @@ static ir_node *create_incdec(const unary_expression_t *expression)
 
        ir_node *offset;
        if(type->type == TYPE_POINTER) {
-               unsigned elem_size = get_type_size(type->v.pointer_type.points_to);
+               pointer_type_t *pointer_type = (pointer_type_t*) type;
+               unsigned        elem_size    = get_type_size(pointer_type->points_to);
                offset = new_Const_long(mode_Is, elem_size);
        } else {
                assert(is_type_arithmetic(type));
@@ -1084,8 +1085,9 @@ static ir_node *pointer_arithmetic(ir_node  *const pointer,
                                    dbg_info *const dbgi,
                                    const create_arithmetic_func func)
 {
-       type_t         *const points_to = type->v.pointer_type.points_to;
-       const unsigned        elem_size = get_type_size(points_to);
+       pointer_type_t *const pointer_type = (pointer_type_t*)type;
+       type_t         *const points_to    = pointer_type->points_to;
+       const unsigned        elem_size    = get_type_size(points_to);
 
        assert(elem_size >= 1);
        if (elem_size > 1) {
@@ -1161,8 +1163,8 @@ static ir_node *create_sub(const binary_expression_t *expression)
                ir_mode *const mode = get_ir_mode(type);
                return new_d_Sub(dbgi, left, right, mode);
        } else if (type_left->type == TYPE_POINTER && type_right->type == TYPE_POINTER) {
-               const type_t *const ptr_type = type_left;
-               const unsigned elem_size     = get_type_size(ptr_type->v.pointer_type.points_to);
+               const pointer_type_t *const ptr_type = (const pointer_type_t*)type_left;
+               const unsigned elem_size             = get_type_size(ptr_type->points_to);
                ir_mode *const mode   = get_ir_mode(type);
                ir_node *const sub    = new_d_Sub(dbgi, left, right, mode);
                ir_node *const cnst   = new_Const_long(mode_Is, (long)elem_size);
@@ -1503,8 +1505,9 @@ static ir_node *classify_type_to_firm(const classify_type_expression_t *const ex
        gcc_type_class tc;
        switch (type->type)
        {
-               case TYPE_ATOMIC:
-                       switch (type->v.atomic_type.atype) {
+               case TYPE_ATOMIC: {
+                       const atomic_type_t *const atomic_type = (const atomic_type_t*)type;
+                       switch (atomic_type->atype) {
                                // should not be reached
                                case ATOMIC_TYPE_INVALID:
                                        tc = no_type_class;
@@ -1553,6 +1556,7 @@ static ir_node *classify_type_to_firm(const classify_type_expression_t *const ex
                                        panic("Unimplemented case in classify_type_to_firm().");
                        }
                        break;
+               }
 
                case TYPE_ARRAY:           // gcc handles this as pointer
                case TYPE_FUNCTION:        // gcc handles this as pointer
@@ -1590,7 +1594,7 @@ static ir_node *statement_expression_to_firm(const statement_expression_t *expr)
        statement_t *statement = expr->statement;
 
        assert(statement->type == STATEMENT_COMPOUND);
-       return compound_statement_to_firm(statement);
+       return compound_statement_to_firm((compound_statement_t*) statement);
 }
 
 static ir_node *dereference_addr(const unary_expression_t *const expression)
@@ -1752,16 +1756,16 @@ static void create_condition_evaluation(const expression_t *expression,
 }
 
 
-static void return_statement_to_firm(statement_t *statement)
+static void return_statement_to_firm(return_statement_t *statement)
 {
        if(get_cur_block() == NULL)
                return;
 
-       dbg_info *dbgi = get_dbg_info(&statement->source_position);
+       dbg_info *dbgi = get_dbg_info(&statement->statement.source_position);
        ir_node  *ret;
 
-       if(statement->v.return_value != NULL) {
-               ir_node *retval = expression_to_firm(statement->v.return_value);
+       if(statement->return_value != NULL) {
+               ir_node *retval = expression_to_firm(statement->return_value);
                ir_node *in[1];
 
                in[0] = retval;
@@ -1775,23 +1779,24 @@ static void return_statement_to_firm(statement_t *statement)
        set_cur_block(NULL);
 }
 
-static ir_node *expression_statement_to_firm(statement_t *statement)
+static ir_node *expression_statement_to_firm(expression_statement_t *statement)
 {
        if(get_cur_block() == NULL)
                return NULL;
 
-       return expression_to_firm(statement->v.expression);
+       return expression_to_firm(statement->expression);
 }
 
-static ir_node *compound_statement_to_firm(statement_t *compound)
+static ir_node *compound_statement_to_firm(compound_statement_t *compound)
 {
        ir_node     *result    = NULL;
-       statement_t *statement = compound->v.compound_stmt.statements;
+       statement_t *statement = compound->statements;
        for( ; statement != NULL; statement = statement->next) {
                //context2firm(&statement->context);
 
                if(statement->next == NULL && statement->type == STATEMENT_EXPRESSION) {
-                       result = expression_statement_to_firm(statement);
+                       result = expression_statement_to_firm(
+                                       (expression_statement_t*) statement);
                        break;
                }
                statement_to_firm(statement);
@@ -1800,7 +1805,7 @@ static ir_node *compound_statement_to_firm(statement_t *compound)
        return result;
 }
 
-static void if_statement_to_firm(statement_t *statement)
+static void if_statement_to_firm(if_statement_t *statement)
 {
        ir_node *cur_block = get_cur_block();
 
@@ -1808,9 +1813,9 @@ static void if_statement_to_firm(statement_t *statement)
 
        /* the true (blocks) */
        ir_node *true_block;
-       if (statement->v.if_stmt.true_statement != NULL) {
+       if (statement->true_statement != NULL) {
                true_block = new_immBlock();
-               statement_to_firm(statement->v.if_stmt.true_statement);
+               statement_to_firm(statement->true_statement);
                if(get_cur_block() != NULL) {
                        ir_node *jmp = new_Jmp();
                        add_immBlock_pred(fallthrough_block, jmp);
@@ -1821,10 +1826,10 @@ static void if_statement_to_firm(statement_t *statement)
 
        /* the false (blocks) */
        ir_node *false_block;
-       if(statement->v.if_stmt.false_statement != NULL) {
+       if(statement->false_statement != NULL) {
                false_block = new_immBlock();
 
-               statement_to_firm(statement->v.if_stmt.false_statement);
+               statement_to_firm(statement->false_statement);
                if(get_cur_block() != NULL) {
                        ir_node *jmp = new_Jmp();
                        add_immBlock_pred(fallthrough_block, jmp);
@@ -1836,7 +1841,7 @@ static void if_statement_to_firm(statement_t *statement)
        /* create the condition */
        if(cur_block != NULL) {
                set_cur_block(cur_block);
-               create_condition_evaluation(statement->v.if_stmt.condition, true_block,
+               create_condition_evaluation(statement->condition, true_block,
                                            false_block);
        }
 
@@ -1849,7 +1854,7 @@ static void if_statement_to_firm(statement_t *statement)
        set_cur_block(fallthrough_block);
 }
 
-static void while_statement_to_firm(statement_t *statement)
+static void while_statement_to_firm(while_statement_t *statement)
 {
        ir_node *jmp = NULL;
        if(get_cur_block() != NULL) {
@@ -1867,14 +1872,14 @@ static void while_statement_to_firm(statement_t *statement)
 
        /* the loop body */
        ir_node *body_block;
-       if (statement->v.while_stmt.body != NULL) {
+       if (statement->body != NULL) {
                ir_node *old_continue_label = continue_label;
                ir_node *old_break_label    = break_label;
                continue_label              = header_block;
                break_label                 = false_block;
 
                body_block = new_immBlock();
-               statement_to_firm(statement->v.while_stmt.body);
+               statement_to_firm(statement->body);
 
                assert(continue_label == header_block);
                assert(break_label    == false_block);
@@ -1892,7 +1897,7 @@ static void while_statement_to_firm(statement_t *statement)
        /* create the condition */
        set_cur_block(header_block);
 
-       create_condition_evaluation(statement->v.while_stmt.condition, body_block, false_block);
+       create_condition_evaluation(statement->condition, body_block, false_block);
        mature_immBlock(body_block);
        mature_immBlock(false_block);
        mature_immBlock(header_block);
@@ -1900,7 +1905,7 @@ static void while_statement_to_firm(statement_t *statement)
        set_cur_block(false_block);
 }
 
-static void do_while_statement_to_firm(statement_t *statement)
+static void do_while_statement_to_firm(do_while_statement_t *statement)
 {
        ir_node *jmp = NULL;
        if(get_cur_block() != NULL) {
@@ -1919,13 +1924,13 @@ static void do_while_statement_to_firm(statement_t *statement)
                add_immBlock_pred(body_block, jmp);
        }
 
-       if (statement->v.while_stmt.body != NULL) {
+       if (statement->body != NULL) {
                ir_node *old_continue_label = continue_label;
                ir_node *old_break_label    = break_label;
                continue_label              = header_block;
                break_label                 = false_block;
 
-               statement_to_firm(statement->v.while_stmt.body);
+               statement_to_firm(statement->body);
 
                assert(continue_label == header_block);
                assert(break_label    == false_block);
@@ -1947,7 +1952,7 @@ static void do_while_statement_to_firm(statement_t *statement)
        /* create the condition */
        set_cur_block(header_block);
 
-       create_condition_evaluation(statement->v.while_stmt.condition, body_block, false_block);
+       create_condition_evaluation(statement->condition, body_block, false_block);
        mature_immBlock(body_block);
        mature_immBlock(false_block);
        mature_immBlock(header_block);
@@ -1955,20 +1960,20 @@ static void do_while_statement_to_firm(statement_t *statement)
        set_cur_block(false_block);
 }
 
-static void for_statement_to_firm(statement_t *statement)
+static void for_statement_to_firm(for_statement_t *statement)
 {
        ir_node *jmp = NULL;
        if (get_cur_block() != NULL) {
-               if(statement->v.for_stmt.initialisation != NULL) {
-                       expression_to_firm(statement->v.for_stmt.initialisation);
+               if(statement->initialisation != NULL) {
+                       expression_to_firm(statement->initialisation);
                }
                jmp = new_Jmp();
        }
 
        /* create the step block */
        ir_node *const step_block = new_immBlock();
-       if (statement->v.for_stmt.step != NULL) {
-               expression_to_firm(statement->v.for_stmt.step);
+       if (statement->step != NULL) {
+               expression_to_firm(statement->step);
        }
        ir_node *const step_jmp = new_Jmp();
 
@@ -1984,14 +1989,14 @@ static void for_statement_to_firm(statement_t *statement)
 
        /* the loop body */
        ir_node * body_block;
-       if (statement->v.for_stmt.body != NULL) {
+       if (statement->body != NULL) {
                ir_node *const old_continue_label = continue_label;
                ir_node *const old_break_label    = break_label;
                continue_label = step_block;
                break_label    = false_block;
 
                body_block = new_immBlock();
-               statement_to_firm(statement->v.for_stmt.body);
+               statement_to_firm(statement->body);
 
                assert(continue_label == step_block);
                assert(break_label    == false_block);
@@ -2008,8 +2013,8 @@ static void for_statement_to_firm(statement_t *statement)
 
        /* create the condition */
        set_cur_block(header_block);
-       if (statement->v.for_stmt.condition != NULL) {
-               create_condition_evaluation(statement->v.for_stmt.condition, body_block,
+       if (statement->condition != NULL) {
+               create_condition_evaluation(statement->condition, body_block,
                                            false_block);
        } else {
                keep_alive(header_block);
@@ -2080,24 +2085,24 @@ static compound_graph_path *create_compound_path(ir_type *type,
        return path;
 }
 
-static void create_initializer_value(initializer_t *initializer,
+static void create_initializer_value(initializer_value_t *initializer,
                                      ir_entity *entity,
                                      compound_graph_path_entry_t *entry,
                                      int len)
 {
-       ir_node             *node = expression_to_firm(initializer->v.value);
+       ir_node             *node = expression_to_firm(initializer->value);
        ir_type             *type = get_entity_type(entity);
        compound_graph_path *path = create_compound_path(type, entry, len);
        add_compound_ent_value_w_path(entity, node, path);
 }
 
-static void create_initializer_compound(initializer_t *initializer,
-                                        type_t *type,
+static void create_initializer_compound(initializer_list_t *initializer,
+                                        compound_type_t *type,
                                         ir_entity *entity,
                                         compound_graph_path_entry_t *last_entry,
                                         int len)
 {
-       declaration_t *compound_declaration = type->v.compound_type.declaration;
+       declaration_t *compound_declaration = type->declaration;
 
        declaration_t *compound_entry = compound_declaration->context.declarations;
 
@@ -2113,19 +2118,20 @@ static void create_initializer_compound(initializer_t *initializer,
                if(compound_entry->namespc != NAMESPACE_NORMAL)
                        continue;
 
-               if(i >= initializer->v.list.len)
+               if(i >= initializer->len)
                        break;
 
                entry.v.entity = compound_entry->v.entity;
 
-               initializer_t *sub_initializer = initializer->v.list.initializers[i];
+               initializer_t *sub_initializer = initializer->initializers[i];
 
                assert(compound_entry != NULL);
                assert(compound_entry->declaration_type
                                == DECLARATION_TYPE_COMPOUND_MEMBER);
 
                if(sub_initializer->type == INITIALIZER_VALUE) {
-                       create_initializer_value(sub_initializer, entity, &entry, len);
+                       create_initializer_value(&sub_initializer->value,
+                                                entity, &entry, len);
                } else {
                        type_t *type = skip_typeref(compound_entry->type);
                        create_initializer_object(sub_initializer, type, entity, &entry,
@@ -2136,12 +2142,12 @@ static void create_initializer_compound(initializer_t *initializer,
        }
 }
 
-static void create_initializer_array(initializer_t *initializer,
-                                     type_t *type, ir_entity *entity,
+static void create_initializer_array(initializer_list_t *initializer,
+                                     array_type_t *type, ir_entity *entity,
                                      compound_graph_path_entry_t *last_entry,
                                      int len)
 {
-       type_t *element_type = type->v.array_type.element_type;
+       type_t *element_type = type->element_type;
        element_type         = skip_typeref(element_type);
 
        compound_graph_path_entry_t entry;
@@ -2149,27 +2155,27 @@ static void create_initializer_array(initializer_t *initializer,
        entry.prev = last_entry;
        ++len;
 
-       for(size_t i = 0; i < initializer->v.list.len; ++i) {
+       for(size_t i = 0; i < initializer->len; ++i) {
                entry.v.array_index = i;
 
-               initializer_t *sub_initializer = initializer->v.list.initializers[i];
+               initializer_t *sub_initializer = initializer->initializers[i];
 
                if(sub_initializer->type == INITIALIZER_VALUE) {
-                       create_initializer_value(sub_initializer, entity, &entry, len);
+                       create_initializer_value(&sub_initializer->value,
+                                                entity, &entry, len);
                } else {
-                       assert(sub_initializer->type == INITIALIZER_LIST);
                        create_initializer_object(sub_initializer, element_type, entity,
                                                  &entry, len);
                }
        }
 }
 
-static void create_initializer_string(initializer_t *initializer,
-                                      type_t *type, ir_entity *entity,
+static void create_initializer_string(initializer_string_t *initializer,
+                                      array_type_t *type, ir_entity *entity,
                                       compound_graph_path_entry_t *last_entry,
                                       int len)
 {
-       type_t *element_type = type->v.array_type.element_type;
+       type_t *element_type = type->element_type;
        element_type         = skip_typeref(element_type);
 
        compound_graph_path_entry_t entry;
@@ -2179,7 +2185,7 @@ static void create_initializer_string(initializer_t *initializer,
 
        ir_type    *irtype  = get_entity_type(entity);
        size_t      arr_len = get_array_type_size(type);
-       const char *p       = initializer->v.string;
+       const char *p       = initializer->string;
        size_t      i       = 0;
        for(i = 0; i < arr_len; ++i, ++p) {
                entry.v.array_index = i;
@@ -2197,18 +2203,24 @@ static void create_initializer_object(initializer_t *initializer, type_t *type,
                ir_entity *entity, compound_graph_path_entry_t *entry, int len)
 {
        if(type->type == TYPE_ARRAY) {
+               array_type_t *array_type = (array_type_t*) type;
+
                if(initializer->type == INITIALIZER_STRING) {
-                       create_initializer_string(initializer, type, entity, entry, len);
+                       initializer_string_t *string = &initializer->string;
+                       create_initializer_string(string, array_type, entity, entry, len);
                } else {
                        assert(initializer->type == INITIALIZER_LIST);
-                       create_initializer_array(initializer, type, entity, entry, len);
+                       initializer_list_t *list = &initializer->list;
+                       create_initializer_array(list, array_type, entity, entry, len);
                }
        } else {
                assert(initializer->type == INITIALIZER_LIST);
+               initializer_list_t *list = &initializer->list;
 
                assert(type->type == TYPE_COMPOUND_STRUCT
                                || type->type == TYPE_COMPOUND_UNION);
-               create_initializer_compound(initializer, type, entity, entry, len);
+               compound_type_t *compound_type = (compound_type_t*) type;
+               create_initializer_compound(list, compound_type, entity, entry, len);
        }
 }
 
@@ -2224,8 +2236,9 @@ static void create_initializer_local_variable_entity(declaration_t *declaration)
 
        if(is_atomic_entity(entity)) {
                assert(initializer->type == INITIALIZER_VALUE);
+               initializer_value_t *initializer_value = &initializer->value;
 
-               ir_node *value     = expression_to_firm(initializer->v.value);
+               ir_node *value     = expression_to_firm(initializer_value->value);
                ir_node *store     = new_d_Store(dbgi, memory, addr, value);
                ir_node *store_mem = new_d_Proj(dbgi, store, mode_M, pn_Store_M);
                set_store(store_mem);
@@ -2271,7 +2284,9 @@ static void create_initializer(declaration_t *declaration)
        }
 
        if(initializer->type == INITIALIZER_VALUE) {
-               ir_node *value = expression_to_firm(initializer->v.value);
+               initializer_value_t *initializer_value = &initializer->value;
+
+               ir_node *value = expression_to_firm(initializer_value->value);
 
                if(declaration_type == DECLARATION_TYPE_LOCAL_VARIABLE) {
                        set_value(declaration->v.value_number, value);
@@ -2348,10 +2363,10 @@ static void create_local_static_variable(declaration_t *declaration)
        current_ir_graph = old_current_ir_graph;
 }
 
-static void declaration_statement_to_firm(statement_t *statement)
+static void declaration_statement_to_firm(declaration_statement_t *statement)
 {
-       declaration_t *declaration = statement->v.declaration_stmt.begin;
-       declaration_t *end         = statement->v.declaration_stmt.end->next;
+       declaration_t *declaration = statement->declarations_begin;
+       declaration_t *end         = statement->declarations_end->next;
        for( ; declaration != end; declaration = declaration->next) {
                type_t *type = declaration->type;
 
@@ -2392,11 +2407,11 @@ static void create_jump_statement(const statement_t *statement,
        set_cur_block(NULL);
 }
 
-static void switch_statement_to_firm(const statement_t *statement)
+static void switch_statement_to_firm(const switch_statement_t *statement)
 {
-       dbg_info *dbgi = get_dbg_info(&statement->source_position);
+       dbg_info *dbgi = get_dbg_info(&statement->statement.source_position);
 
-       ir_node *expression  = expression_to_firm(statement->v.switch_stmt.expression);
+       ir_node *expression  = expression_to_firm(statement->expression);
        ir_node *cond        = new_d_Cond(dbgi, expression);
        ir_node *break_block = new_immBlock();
 
@@ -2408,7 +2423,7 @@ static void switch_statement_to_firm(const statement_t *statement)
        current_switch_cond                  = cond;
        break_label                          = break_block;
 
-       statement_to_firm(statement->v.switch_stmt.body);
+       statement_to_firm(statement->body);
 
        if(get_cur_block() != NULL) {
                ir_node *jmp = new_Jmp();
@@ -2439,7 +2454,7 @@ static long fold_constant(const expression_t *expression)
 
        ir_node *cnst = expression_to_firm(expression);
        if(!is_Const(cnst)) {
-               panic("couldn't fold constant");
+               panic("couldn't fold constantl");
        }
        tarval *tv = get_Const_tarval(cnst);
        if(!tarval_is_long(tv)) {
@@ -2452,9 +2467,9 @@ static long fold_constant(const expression_t *expression)
        return res;
 }
 
-static void case_label_to_firm(const statement_t *statement)
+static void case_label_to_firm(const case_label_statement_t *statement)
 {
-       dbg_info *dbgi = get_dbg_info(&statement->source_position);
+       dbg_info *dbgi = get_dbg_info(&statement->statement.source_position);
 
        ir_node *const fallthrough = (get_cur_block() == NULL ? NULL : new_Jmp());
 
@@ -2462,8 +2477,8 @@ static void case_label_to_firm(const statement_t *statement)
         * node... */
        ir_node *proj;
        set_cur_block(get_nodes_block(current_switch_cond));
-       if(statement->v.case_label_stmt.expression) {
-               long pn = fold_constant(statement->v.case_label_stmt.expression);
+       if(statement->expression) {
+               long pn = fold_constant(statement->expression);
                if(pn == MAGIC_DEFAULT_PN_NUMBER) {
                        /* oops someone detected our cheating... */
                        panic("magic default pn used");
@@ -2482,7 +2497,7 @@ static void case_label_to_firm(const statement_t *statement)
        add_immBlock_pred(block, proj);
        mature_immBlock(block);
 
-       statement_to_firm(statement->v.case_label_stmt.label_statement);
+       statement_to_firm(statement->label_statement);
 }
 
 static ir_node *get_label_block(declaration_t *label)
@@ -2506,9 +2521,9 @@ static ir_node *get_label_block(declaration_t *label)
        return block;
 }
 
-static void label_to_firm(const statement_t *statement)
+static void label_to_firm(const label_statement_t *statement)
 {
-       ir_node *block = get_label_block(statement->v.label_stmt.label);
+       ir_node *block = get_label_block(statement->label);
 
        if(get_cur_block() != NULL) {
                ir_node *jmp = new_Jmp();
@@ -2518,15 +2533,15 @@ static void label_to_firm(const statement_t *statement)
        set_cur_block(block);
        keep_alive(block);
 
-       statement_to_firm(statement->v.label_stmt.label_statement);
+       statement_to_firm(statement->label_statement);
 }
 
-static void goto_to_firm(const statement_t *statement)
+static void goto_to_firm(const goto_statement_t *statement)
 {
        if(get_cur_block() == NULL)
                return;
 
-       ir_node *block = get_label_block(statement->v.goto_label);
+       ir_node *block = get_label_block(statement->label);
        ir_node *jmp   = new_Jmp();
        add_immBlock_pred(block, jmp);
 
@@ -2537,25 +2552,25 @@ static void statement_to_firm(statement_t *statement)
 {
        switch(statement->type) {
        case STATEMENT_COMPOUND:
-               compound_statement_to_firm(statement);
+               compound_statement_to_firm((compound_statement_t*) statement);
                return;
        case STATEMENT_RETURN:
-               return_statement_to_firm(statement);
+               return_statement_to_firm((return_statement_t*) statement);
                return;
        case STATEMENT_EXPRESSION:
-               expression_statement_to_firm(statement);
+               expression_statement_to_firm((expression_statement_t*) statement);
                return;
        case STATEMENT_IF:
-               if_statement_to_firm(statement);
+               if_statement_to_firm((if_statement_t*) statement);
                return;
        case STATEMENT_WHILE:
-               while_statement_to_firm(statement);
+               while_statement_to_firm((while_statement_t*) statement);
                return;
        case STATEMENT_DO_WHILE:
-               do_while_statement_to_firm(statement);
+               do_while_statement_to_firm((do_while_statement_t*) statement);
                return;
        case STATEMENT_DECLARATION:
-               declaration_statement_to_firm(statement);
+               declaration_statement_to_firm((declaration_statement_t*) statement);
                return;
        case STATEMENT_BREAK:
                create_jump_statement(statement, break_label);
@@ -2564,19 +2579,19 @@ static void statement_to_firm(statement_t *statement)
                create_jump_statement(statement, continue_label);
                return;
        case STATEMENT_SWITCH:
-               switch_statement_to_firm(statement);
+               switch_statement_to_firm((switch_statement_t*) statement);
                return;
        case STATEMENT_CASE_LABEL:
-               case_label_to_firm(statement);
+               case_label_to_firm((case_label_statement_t*) statement);
                return;
        case STATEMENT_FOR:
-               for_statement_to_firm(statement);
+               for_statement_to_firm((for_statement_t*) statement);
                return;
        case STATEMENT_LABEL:
-               label_to_firm(statement);
+               label_to_firm((label_statement_t*) statement);
                return;
        case STATEMENT_GOTO:
-               goto_to_firm(statement);
+               goto_to_firm((goto_statement_t*) statement);
                return;
        default:
                break;
@@ -2608,39 +2623,61 @@ static int count_decls_in_stmts(const statement_t *stmt)
        int count = 0;
        for (; stmt != NULL; stmt = stmt->next) {
                switch (stmt->type) {
-                       case STATEMENT_DECLARATION:
-                               count += count_local_declarations(stmt->v.declaration_stmt.begin,
-                                                                 stmt->v.declaration_stmt.end->next);
+                       case STATEMENT_DECLARATION: {
+                               const declaration_statement_t *const decl_stmt =
+                                       (const declaration_statement_t*)stmt;
+                               count += count_local_declarations(decl_stmt->declarations_begin,
+                                                                 decl_stmt->declarations_end->next);
                                break;
+                       }
 
-                       case STATEMENT_COMPOUND:
-                               count += count_decls_in_stmts(stmt->v.compound_stmt.statements);
+                       case STATEMENT_COMPOUND: {
+                               const compound_statement_t *const comp =
+                                       (const compound_statement_t*)stmt;
+                               count += count_decls_in_stmts(comp->statements);
                                break;
+                       }
 
-                       case STATEMENT_IF:
-                               count += count_decls_in_stmts(stmt->v.if_stmt.true_statement);
-                               count += count_decls_in_stmts(stmt->v.if_stmt.false_statement);
+                       case STATEMENT_IF: {
+                               const if_statement_t *const if_stmt = (const if_statement_t*)stmt;
+                               count += count_decls_in_stmts(if_stmt->true_statement);
+                               count += count_decls_in_stmts(if_stmt->false_statement);
                                break;
+                       }
 
-                       case STATEMENT_SWITCH:
-                               count += count_decls_in_stmts(stmt->v.switch_stmt.body);
+                       case STATEMENT_SWITCH: {
+                               const switch_statement_t *const switch_stmt =
+                                       (const switch_statement_t*)stmt;
+                               count += count_decls_in_stmts(switch_stmt->body);
                                break;
+                       }
 
-                       case STATEMENT_LABEL:
-                               count += count_decls_in_stmts(stmt->v.label_stmt.label_statement);
+                       case STATEMENT_LABEL: {
+                               const label_statement_t *const label_stmt =
+                                       (const label_statement_t*)stmt;
+                               count += count_decls_in_stmts(label_stmt->label_statement);
                                break;
+                       }
 
-                       case STATEMENT_WHILE:
-                               count += count_decls_in_stmts(stmt->v.while_stmt.body);
+                       case STATEMENT_WHILE: {
+                               const while_statement_t *const while_stmt =
+                                       (const while_statement_t*)stmt;
+                               count += count_decls_in_stmts(while_stmt->body);
                                break;
+                       }
 
-                       case STATEMENT_DO_WHILE:
-                               count += count_decls_in_stmts(stmt->v.while_stmt.body);
+                       case STATEMENT_DO_WHILE: {
+                               const do_while_statement_t *const do_while_stmt =
+                                       (const do_while_statement_t*)stmt;
+                               count += count_decls_in_stmts(do_while_stmt->body);
                                break;
+                       }
 
                        case STATEMENT_FOR: {
+                               const for_statement_t *const for_stmt =
+                                       (const for_statement_t*)stmt;
                                /* TODO initialisation */
-                               count += count_decls_in_stmts(stmt->v.for_stmt.body);
+                               count += count_decls_in_stmts(for_stmt->body);
                                break;
                        }
 
@@ -2743,12 +2780,13 @@ static void create_function(declaration_t *declaration)
        /* do we have a return statement yet? */
        if(get_cur_block() != NULL) {
                assert(declaration->type->type == TYPE_FUNCTION);
-               const type_t* const type = declaration->type;
+               const function_type_t* const func_type
+                       = (const function_type_t*) declaration->type;
                ir_node *ret;
-               if (type->v.function_type.result_type == type_void) {
+               if (func_type->result_type == type_void) {
                        ret = new_Return(get_store(), 0, NULL);
                } else {
-                       ir_mode *const mode = get_ir_mode(type->v.function_type.result_type);
+                       ir_mode *const mode = get_ir_mode(func_type->result_type);
                        ir_node *      in[1];
                        // Â§5.1.2.2.3 main implicitly returns 0
                        if (strcmp(declaration->symbol->string, "main") == 0) {
diff --git a/ast_t.h b/ast_t.h
index ca5ad73..902a2ce 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"
@@ -217,22 +218,36 @@ typedef enum {
 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 {
@@ -288,58 +303,79 @@ struct statement_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_t   statement;
+       expression_t *return_value;
+};
+
+struct compound_statement_t {
+       statement_t  statement;
+       statement_t *statements;
+       context_t    context;
+};
+
+struct declaration_statement_t {
+       statement_t    statement;
+       declaration_t *declarations_begin;
+       declaration_t *declarations_end;
+};
+
+struct if_statement_t {
+       statement_t   statement;
+       expression_t *condition;
+       statement_t  *true_statement;
+       statement_t  *false_statement;
+};
+
+struct switch_statement_t {
+       statement_t   statement;
+       expression_t *expression;
+       statement_t  *body;
+};
+
+struct goto_statement_t {
+       statement_t    statement;
+       declaration_t *label;
+};
+
+struct case_label_statement_t {
+       statement_t   statement;
+       expression_t *expression;
+       statement_t  *label_statement;
+};
+
+struct label_statement_t {
+       statement_t    statement;
+       declaration_t *label;
+       statement_t   *label_statement;
+};
+
+struct expression_statement_t {
+       statement_t   statement;
+       expression_t *expression;
+};
+
+struct while_statement_t {
+       statement_t   statement;
+       expression_t *condition;
+       statement_t  *body;
+};
+
+struct do_while_statement_t {
+       statement_t   statement;
+       expression_t *condition;
+       statement_t  *body;
+};
+
+struct for_statement_t {
+       statement_t   statement;
+       expression_t  *initialisation;
+       expression_t  *condition;
+       expression_t  *step;
+       statement_t   *body;
+       context_t      context;
 };
 
 struct translation_unit_t {
index 258d139..d1f4930 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -120,6 +120,26 @@ static inline void *allocate_type_zero(size_t size)
        return res;
 }
 
+static inline size_t get_initializer_size(initializer_type_t type)
+{
+       static const size_t size[] = {
+               [INITIALIZER_VALUE]  = sizeof(initializer_value_t),
+               [INITIALIZER_STRING] = sizeof(initializer_string_t),
+               [INITIALIZER_LIST]   = sizeof(initializer_list_t)
+       };
+       assert(type < INITIALIZER_COUNT);
+       assert(size[type] != 0);
+       return size[type];
+}
+
+static inline initializer_t *allocate_initializer(initializer_type_t type)
+{
+       initializer_t *result = allocate_ast_zero(get_initializer_size(type));
+       result->type          = type;
+
+       return result;
+}
+
 static inline void free_type(void *type)
 {
        obstack_free(type_obst, type);
@@ -437,8 +457,8 @@ static declaration_t *stack_push(stack_entry_t **stack_ptr,
                        print_type_quoted(previous_declaration->type);
                        fputc('\n', stderr);
                } else {
-                       const storage_class_t old_storage = (storage_class_t)previous_declaration->storage_class;
-                       const storage_class_t new_storage = (storage_class_t)declaration->storage_class;
+                       const storage_class_t old_storage = previous_declaration->storage_class;
+                       const storage_class_t new_storage = declaration->storage_class;
                        if (current_function == NULL) {
                                if (old_storage != STORAGE_CLASS_STATIC &&
                                    new_storage == STORAGE_CLASS_STATIC) {
@@ -596,14 +616,15 @@ static int get_rank(const type_t *type)
 {
        /* The C-standard allows promoting to int or unsigned int (see Â§ 7.2.2
         * and esp. footnote 108). However we can't fold constants (yet), so we
-        * can't decide whether unsigned int is possible, while int always works.
+        * can't decide wether unsigned int is possible, while int always works.
         * (unsigned int would be preferable when possible... for stuff like
         *  struct { enum { ... } bla : 4; } ) */
        if(type->type == TYPE_ENUM)
                return ATOMIC_TYPE_INT;
 
        assert(type->type == TYPE_ATOMIC);
-       atomic_type_type_t atype = type->v.atomic_type.atype;
+       atomic_type_t      *atomic_type = (atomic_type_t*) type;
+       atomic_type_type_t  atype       = atomic_type->atype;
        return atype;
 }
 
@@ -686,9 +707,11 @@ static expression_t *create_implicit_cast(expression_t *expression,
                                        break;
 
                                case TYPE_ARRAY: {
-                                       type_t *const array_type = source_type;
-                                       if (types_compatible(array_type->v.array_type.element_type,
-                                                                                                                        dest_type->v.pointer_type.points_to)) {
+                                       array_type_t   *array_type = (array_type_t*) source_type;
+                                       pointer_type_t *pointer_type
+                                               = (pointer_type_t*) dest_type;
+                                       if (types_compatible(array_type->element_type,
+                                                                                pointer_type->points_to)) {
                                                return create_cast_expression(expression, dest_type);
                                        }
                                        break;
@@ -712,7 +735,9 @@ static bool is_atomic_type(const type_t *type, atomic_type_type_t atype)
 {
        if(type->type != TYPE_ATOMIC)
                return false;
-       return type->v.atomic_type.atype == atype;
+       const atomic_type_t *atomic_type = (const atomic_type_t*) type;
+
+       return atomic_type->atype == atype;
 }
 
 static bool is_pointer(const type_t *type)
@@ -747,10 +772,10 @@ static void semantic_assign(type_t *orig_type_left, expression_t **right,
        }
 
        if (is_pointer(type_left) && is_pointer(type_right)) {
-               type_t *pointer_type_left  = type_left;
-               type_t *pointer_type_right = type_right;
-               type_t *points_to_left     = pointer_type_left->v.pointer_type.points_to;
-               type_t *points_to_right    = pointer_type_right->v.pointer_type.points_to;
+               pointer_type_t *pointer_type_left  = (pointer_type_t*) type_left;
+               pointer_type_t *pointer_type_right = (pointer_type_t*) type_right;
+               type_t         *points_to_left     = pointer_type_left->points_to;
+               type_t         *points_to_right    = pointer_type_right->points_to;
 
                if(!is_atomic_type(points_to_left, ATOMIC_TYPE_VOID)
                                && !is_atomic_type(points_to_right, ATOMIC_TYPE_VOID)
@@ -842,7 +867,8 @@ static void parse_attributes(void)
                        next_token();
 
                        expect_void('(');
-                       for (int depth = 1; depth > 0;) {
+                       int depth = 1;
+                       while(depth > 0) {
                                switch(token.type) {
                                case T_EOF:
                                        parse_error("EOF while parsing attribute");
@@ -927,16 +953,14 @@ static designator_t *parse_designation(void)
 }
 #endif
 
-static initializer_t *initializer_from_string(type_t *type, const char *string)
+static initializer_t *initializer_from_string(array_type_t *type,
+                                              const char *string)
 {
        /* TODO: check len vs. size of array type */
        (void) type;
 
-       initializer_t *initializer
-               = allocate_ast_zero(sizeof(initializer[0]));
-
-       initializer->type     = INITIALIZER_STRING;
-       initializer->v.string = string;
+       initializer_t *initializer = allocate_initializer(INITIALIZER_STRING);
+       initializer->string.string = string;
 
        return initializer;
 }
@@ -949,10 +973,12 @@ static initializer_t *initializer_from_expression(type_t *type,
 
        /* Â§ 6.7.8.14/15 char array may be initialized by string literals */
        if(type->type == TYPE_ARRAY && expression->type == EXPR_STRING_LITERAL) {
-               type_t *element_type = type->v.array_type.element_type;
+               array_type_t *array_type   = (array_type_t*) type;
+               type_t       *element_type = array_type->element_type;
 
                if(element_type->type == TYPE_ATOMIC) {
-                       atomic_type_type_t atype = element_type->v.atomic_type.atype;
+                       atomic_type_t      *atomic_type = (atomic_type_t*) element_type;
+                       atomic_type_type_t  atype       = atomic_type->atype;
 
                        /* TODO handle wide strings */
                        if(atype == ATOMIC_TYPE_CHAR
@@ -960,16 +986,15 @@ static initializer_t *initializer_from_expression(type_t *type,
                                        || atype == ATOMIC_TYPE_UCHAR) {
 
                                string_literal_t *literal = (string_literal_t*) expression;
-                               return initializer_from_string(type, literal->value);
+                               return initializer_from_string(array_type, literal->value);
                        }
                }
        }
 
        semantic_assign(type, &expression, "initializer");
 
-       initializer_t *result = allocate_ast_zero(sizeof(result[0]));
-       result->type    = INITIALIZER_VALUE;
-       result->v.value = expression;
+       initializer_t *result = allocate_initializer(INITIALIZER_VALUE);
+       result->value.value   = expression;
 
        return result;
 }
@@ -1022,13 +1047,12 @@ static initializer_t *parse_sub_initializer(type_t *type,
        /* TODO: ignore qualifiers, comparing pointers is probably
         * not correct */
        if(expression != NULL && expression_type == type) {
-               initializer_t *result = allocate_ast_zero(sizeof(result[0]));
-               result->type          = INITIALIZER_VALUE;
+               initializer_t *result = allocate_initializer(INITIALIZER_VALUE);
 
                if(type != NULL) {
                        semantic_assign(type, &expression, "initializer");
                }
-               result->v.value = expression;
+               result->value.value = expression;
 
                return result;
        }
@@ -1043,8 +1067,9 @@ static initializer_t *parse_sub_initializer(type_t *type,
        initializer_t  *result = NULL;
        initializer_t **elems;
        if(type->type == TYPE_ARRAY) {
-               type_t *element_type = type->v.array_type.element_type;
-               element_type         = skip_typeref(element_type);
+               array_type_t *array_type   = (array_type_t*) type;
+               type_t       *element_type = array_type->element_type;
+               element_type               = skip_typeref(element_type);
 
                initializer_t *sub;
                had_initializer_brace_warning = false;
@@ -1084,7 +1109,8 @@ static initializer_t *parse_sub_initializer(type_t *type,
        } else {
                assert(type->type == TYPE_COMPOUND_STRUCT
                                || type->type == TYPE_COMPOUND_UNION);
-               context_t *context = &type->v.compound_type.declaration->context;
+               compound_type_t *compound_type = (compound_type_t*) type;
+               context_t       *context       = & compound_type->declaration->context;
 
                declaration_t *first = context->declarations;
                if(first == NULL)
@@ -1137,14 +1163,14 @@ static initializer_t *parse_sub_initializer(type_t *type,
        int    len        = ARR_LEN(elems);
        size_t elems_size = sizeof(initializer_t*) * len;
 
-       initializer_t *init = allocate_ast_zero(sizeof(init[0]) + elems_size);
+       initializer_list_t *init = allocate_ast_zero(sizeof(init[0]) + elems_size);
 
-       init->type       = INITIALIZER_LIST;
-       init->v.list.len = len;
-       memcpy(init->v.list.initializers, elems, elems_size);
+       init->initializer.type = INITIALIZER_LIST;
+       init->len              = len;
+       memcpy(init->initializers, elems, elems_size);
        DEL_ARR_F(elems);
 
-       result = init;
+       result = (initializer_t*) init;
 
        if(read_paren) {
                if(token.type == ',')
@@ -1261,7 +1287,7 @@ static declaration_t *parse_compound_type_specifier(bool is_struct)
        return declaration;
 }
 
-static void parse_enum_entries(type_t *const enum_type)
+static void parse_enum_entries(enum_type_t *const enum_type)
 {
        eat('{');
 
@@ -1280,7 +1306,7 @@ static void parse_enum_entries(type_t *const enum_type)
                        return;
                }
                entry->storage_class   = STORAGE_CLASS_ENUM_ENTRY;
-               entry->type            = enum_type;
+               entry->type            = (type_t*) enum_type;
                entry->symbol          = token.v.symbol;
                entry->source_position = token.source_position;
                next_token();
@@ -1331,9 +1357,9 @@ static type_t *parse_enum_specifier(void)
                declaration->symbol          = symbol;
        }
 
-       type_t *const enum_type = allocate_type_zero(sizeof(enum_type[0]));
-       enum_type->type        = TYPE_ENUM;
-       enum_type->v.enum_type.declaration = declaration;
+       enum_type_t *const enum_type = allocate_type_zero(sizeof(enum_type[0]));
+       enum_type->type.type         = TYPE_ENUM;
+       enum_type->declaration       = declaration;
 
        if(token.type == '{') {
                if(declaration->init.is_defined) {
@@ -1348,7 +1374,7 @@ static type_t *parse_enum_specifier(void)
                parse_attributes();
        }
 
-       return enum_type;
+       return (type_t*) enum_type;
 }
 
 /**
@@ -1404,12 +1430,12 @@ restart:
 
        expect(')');
 
-       type_t *typeof = allocate_type_zero(sizeof(typeof[0]));
-       typeof->type   = TYPE_TYPEOF;
-       typeof->v.typeof_type.expression  = expression;
-       typeof->v.typeof_type.typeof_type = type;
+       typeof_type_t *typeof = allocate_type_zero(sizeof(typeof[0]));
+       typeof->type.type     = TYPE_TYPEOF;
+       typeof->expression    = expression;
+       typeof->typeof_type   = type;
 
-       return typeof;
+       return (type_t*) typeof;
 }
 
 typedef enum {
@@ -1432,13 +1458,13 @@ typedef enum {
 
 static type_t *create_builtin_type(symbol_t *symbol)
 {
-       type_t *type = allocate_type_zero(sizeof(type[0]));
-       type->type   = TYPE_BUILTIN;
-       type->v.builtin_type.symbol    = symbol;
+       builtin_type_t *type = allocate_type_zero(sizeof(type[0]));
+       type->type.type      = TYPE_BUILTIN;
+       type->symbol         = symbol;
        /* TODO... */
-       type->v.builtin_type.real_type = type_int;
+       type->real_type      = type_int;
 
-       return type;
+       return (type_t*) type;
 }
 
 static type_t *get_typedef_type(symbol_t *symbol)
@@ -1448,19 +1474,19 @@ static type_t *get_typedef_type(symbol_t *symbol)
                        || declaration->storage_class != STORAGE_CLASS_TYPEDEF)
                return NULL;
 
-       type_t *type = allocate_type_zero(sizeof(type[0]));
-       type->type   = TYPE_TYPEDEF;
-       type->v.typedef_type.declaration = declaration;
+       typedef_type_t *typedef_type = allocate_type_zero(sizeof(typedef_type[0]));
+       typedef_type->type.type    = TYPE_TYPEDEF;
+       typedef_type->declaration  = declaration;
 
-       return type;
+       return (type_t*) typedef_type;
 }
 
 static void parse_declaration_specifiers(declaration_specifiers_t *specifiers)
 {
-       type_t            *type            = NULL;
-       type_qualifiers_t type_qualifiers = TYPE_QUALIFIER_NONE;
-       unsigned          type_specifiers = 0;
-       int               newtype         = 0;
+       type_t        *type            = NULL;
+       unsigned       type_qualifiers = 0;
+       unsigned       type_specifiers = 0;
+       int            newtype         = 0;
 
        while(true) {
                switch(token.type) {
@@ -1540,18 +1566,22 @@ static void parse_declaration_specifiers(declaration_specifiers_t *specifiers)
 
                /* TODO: if type != NULL for the following rules should issue
                 * an error */
-               case T_struct:
-                       type       = allocate_type_zero(sizeof(type[0]));
-                       type->type = TYPE_COMPOUND_STRUCT;
-                       type->v.compound_type.declaration = parse_compound_type_specifier(true);
+               case T_struct: {
+                       type = allocate_type_zero(sizeof(struct compound_type_t));
 
+                       compound_type_t *compound_type = (compound_type_t*) type;
+                       compound_type->type.type   = TYPE_COMPOUND_STRUCT;
+                       compound_type->declaration = parse_compound_type_specifier(true);
                        break;
-               case T_union:
-                       type       = allocate_type_zero(sizeof(type[0]));
-                       type->type = TYPE_COMPOUND_UNION;
-                       type->v.compound_type.declaration = parse_compound_type_specifier(false);
+               }
+               case T_union: {
+                       type = allocate_type_zero(sizeof(compound_type_t));
 
+                       compound_type_t *compound_type = (compound_type_t*) type;
+                       compound_type->type.type   = TYPE_COMPOUND_UNION;
+                       compound_type->declaration = parse_compound_type_specifier(false);
                        break;
+               }
                case T_enum:
                        type = parse_enum_specifier();
                        break;
@@ -1698,20 +1728,22 @@ finish_specifiers:
                        atomic_type = ATOMIC_TYPE_INVALID;
                }
 
-               type       = allocate_type_zero(sizeof(type[0]));
-               type->type = TYPE_ATOMIC;
-               type->v.atomic_type.atype = atomic_type;
-               newtype = 1;
+               atomic_type_t *atype = allocate_type_zero(sizeof(atype[0]));
+               atype->type.type     = TYPE_ATOMIC;
+               atype->atype         = atomic_type;
+               newtype              = 1;
+
+               type = (type_t*) atype;
        } else {
                if(type_specifiers != 0) {
                        parse_error("multiple datatypes in declaration");
                }
        }
 
-       type->qualifiers = type_qualifiers;
+       type->qualifiers = (type_qualifier_t)type_qualifiers;
 
        type_t *result = typehash_insert(type);
-       if(newtype && result != type) {
+       if(newtype && result != (type_t*) type) {
                free_type(type);
        }
 
@@ -1765,18 +1797,19 @@ static declaration_t *parse_parameter(void)
                parse_error("typedef not allowed in parameter list");
        }
 
-       /* Array as last part of a parameter type is just syntactic sugar.  Turn it
+       /* Array as last part of a paramter type is just syntactic sugar.  Turn it
         * into a pointer */
        if (declaration->type->type == TYPE_ARRAY) {
-               const type_t *const arr_type = declaration->type;
+               const array_type_t *const arr_type =
+                       (const array_type_t*)declaration->type;
                declaration->type =
-                       make_pointer_type(arr_type->v.array_type.element_type, TYPE_QUALIFIER_NONE);
+                       make_pointer_type(arr_type->element_type, TYPE_QUALIFIER_NONE);
        }
 
        return declaration;
 }
 
-static declaration_t *parse_parameters(type_t *type)
+static declaration_t *parse_parameters(function_type_t *type)
 {
        if(token.type == T_IDENTIFIER) {
                symbol_t      *symbol = token.v.symbol;
@@ -1788,7 +1821,7 @@ static declaration_t *parse_parameters(type_t *type)
        }
 
        if(token.type == ')') {
-               type->v.function_type.unspecified_parameters = 1;
+               type->unspecified_parameters = 1;
                return NULL;
        }
        if(token.type == T_void && look_ahead(1)->type == ')') {
@@ -1806,7 +1839,7 @@ static declaration_t *parse_parameters(type_t *type)
                switch(token.type) {
                case T_DOTDOTDOT:
                        next_token();
-                       type->v.function_type.variadic = 1;
+                       type->variadic = 1;
                        return declarations;
 
                case T_IDENTIFIER:
@@ -1821,7 +1854,7 @@ static declaration_t *parse_parameters(type_t *type)
                                last_declaration->next = declaration;
                                last_parameter->next   = parameter;
                        } else {
-                               type->v.function_type.parameters = parameter;
+                               type->parameters = parameter;
                                declarations     = declaration;
                        }
                        last_parameter   = parameter;
@@ -1859,7 +1892,7 @@ struct parsed_pointer_t {
 typedef struct construct_function_type_t construct_function_type_t;
 struct construct_function_type_t {
        construct_type_t    construct_type;
-       type_t             *function_type;
+       function_type_t    *function_type;
 };
 
 typedef struct parsed_array_t parsed_array_t;
@@ -1927,8 +1960,8 @@ static construct_type_t *parse_function_declarator(declaration_t *declaration)
 {
        eat('(');
 
-       type_t *type = allocate_type_zero(sizeof(type[0]));
-       type->type   = TYPE_FUNCTION;
+       function_type_t *type = allocate_type_zero(sizeof(type[0]));
+       type->type.type       = TYPE_FUNCTION;
 
        declaration_t *parameters = parse_parameters(type);
        if(declaration != NULL) {
@@ -2052,46 +2085,46 @@ static type_t *construct_declarator_type(construct_type_t *construct_list,
                parsed_pointer_t          *parsed_pointer;
                parsed_array_t            *parsed_array;
                construct_function_type_t *construct_function_type;
-               type_t                    *ftype;
-               type_t                    *ptype;
-               type_t                    *atype;
+               function_type_t           *function_type;
+               pointer_type_t            *pointer_type;
+               array_type_t              *array_type;
 
                switch(iter->type) {
                case CONSTRUCT_INVALID:
                        panic("invalid type construction found");
                case CONSTRUCT_FUNCTION:
                        construct_function_type = (construct_function_type_t*) iter;
-                       ftype                   = construct_function_type->function_type;
+                       function_type           = construct_function_type->function_type;
 
-                       ftype->v.function_type.result_type = type;
-                       type                               = ftype;
+                       function_type->result_type = type;
+                       type                       = (type_t*) function_type;
                        break;
 
                case CONSTRUCT_POINTER:
                        parsed_pointer = (parsed_pointer_t*) iter;
-                       ptype          = allocate_type_zero(sizeof(ptype[0]));
+                       pointer_type   = allocate_type_zero(sizeof(pointer_type[0]));
 
-                       ptype->type                     = TYPE_POINTER;
-                       ptype->v.pointer_type.points_to = type;
-                       ptype->qualifiers               = parsed_pointer->type_qualifiers;
-                       type                            = ptype;
+                       pointer_type->type.type       = TYPE_POINTER;
+                       pointer_type->points_to       = type;
+                       pointer_type->type.qualifiers = parsed_pointer->type_qualifiers;
+                       type                          = (type_t*) pointer_type;
                        break;
 
                case CONSTRUCT_ARRAY:
-                       parsed_array = (parsed_array_t*) iter;
-                       atype        = allocate_type_zero(sizeof(atype[0]));
-
-                       atype->type                      = TYPE_ARRAY;
-                       atype->v.array_type.element_type = type;
-                       atype->qualifiers                = parsed_array->type_qualifiers;
-                       atype->v.array_type.is_static    = parsed_array->is_static;
-                       atype->v.array_type.is_variable  = parsed_array->is_variable;
-                       atype->v.array_type.size         = parsed_array->size;
-                       type                             = atype;
+                       parsed_array  = (parsed_array_t*) iter;
+                       array_type    = allocate_type_zero(sizeof(array_type[0]));
+
+                       array_type->type.type       = TYPE_ARRAY;
+                       array_type->element_type    = type;
+                       array_type->type.qualifiers = parsed_array->type_qualifiers;
+                       array_type->is_static       = parsed_array->is_static;
+                       array_type->is_variable     = parsed_array->is_variable;
+                       array_type->size            = parsed_array->size;
+                       type                        = (type_t*) array_type;
                        break;
                }
 
-               type_t *hashed_type = typehash_insert(type);
+               type_t *hashed_type = typehash_insert((type_t*) type);
                if(hashed_type != type) {
                        /* the function type was constructed earlier freeing it here will
                         * destroy other types... */
@@ -2197,23 +2230,28 @@ static void parse_init_declarators(const declaration_specifiers_t *specifiers)
                        initializer_t *initializer = parse_initializer(type);
 
                        if(type->type == TYPE_ARRAY && initializer != NULL) {
-                               if(type->v.array_type.size == NULL) {
+                               array_type_t       *array_type = (array_type_t*) type;
+
+                               if(array_type->size == NULL) {
                                        const_t *cnst = allocate_ast_zero(sizeof(cnst[0]));
 
                                        cnst->expression.type     = EXPR_CONST;
                                        cnst->expression.datatype = type_size_t;
 
                                        if(initializer->type == INITIALIZER_LIST) {
-                                               cnst->v.int_value = initializer->v.list.len;
+                                               initializer_list_t *list = &initializer->list;
+                                               cnst->v.int_value = list->len;
                                        } else {
                                                assert(initializer->type == INITIALIZER_STRING);
-                                               cnst->v.int_value = strlen(initializer->v.string) + 1;
+                                               initializer_string_t *string = &initializer->string;
+                                               cnst->v.int_value = strlen(string->string) + 1;
                                        }
 
-                                       type->v.array_type.size = (expression_t*) cnst;
+                                       array_type->size = (expression_t*) cnst;
                                }
                        }
 
+
                        ndeclaration->init.initializer = initializer;
                } else if(token.type == '{') {
                        if(type->type != TYPE_FUNCTION) {
@@ -2330,8 +2368,9 @@ static void parse_declaration(void)
                switch (specifiers.type->type) {
                        case TYPE_COMPOUND_STRUCT:
                        case TYPE_COMPOUND_UNION: {
-                               const type_t *const comp_type = specifiers.type;
-                               if (comp_type->v.compound_type.declaration->symbol == NULL) {
+                               const compound_type_t *const comp_type =
+                                       (const compound_type_t*)specifiers.type;
+                               if (comp_type->declaration->symbol == NULL) {
                                        parse_warning_pos(source_position,
                                                                                                                "unnamed struct/union that defines no instances");
                                }
@@ -2452,15 +2491,16 @@ static expression_t *parse_float_const(void)
 static declaration_t *create_implicit_function(symbol_t *symbol,
                const source_position_t source_position)
 {
-       type_t *ftype = allocate_type_zero(sizeof(ftype[0]));
+       function_type_t *function_type
+               = allocate_type_zero(sizeof(function_type[0]));
 
-       ftype->type                                   = TYPE_FUNCTION;
-       ftype->v.function_type.result_type            = type_int;
-       ftype->v.function_type.unspecified_parameters = true;
+       function_type->type.type              = TYPE_FUNCTION;
+       function_type->result_type            = type_int;
+       function_type->unspecified_parameters = true;
 
-       type_t *type = typehash_insert(ftype);
-       if(type != ftype) {
-               free_type(ftype);
+       type_t *type = typehash_insert((type_t*) function_type);
+       if(type != (type_t*) function_type) {
+               free_type(function_type);
        }
 
        declaration_t *declaration = allocate_ast_zero(sizeof(declaration[0]));
@@ -2566,17 +2606,21 @@ static expression_t *parse_statement_expression(void)
        }
 
        assert(statement->type == STATEMENT_COMPOUND);
+       compound_statement_t *compound_statement
+               = (compound_statement_t*) statement;
 
        /* find last statement and use it's type */
        const statement_t *last_statement = NULL;
-       const statement_t *iter           = statement->v.compound_stmt.statements;
+       const statement_t *iter           = compound_statement->statements;
        for( ; iter != NULL; iter = iter->next) {
                last_statement = iter;
        }
 
        if(last_statement->type == STATEMENT_EXPRESSION) {
+               const expression_statement_t *expression_statement =
+                       (const expression_statement_t*) last_statement;
                expression->expression.datatype
-                       = last_statement->v.expression->datatype;
+                       = expression_statement->expression->datatype;
        } else {
                expression->expression.datatype = type_void;
        }
@@ -2730,13 +2774,13 @@ static type_t *make_function_1_type(type_t *result_type, type_t *argument_type)
        function_parameter_t *parameter = allocate_type_zero(sizeof(parameter[0]));
        parameter->type = argument_type;
 
-       type_t *type = allocate_type_zero(sizeof(type[0]));
-       type->type                        = TYPE_FUNCTION;
-       type->v.function_type.result_type = result_type;
-       type->v.function_type.parameters  = parameter;
+       function_type_t *type = allocate_type_zero(sizeof(type[0]));
+       type->type.type   = TYPE_FUNCTION;
+       type->result_type = result_type;
+       type->parameters  = parameter;
 
-       type_t *result = typehash_insert(type);
-       if(result != type) {
+       type_t *result = typehash_insert((type_t*) type);
+       if(result != (type_t*) type) {
                free_type(type);
        }
 
@@ -2824,17 +2868,17 @@ static expression_t *parse_array_expression(unsigned precedence,
 
        if(type_left != NULL && type_right != NULL) {
                if(type_left->type == TYPE_POINTER) {
-                       type_t *pointer = type_left;
-                       array_access->expression.datatype = pointer->v.pointer_type.points_to;
+                       pointer_type_t *pointer           = (pointer_type_t*) type_left;
+                       array_access->expression.datatype = pointer->points_to;
                } else if(type_left->type == TYPE_ARRAY) {
-                       type_t *array_type = type_left;
-                       array_access->expression.datatype = array_type->v.array_type.element_type;
+                       array_type_t *array_type          = (array_type_t*) type_left;
+                       array_access->expression.datatype = array_type->element_type;
                } else if(type_right->type == TYPE_POINTER) {
-                       type_t *pointer = type_right;
-                       array_access->expression.datatype = pointer->v.pointer_type.points_to;
+                       pointer_type_t *pointer           = (pointer_type_t*) type_right;
+                       array_access->expression.datatype = pointer->points_to;
                } else if(type_right->type == TYPE_ARRAY) {
-                       type_t *array_type = type_right;
-                       array_access->expression.datatype = array_type->v.array_type.element_type;
+                       array_type_t *array_type          = (array_type_t*) type_right;
+                       array_access->expression.datatype = array_type->element_type;
                } else {
                        parser_print_error_prefix();
                        fprintf(stderr, "array access on object with non-pointer types ");
@@ -2932,7 +2976,8 @@ static expression_t *parse_select_expression(unsigned precedence,
                        fputc('\n', stderr);
                        return make_invalid_expression();
                }
-               type_left = type->v.pointer_type.points_to;
+               pointer_type_t *pointer_type = (pointer_type_t*) type;
+               type_left                    = pointer_type->points_to;
        }
        type_left = skip_typeref(type_left);
 
@@ -2946,8 +2991,8 @@ static expression_t *parse_select_expression(unsigned precedence,
                return make_invalid_expression();
        }
 
-       type_t        *compound_type = type_left;
-       declaration_t *declaration   = compound_type->v.compound_type.declaration;
+       compound_type_t *compound_type = (compound_type_t*) type_left;
+       declaration_t   *declaration   = compound_type->declaration;
 
        if(!declaration->init.is_defined) {
                parser_print_error_prefix();
@@ -2984,16 +3029,18 @@ static expression_t *parse_call_expression(unsigned precedence,
        call->expression.type   = EXPR_CALL;
        call->function          = expression;
 
-       type_t *function_type;
-       type_t *orig_type     = expression->datatype;
-       type_t *type          = skip_typeref(orig_type);
+       function_type_t *function_type;
+       type_t          *orig_type     = expression->datatype;
+       type_t          *type          = skip_typeref(orig_type);
 
        if(type->type == TYPE_POINTER) {
-               type = skip_typeref(type->v.pointer_type.points_to);
+               pointer_type_t *pointer_type = (pointer_type_t*) type;
+
+               type = skip_typeref(pointer_type->points_to);
        }
        if (type->type == TYPE_FUNCTION) {
-               function_type             = type;
-               call->expression.datatype = type->v.function_type.result_type;
+               function_type             = (function_type_t*) type;
+               call->expression.datatype = function_type->result_type;
        } else {
                parser_print_error_prefix();
                fputs("called object '", stderr);
@@ -3031,7 +3078,7 @@ static expression_t *parse_call_expression(unsigned precedence,
        expect(')');
 
        if(function_type != NULL) {
-               function_parameter_t *parameter = function_type->v.function_type.parameters;
+               function_parameter_t *parameter = function_type->parameters;
                call_argument_t      *argument  = call->arguments;
                for( ; parameter != NULL && argument != NULL;
                                parameter = parameter->next, argument = argument->next) {
@@ -3048,8 +3095,8 @@ static expression_t *parse_call_expression(unsigned precedence,
                        fprintf(stderr, "'\n");
                } else if(argument != NULL) {
                        /* too many parameters */
-                       if(!function_type->v.function_type.variadic
-                                       && !function_type->v.function_type.unspecified_parameters) {
+                       if(!function_type->variadic
+                                       && !function_type->unspecified_parameters) {
                                parser_print_error_prefix();
                                fprintf(stderr, "too many arguments to function '");
                                print_expression(expression);
@@ -3243,17 +3290,21 @@ static void semantic_dereference(unary_expression_t *expression)
 
        type_t *type = skip_typeref(orig_type);
        switch (type->type) {
-               case TYPE_ARRAY:
-                       expression->expression.datatype = type->v.array_type.element_type;
+               case TYPE_ARRAY: {
+                       array_type_t *const array_type  = (array_type_t*)type;
+                       expression->expression.datatype = array_type->element_type;
                        break;
+               }
 
-               case TYPE_POINTER:
-                       expression->expression.datatype = type->v.pointer_type.points_to;
+               case TYPE_POINTER: {
+                       pointer_type_t *pointer_type    = (pointer_type_t*)type;
+                       expression->expression.datatype = pointer_type->points_to;
                        break;
+               }
 
                default:
                        parser_print_error_prefix();
-                       fputs("'Unary *' needs pointer or array type, but type ", stderr);
+                       fputs("'Unary *' needs pointer or arrray type, but type ", stderr);
                        print_type_quoted(orig_type);
                        fputs(" given.\n", stderr);
                        return;
@@ -3445,13 +3496,13 @@ static void semantic_add(binary_expression_t *expression)
        } else if(type_right->type == TYPE_POINTER && is_type_integer(type_left)) {
                expression->expression.datatype = type_right;
        } else if (type_left->type == TYPE_ARRAY && is_type_integer(type_right)) {
-               const type_t *const arr_type = type_left;
+               const array_type_t *const arr_type = (const array_type_t*)type_left;
                expression->expression.datatype =
-                 make_pointer_type(arr_type->v.array_type.element_type, TYPE_QUALIFIER_NONE);
+                 make_pointer_type(arr_type->element_type, TYPE_QUALIFIER_NONE);
        } else if (type_right->type == TYPE_ARRAY && is_type_integer(type_left)) {
-               const type_t *const arr_type = type_right;
+               const array_type_t *const arr_type = (const array_type_t*)type_right;
                expression->expression.datatype =
-                       make_pointer_type(arr_type->v.array_type.element_type, TYPE_QUALIFIER_NONE);
+                       make_pointer_type(arr_type->element_type, TYPE_QUALIFIER_NONE);
        } else {
                parser_print_error_prefix();
                fprintf(stderr, "invalid operands to binary + (");
@@ -3877,28 +3928,28 @@ static void init_expression_parsers(void)
 static statement_t *parse_case_statement(void)
 {
        eat(T_case);
-       statement_t *label = allocate_ast_zero(sizeof(label[0]));
-       label->type            = STATEMENT_CASE_LABEL;
-       label->source_position = token.source_position;
+       case_label_statement_t *label = allocate_ast_zero(sizeof(label[0]));
+       label->statement.type            = STATEMENT_CASE_LABEL;
+       label->statement.source_position = token.source_position;
 
-       label->v.case_label_stmt.expression = parse_expression();
+       label->expression = parse_expression();
 
        expect(':');
-       label->v.case_label_stmt.label_statement = parse_statement();
+       label->label_statement = parse_statement();
 
-       return label;
+       return (statement_t*) label;
 }
 
 static statement_t *parse_default_statement(void)
 {
        eat(T_default);
 
-       statement_t *label = allocate_ast_zero(sizeof(label[0]));
-       label->type            = STATEMENT_CASE_LABEL;
-       label->source_position = token.source_position;
+       case_label_statement_t *label = allocate_ast_zero(sizeof(label[0]));
+       label->statement.type            = STATEMENT_CASE_LABEL;
+       label->statement.source_position = token.source_position;
 
        expect(':');
-       label->v.case_label_stmt.label_statement = parse_statement();
+       label->label_statement = parse_statement();
 
        return (statement_t*) label;
 }
@@ -3944,11 +3995,11 @@ static statement_t *parse_label_statement(void)
                label->source_position = token.source_position;
        }
 
-       statement_t *label_statement = allocate_ast_zero(sizeof(label[0]));
+       label_statement_t *label_statement = allocate_ast_zero(sizeof(label[0]));
 
-       label_statement->type               = STATEMENT_LABEL;
-       label_statement->source_position    = token.source_position;
-       label_statement->v.label_stmt.label = label;
+       label_statement->statement.type            = STATEMENT_LABEL;
+       label_statement->statement.source_position = token.source_position;
+       label_statement->label                     = label;
 
        expect(':');
 
@@ -3956,102 +4007,102 @@ static statement_t *parse_label_statement(void)
                parse_error("label at end of compound statement");
                return (statement_t*) label_statement;
        } else {
-               label_statement->v.label_stmt.label_statement = parse_statement();
+               label_statement->label_statement = parse_statement();
        }
 
-       return label_statement;
+       return (statement_t*) label_statement;
 }
 
 static statement_t *parse_if(void)
 {
        eat(T_if);
 
-       statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
-       statement->type            = STATEMENT_IF;
-       statement->source_position = token.source_position;
+       if_statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
+       statement->statement.type            = STATEMENT_IF;
+       statement->statement.source_position = token.source_position;
 
        expect('(');
-       statement->v.if_stmt.condition = parse_expression();
+       statement->condition = parse_expression();
        expect(')');
 
-       statement->v.if_stmt.true_statement = parse_statement();
+       statement->true_statement = parse_statement();
        if(token.type == T_else) {
                next_token();
-               statement->v.if_stmt.false_statement = parse_statement();
+               statement->false_statement = parse_statement();
        }
 
-       return statement;
+       return (statement_t*) statement;
 }
 
 static statement_t *parse_switch(void)
 {
        eat(T_switch);
 
-       statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
-       statement->type            = STATEMENT_SWITCH;
-       statement->source_position = token.source_position;
+       switch_statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
+       statement->statement.type            = STATEMENT_SWITCH;
+       statement->statement.source_position = token.source_position;
 
        expect('(');
-       statement->v.switch_stmt.expression = parse_expression();
+       statement->expression = parse_expression();
        expect(')');
-       statement->v.switch_stmt.body = parse_statement();
+       statement->body = parse_statement();
 
-       return statement;
+       return (statement_t*) statement;
 }
 
 static statement_t *parse_while(void)
 {
        eat(T_while);
 
-       statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
-       statement->type            = STATEMENT_WHILE;
-       statement->source_position = token.source_position;
+       while_statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
+       statement->statement.type            = STATEMENT_WHILE;
+       statement->statement.source_position = token.source_position;
 
        expect('(');
-       statement->v.while_stmt.condition = parse_expression();
+       statement->condition = parse_expression();
        expect(')');
-       statement->v.while_stmt.body = parse_statement();
+       statement->body = parse_statement();
 
-       return statement;
+       return (statement_t*) statement;
 }
 
 static statement_t *parse_do(void)
 {
        eat(T_do);
 
-       statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
-       statement->type            = STATEMENT_DO_WHILE;
-       statement->source_position = token.source_position;
+       do_while_statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
+       statement->statement.type            = STATEMENT_DO_WHILE;
+       statement->statement.source_position = token.source_position;
 
-       statement->v.while_stmt.body = parse_statement();
+       statement->body = parse_statement();
        expect(T_while);
        expect('(');
-       statement->v.while_stmt.condition = parse_expression();
+       statement->condition = parse_expression();
        expect(')');
        expect(';');
 
-       return statement;
+       return (statement_t*) statement;
 }
 
 static statement_t *parse_for(void)
 {
        eat(T_for);
 
-       statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
-       statement->type            = STATEMENT_FOR;
-       statement->source_position = token.source_position;
+       for_statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
+       statement->statement.type            = STATEMENT_FOR;
+       statement->statement.source_position = token.source_position;
 
        expect('(');
 
        int         top          = environment_top();
        context_t  *last_context = context;
-       set_context(&statement->v.for_stmt.context);
+       set_context(&statement->context);
 
        if(token.type != ';') {
                if(is_declaration_specifier(&token, false)) {
                        parse_declaration();
                } else {
-                       statement->v.for_stmt.initialisation = parse_expression();
+                       statement->initialisation = parse_expression();
                        expect(';');
                }
        } else {
@@ -4059,20 +4110,20 @@ static statement_t *parse_for(void)
        }
 
        if(token.type != ';') {
-               statement->v.for_stmt.condition = parse_expression();
+               statement->condition = parse_expression();
        }
        expect(';');
        if(token.type != ')') {
-               statement->v.for_stmt.step = parse_expression();
+               statement->step = parse_expression();
        }
        expect(')');
-       statement->v.for_stmt.body = parse_statement();
+       statement->body = parse_statement();
 
-       assert(context == &statement->v.for_stmt.context);
+       assert(context == &statement->context);
        set_context(last_context);
        environment_pop_to(top);
 
-       return statement;
+       return (statement_t*) statement;
 }
 
 static statement_t *parse_goto(void)
@@ -4089,16 +4140,16 @@ static statement_t *parse_goto(void)
 
        declaration_t *label = get_label(symbol);
 
-       statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
+       goto_statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
 
-       statement->type            = STATEMENT_GOTO;
-       statement->source_position = token.source_position;
+       statement->statement.type            = STATEMENT_GOTO;
+       statement->statement.source_position = token.source_position;
 
-       statement->v.goto_label = label;
+       statement->label = label;
 
        expect(';');
 
-       return statement;
+       return (statement_t*) statement;
 }
 
 static statement_t *parse_continue(void)
@@ -4129,14 +4180,14 @@ static statement_t *parse_return(void)
 {
        eat(T_return);
 
-       statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
+       return_statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
 
-       statement->type            = STATEMENT_RETURN;
-       statement->source_position = token.source_position;
+       statement->statement.type            = STATEMENT_RETURN;
+       statement->statement.source_position = token.source_position;
 
        assert(current_function->type->type == TYPE_FUNCTION);
-       type_t *function_type = current_function->type;
-       type_t *return_type   = function_type->v.function_type.result_type;
+       function_type_t *function_type = (function_type_t*) current_function->type;
+       type_t          *return_type   = function_type->result_type;
 
        expression_t *return_value;
        if(token.type != ';') {
@@ -4157,21 +4208,21 @@ static statement_t *parse_return(void)
                                      "non-void");
                }
        }
-       statement->v.return_value = return_value;
+       statement->return_value = return_value;
 
        expect(';');
 
-       return statement;
+       return (statement_t*) statement;
 }
 
 static statement_t *parse_declaration_statement(void)
 {
        declaration_t *before = last_declaration;
 
-       statement_t *statement
+       declaration_statement_t *statement
                = allocate_ast_zero(sizeof(statement[0]));
-       statement->type            = STATEMENT_DECLARATION;
-       statement->source_position = token.source_position;
+       statement->statement.type            = STATEMENT_DECLARATION;
+       statement->statement.source_position = token.source_position;
 
        declaration_specifiers_t specifiers;
        memset(&specifiers, 0, sizeof(specifiers));
@@ -4184,26 +4235,26 @@ static statement_t *parse_declaration_statement(void)
        }
 
        if(before == NULL) {
-               statement->v.declaration_stmt.begin = context->declarations;
+               statement->declarations_begin = context->declarations;
        } else {
-               statement->v.declaration_stmt.begin = before->next;
+               statement->declarations_begin = before->next;
        }
-       statement->v.declaration_stmt.end = last_declaration;
+       statement->declarations_end = last_declaration;
 
-       return statement;
+       return (statement_t*) statement;
 }
 
 static statement_t *parse_expression_statement(void)
 {
-       statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
-       statement->type            = STATEMENT_EXPRESSION;
-       statement->source_position = token.source_position;
+       expression_statement_t *statement = allocate_ast_zero(sizeof(statement[0]));
+       statement->statement.type            = STATEMENT_EXPRESSION;
+       statement->statement.source_position = token.source_position;
 
-       statement->v.expression = parse_expression();
+       statement->expression = parse_expression();
 
        expect(';');
 
-       return statement;
+       return (statement_t*) statement;
 }
 
 static statement_t *parse_statement(void)
@@ -4304,16 +4355,16 @@ static statement_t *parse_statement(void)
 
 static statement_t *parse_compound_statement(void)
 {
-       statement_t *compound_statement
+       compound_statement_t *compound_statement
                = allocate_ast_zero(sizeof(compound_statement[0]));
-       compound_statement->type            = STATEMENT_COMPOUND;
-       compound_statement->source_position = token.source_position;
+       compound_statement->statement.type            = STATEMENT_COMPOUND;
+       compound_statement->statement.source_position = token.source_position;
 
        eat('{');
 
        int        top          = environment_top();
        context_t *last_context = context;
-       set_context(&compound_statement->v.compound_stmt.context);
+       set_context(&compound_statement->context);
 
        statement_t *last_statement = NULL;
 
@@ -4325,7 +4376,7 @@ static statement_t *parse_compound_statement(void)
                if(last_statement != NULL) {
                        last_statement->next = statement;
                } else {
-                       compound_statement->v.compound_stmt.statements = statement;
+                       compound_statement->statements = statement;
                }
 
                while(statement->next != NULL)
@@ -4336,16 +4387,16 @@ static statement_t *parse_compound_statement(void)
 
        if(token.type != '}') {
                parser_print_error_prefix_pos(
-                               compound_statement->source_position);
+                               compound_statement->statement.source_position);
                fprintf(stderr, "end of file while looking for closing '}'\n");
        }
        next_token();
 
-       assert(context == &compound_statement->v.compound_stmt.context);
+       assert(context == &compound_statement->context);
        set_context(last_context);
        environment_pop_to(top);
 
-       return compound_statement;
+       return (statement_t*) compound_statement;
 }
 
 static translation_unit_t *parse_translation_unit(void)
diff --git a/type.c b/type.c
index c6c0801..92fcd15 100644 (file)
--- a/type.c
+++ b/type.c
@@ -48,12 +48,12 @@ void print_type_qualifiers(unsigned qualifiers)
 }
 
 static
-void print_atomic_type(const type_t *type)
+void print_atomic_type(const atomic_type_t *type)
 {
-       print_type_qualifiers(type->qualifiers);
+       print_type_qualifiers(type->type.qualifiers);
 
        const char *s;
-       switch(type->v.atomic_type.atype) {
+       switch(type->atype) {
        case ATOMIC_TYPE_INVALID:     s = "INVALIDATOMIC";      break;
        case ATOMIC_TYPE_VOID:        s = "void";               break;
        case ATOMIC_TYPE_BOOL:        s = "_Bool";              break;
@@ -76,28 +76,28 @@ void print_atomic_type(const type_t *type)
        fputs(s, out);
 }
 
-static void print_function_type_pre(const type_t *type)
+static void print_function_type_pre(const function_type_t *type)
 {
-       print_type_qualifiers(type->qualifiers);
+       print_type_qualifiers(type->type.qualifiers);
 
-       intern_print_type_pre(type->v.function_type.result_type);
+       intern_print_type_pre(type->result_type);
 
        /* TODO: don't emit braces if we're the toplevel type... */
        fputc('(', out);
 }
 
-static void print_function_type_post(const type_t *type,
+static void print_function_type_post(const function_type_t *type,
                                      const context_t *context)
 {
        /* TODO: don't emit braces if we're the toplevel type... */
-       intern_print_type_post(type->v.function_type.result_type);
+       intern_print_type_post(type->result_type);
        fputc(')', out);
 
        fputc('(', out);
 
        int                 first     = 1;
        if(context == NULL) {
-               function_parameter_t *parameter = type->v.function_type.parameters;
+               function_parameter_t *parameter = type->parameters;
                for( ; parameter != NULL; parameter = parameter->next) {
                        if(first) {
                                first = 0;
@@ -118,7 +118,7 @@ static void print_function_type_post(const type_t *type,
                                       &parameter->context);
                }
        }
-       if(type->v.function_type.variadic) {
+       if(type->variadic) {
                if(first) {
                        first = 0;
                } else {
@@ -126,41 +126,41 @@ static void print_function_type_post(const type_t *type,
                }
                fputs("...", out);
        }
-       if(first && !type->v.function_type.unspecified_parameters) {
+       if(first && !type->unspecified_parameters) {
                fputs("void", out);
        }
        fputc(')', out);
 }
 
-static void print_pointer_type_pre(const type_t *type)
+static void print_pointer_type_pre(const pointer_type_t *type)
 {
-       intern_print_type_pre(type->v.pointer_type.points_to);
+       intern_print_type_pre(type->points_to);
        fputs("*", out);
-       print_type_qualifiers(type->qualifiers);
+       print_type_qualifiers(type->type.qualifiers);
 }
 
-static void print_pointer_type_post(const type_t *type)
+static void print_pointer_type_post(const pointer_type_t *type)
 {
-       intern_print_type_post(type->v.pointer_type.points_to);
+       intern_print_type_post(type->points_to);
 }
 
-static void print_array_type_pre(const type_t *type)
+static void print_array_type_pre(const array_type_t *type)
 {
-       intern_print_type_pre(type->v.array_type.element_type);
+       intern_print_type_pre(type->element_type);
 }
 
-static void print_array_type_post(const type_t *type)
+static void print_array_type_post(const array_type_t *type)
 {
        fputc('[', out);
-       if(type->v.array_type.is_static) {
+       if(type->is_static) {
                fputs("static ", out);
        }
-       print_type_qualifiers(type->qualifiers);
-       if(type->v.array_type.size != NULL) {
-               print_expression(type->v.array_type.size);
+       print_type_qualifiers(type->type.qualifiers);
+       if(type->size != NULL) {
+               print_expression(type->size);
        }
        fputc(']', out);
-       intern_print_type_post(type->v.array_type.element_type);
+       intern_print_type_post(type->element_type);
 }
 
 void print_enum_definition(const declaration_t *declaration)
@@ -187,12 +187,12 @@ void print_enum_definition(const declaration_t *declaration)
        fputs("}", out);
 }
 
-static void print_type_enum(const type_t *type)
+static void print_type_enum(const enum_type_t *type)
 {
-       print_type_qualifiers(type->qualifiers);
+       print_type_qualifiers(type->type.qualifiers);
        fputs("enum ", out);
 
-       declaration_t *declaration = type->v.enum_type.declaration;
+       declaration_t *declaration = type->declaration;
        symbol_t      *symbol      = declaration->symbol;
        if(symbol != NULL) {
                fputs(symbol->string, out);
@@ -218,18 +218,18 @@ void print_compound_definition(const declaration_t *declaration)
        fputs("}", out);
 }
 
-static void print_compound_type(const type_t *type)
+static void print_compound_type(const compound_type_t *type)
 {
-       print_type_qualifiers(type->qualifiers);
+       print_type_qualifiers(type->type.qualifiers);
 
-       if(type->type == TYPE_COMPOUND_STRUCT) {
+       if(type->type.type == TYPE_COMPOUND_STRUCT) {
                fputs("struct ", out);
        } else {
-               assert(type->type == TYPE_COMPOUND_UNION);
+               assert(type->type.type == TYPE_COMPOUND_UNION);
                fputs("union ", out);
        }
 
-       declaration_t *declaration = type->v.compound_type.declaration;
+       declaration_t *declaration = type->declaration;
        symbol_t      *symbol      = declaration->symbol;
        if(symbol != NULL) {
                fputs(symbol->string, out);
@@ -238,19 +238,19 @@ static void print_compound_type(const type_t *type)
        }
 }
 
-static void print_typedef_type_pre(type_t *type)
+static void print_typedef_type_pre(typedef_type_t *type)
 {
-       fputs(type->v.typedef_type.declaration->symbol->string, out);
+       fputs(type->declaration->symbol->string, out);
 }
 
-static void print_typeof_type_pre(type_t *type)
+static void print_typeof_type_pre(typeof_type_t *type)
 {
        fputs("typeof(", out);
-       if(type->v.typeof_type.expression != NULL) {
-               assert(type->v.typeof_type.typeof_type == NULL);
-               print_expression(type->v.typeof_type.expression);
+       if(type->expression != NULL) {
+               assert(type->typeof_type == NULL);
+               print_expression(type->expression);
        } else {
-               print_type(type->v.typeof_type.typeof_type);
+               print_type(type->typeof_type);
        }
        fputc(')', out);
 }
@@ -262,32 +262,32 @@ static void intern_print_type_pre(type_t *type)
                fputs("invalid", out);
                return;
        case TYPE_ENUM:
-               print_type_enum(type);
+               print_type_enum((enum_type_t*) type);
                return;
        case TYPE_ATOMIC:
-               print_atomic_type(type);
+               print_atomic_type((atomic_type_t*) type);
                return;
        case TYPE_COMPOUND_STRUCT:
        case TYPE_COMPOUND_UNION:
-               print_compound_type(type);
+               print_compound_type((compound_type_t*) type);
                return;
        case TYPE_BUILTIN:
-               fputs(type->v.builtin_type.symbol->string, out);
+               fputs(((builtin_type_t*) type)->symbol->string, out);
                return;
        case TYPE_FUNCTION:
-               print_function_type_pre(type);
+               print_function_type_pre((function_type_t*) type);
                return;
        case TYPE_POINTER:
-               print_pointer_type_pre(type);
+               print_pointer_type_pre((pointer_type_t*) type);
                return;
        case TYPE_ARRAY:
-               print_array_type_pre(type);
+               print_array_type_pre((array_type_t*) type);
                return;
        case TYPE_TYPEDEF:
-               print_typedef_type_pre(type);
+               print_typedef_type_pre((typedef_type_t*) type);
                return;
        case TYPE_TYPEOF:
-               print_typeof_type_pre(type);
+               print_typeof_type_pre((typeof_type_t*) type);
                return;
        }
        fputs("unknown", out);
@@ -297,13 +297,13 @@ static void intern_print_type_post(type_t *type)
 {
        switch(type->type) {
        case TYPE_FUNCTION:
-               print_function_type_post(type, NULL);
+               print_function_type_post((const function_type_t*) type, NULL);
                return;
        case TYPE_POINTER:
-               print_pointer_type_post(type);
+               print_pointer_type_post((const pointer_type_t*) type);
                return;
        case TYPE_ARRAY:
-               print_array_type_post(type);
+               print_array_type_post((const array_type_t*) type);
                return;
        case TYPE_INVALID:
        case TYPE_ATOMIC:
@@ -336,7 +336,7 @@ void print_type_ext(type_t *type, const symbol_t *symbol,
                fputs(symbol->string, out);
        }
        if(type->type == TYPE_FUNCTION) {
-               print_function_type_post(type, context);
+               print_function_type_post((const function_type_t*) type, context);
        } else {
                intern_print_type_post(type);
        }
@@ -355,7 +355,8 @@ bool is_type_integer(const type_t *type)
        if(type->type != TYPE_ATOMIC)
                return false;
 
-       switch(type->v.atomic_type.atype) {
+       atomic_type_t *atomic_type = (atomic_type_t*) type;
+       switch(atomic_type->atype) {
        case ATOMIC_TYPE_BOOL:
        case ATOMIC_TYPE_CHAR:
        case ATOMIC_TYPE_SCHAR:
@@ -379,7 +380,8 @@ bool is_type_floating(const type_t *type)
        if(type->type != TYPE_ATOMIC)
                return false;
 
-       switch(type->v.atomic_type.atype) {
+       atomic_type_t *atomic_type = (atomic_type_t*) type;
+       switch(atomic_type->atype) {
        case ATOMIC_TYPE_FLOAT:
        case ATOMIC_TYPE_DOUBLE:
        case ATOMIC_TYPE_LONG_DOUBLE:
@@ -406,7 +408,8 @@ bool is_type_signed(const type_t *type)
        if(type->type != TYPE_ATOMIC)
                return false;
 
-       switch(type->v.atomic_type.atype) {
+       atomic_type_t *atomic_type = (atomic_type_t*) type;
+       switch(atomic_type->atype) {
        case ATOMIC_TYPE_CHAR:
        case ATOMIC_TYPE_SCHAR:
        case ATOMIC_TYPE_SHORT:
@@ -464,14 +467,19 @@ bool is_type_incomplete(const type_t *type)
        switch(type->type) {
        case TYPE_COMPOUND_STRUCT:
        case TYPE_COMPOUND_UNION: {
-               declaration_t *declaration = type->v.compound_type.declaration;
+               const compound_type_t *compound_type
+                       = (const compound_type_t*) type;
+               declaration_t *declaration = compound_type->declaration;
                return !declaration->init.is_defined;
        }
        case TYPE_FUNCTION:
                return true;
 
-       case TYPE_ARRAY:
-               return type->v.array_type.size == NULL;
+       case TYPE_ARRAY: {
+               const array_type_t *array_type = (const array_type_t*) type;
+
+               return array_type->size == NULL;
+       }
 
        case TYPE_ATOMIC:
        case TYPE_POINTER:
@@ -495,8 +503,12 @@ bool types_compatible(const type_t *type1, const type_t *type2)
        if(type1 == type2)
                return true;
 
-       if(type1->type == TYPE_ATOMIC && type2->type == TYPE_ATOMIC)
-               return type1->v.atomic_type.atype == type2->v.atomic_type.atype;
+       if(type1->type == TYPE_ATOMIC && type2->type == TYPE_ATOMIC) {
+               const atomic_type_t *atomic1 = (const atomic_type_t*) type1;
+               const atomic_type_t *atomic2 = (const atomic_type_t*) type2;
+
+               return atomic1->atype == atomic2->atype;
+       }
 
        return false;
 }
@@ -506,20 +518,42 @@ bool pointers_compatible(const type_t *type1, const type_t *type2)
        assert(type1->type == TYPE_POINTER);
        assert(type2->type == TYPE_POINTER);
 #if 0
-       return types_compatible(type1->v.pointer_type.points_to,
-                               type2->v.pointer_type.points_to);
+       pointer_type_t *pointer_type1 = (pointer_type_t*) type1;
+       pointer_type_t *pointer_type2 = (pointer_type_t*) type2;
+       return types_compatible(pointer_type1->points_to,
+                               pointer_type2->points_to);
 #endif
        return true;
 }
 
+static size_t get_type_size(type_t *type)
+{
+       switch(type->type) {
+       case TYPE_ATOMIC:          return sizeof(atomic_type_t); break;
+       case TYPE_COMPOUND_STRUCT:
+       case TYPE_COMPOUND_UNION:  return sizeof(compound_type_t); break;
+       case TYPE_ENUM:            return sizeof(enum_type_t); break;
+       case TYPE_FUNCTION:        return sizeof(function_type_t); break;
+       case TYPE_POINTER:         return sizeof(pointer_type_t); break;
+       case TYPE_ARRAY:           return sizeof(array_type_t); break;
+       case TYPE_BUILTIN:         return sizeof(builtin_type_t); break;
+       case TYPE_TYPEDEF:         return sizeof(typedef_type_t); break;
+       case TYPE_TYPEOF:          return sizeof(typeof_type_t); break;
+       case TYPE_INVALID:         panic("invalid type found"); break;
+       }
+       panic("unknown type found");
+}
+
 /**
  * duplicates a type
  * note that this does not produce a deep copy!
  */
 static type_t *duplicate_type(type_t *type)
 {
-       type_t *copy = obstack_alloc(type_obst, sizeof(*copy));
-       memcpy(copy, type, sizeof(*copy));
+       size_t size = get_type_size(type);
+
+       type_t *copy = obstack_alloc(type_obst, size);
+       memcpy(copy, type, size);
 
        (void) duplicate_type;
 
@@ -532,24 +566,30 @@ type_t *skip_typeref(type_t *type)
 
        while(1) {
                switch(type->type) {
-               case TYPE_TYPEDEF:
+               case TYPE_TYPEDEF: {
                        qualifiers |= type->qualifiers;
-                       if(type->v.typedef_type.resolved_type != NULL) {
-                               type = type->v.typedef_type.resolved_type;
+                       const typedef_type_t *typedef_type = (const typedef_type_t*) type;
+                       if(typedef_type->resolved_type != NULL) {
+                               type = typedef_type->resolved_type;
                                break;
                        }
-                       type = type->v.typedef_type.declaration->type;
+                       type = typedef_type->declaration->type;
                        continue;
-               case TYPE_TYPEOF:
-                       if(type->v.typeof_type.typeof_type != NULL) {
-                               type = type->v.typeof_type.typeof_type;
+               }
+               case TYPE_TYPEOF: {
+                       const typeof_type_t *typeof_type = (const typeof_type_t *) type;
+                       if(typeof_type->typeof_type != NULL) {
+                               type = typeof_type->typeof_type;
                        } else {
-                               type = type->v.typeof_type.expression->datatype;
+                               type = typeof_type->expression->datatype;
                        }
                        continue;
-               case TYPE_BUILTIN:
-                       type = type->v.builtin_type.real_type;
+               }
+               case TYPE_BUILTIN: {
+                       const builtin_type_t *builtin_type = (const builtin_type_t*) type;
+                       type = builtin_type->real_type;
                        continue;
+               }
                default:
                        break;
                }
@@ -572,24 +612,26 @@ static type_t *identify_new_type(type_t *type)
 
 type_t *make_atomic_type(atomic_type_type_t type, type_qualifiers_t qualifiers)
 {
-       type_t *atomic_type = obstack_alloc(type_obst, sizeof(atomic_type[0]));
+       atomic_type_t *atomic_type
+               = obstack_alloc(type_obst, sizeof(atomic_type[0]));
        memset(atomic_type, 0, sizeof(atomic_type[0]));
-       atomic_type->type                = TYPE_ATOMIC;
-       atomic_type->qualifiers          = qualifiers;
-       atomic_type->v.atomic_type.atype = type;
+       atomic_type->type.type       = TYPE_ATOMIC;
+       atomic_type->type.qualifiers = qualifiers;
+       atomic_type->atype           = type;
 
-       return identify_new_type(atomic_type);
+       return identify_new_type((type_t*) atomic_type);
 }
 
 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers)
 {
-       type_t *pointer_type = obstack_alloc(type_obst, sizeof(pointer_type[0]));
+       pointer_type_t *pointer_type
+               = obstack_alloc(type_obst, sizeof(pointer_type[0]));
        memset(pointer_type, 0, sizeof(pointer_type[0]));
-       pointer_type->type                     = TYPE_POINTER;
-       pointer_type->qualifiers               = qualifiers;
-       pointer_type->v.pointer_type.points_to = points_to;
+       pointer_type->type.type       = TYPE_POINTER;
+       pointer_type->type.qualifiers = qualifiers;
+       pointer_type->points_to       = points_to;
 
-       return identify_new_type(pointer_type);
+       return identify_new_type((type_t*) pointer_type);
 }
 
 static __attribute__((unused))
diff --git a/type.h b/type.h
index 6811eb7..44b721c 100644 (file)
--- a/type.h
+++ b/type.h
@@ -6,7 +6,16 @@
 #include "symbol.h"
 
 typedef struct type_t                type_t;
+typedef struct atomic_type_t         atomic_type_t;
+typedef struct pointer_type_t        pointer_type_t;
 typedef struct function_parameter_t  function_parameter_t;
+typedef struct function_type_t       function_type_t;
+typedef struct compound_type_t       compound_type_t;
+typedef struct enum_type_t           enum_type_t;
+typedef struct builtin_type_t        builtin_type_t;
+typedef struct array_type_t          array_type_t;
+typedef struct typedef_type_t        typedef_type_t;
+typedef struct typeof_type_t         typeof_type_t;
 
 void init_types(void);
 void exit_types(void);
index 59a5667..1e07c1f 100644 (file)
@@ -26,36 +26,36 @@ static unsigned hash_ptr(const void *ptr)
        return ptr_int >> 3;
 }
 
-static unsigned hash_atomic_type(const type_t *type)
+static unsigned hash_atomic_type(const atomic_type_t *type)
 {
        unsigned some_prime = 27644437;
-       unsigned result     = type->v.atomic_type.atype * some_prime;
+       unsigned result     = type->atype * some_prime;
 
        return result;
 }
 
-static unsigned hash_pointer_type(const type_t *type)
+static unsigned hash_pointer_type(const pointer_type_t *type)
 {
-       return hash_ptr(type->v.pointer_type.points_to);
+       return hash_ptr(type->points_to);
 }
 
-static unsigned hash_array_type(const type_t *type)
+static unsigned hash_array_type(const array_type_t *type)
 {
-       return hash_ptr(type->v.array_type.element_type);
+       return hash_ptr(type->element_type);
 }
 
-static unsigned hash_compound_type(const type_t *type)
+static unsigned hash_compound_type(const compound_type_t *type)
 {
-       return hash_ptr(type->v.compound_type.declaration);
+       return hash_ptr(type->declaration);
 }
 
 static unsigned hash_type(const type_t *type);
 
-static unsigned hash_function_type(const type_t *type)
+static unsigned hash_function_type(const function_type_t *type)
 {
-       unsigned result = hash_ptr(type->v.function_type.result_type);
+       unsigned result = hash_ptr(type->result_type);
 
-       function_parameter_t *parameter = type->v.function_type.parameters;
+       function_parameter_t *parameter = type->parameters;
        while(parameter != NULL) {
                result   ^= hash_ptr(parameter->type);
                parameter = parameter->next;
@@ -64,15 +64,15 @@ static unsigned hash_function_type(const type_t *type)
        return result;
 }
 
-static unsigned hash_enum_type(const type_t *type)
+static unsigned hash_enum_type(const enum_type_t *type)
 {
-       return hash_ptr(type->v.enum_type.declaration);
+       return hash_ptr(type->declaration);
 }
 
-static unsigned hash_typeof_type(const type_t *type)
+static unsigned hash_typeof_type(const typeof_type_t *type)
 {
-       unsigned result = hash_ptr(type->v.typeof_type.expression);
-       result         ^= hash_ptr(type->v.typeof_type.typeof_type);
+       unsigned result = hash_ptr(type->expression);
+       result         ^= hash_ptr(type->typeof_type);
 
        return result;
 }
@@ -86,32 +86,32 @@ static unsigned hash_type(const type_t *type)
                panic("internalizing void or invalid types not possible");
                return 0;
        case TYPE_ATOMIC:
-               hash = hash_atomic_type(type);
+               hash = hash_atomic_type((const atomic_type_t*) type);
                break;
        case TYPE_ENUM:
-               hash = hash_enum_type(type);
+               hash = hash_enum_type((const enum_type_t*) type);
                break;
        case TYPE_COMPOUND_STRUCT:
        case TYPE_COMPOUND_UNION:
-               hash = hash_compound_type(type);
+               hash = hash_compound_type((const compound_type_t*) type);
                break;
        case TYPE_FUNCTION:
-               hash = hash_function_type(type);
+               hash = hash_function_type((const function_type_t*) type);
                break;
        case TYPE_POINTER:
-               hash = hash_pointer_type(type);
+               hash = hash_pointer_type((const pointer_type_t*) type);
                break;
        case TYPE_ARRAY:
-               hash = hash_array_type(type);
+               hash = hash_array_type((const array_type_t*) type);
                break;
        case TYPE_BUILTIN:
-               hash = hash_ptr(type->v.builtin_type.symbol);
+               hash = hash_ptr(((const builtin_type_t*) type)->symbol);
                break;
        case TYPE_TYPEDEF:
-               hash = hash_ptr(type->v.typedef_type.declaration);
+               hash = hash_ptr(((const compound_type_t*) type)->declaration);
                break;
        case TYPE_TYPEOF:
-               hash = hash_typeof_type(type);
+               hash = hash_typeof_type((const typeof_type_t*) type);
                break;
        }
 
@@ -121,25 +121,24 @@ static unsigned hash_type(const type_t *type)
        return hash;
 }
 
-static bool atomic_types_equal(const type_t *type1,
-                               const type_t *type2)
+static bool atomic_types_equal(const atomic_type_t *type1,
+                               const atomic_type_t *type2)
 {
-       return type1->v.atomic_type.atype == type2->v.atomic_type.atype;
+       return type1->atype == type2->atype;
 }
 
-static bool function_types_equal(const type_t *type1,
-                                 const type_t *type2)
+static bool function_types_equal(const function_type_t *type1,
+                                 const function_type_t *type2)
 {
-       if(type1->v.function_type.result_type != type2->v.function_type.result_type)
+       if(type1->result_type != type2->result_type)
                return false;
-       if(type1->v.function_type.variadic != type2->v.function_type.variadic)
+       if(type1->variadic != type2->variadic)
                return false;
-       if(type1->v.function_type.unspecified_parameters !=
-          type2->v.function_type.unspecified_parameters)
+       if(type1->unspecified_parameters != type2->unspecified_parameters)
                return false;
 
-       function_parameter_t *param1 = type1->v.function_type.parameters;
-       function_parameter_t *param2 = type2->v.function_type.parameters;
+       function_parameter_t *param1 = type1->parameters;
+       function_parameter_t *param2 = type2->parameters;
        while(param1 != NULL && param2 != NULL) {
                if(param1->type != param2->type)
                        return false;
@@ -152,58 +151,58 @@ static bool function_types_equal(const type_t *type1,
        return true;
 }
 
-static bool pointer_types_equal(const type_t *type1,
-                                const type_t *type2)
+static bool pointer_types_equal(const pointer_type_t *type1,
+                                const pointer_type_t *type2)
 {
-       return type1->v.pointer_type.points_to == type2->v.pointer_type.points_to;
+       return type1->points_to == type2->points_to;
 }
 
-static bool array_types_equal(const type_t *type1,
-                              const type_t *type2)
+static bool array_types_equal(const array_type_t *type1,
+                              const array_type_t *type2)
 {
-       if(type1->v.array_type.element_type != type2->v.array_type.element_type)
+       if(type1->element_type != type2->element_type)
                return false;
-       if(type1->v.array_type.is_variable != type2->v.array_type.is_variable)
+       if(type1->is_variable != type2->is_variable)
                return false;
-       if(type1->v.array_type.is_static != type2->v.array_type.is_static)
+       if(type1->is_static != type2->is_static)
                return false;
        /* TODO: compare expressions for equality... */
-       if(type1->v.array_type.size != type2->v.array_type.size)
+       if(type1->size != type2->size)
                return false;
 
        return true;
 }
 
-static bool builtin_types_equal(const type_t *type1,
-                                const type_t *type2)
+static bool builtin_types_equal(const builtin_type_t *type1,
+                                const builtin_type_t *type2)
 {
-       return type1->v.builtin_type.symbol == type2->v.builtin_type.symbol;
+       return type1->symbol == type2->symbol;
 }
 
-static bool compound_types_equal(const type_t *type1,
-                                 const type_t *type2)
+static bool compound_types_equal(const compound_type_t *type1,
+                                 const compound_type_t *type2)
 {
-       return type1->v.compound_type.declaration == type2->v.compound_type.declaration;
+       return type1->declaration == type2->declaration;
 }
 
-static bool enum_types_equal(const type_t *type1,
-                             const type_t *type2)
+static bool enum_types_equal(const enum_type_t *type1,
+                             const enum_type_t *type2)
 {
-       return type1->v.enum_type.declaration == type2->v.enum_type.declaration;
+       return type1->declaration == type2->declaration;
 }
 
-static bool typedef_types_equal(const type_t *type1,
-                                const type_t *type2)
+static bool typedef_types_equal(const typedef_type_t *type1,
+                                const typedef_type_t *type2)
 {
-       return type1->v.typedef_type.declaration == type2->v.typedef_type.declaration;
+       return type1->declaration == type2->declaration;
 }
 
-static bool typeof_types_equal(const type_t *type1,
-                               const type_t *type2)
+static bool typeof_types_equal(const typeof_type_t *type1,
+                               const typeof_type_t *type2)
 {
-       if(type1->v.typeof_type.expression != type2->v.typeof_type.expression)
+       if(type1->expression != type2->expression)
                return false;
-       if(type1->v.typeof_type.typeof_type != type2->v.typeof_type.typeof_type)
+       if(type1->typeof_type != type2->typeof_type)
                return false;
 
        return true;
@@ -222,24 +221,33 @@ static bool types_equal(const type_t *type1, const type_t *type2)
        case TYPE_INVALID:
                return false;
        case TYPE_ATOMIC:
-               return atomic_types_equal(type1, type2);
+               return atomic_types_equal((const atomic_type_t*) type1,
+                                         (const atomic_type_t*) type2);
        case TYPE_ENUM:
-               return enum_types_equal(type1, type2);
+               return enum_types_equal((const enum_type_t*) type1,
+                                       (const enum_type_t*) type2);
        case TYPE_COMPOUND_STRUCT:
        case TYPE_COMPOUND_UNION:
-               return compound_types_equal(type1, type2);
+               return compound_types_equal((const compound_type_t*) type1,
+                                           (const compound_type_t*) type2);
        case TYPE_FUNCTION:
-               return function_types_equal(type1, type2);
+               return function_types_equal((const function_type_t*) type1,
+                                           (const function_type_t*) type2);
        case TYPE_POINTER:
-               return pointer_types_equal(type1, type2);
+               return pointer_types_equal((const pointer_type_t*) type1,
+                                          (const pointer_type_t*) type2);
        case TYPE_ARRAY:
-               return array_types_equal(type1, type2);
+               return array_types_equal((const array_type_t*) type1,
+                                        (const array_type_t*) type2);
        case TYPE_BUILTIN:
-               return builtin_types_equal(type1, type2);
+               return builtin_types_equal((const builtin_type_t*) type1,
+                                          (const builtin_type_t*) type2);
        case TYPE_TYPEOF:
-               return typeof_types_equal(type1, type2);
+               return typeof_types_equal((const typeof_type_t*) type1,
+                                         (const typeof_type_t*) type2);
        case TYPE_TYPEDEF:
-               return typedef_types_equal(type1, type2);
+               return typedef_types_equal((const typedef_type_t*) type1,
+                                          (const typedef_type_t*) type2);
        }
 
        abort();
index 4a0428c..2e0ece2 100644 (file)
--- a/type_t.h
+++ b/type_t.h
@@ -66,70 +66,76 @@ typedef enum {
 
 typedef unsigned int type_qualifiers_t;
 
+struct type_t {
+       type_type_t       type;
+       type_qualifiers_t qualifiers;
+
+       ir_type          *firm_type;
+};
+
+struct atomic_type_t {
+       type_t              type;
+       atomic_type_type_t  atype;
+};
+
+struct builtin_type_t {
+       type_t    type;
+       symbol_t *symbol;
+       type_t   *real_type;
+};
+
+struct pointer_type_t {
+       type_t   type;
+       type_t  *points_to;
+};
+
+struct array_type_t {
+       type_t        type;
+       type_t       *element_type;
+       bool          is_static;
+       bool          is_variable;
+       expression_t *size;
+};
+
 struct function_parameter_t {
        type_t               *type;
        function_parameter_t *next;
 };
 
-struct type_t {
-       type_type_t       type;
-       type_qualifiers_t qualifiers;
+struct function_type_t {
+       type_t                type;
+       type_t               *result_type;
+       function_parameter_t *parameters;
+       bool                  variadic;
+       bool                  unspecified_parameters;
+};
 
-       union {
-               /* if type == TYPE_ATOMIC */
-               struct {
-                       atomic_type_type_t  atype;
-               } atomic_type;
-               /* if type == TYPE_COMPOUND_STRUCT or type == TYPE_COMPOUND_UNION */
-               struct {
-                       /** the declaration of the compound type, its context field
-                        * contains the compound entries. */
-                       declaration_t *declaration;
-               } compound_type;
-               /* if type == TYPE_ENUM */
-               struct {
-                       /** the declaration of the enum type. You can find the enum entries by
-                        * walking the declaration->next list until you don't find
-                        * STORAGE_CLASS_ENUM_ENTRY declarations anymore */
-                       declaration_t *declaration;
-               } enum_type;
-               /* if type == TYPE_FUNCTION */
-               struct  {
-                       type_t               *result_type;
-                       function_parameter_t *parameters;
-                       bool                  variadic;
-                       bool                  unspecified_parameters;
-               } function_type;
-               /* if type == TYPE_POINTER */
-               struct {
-                       type_t  *points_to;
-               } pointer_type;
-               /* if type == TYPE_ARRAY */
-               struct {
-                       type_t       *element_type;
-                       bool          is_static;
-                       bool          is_variable;
-                       expression_t *size;
-               } array_type;
-               /* if type == TYPE_BUILTIN */
-               struct {
-                       symbol_t *symbol;
-                       type_t   *real_type;
-               } builtin_type;
-               /* if type == TYPE_TYPEDEF */
-               struct {
-                       declaration_t *declaration;
-                       type_t        *resolved_type;
-               } typedef_type;
-               /* if type == TYPE_TYPEOF */
-               struct {
-                       expression_t *expression;
-                       type_t       *typeof_type;
-                       type_t       *resolved_type;
-               } typeof_type;
-       } v;
+struct compound_type_t {
+       type_t         type;
+       /** the declaration of the compound type, its context field
+        * contains the compound entries. */
+       declaration_t *declaration;
+};
 
-       ir_type          *firm_type;
+struct enum_type_t {
+       type_t         type;
+       /** the declaration of the enum type. You can find the enum entries by
+        * walking the declaration->next list until you don't find
+        * STORAGE_CLASS_ENUM_ENTRY declarations anymore */
+       declaration_t *declaration;
+};
+
+struct typedef_type_t {
+       type_t         type;
+       declaration_t *declaration;
+       type_t        *resolved_type;
+};
+
+struct typeof_type_t {
+       type_t        type;
+       expression_t *expression;
+       type_t       *typeof_type;
+       type_t       *resolved_type;
 };
 
 type_t *make_atomic_type(atomic_type_type_t type, type_qualifiers_t qualifiers);
index 1213383..4ad6fc0 100644 (file)
@@ -37,14 +37,14 @@ static const char *get_atomic_type_string(const atomic_type_type_t type)
        }
 }
 
-static void write_atomic_type(const type_t *type)
+static void write_atomic_type(const atomic_type_t *type)
 {
-       fprintf(out, "%s", get_atomic_type_string(type->v.atomic_type.atype));
+       fprintf(out, "%s", get_atomic_type_string(type->atype));
 }
 
-static void write_pointer_type(const type_t *type)
+static void write_pointer_type(const pointer_type_t *type)
 {
-       write_type(type->v.pointer_type.points_to);
+       write_type(type->points_to);
        fputc('*', out);
 }
 
@@ -65,16 +65,16 @@ static declaration_t *find_typedef(const type_t *type)
        return declaration;
 }
 
-static void write_compound_type(const type_t *type)
+static void write_compound_type(const compound_type_t *type)
 {
-       declaration_t *declaration = find_typedef(type);
+       declaration_t *declaration = find_typedef((const type_t*) type);
        if(declaration != NULL) {
                fprintf(out, "%s", declaration->symbol->string);
                return;
        }
 
        /* does the struct have a name? */
-       symbol_t *symbol = type->v.compound_type.declaration->symbol;
+       symbol_t *symbol = type->declaration->symbol;
        if(symbol != NULL) {
                /* TODO: make sure we create a struct for it... */
                fprintf(out, "%s", symbol->string);
@@ -84,16 +84,16 @@ static void write_compound_type(const type_t *type)
        fprintf(out, "/* TODO anonymous struct */byte");
 }
 
-static void write_enum_type(const type_t *type)
+static void write_enum_type(const enum_type_t *type)
 {
-       declaration_t *declaration = find_typedef(type);
+       declaration_t *declaration = find_typedef((const type_t*) type);
        if(declaration != NULL) {
                fprintf(out, "%s", declaration->symbol->string);
                return;
        }
 
        /* does the enum have a name? */
-       symbol_t *symbol = type->v.enum_type.declaration->symbol;
+       symbol_t *symbol = type->declaration->symbol;
        if(symbol != NULL) {
                /* TODO: make sure we create an enum for it... */
                fprintf(out, "%s", symbol->string);
@@ -103,11 +103,11 @@ static void write_enum_type(const type_t *type)
        fprintf(out, "/* TODO anonymous enum */byte");
 }
 
-static void write_function_type(const type_t *type)
+static void write_function_type(const function_type_t *type)
 {
        fprintf(out, "(func(");
 
-       function_parameter_t *parameter = type->v.function_type.parameters;
+       function_parameter_t *parameter = type->parameters;
        int                   first     = 1;
        while(parameter != NULL) {
                if(!first) {
@@ -131,7 +131,7 @@ static void write_function_type(const type_t *type)
        }
 
        fprintf(out, ") : ");
-       write_type(type->v.function_type.result_type);
+       write_type(type->result_type);
        fprintf(out, ")");
 }
 
@@ -139,20 +139,20 @@ static void write_type(const type_t *type)
 {
        switch(type->type) {
        case TYPE_ATOMIC:
-               write_atomic_type(type);
+               write_atomic_type((const atomic_type_t*) type);
                return;
        case TYPE_POINTER:
-               write_pointer_type(type);
+               write_pointer_type((const pointer_type_t*) type);
                return;
        case TYPE_COMPOUND_UNION:
        case TYPE_COMPOUND_STRUCT:
-               write_compound_type(type);
+               write_compound_type((const compound_type_t*) type);
                return;
        case TYPE_ENUM:
-               write_enum_type(type);
+               write_enum_type((const enum_type_t*) type);
                return;
        case TYPE_FUNCTION:
-               write_function_type(type);
+               write_function_type((const function_type_t*) type);
                return;
        case TYPE_INVALID:
                panic("invalid type found");
@@ -170,11 +170,11 @@ static void write_struct_entry(const declaration_t *declaration)
        fprintf(out, "\n");
 }
 
-static void write_struct(const symbol_t *symbol, const type_t *type)
+static void write_struct(const symbol_t *symbol, const compound_type_t *type)
 {
        fprintf(out, "struct %s:\n", symbol->string);
 
-       const declaration_t *declaration = type->v.compound_type.declaration->context.declarations;
+       const declaration_t *declaration = type->declaration->context.declarations;
        while(declaration != NULL) {
                write_struct_entry(declaration);
                declaration = declaration->next;
@@ -183,11 +183,11 @@ static void write_struct(const symbol_t *symbol, const type_t *type)
        fprintf(out, "\n");
 }
 
-static void write_union(const symbol_t *symbol, const type_t *type)
+static void write_union(const symbol_t *symbol, const compound_type_t *type)
 {
        fprintf(out, "union %s:\n", symbol->string);
 
-       const declaration_t *declaration = type->v.compound_type.declaration->context.declarations;
+       const declaration_t *declaration = type->declaration->context.declarations;
        while(declaration != NULL) {
                write_struct_entry(declaration);
                declaration = declaration->next;
@@ -208,7 +208,7 @@ static void write_unary_expression(const unary_expression_t *expression)
                fputc('!', out);
                break;
        default:
-               panic("unimplemented unary expression found");
+               panic("unimeplemented unary expression found");
        }
        write_expression(expression->value);
 }
@@ -234,11 +234,11 @@ static void write_expression(const expression_t *expression)
        }
 }
 
-static void write_enum(const symbol_t *symbol, const type_t *type)
+static void write_enum(const symbol_t *symbol, const enum_type_t *type)
 {
        fprintf(out, "enum %s:\n", symbol->string);
 
-       declaration_t *entry = type->v.enum_type.declaration->next;
+       declaration_t *entry = type->declaration->next;
        for ( ; entry != NULL && entry->storage_class == STORAGE_CLASS_ENUM_ENTRY;
                        entry = entry->next) {
                fprintf(out, "\t%s", entry->symbol->string);
@@ -270,7 +270,8 @@ static void write_function(const declaration_t *declaration)
        fprintf(out, "func extern %s(",
                declaration->symbol->string);
 
-       const type_t *function_type = declaration->type;
+       const function_type_t *function_type
+               = (const function_type_t*) declaration->type;
 
        declaration_t *parameter = declaration->context.declarations;
        int            first     = 1;
@@ -287,7 +288,7 @@ static void write_function(const declaration_t *declaration)
                }
                write_type(parameter->type);
        }
-       if(function_type->v.function_type.variadic) {
+       if(function_type->variadic) {
                if(!first) {
                        fprintf(out, ", ");
                } else {
@@ -297,9 +298,9 @@ static void write_function(const declaration_t *declaration)
        }
        fprintf(out, ")");
 
-       const type_t *result_type = function_type->v.function_type.result_type;
+       const type_t *result_type = function_type->result_type;
        if(result_type->type != TYPE_ATOMIC ||
-          result_type->v.atomic_type.atype != ATOMIC_TYPE_VOID) {
+                       ((const atomic_type_t*) result_type)->atype != ATOMIC_TYPE_VOID) {
                fprintf(out, " : ");
                write_type(result_type);
        }
@@ -320,7 +321,7 @@ void write_fluffy_decls(const translation_unit_t *unit)
 
        fprintf(out, "/* WARNING: Automatically generated file */\n");
 
-       /* write structs, unions + enums */
+       /* write structs,unions + enums */
        declaration_t *declaration = unit->context.declarations;
        for( ; declaration != NULL; declaration = declaration->next) {
                //fprintf(out, "// Decl: %s\n", declaration->symbol->string);
@@ -329,11 +330,11 @@ void write_fluffy_decls(const translation_unit_t *unit)
                }
                type_t *type = declaration->type;
                if(type->type == TYPE_COMPOUND_STRUCT) {
-                       write_struct(declaration->symbol, type);
+                       write_struct(declaration->symbol, (compound_type_t*) type);
                } else if(type->type == TYPE_COMPOUND_UNION) {
-                       write_union(declaration->symbol, type);
+                       write_union(declaration->symbol, (compound_type_t*) type);
                } else if(type->type == TYPE_ENUM) {
-                       write_enum(declaration->symbol, type);
+                       write_enum(declaration->symbol, (enum_type_t*) type);
                }
        }