replaced the different type types by one union type saving a lot of casts (and adding...
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Mon, 26 Nov 2007 01:35:06 +0000 (01:35 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Mon, 26 Nov 2007 01:35:06 +0000 (01:35 +0000)
[r18534]

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

index cf9eb47..83e9743 100644 (file)
@@ -118,9 +118,9 @@ static ident *unique_ident(const char *tag)
        return new_id_from_str(buf);
 }
 
-static ir_mode *get_atomic_mode(const atomic_type_t* atomic_type)
+static ir_mode *get_atomic_mode(const type_t* atomic_type)
 {
-       switch(atomic_type->atype) {
+       switch(atomic_type->v.atomic_type.atype) {
        case ATOMIC_TYPE_SCHAR:
        case ATOMIC_TYPE_CHAR:
                return mode_Bs;
@@ -172,9 +172,9 @@ static ir_mode *get_atomic_mode(const atomic_type_t* atomic_type)
 
 static unsigned get_type_size(type_t *type);
 
-static unsigned get_atomic_type_size(const atomic_type_t *type)
+static unsigned get_atomic_type_size(const type_t *type)
 {
-       switch(type->atype) {
+       switch(type->v.atomic_type.atype) {
        case ATOMIC_TYPE_CHAR:
        case ATOMIC_TYPE_SCHAR:
        case ATOMIC_TYPE_UCHAR:
@@ -209,15 +209,15 @@ static unsigned get_atomic_type_size(const atomic_type_t *type)
        panic("Trying to determine size of invalid atomic type");
 }
 
-static unsigned get_compound_type_size(compound_type_t *type)
+static unsigned get_compound_type_size(type_t *type)
 {
-       ir_type *irtype = get_ir_type(&type->type);
+       ir_type *irtype = get_ir_type(type);
        return get_type_size_bytes(irtype);
 }
 
-static unsigned get_array_type_size(array_type_t *type)
+static unsigned get_array_type_size(type_t *type)
 {
-       ir_type *irtype = get_ir_type(&type->type);
+       ir_type *irtype = get_ir_type(type);
        return get_type_size_bytes(irtype);
 }
 
@@ -227,19 +227,19 @@ static unsigned get_type_size(type_t *type)
 
        switch(type->type) {
        case TYPE_ATOMIC:
-               return get_atomic_type_size((const atomic_type_t*) type);
+               return get_atomic_type_size(type);
        case TYPE_ENUM:
                return get_mode_size_bytes(mode_Is);
        case TYPE_COMPOUND_UNION:
        case TYPE_COMPOUND_STRUCT:
-               return get_compound_type_size((compound_type_t*) type);
+               return get_compound_type_size(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((array_type_t*) type);
+               return get_array_type_size(type);
        case TYPE_BUILTIN:
        case TYPE_TYPEDEF:
        case TYPE_TYPEOF:
@@ -249,11 +249,11 @@ static unsigned get_type_size(type_t *type)
        panic("Trying to determine size of invalid type");
 }
 
-static unsigned count_parameters(const function_type_t *function_type)
+static unsigned count_parameters(const type_t *type)
 {
        unsigned count = 0;
 
-       function_parameter_t *parameter = function_type->parameters;
+       function_parameter_t *parameter = type->v.function_type.parameters;
        for ( ; parameter != NULL; parameter = parameter->next) {
                ++count;
        }
@@ -266,7 +266,7 @@ static unsigned count_parameters(const function_type_t *function_type)
 
 static long fold_constant(const expression_t *expression);
 
-static ir_type *create_atomic_type(const atomic_type_t *type)
+static ir_type *create_atomic_type(const type_t *type)
 {
        ir_mode *mode   = get_atomic_mode(type);
        ident   *id     = get_mode_ident(mode);
@@ -275,12 +275,12 @@ static ir_type *create_atomic_type(const atomic_type_t *type)
        return irtype;
 }
 
-static ir_type *create_method_type(const function_type_t *function_type)
+static ir_type *create_method_type(const type_t *type)
 {
-       type_t  *result_type  = function_type->result_type;
+       type_t  *result_type  = type->v.function_type.result_type;
 
        ident   *id           = unique_ident("functiontype");
-       int      n_parameters = count_parameters(function_type);
+       int      n_parameters = count_parameters(type);
        int      n_results    = result_type == type_void ? 0 : 1;
        ir_type *irtype       = new_type_method(id, n_parameters, n_results);
 
@@ -289,7 +289,7 @@ static ir_type *create_method_type(const function_type_t *function_type)
                set_method_res_type(irtype, 0, restype);
        }
 
-       function_parameter_t *parameter = function_type->parameters;
+       function_parameter_t *parameter = type->v.function_type.parameters;
        int                   n         = 0;
        for( ; parameter != NULL; parameter = parameter->next) {
                ir_type *p_irtype = get_ir_type(parameter->type);
@@ -297,16 +297,16 @@ static ir_type *create_method_type(const function_type_t *function_type)
                ++n;
        }
 
-       if(function_type->variadic || function_type->unspecified_parameters) {
+       if(type->v.function_type.variadic || type->v.function_type.unspecified_parameters) {
                set_method_variadicity(irtype, variadicity_variadic);
        }
 
        return irtype;
 }
 
-static ir_type *create_pointer_type(pointer_type_t *type)
+static ir_type *create_pointer_type(type_t *type)
 {
-       type_t  *points_to = type->points_to;
+       type_t  *points_to = type->v.pointer_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
@@ -314,7 +314,7 @@ static ir_type *create_pointer_type(pointer_type_t *type)
         */
        ir_type *ir_type = new_type_pointer(unique_ident("pointer"),
                                            ir_type_void, mode_P_data);
-       type->type.firm_type  = ir_type;
+       type->firm_type  = ir_type;
 
        ir_points_to = get_ir_type(points_to);
        set_pointer_points_to_type(ir_type, ir_points_to);
@@ -322,16 +322,16 @@ static ir_type *create_pointer_type(pointer_type_t *type)
        return ir_type;
 }
 
-static ir_type *create_array_type(array_type_t *type)
+static ir_type *create_array_type(type_t *type)
 {
-       type_t  *element_type    = type->element_type;
+       type_t  *element_type    = type->v.array_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->size != NULL) {
-               int n_elements = fold_constant(type->size);
+       if(type->v.array_type.size != NULL) {
+               int n_elements = fold_constant(type->v.array_type.size);
 
                set_array_bounds_int(ir_type, 0, 0, n_elements);
 
@@ -350,9 +350,9 @@ static ir_type *create_array_type(array_type_t *type)
 
 #define INVALID_TYPE ((ir_type_ptr)-1)
 
-static ir_type *create_struct_type(compound_type_t *type)
+static ir_type *create_struct_type(type_t *type)
 {
-       symbol_t *symbol = type->declaration->symbol;
+       symbol_t *symbol = type->v.compound_type.declaration->symbol;
        ident    *id;
        if(symbol != NULL) {
                id = unique_ident(symbol->string);
@@ -361,11 +361,11 @@ static ir_type *create_struct_type(compound_type_t *type)
        }
        ir_type *ir_type = new_type_struct(id);
 
-       type->type.firm_type = ir_type;
+       type->firm_type = ir_type;
 
        int align_all = 1;
        int offset    = 0;
-       declaration_t *entry = type->declaration->context.declarations;
+       declaration_t *entry = type->v.compound_type.declaration->context.declarations;
        for( ; entry != NULL; entry = entry->next) {
                if(entry->namespc != NAMESPACE_NORMAL)
                        continue;
@@ -403,9 +403,9 @@ static ir_type *create_struct_type(compound_type_t *type)
        return ir_type;
 }
 
-static ir_type *create_union_type(compound_type_t *type)
+static ir_type *create_union_type(type_t *type)
 {
-       declaration_t *declaration = type->declaration;
+       declaration_t *declaration = type->v.compound_type.declaration;
        symbol_t      *symbol      = declaration->symbol;
        ident         *id;
        if(symbol != NULL) {
@@ -415,7 +415,7 @@ static ir_type *create_union_type(compound_type_t *type)
        }
        ir_type  *ir_type = new_type_union(id);
 
-       type->type.firm_type = ir_type;
+       type->firm_type = ir_type;
 
        int align_all = 1;
        int size      = 0;
@@ -468,22 +468,22 @@ 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((atomic_type_t*) type);
+               firm_type = create_atomic_type(type);
                break;
        case TYPE_FUNCTION:
-               firm_type = create_method_type((function_type_t*) type);
+               firm_type = create_method_type(type);
                break;
        case TYPE_POINTER:
-               firm_type = create_pointer_type((pointer_type_t*) type);
+               firm_type = create_pointer_type(type);
                break;
        case TYPE_ARRAY:
-               firm_type = create_array_type((array_type_t*) type);
+               firm_type = create_array_type(type);
                break;
        case TYPE_COMPOUND_STRUCT:
-               firm_type = create_struct_type((compound_type_t*) type);
+               firm_type = create_struct_type(type);
                break;
        case TYPE_COMPOUND_UNION:
-               firm_type = create_union_type((compound_type_t*) type);
+               firm_type = create_union_type(type);
                break;
        case TYPE_ENUM:
                firm_type = ir_type_int;
@@ -755,14 +755,14 @@ static ir_node *call_expression_to_firm(const call_expression_t *call)
        }
        ir_node       *callee   = expression_to_firm(function);
 
-       function_type_t *function_type;
+       type_t *type;
        if (function->datatype->type == TYPE_POINTER) {
-               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;
+               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;
        } else {
                assert(function->datatype->type == TYPE_FUNCTION);
-               function_type = (function_type_t*)function->datatype;
+               type = function->datatype;
        }
 
        int              n_parameters = 0;
@@ -771,9 +771,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*) function_type);
+       ir_type *ir_method_type  = get_ir_type((type_t*) type);
        ir_type *new_method_type = NULL;
-       if(function_type->variadic || function_type->unspecified_parameters) {
+       if(type->v.function_type.variadic || type->v.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);
@@ -817,7 +817,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 = function_type->result_type;
+       type_t  *result_type = type->v.function_type.result_type;
        ir_node *result      = NULL;
        if(result_type != type_void) {
                ir_mode *mode    = get_ir_mode(result_type);
@@ -887,8 +887,7 @@ static ir_node *create_incdec(const unary_expression_t *expression)
 
        ir_node *offset;
        if(type->type == TYPE_POINTER) {
-               pointer_type_t *pointer_type = (pointer_type_t*) type;
-               unsigned        elem_size    = get_type_size(pointer_type->points_to);
+               unsigned elem_size = get_type_size(type->v.pointer_type.points_to);
                offset = new_Const_long(mode_Is, elem_size);
        } else {
                assert(is_type_arithmetic(type));
@@ -1041,9 +1040,8 @@ static ir_node *pointer_arithmetic(ir_node  *const pointer,
                                    dbg_info *const dbgi,
                                    const create_arithmetic_func func)
 {
-       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);
+       type_t         *const points_to = type->v.pointer_type.points_to;
+       const unsigned        elem_size = get_type_size(points_to);
 
        assert(elem_size >= 1);
        if (elem_size > 1) {
@@ -1119,8 +1117,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 pointer_type_t *const ptr_type = (const pointer_type_t*)type_left;
-               const unsigned elem_size             = get_type_size(ptr_type->points_to);
+               const type_t *const ptr_type = type_left;
+               const unsigned elem_size     = get_type_size(ptr_type->v.pointer_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);
@@ -1461,9 +1459,8 @@ static ir_node *classify_type_to_firm(const classify_type_expression_t *const ex
        gcc_type_class tc;
        switch (type->type)
        {
-               case TYPE_ATOMIC: {
-                       const atomic_type_t *const atomic_type = (const atomic_type_t*)type;
-                       switch (atomic_type->atype) {
+               case TYPE_ATOMIC:
+                       switch (type->v.atomic_type.atype) {
                                // should not be reached
                                case ATOMIC_TYPE_INVALID:
                                        tc = no_type_class;
@@ -1512,7 +1509,6 @@ 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
@@ -2052,12 +2048,12 @@ static void create_initializer_value(initializer_t *initializer,
 }
 
 static void create_initializer_compound(initializer_t *initializer,
-                                        compound_type_t *type,
+                                        type_t *type,
                                         ir_entity *entity,
                                         compound_graph_path_entry_t *last_entry,
                                         int len)
 {
-       declaration_t *compound_declaration = type->declaration;
+       declaration_t *compound_declaration = type->v.compound_type.declaration;
 
        declaration_t *compound_entry = compound_declaration->context.declarations;
 
@@ -2097,11 +2093,11 @@ static void create_initializer_compound(initializer_t *initializer,
 }
 
 static void create_initializer_array(initializer_t *initializer,
-                                     array_type_t *type, ir_entity *entity,
+                                     type_t *type, ir_entity *entity,
                                      compound_graph_path_entry_t *last_entry,
                                      int len)
 {
-       type_t *element_type = type->element_type;
+       type_t *element_type = type->v.array_type.element_type;
        element_type         = skip_typeref(element_type);
 
        compound_graph_path_entry_t entry;
@@ -2125,11 +2121,11 @@ static void create_initializer_array(initializer_t *initializer,
 }
 
 static void create_initializer_string(initializer_t *initializer,
-                                      array_type_t *type, ir_entity *entity,
+                                      type_t *type, ir_entity *entity,
                                       compound_graph_path_entry_t *last_entry,
                                       int len)
 {
-       type_t *element_type = type->element_type;
+       type_t *element_type = type->v.array_type.element_type;
        element_type         = skip_typeref(element_type);
 
        compound_graph_path_entry_t entry;
@@ -2157,21 +2153,18 @@ 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, array_type, entity, entry, len);
+                       create_initializer_string(initializer, type, entity, entry, len);
                } else {
                        assert(initializer->type == INITIALIZER_LIST);
-                       create_initializer_array(initializer, array_type, entity, entry, len);
+                       create_initializer_array(initializer, type, entity, entry, len);
                }
        } else {
                assert(initializer->type == INITIALIZER_LIST);
 
                assert(type->type == TYPE_COMPOUND_STRUCT
                                || type->type == TYPE_COMPOUND_UNION);
-               compound_type_t *compound_type = (compound_type_t*) type;
-               create_initializer_compound(initializer, compound_type, entity, entry, len);
+               create_initializer_compound(initializer, type, entity, entry, len);
        }
 }
 
@@ -2706,13 +2699,12 @@ 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 function_type_t* const func_type
-                       = (const function_type_t*) declaration->type;
+               const type_t* const type = declaration->type;
                ir_node *ret;
-               if (func_type->result_type == type_void) {
+               if (type->v.function_type.result_type == type_void) {
                        ret = new_Return(get_store(), 0, NULL);
                } else {
-                       ir_mode *const mode = get_ir_mode(func_type->result_type);
+                       ir_mode *const mode = get_ir_mode(type->v.function_type.result_type);
                        ir_node *      in[1];
                        // Â§5.1.2.2.3 main implicitly returns 0
                        if (strcmp(declaration->symbol->string, "main") == 0) {
index 91aba28..9ec5e59 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -596,15 +596,14 @@ 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 wether unsigned int is possible, while int always works.
+        * can't decide whether 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_t      *atomic_type = (atomic_type_t*) type;
-       atomic_type_type_t  atype       = atomic_type->atype;
+       atomic_type_type_t atype = type->v.atomic_type.atype;
        return atype;
 }
 
@@ -668,8 +667,7 @@ static expression_t *create_implicit_cast(expression_t *expression,
                return create_cast_expression(expression, dest_type);
        }
        if(dest_type->type == TYPE_POINTER) {
-               pointer_type_t *pointer_type
-                       = (pointer_type_t*) dest_type;
+               type_t *pointer_type = dest_type;
                switch (source_type->type) {
                        case TYPE_ATOMIC:
                                if (is_null_expression(expression)) {
@@ -684,9 +682,9 @@ static expression_t *create_implicit_cast(expression_t *expression,
                                break;
 
                        case TYPE_ARRAY: {
-                               array_type_t *const array_type = (array_type_t*) source_type;
-                               if (types_compatible(array_type->element_type,
-                                                                                                                pointer_type->points_to)) {
+                               type_t *const array_type = source_type;
+                               if (types_compatible(array_type->v.array_type.element_type,
+                                                    pointer_type->v.pointer_type.points_to)) {
                                        return create_cast_expression(expression, dest_type);
                                }
                                break;
@@ -709,9 +707,7 @@ static bool is_atomic_type(const type_t *type, atomic_type_type_t atype)
 {
        if(type->type != TYPE_ATOMIC)
                return false;
-       const atomic_type_t *atomic_type = (const atomic_type_t*) type;
-
-       return atomic_type->atype == atype;
+       return type->v.atomic_type.atype == atype;
 }
 
 static bool is_pointer(const type_t *type)
@@ -746,10 +742,10 @@ static void semantic_assign(type_t *orig_type_left, expression_t **right,
        }
 
        if (is_pointer(type_left) && is_pointer(type_right)) {
-               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;
+               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;
 
                if(!is_atomic_type(points_to_left, ATOMIC_TYPE_VOID)
                                && !is_atomic_type(points_to_right, ATOMIC_TYPE_VOID)
@@ -926,8 +922,7 @@ static designator_t *parse_designation(void)
 }
 #endif
 
-static initializer_t *initializer_from_string(array_type_t *type,
-                                              const char *string)
+static initializer_t *initializer_from_string(type_t *type, const char *string)
 {
        /* TODO: check len vs. size of array type */
        (void) type;
@@ -949,12 +944,10 @@ 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) {
-               array_type_t *array_type   = (array_type_t*) type;
-               type_t       *element_type = array_type->element_type;
+               type_t *element_type = type->v.array_type.element_type;
 
                if(element_type->type == TYPE_ATOMIC) {
-                       atomic_type_t      *atomic_type = (atomic_type_t*) element_type;
-                       atomic_type_type_t  atype       = atomic_type->atype;
+                       atomic_type_type_t atype = element_type->v.atomic_type.atype;
 
                        /* TODO handle wide strings */
                        if(atype == ATOMIC_TYPE_CHAR
@@ -962,7 +955,7 @@ 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(array_type, literal->value);
+                               return initializer_from_string(type, literal->value);
                        }
                }
        }
@@ -1045,9 +1038,8 @@ static initializer_t *parse_sub_initializer(type_t *type,
        initializer_t  *result = NULL;
        initializer_t **elems;
        if(type->type == TYPE_ARRAY) {
-               array_type_t *array_type   = (array_type_t*) type;
-               type_t       *element_type = array_type->element_type;
-               element_type               = skip_typeref(element_type);
+               type_t *element_type = type->v.array_type.element_type;
+               element_type         = skip_typeref(element_type);
 
                initializer_t *sub;
                had_initializer_brace_warning = false;
@@ -1087,8 +1079,7 @@ static initializer_t *parse_sub_initializer(type_t *type,
        } else {
                assert(type->type == TYPE_COMPOUND_STRUCT
                                || type->type == TYPE_COMPOUND_UNION);
-               compound_type_t *compound_type = (compound_type_t*) type;
-               context_t       *context       = & compound_type->declaration->context;
+               context_t *context = &type->v.compound_type.declaration->context;
 
                declaration_t *first = context->declarations;
                if(first == NULL)
@@ -1404,12 +1395,12 @@ restart:
 
        expect(')');
 
-       typeof_type_t *typeof = allocate_type_zero(sizeof(typeof[0]));
-       typeof->type.type     = TYPE_TYPEOF;
-       typeof->expression    = expression;
-       typeof->typeof_type   = type;
+       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;
 
-       return (type_t*) typeof;
+       return typeof;
 }
 
 typedef enum {
@@ -1432,13 +1423,13 @@ typedef enum {
 
 static type_t *create_builtin_type(symbol_t *symbol)
 {
-       builtin_type_t *type = allocate_type_zero(sizeof(type[0]));
-       type->type.type      = TYPE_BUILTIN;
-       type->symbol         = symbol;
+       type_t *type = allocate_type_zero(sizeof(type[0]));
+       type->type   = TYPE_BUILTIN;
+       type->v.builtin_type.symbol    = symbol;
        /* TODO... */
-       type->real_type      = type_int;
+       type->v.builtin_type.real_type = type_int;
 
-       return (type_t*) type;
+       return type;
 }
 
 static type_t *get_typedef_type(symbol_t *symbol)
@@ -1448,19 +1439,19 @@ static type_t *get_typedef_type(symbol_t *symbol)
                        || declaration->storage_class != STORAGE_CLASS_TYPEDEF)
                return NULL;
 
-       typedef_type_t *typedef_type = allocate_type_zero(sizeof(typedef_type[0]));
-       typedef_type->type.type    = TYPE_TYPEDEF;
-       typedef_type->declaration  = declaration;
+       type_t *type = allocate_type_zero(sizeof(type[0]));
+       type->type   = TYPE_TYPEDEF;
+       type->v.typedef_type.declaration = declaration;
 
-       return (type_t*) typedef_type;
+       return type;
 }
 
 static void parse_declaration_specifiers(declaration_specifiers_t *specifiers)
 {
-       type_t        *type            = NULL;
-       unsigned       type_qualifiers = 0;
-       unsigned       type_specifiers = 0;
-       int            newtype         = 0;
+       type_t            *type            = NULL;
+       type_qualifiers_t type_qualifiers = TYPE_QUALIFIER_NONE;
+       unsigned          type_specifiers = 0;
+       int               newtype         = 0;
 
        while(true) {
                switch(token.type) {
@@ -1540,32 +1531,24 @@ static void parse_declaration_specifiers(declaration_specifiers_t *specifiers)
 
                /* TODO: if type != NULL for the following rules should issue
                 * an error */
-               case T_struct: {
-                       compound_type_t *compound_type
-                               = allocate_type_zero(sizeof(compound_type[0]));
-                       compound_type->type.type = TYPE_COMPOUND_STRUCT;
-                       compound_type->declaration = parse_compound_type_specifier(true);
+               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);
 
-                       type = (type_t*) compound_type;
                        break;
-               }
-               case T_union: {
-                       compound_type_t *compound_type
-                               = allocate_type_zero(sizeof(compound_type[0]));
-                       compound_type->type.type = TYPE_COMPOUND_UNION;
-                       compound_type->declaration = parse_compound_type_specifier(false);
+               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);
 
-                       type = (type_t*) compound_type;
                        break;
-               }
-               case T_enum: {
-                       enum_type_t *enum_type = allocate_type_zero(sizeof(enum_type[0]));
-                       enum_type->type.type   = TYPE_ENUM;
-                       enum_type->declaration = parse_enum_specifier();
+               case T_enum:
+                       type       = allocate_type_zero(sizeof(type[0]));
+                       type->type = TYPE_ENUM;
+                       type->v.enum_type.declaration = parse_enum_specifier();
 
-                       type = (type_t*) enum_type;
                        break;
-               }
                case T___typeof__:
                        type = parse_typeof();
                        break;
@@ -1709,22 +1692,20 @@ finish_specifiers:
                        atomic_type = ATOMIC_TYPE_INVALID;
                }
 
-               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;
+               type       = allocate_type_zero(sizeof(type[0]));
+               type->type = TYPE_ATOMIC;
+               type->v.atomic_type.atype = atomic_type;
+               newtype = 1;
        } else {
                if(type_specifiers != 0) {
                        parse_error("multiple datatypes in declaration");
                }
        }
 
-       type->qualifiers = (type_qualifier_t)type_qualifiers;
+       type->qualifiers = type_qualifiers;
 
        type_t *result = typehash_insert(type);
-       if(newtype && result != (type_t*) type) {
+       if(newtype && result != type) {
                free_type(type);
        }
 
@@ -1778,19 +1759,18 @@ static declaration_t *parse_parameter(void)
                parse_error("typedef not allowed in parameter list");
        }
 
-       /* Array as last part of a paramter type is just syntactic sugar.  Turn it
+       /* Array as last part of a parameter type is just syntactic sugar.  Turn it
         * into a pointer */
        if (declaration->type->type == TYPE_ARRAY) {
-               const array_type_t *const arr_type =
-                       (const array_type_t*)declaration->type;
+               const type_t *const arr_type = declaration->type;
                declaration->type =
-                       make_pointer_type(arr_type->element_type, TYPE_QUALIFIER_NONE);
+                       make_pointer_type(arr_type->v.array_type.element_type, TYPE_QUALIFIER_NONE);
        }
 
        return declaration;
 }
 
-static declaration_t *parse_parameters(function_type_t *type)
+static declaration_t *parse_parameters(type_t *type)
 {
        if(token.type == T_IDENTIFIER) {
                symbol_t      *symbol = token.v.symbol;
@@ -1802,7 +1782,7 @@ static declaration_t *parse_parameters(function_type_t *type)
        }
 
        if(token.type == ')') {
-               type->unspecified_parameters = 1;
+               type->v.function_type.unspecified_parameters = 1;
                return NULL;
        }
        if(token.type == T_void && look_ahead(1)->type == ')') {
@@ -1820,7 +1800,7 @@ static declaration_t *parse_parameters(function_type_t *type)
                switch(token.type) {
                case T_DOTDOTDOT:
                        next_token();
-                       type->variadic = 1;
+                       type->v.function_type.variadic = 1;
                        return declarations;
 
                case T_IDENTIFIER:
@@ -1835,7 +1815,7 @@ static declaration_t *parse_parameters(function_type_t *type)
                                last_declaration->next = declaration;
                                last_parameter->next   = parameter;
                        } else {
-                               type->parameters = parameter;
+                               type->v.function_type.parameters = parameter;
                                declarations     = declaration;
                        }
                        last_parameter   = parameter;
@@ -1873,7 +1853,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;
-       function_type_t    *function_type;
+       type_t             *function_type;
 };
 
 typedef struct parsed_array_t parsed_array_t;
@@ -1941,8 +1921,8 @@ static construct_type_t *parse_function_declarator(declaration_t *declaration)
 {
        eat('(');
 
-       function_type_t *type = allocate_type_zero(sizeof(type[0]));
-       type->type.type       = TYPE_FUNCTION;
+       type_t *type = allocate_type_zero(sizeof(type[0]));
+       type->type   = TYPE_FUNCTION;
 
        declaration_t *parameters = parse_parameters(type);
        if(declaration != NULL) {
@@ -2066,46 +2046,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;
-               function_type_t           *function_type;
-               pointer_type_t            *pointer_type;
-               array_type_t              *array_type;
+               type_t                    *ftype;
+               type_t                    *ptype;
+               type_t                    *atype;
 
                switch(iter->type) {
                case CONSTRUCT_INVALID:
                        panic("invalid type construction found");
                case CONSTRUCT_FUNCTION:
                        construct_function_type = (construct_function_type_t*) iter;
-                       function_type           = construct_function_type->function_type;
+                       ftype                   = construct_function_type->function_type;
 
-                       function_type->result_type = type;
-                       type                       = (type_t*) function_type;
+                       ftype->v.function_type.result_type = type;
+                       type                               = ftype;
                        break;
 
                case CONSTRUCT_POINTER:
                        parsed_pointer = (parsed_pointer_t*) iter;
-                       pointer_type   = allocate_type_zero(sizeof(pointer_type[0]));
+                       ptype          = allocate_type_zero(sizeof(ptype[0]));
 
-                       pointer_type->type.type       = TYPE_POINTER;
-                       pointer_type->points_to       = type;
-                       pointer_type->type.qualifiers = parsed_pointer->type_qualifiers;
-                       type                          = (type_t*) pointer_type;
+                       ptype->type                     = TYPE_POINTER;
+                       ptype->v.pointer_type.points_to = type;
+                       ptype->qualifiers               = parsed_pointer->type_qualifiers;
+                       type                            = ptype;
                        break;
 
                case CONSTRUCT_ARRAY:
-                       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;
+                       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;
                        break;
                }
 
-               type_t *hashed_type = typehash_insert((type_t*) type);
+               type_t *hashed_type = typehash_insert(type);
                if(hashed_type != type) {
                        /* the function type was constructed earlier freeing it here will
                         * destroy other types... */
@@ -2211,9 +2191,7 @@ static void parse_init_declarators(const declaration_specifiers_t *specifiers)
                        initializer_t *initializer = parse_initializer(type);
 
                        if(type->type == TYPE_ARRAY && initializer != NULL) {
-                               array_type_t       *array_type = (array_type_t*) type;
-
-                               if(array_type->size == NULL) {
+                               if(type->v.array_type.size == NULL) {
                                        const_t *cnst = allocate_ast_zero(sizeof(cnst[0]));
 
                                        cnst->expression.type     = EXPR_CONST;
@@ -2226,11 +2204,10 @@ static void parse_init_declarators(const declaration_specifiers_t *specifiers)
                                                cnst->v.int_value = strlen(initializer->v.string) + 1;
                                        }
 
-                                       array_type->size = (expression_t*) cnst;
+                                       type->v.array_type.size = (expression_t*) cnst;
                                }
                        }
 
-
                        ndeclaration->init.initializer = initializer;
                } else if(token.type == '{') {
                        if(type->type != TYPE_FUNCTION) {
@@ -2347,9 +2324,8 @@ static void parse_declaration(void)
                switch (specifiers.type->type) {
                        case TYPE_COMPOUND_STRUCT:
                        case TYPE_COMPOUND_UNION: {
-                               const compound_type_t *const comp_type =
-                                       (const compound_type_t*)specifiers.type;
-                               if (comp_type->declaration->symbol == NULL) {
+                               const type_t *const comp_type = specifiers.type;
+                               if (comp_type->v.compound_type.declaration->symbol == NULL) {
                                        parse_warning_pos(source_position,
                                                                                                                "unnamed struct/union that defines no instances");
                                }
@@ -2470,16 +2446,15 @@ static expression_t *parse_float_const(void)
 static declaration_t *create_implicit_function(symbol_t *symbol,
                const source_position_t source_position)
 {
-       function_type_t *function_type
-               = allocate_type_zero(sizeof(function_type[0]));
+       type_t *ftype = allocate_type_zero(sizeof(ftype[0]));
 
-       function_type->type.type              = TYPE_FUNCTION;
-       function_type->result_type            = type_int;
-       function_type->unspecified_parameters = true;
+       ftype->type                                   = TYPE_FUNCTION;
+       ftype->v.function_type.result_type            = type_int;
+       ftype->v.function_type.unspecified_parameters = true;
 
-       type_t *type = typehash_insert((type_t*) function_type);
-       if(type != (type_t*) function_type) {
-               free_type(function_type);
+       type_t *type = typehash_insert(ftype);
+       if(type != ftype) {
+               free_type(ftype);
        }
 
        declaration_t *declaration = allocate_ast_zero(sizeof(declaration[0]));
@@ -2749,13 +2724,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;
 
-       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 *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;
 
-       type_t *result = typehash_insert((type_t*) type);
-       if(result != (type_t*) type) {
+       type_t *result = typehash_insert(type);
+       if(result != type) {
                free_type(type);
        }
 
@@ -2843,17 +2818,17 @@ static expression_t *parse_array_expression(unsigned precedence,
 
        if(type_left != NULL && type_right != NULL) {
                if(type_left->type == TYPE_POINTER) {
-                       pointer_type_t *pointer           = (pointer_type_t*) type_left;
-                       array_access->expression.datatype = pointer->points_to;
+                       type_t *pointer = type_left;
+                       array_access->expression.datatype = pointer->v.pointer_type.points_to;
                } else if(type_left->type == TYPE_ARRAY) {
-                       array_type_t *array_type          = (array_type_t*) type_left;
-                       array_access->expression.datatype = array_type->element_type;
+                       type_t *array_type = type_left;
+                       array_access->expression.datatype = array_type->v.array_type.element_type;
                } else if(type_right->type == TYPE_POINTER) {
-                       pointer_type_t *pointer           = (pointer_type_t*) type_right;
-                       array_access->expression.datatype = pointer->points_to;
+                       type_t *pointer = type_right;
+                       array_access->expression.datatype = pointer->v.pointer_type.points_to;
                } else if(type_right->type == TYPE_ARRAY) {
-                       array_type_t *array_type          = (array_type_t*) type_right;
-                       array_access->expression.datatype = array_type->element_type;
+                       type_t *array_type = type_right;
+                       array_access->expression.datatype = array_type->v.array_type.element_type;
                } else {
                        parser_print_error_prefix();
                        fprintf(stderr, "array access on object with non-pointer types ");
@@ -2951,8 +2926,7 @@ static expression_t *parse_select_expression(unsigned precedence,
                        fputc('\n', stderr);
                        return make_invalid_expression();
                }
-               pointer_type_t *pointer_type = (pointer_type_t*) type;
-               type_left                    = pointer_type->points_to;
+               type_left = type->v.pointer_type.points_to;
        }
        type_left = skip_typeref(type_left);
 
@@ -2966,8 +2940,8 @@ static expression_t *parse_select_expression(unsigned precedence,
                return make_invalid_expression();
        }
 
-       compound_type_t *compound_type = (compound_type_t*) type_left;
-       declaration_t   *declaration   = compound_type->declaration;
+       type_t        *compound_type = type_left;
+       declaration_t *declaration   = compound_type->v.compound_type.declaration;
 
        if(!declaration->init.is_defined) {
                parser_print_error_prefix();
@@ -3004,18 +2978,16 @@ static expression_t *parse_call_expression(unsigned precedence,
        call->expression.type   = EXPR_CALL;
        call->function          = expression;
 
-       function_type_t *function_type;
-       type_t          *orig_type     = expression->datatype;
-       type_t          *type          = skip_typeref(orig_type);
+       type_t *function_type;
+       type_t *orig_type     = expression->datatype;
+       type_t *type          = skip_typeref(orig_type);
 
        if(type->type == TYPE_POINTER) {
-               pointer_type_t *pointer_type = (pointer_type_t*) type;
-
-               type = skip_typeref(pointer_type->points_to);
+               type = skip_typeref(type->v.pointer_type.points_to);
        }
        if (type->type == TYPE_FUNCTION) {
-               function_type             = (function_type_t*) type;
-               call->expression.datatype = function_type->result_type;
+               function_type             = type;
+               call->expression.datatype = type->v.function_type.result_type;
        } else {
                parser_print_error_prefix();
                fputs("called object '", stderr);
@@ -3053,7 +3025,7 @@ static expression_t *parse_call_expression(unsigned precedence,
        expect(')');
 
        if(function_type != NULL) {
-               function_parameter_t *parameter = function_type->parameters;
+               function_parameter_t *parameter = function_type->v.function_type.parameters;
                call_argument_t      *argument  = call->arguments;
                for( ; parameter != NULL && argument != NULL;
                                parameter = parameter->next, argument = argument->next) {
@@ -3070,8 +3042,8 @@ static expression_t *parse_call_expression(unsigned precedence,
                        fprintf(stderr, "'\n");
                } else if(argument != NULL) {
                        /* too many parameters */
-                       if(!function_type->variadic
-                                       && !function_type->unspecified_parameters) {
+                       if(!function_type->v.function_type.variadic
+                                       && !function_type->v.function_type.unspecified_parameters) {
                                parser_print_error_prefix();
                                fprintf(stderr, "too many arguments to function '");
                                print_expression(expression);
@@ -3265,21 +3237,17 @@ static void semantic_dereference(unary_expression_t *expression)
 
        type_t *type = skip_typeref(orig_type);
        switch (type->type) {
-               case TYPE_ARRAY: {
-                       array_type_t *const array_type  = (array_type_t*)type;
-                       expression->expression.datatype = array_type->element_type;
+               case TYPE_ARRAY:
+                       expression->expression.datatype = type->v.array_type.element_type;
                        break;
-               }
 
-               case TYPE_POINTER: {
-                       pointer_type_t *pointer_type    = (pointer_type_t*)type;
-                       expression->expression.datatype = pointer_type->points_to;
+               case TYPE_POINTER:
+                       expression->expression.datatype = type->v.pointer_type.points_to;
                        break;
-               }
 
                default:
                        parser_print_error_prefix();
-                       fputs("'Unary *' needs pointer or arrray type, but type ", stderr);
+                       fputs("'Unary *' needs pointer or array type, but type ", stderr);
                        print_type_quoted(orig_type);
                        fputs(" given.\n", stderr);
                        return;
@@ -3471,13 +3439,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 array_type_t *const arr_type = (const array_type_t*)type_left;
+               const type_t *const arr_type = type_left;
                expression->expression.datatype =
-                 make_pointer_type(arr_type->element_type, TYPE_QUALIFIER_NONE);
+                 make_pointer_type(arr_type->v.array_type.element_type, TYPE_QUALIFIER_NONE);
        } else if (type_right->type == TYPE_ARRAY && is_type_integer(type_left)) {
-               const array_type_t *const arr_type = (const array_type_t*)type_right;
+               const type_t *const arr_type = type_right;
                expression->expression.datatype =
-                       make_pointer_type(arr_type->element_type, TYPE_QUALIFIER_NONE);
+                       make_pointer_type(arr_type->v.array_type.element_type, TYPE_QUALIFIER_NONE);
        } else {
                parser_print_error_prefix();
                fprintf(stderr, "invalid operands to binary + (");
@@ -4161,8 +4129,8 @@ static statement_t *parse_return(void)
        statement->source_position = token.source_position;
 
        assert(current_function->type->type == TYPE_FUNCTION);
-       function_type_t *function_type = (function_type_t*) current_function->type;
-       type_t          *return_type   = function_type->result_type;
+       type_t *function_type = current_function->type;
+       type_t *return_type   = function_type->v.function_type.result_type;
 
        expression_t *return_value;
        if(token.type != ';') {
diff --git a/type.c b/type.c
index 92fcd15..c6c0801 100644 (file)
--- a/type.c
+++ b/type.c
@@ -48,12 +48,12 @@ void print_type_qualifiers(unsigned qualifiers)
 }
 
 static
-void print_atomic_type(const atomic_type_t *type)
+void print_atomic_type(const type_t *type)
 {
-       print_type_qualifiers(type->type.qualifiers);
+       print_type_qualifiers(type->qualifiers);
 
        const char *s;
-       switch(type->atype) {
+       switch(type->v.atomic_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 atomic_type_t *type)
        fputs(s, out);
 }
 
-static void print_function_type_pre(const function_type_t *type)
+static void print_function_type_pre(const type_t *type)
 {
-       print_type_qualifiers(type->type.qualifiers);
+       print_type_qualifiers(type->qualifiers);
 
-       intern_print_type_pre(type->result_type);
+       intern_print_type_pre(type->v.function_type.result_type);
 
        /* TODO: don't emit braces if we're the toplevel type... */
        fputc('(', out);
 }
 
-static void print_function_type_post(const function_type_t *type,
+static void print_function_type_post(const type_t *type,
                                      const context_t *context)
 {
        /* TODO: don't emit braces if we're the toplevel type... */
-       intern_print_type_post(type->result_type);
+       intern_print_type_post(type->v.function_type.result_type);
        fputc(')', out);
 
        fputc('(', out);
 
        int                 first     = 1;
        if(context == NULL) {
-               function_parameter_t *parameter = type->parameters;
+               function_parameter_t *parameter = type->v.function_type.parameters;
                for( ; parameter != NULL; parameter = parameter->next) {
                        if(first) {
                                first = 0;
@@ -118,7 +118,7 @@ static void print_function_type_post(const function_type_t *type,
                                       &parameter->context);
                }
        }
-       if(type->variadic) {
+       if(type->v.function_type.variadic) {
                if(first) {
                        first = 0;
                } else {
@@ -126,41 +126,41 @@ static void print_function_type_post(const function_type_t *type,
                }
                fputs("...", out);
        }
-       if(first && !type->unspecified_parameters) {
+       if(first && !type->v.function_type.unspecified_parameters) {
                fputs("void", out);
        }
        fputc(')', out);
 }
 
-static void print_pointer_type_pre(const pointer_type_t *type)
+static void print_pointer_type_pre(const type_t *type)
 {
-       intern_print_type_pre(type->points_to);
+       intern_print_type_pre(type->v.pointer_type.points_to);
        fputs("*", out);
-       print_type_qualifiers(type->type.qualifiers);
+       print_type_qualifiers(type->qualifiers);
 }
 
-static void print_pointer_type_post(const pointer_type_t *type)
+static void print_pointer_type_post(const type_t *type)
 {
-       intern_print_type_post(type->points_to);
+       intern_print_type_post(type->v.pointer_type.points_to);
 }
 
-static void print_array_type_pre(const array_type_t *type)
+static void print_array_type_pre(const type_t *type)
 {
-       intern_print_type_pre(type->element_type);
+       intern_print_type_pre(type->v.array_type.element_type);
 }
 
-static void print_array_type_post(const array_type_t *type)
+static void print_array_type_post(const type_t *type)
 {
        fputc('[', out);
-       if(type->is_static) {
+       if(type->v.array_type.is_static) {
                fputs("static ", out);
        }
-       print_type_qualifiers(type->type.qualifiers);
-       if(type->size != NULL) {
-               print_expression(type->size);
+       print_type_qualifiers(type->qualifiers);
+       if(type->v.array_type.size != NULL) {
+               print_expression(type->v.array_type.size);
        }
        fputc(']', out);
-       intern_print_type_post(type->element_type);
+       intern_print_type_post(type->v.array_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 enum_type_t *type)
+static void print_type_enum(const type_t *type)
 {
-       print_type_qualifiers(type->type.qualifiers);
+       print_type_qualifiers(type->qualifiers);
        fputs("enum ", out);
 
-       declaration_t *declaration = type->declaration;
+       declaration_t *declaration = type->v.enum_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 compound_type_t *type)
+static void print_compound_type(const type_t *type)
 {
-       print_type_qualifiers(type->type.qualifiers);
+       print_type_qualifiers(type->qualifiers);
 
-       if(type->type.type == TYPE_COMPOUND_STRUCT) {
+       if(type->type == TYPE_COMPOUND_STRUCT) {
                fputs("struct ", out);
        } else {
-               assert(type->type.type == TYPE_COMPOUND_UNION);
+               assert(type->type == TYPE_COMPOUND_UNION);
                fputs("union ", out);
        }
 
-       declaration_t *declaration = type->declaration;
+       declaration_t *declaration = type->v.compound_type.declaration;
        symbol_t      *symbol      = declaration->symbol;
        if(symbol != NULL) {
                fputs(symbol->string, out);
@@ -238,19 +238,19 @@ static void print_compound_type(const compound_type_t *type)
        }
 }
 
-static void print_typedef_type_pre(typedef_type_t *type)
+static void print_typedef_type_pre(type_t *type)
 {
-       fputs(type->declaration->symbol->string, out);
+       fputs(type->v.typedef_type.declaration->symbol->string, out);
 }
 
-static void print_typeof_type_pre(typeof_type_t *type)
+static void print_typeof_type_pre(type_t *type)
 {
        fputs("typeof(", out);
-       if(type->expression != NULL) {
-               assert(type->typeof_type == NULL);
-               print_expression(type->expression);
+       if(type->v.typeof_type.expression != NULL) {
+               assert(type->v.typeof_type.typeof_type == NULL);
+               print_expression(type->v.typeof_type.expression);
        } else {
-               print_type(type->typeof_type);
+               print_type(type->v.typeof_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((enum_type_t*) type);
+               print_type_enum(type);
                return;
        case TYPE_ATOMIC:
-               print_atomic_type((atomic_type_t*) type);
+               print_atomic_type(type);
                return;
        case TYPE_COMPOUND_STRUCT:
        case TYPE_COMPOUND_UNION:
-               print_compound_type((compound_type_t*) type);
+               print_compound_type(type);
                return;
        case TYPE_BUILTIN:
-               fputs(((builtin_type_t*) type)->symbol->string, out);
+               fputs(type->v.builtin_type.symbol->string, out);
                return;
        case TYPE_FUNCTION:
-               print_function_type_pre((function_type_t*) type);
+               print_function_type_pre(type);
                return;
        case TYPE_POINTER:
-               print_pointer_type_pre((pointer_type_t*) type);
+               print_pointer_type_pre(type);
                return;
        case TYPE_ARRAY:
-               print_array_type_pre((array_type_t*) type);
+               print_array_type_pre(type);
                return;
        case TYPE_TYPEDEF:
-               print_typedef_type_pre((typedef_type_t*) type);
+               print_typedef_type_pre(type);
                return;
        case TYPE_TYPEOF:
-               print_typeof_type_pre((typeof_type_t*) type);
+               print_typeof_type_pre(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((const function_type_t*) type, NULL);
+               print_function_type_post(type, NULL);
                return;
        case TYPE_POINTER:
-               print_pointer_type_post((const pointer_type_t*) type);
+               print_pointer_type_post(type);
                return;
        case TYPE_ARRAY:
-               print_array_type_post((const array_type_t*) type);
+               print_array_type_post(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((const function_type_t*) type, context);
+               print_function_type_post(type, context);
        } else {
                intern_print_type_post(type);
        }
@@ -355,8 +355,7 @@ bool is_type_integer(const type_t *type)
        if(type->type != TYPE_ATOMIC)
                return false;
 
-       atomic_type_t *atomic_type = (atomic_type_t*) type;
-       switch(atomic_type->atype) {
+       switch(type->v.atomic_type.atype) {
        case ATOMIC_TYPE_BOOL:
        case ATOMIC_TYPE_CHAR:
        case ATOMIC_TYPE_SCHAR:
@@ -380,8 +379,7 @@ bool is_type_floating(const type_t *type)
        if(type->type != TYPE_ATOMIC)
                return false;
 
-       atomic_type_t *atomic_type = (atomic_type_t*) type;
-       switch(atomic_type->atype) {
+       switch(type->v.atomic_type.atype) {
        case ATOMIC_TYPE_FLOAT:
        case ATOMIC_TYPE_DOUBLE:
        case ATOMIC_TYPE_LONG_DOUBLE:
@@ -408,8 +406,7 @@ bool is_type_signed(const type_t *type)
        if(type->type != TYPE_ATOMIC)
                return false;
 
-       atomic_type_t *atomic_type = (atomic_type_t*) type;
-       switch(atomic_type->atype) {
+       switch(type->v.atomic_type.atype) {
        case ATOMIC_TYPE_CHAR:
        case ATOMIC_TYPE_SCHAR:
        case ATOMIC_TYPE_SHORT:
@@ -467,19 +464,14 @@ bool is_type_incomplete(const type_t *type)
        switch(type->type) {
        case TYPE_COMPOUND_STRUCT:
        case TYPE_COMPOUND_UNION: {
-               const compound_type_t *compound_type
-                       = (const compound_type_t*) type;
-               declaration_t *declaration = compound_type->declaration;
+               declaration_t *declaration = type->v.compound_type.declaration;
                return !declaration->init.is_defined;
        }
        case TYPE_FUNCTION:
                return true;
 
-       case TYPE_ARRAY: {
-               const array_type_t *array_type = (const array_type_t*) type;
-
-               return array_type->size == NULL;
-       }
+       case TYPE_ARRAY:
+               return type->v.array_type.size == NULL;
 
        case TYPE_ATOMIC:
        case TYPE_POINTER:
@@ -503,12 +495,8 @@ 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) {
-               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;
-       }
+       if(type1->type == TYPE_ATOMIC && type2->type == TYPE_ATOMIC)
+               return type1->v.atomic_type.atype == type2->v.atomic_type.atype;
 
        return false;
 }
@@ -518,42 +506,20 @@ bool pointers_compatible(const type_t *type1, const type_t *type2)
        assert(type1->type == TYPE_POINTER);
        assert(type2->type == TYPE_POINTER);
 #if 0
-       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);
+       return types_compatible(type1->v.pointer_type.points_to,
+                               type2->v.pointer_type.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)
 {
-       size_t size = get_type_size(type);
-
-       type_t *copy = obstack_alloc(type_obst, size);
-       memcpy(copy, type, size);
+       type_t *copy = obstack_alloc(type_obst, sizeof(*copy));
+       memcpy(copy, type, sizeof(*copy));
 
        (void) duplicate_type;
 
@@ -566,30 +532,24 @@ type_t *skip_typeref(type_t *type)
 
        while(1) {
                switch(type->type) {
-               case TYPE_TYPEDEF: {
+               case TYPE_TYPEDEF:
                        qualifiers |= type->qualifiers;
-                       const typedef_type_t *typedef_type = (const typedef_type_t*) type;
-                       if(typedef_type->resolved_type != NULL) {
-                               type = typedef_type->resolved_type;
+                       if(type->v.typedef_type.resolved_type != NULL) {
+                               type = type->v.typedef_type.resolved_type;
                                break;
                        }
-                       type = typedef_type->declaration->type;
+                       type = type->v.typedef_type.declaration->type;
                        continue;
-               }
-               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;
+               case TYPE_TYPEOF:
+                       if(type->v.typeof_type.typeof_type != NULL) {
+                               type = type->v.typeof_type.typeof_type;
                        } else {
-                               type = typeof_type->expression->datatype;
+                               type = type->v.typeof_type.expression->datatype;
                        }
                        continue;
-               }
-               case TYPE_BUILTIN: {
-                       const builtin_type_t *builtin_type = (const builtin_type_t*) type;
-                       type = builtin_type->real_type;
+               case TYPE_BUILTIN:
+                       type = type->v.builtin_type.real_type;
                        continue;
-               }
                default:
                        break;
                }
@@ -612,26 +572,24 @@ static type_t *identify_new_type(type_t *type)
 
 type_t *make_atomic_type(atomic_type_type_t type, type_qualifiers_t qualifiers)
 {
-       atomic_type_t *atomic_type
-               = obstack_alloc(type_obst, sizeof(atomic_type[0]));
+       type_t *atomic_type = obstack_alloc(type_obst, sizeof(atomic_type[0]));
        memset(atomic_type, 0, sizeof(atomic_type[0]));
-       atomic_type->type.type       = TYPE_ATOMIC;
-       atomic_type->type.qualifiers = qualifiers;
-       atomic_type->atype           = type;
+       atomic_type->type                = TYPE_ATOMIC;
+       atomic_type->qualifiers          = qualifiers;
+       atomic_type->v.atomic_type.atype = type;
 
-       return identify_new_type((type_t*) atomic_type);
+       return identify_new_type(atomic_type);
 }
 
 type_t *make_pointer_type(type_t *points_to, type_qualifiers_t qualifiers)
 {
-       pointer_type_t *pointer_type
-               = obstack_alloc(type_obst, sizeof(pointer_type[0]));
+       type_t *pointer_type = obstack_alloc(type_obst, sizeof(pointer_type[0]));
        memset(pointer_type, 0, sizeof(pointer_type[0]));
-       pointer_type->type.type       = TYPE_POINTER;
-       pointer_type->type.qualifiers = qualifiers;
-       pointer_type->points_to       = points_to;
+       pointer_type->type                     = TYPE_POINTER;
+       pointer_type->qualifiers               = qualifiers;
+       pointer_type->v.pointer_type.points_to = points_to;
 
-       return identify_new_type((type_t*) pointer_type);
+       return identify_new_type(pointer_type);
 }
 
 static __attribute__((unused))
diff --git a/type.h b/type.h
index 44b721c..6811eb7 100644 (file)
--- a/type.h
+++ b/type.h
@@ -6,16 +6,7 @@
 #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 1e07c1f..59a5667 100644 (file)
@@ -26,36 +26,36 @@ static unsigned hash_ptr(const void *ptr)
        return ptr_int >> 3;
 }
 
-static unsigned hash_atomic_type(const atomic_type_t *type)
+static unsigned hash_atomic_type(const type_t *type)
 {
        unsigned some_prime = 27644437;
-       unsigned result     = type->atype * some_prime;
+       unsigned result     = type->v.atomic_type.atype * some_prime;
 
        return result;
 }
 
-static unsigned hash_pointer_type(const pointer_type_t *type)
+static unsigned hash_pointer_type(const type_t *type)
 {
-       return hash_ptr(type->points_to);
+       return hash_ptr(type->v.pointer_type.points_to);
 }
 
-static unsigned hash_array_type(const array_type_t *type)
+static unsigned hash_array_type(const type_t *type)
 {
-       return hash_ptr(type->element_type);
+       return hash_ptr(type->v.array_type.element_type);
 }
 
-static unsigned hash_compound_type(const compound_type_t *type)
+static unsigned hash_compound_type(const type_t *type)
 {
-       return hash_ptr(type->declaration);
+       return hash_ptr(type->v.compound_type.declaration);
 }
 
 static unsigned hash_type(const type_t *type);
 
-static unsigned hash_function_type(const function_type_t *type)
+static unsigned hash_function_type(const type_t *type)
 {
-       unsigned result = hash_ptr(type->result_type);
+       unsigned result = hash_ptr(type->v.function_type.result_type);
 
-       function_parameter_t *parameter = type->parameters;
+       function_parameter_t *parameter = type->v.function_type.parameters;
        while(parameter != NULL) {
                result   ^= hash_ptr(parameter->type);
                parameter = parameter->next;
@@ -64,15 +64,15 @@ static unsigned hash_function_type(const function_type_t *type)
        return result;
 }
 
-static unsigned hash_enum_type(const enum_type_t *type)
+static unsigned hash_enum_type(const type_t *type)
 {
-       return hash_ptr(type->declaration);
+       return hash_ptr(type->v.enum_type.declaration);
 }
 
-static unsigned hash_typeof_type(const typeof_type_t *type)
+static unsigned hash_typeof_type(const type_t *type)
 {
-       unsigned result = hash_ptr(type->expression);
-       result         ^= hash_ptr(type->typeof_type);
+       unsigned result = hash_ptr(type->v.typeof_type.expression);
+       result         ^= hash_ptr(type->v.typeof_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((const atomic_type_t*) type);
+               hash = hash_atomic_type(type);
                break;
        case TYPE_ENUM:
-               hash = hash_enum_type((const enum_type_t*) type);
+               hash = hash_enum_type(type);
                break;
        case TYPE_COMPOUND_STRUCT:
        case TYPE_COMPOUND_UNION:
-               hash = hash_compound_type((const compound_type_t*) type);
+               hash = hash_compound_type(type);
                break;
        case TYPE_FUNCTION:
-               hash = hash_function_type((const function_type_t*) type);
+               hash = hash_function_type(type);
                break;
        case TYPE_POINTER:
-               hash = hash_pointer_type((const pointer_type_t*) type);
+               hash = hash_pointer_type(type);
                break;
        case TYPE_ARRAY:
-               hash = hash_array_type((const array_type_t*) type);
+               hash = hash_array_type(type);
                break;
        case TYPE_BUILTIN:
-               hash = hash_ptr(((const builtin_type_t*) type)->symbol);
+               hash = hash_ptr(type->v.builtin_type.symbol);
                break;
        case TYPE_TYPEDEF:
-               hash = hash_ptr(((const compound_type_t*) type)->declaration);
+               hash = hash_ptr(type->v.typedef_type.declaration);
                break;
        case TYPE_TYPEOF:
-               hash = hash_typeof_type((const typeof_type_t*) type);
+               hash = hash_typeof_type(type);
                break;
        }
 
@@ -121,24 +121,25 @@ static unsigned hash_type(const type_t *type)
        return hash;
 }
 
-static bool atomic_types_equal(const atomic_type_t *type1,
-                               const atomic_type_t *type2)
+static bool atomic_types_equal(const type_t *type1,
+                               const type_t *type2)
 {
-       return type1->atype == type2->atype;
+       return type1->v.atomic_type.atype == type2->v.atomic_type.atype;
 }
 
-static bool function_types_equal(const function_type_t *type1,
-                                 const function_type_t *type2)
+static bool function_types_equal(const type_t *type1,
+                                 const type_t *type2)
 {
-       if(type1->result_type != type2->result_type)
+       if(type1->v.function_type.result_type != type2->v.function_type.result_type)
                return false;
-       if(type1->variadic != type2->variadic)
+       if(type1->v.function_type.variadic != type2->v.function_type.variadic)
                return false;
-       if(type1->unspecified_parameters != type2->unspecified_parameters)
+       if(type1->v.function_type.unspecified_parameters !=
+          type2->v.function_type.unspecified_parameters)
                return false;
 
-       function_parameter_t *param1 = type1->parameters;
-       function_parameter_t *param2 = type2->parameters;
+       function_parameter_t *param1 = type1->v.function_type.parameters;
+       function_parameter_t *param2 = type2->v.function_type.parameters;
        while(param1 != NULL && param2 != NULL) {
                if(param1->type != param2->type)
                        return false;
@@ -151,58 +152,58 @@ static bool function_types_equal(const function_type_t *type1,
        return true;
 }
 
-static bool pointer_types_equal(const pointer_type_t *type1,
-                                const pointer_type_t *type2)
+static bool pointer_types_equal(const type_t *type1,
+                                const type_t *type2)
 {
-       return type1->points_to == type2->points_to;
+       return type1->v.pointer_type.points_to == type2->v.pointer_type.points_to;
 }
 
-static bool array_types_equal(const array_type_t *type1,
-                              const array_type_t *type2)
+static bool array_types_equal(const type_t *type1,
+                              const type_t *type2)
 {
-       if(type1->element_type != type2->element_type)
+       if(type1->v.array_type.element_type != type2->v.array_type.element_type)
                return false;
-       if(type1->is_variable != type2->is_variable)
+       if(type1->v.array_type.is_variable != type2->v.array_type.is_variable)
                return false;
-       if(type1->is_static != type2->is_static)
+       if(type1->v.array_type.is_static != type2->v.array_type.is_static)
                return false;
        /* TODO: compare expressions for equality... */
-       if(type1->size != type2->size)
+       if(type1->v.array_type.size != type2->v.array_type.size)
                return false;
 
        return true;
 }
 
-static bool builtin_types_equal(const builtin_type_t *type1,
-                                const builtin_type_t *type2)
+static bool builtin_types_equal(const type_t *type1,
+                                const type_t *type2)
 {
-       return type1->symbol == type2->symbol;
+       return type1->v.builtin_type.symbol == type2->v.builtin_type.symbol;
 }
 
-static bool compound_types_equal(const compound_type_t *type1,
-                                 const compound_type_t *type2)
+static bool compound_types_equal(const type_t *type1,
+                                 const type_t *type2)
 {
-       return type1->declaration == type2->declaration;
+       return type1->v.compound_type.declaration == type2->v.compound_type.declaration;
 }
 
-static bool enum_types_equal(const enum_type_t *type1,
-                             const enum_type_t *type2)
+static bool enum_types_equal(const type_t *type1,
+                             const type_t *type2)
 {
-       return type1->declaration == type2->declaration;
+       return type1->v.enum_type.declaration == type2->v.enum_type.declaration;
 }
 
-static bool typedef_types_equal(const typedef_type_t *type1,
-                                const typedef_type_t *type2)
+static bool typedef_types_equal(const type_t *type1,
+                                const type_t *type2)
 {
-       return type1->declaration == type2->declaration;
+       return type1->v.typedef_type.declaration == type2->v.typedef_type.declaration;
 }
 
-static bool typeof_types_equal(const typeof_type_t *type1,
-                               const typeof_type_t *type2)
+static bool typeof_types_equal(const type_t *type1,
+                               const type_t *type2)
 {
-       if(type1->expression != type2->expression)
+       if(type1->v.typeof_type.expression != type2->v.typeof_type.expression)
                return false;
-       if(type1->typeof_type != type2->typeof_type)
+       if(type1->v.typeof_type.typeof_type != type2->v.typeof_type.typeof_type)
                return false;
 
        return true;
@@ -221,33 +222,24 @@ static bool types_equal(const type_t *type1, const type_t *type2)
        case TYPE_INVALID:
                return false;
        case TYPE_ATOMIC:
-               return atomic_types_equal((const atomic_type_t*) type1,
-                                         (const atomic_type_t*) type2);
+               return atomic_types_equal(type1, type2);
        case TYPE_ENUM:
-               return enum_types_equal((const enum_type_t*) type1,
-                                       (const enum_type_t*) type2);
+               return enum_types_equal(type1, type2);
        case TYPE_COMPOUND_STRUCT:
        case TYPE_COMPOUND_UNION:
-               return compound_types_equal((const compound_type_t*) type1,
-                                           (const compound_type_t*) type2);
+               return compound_types_equal(type1, type2);
        case TYPE_FUNCTION:
-               return function_types_equal((const function_type_t*) type1,
-                                           (const function_type_t*) type2);
+               return function_types_equal(type1, type2);
        case TYPE_POINTER:
-               return pointer_types_equal((const pointer_type_t*) type1,
-                                          (const pointer_type_t*) type2);
+               return pointer_types_equal(type1, type2);
        case TYPE_ARRAY:
-               return array_types_equal((const array_type_t*) type1,
-                                        (const array_type_t*) type2);
+               return array_types_equal(type1, type2);
        case TYPE_BUILTIN:
-               return builtin_types_equal((const builtin_type_t*) type1,
-                                          (const builtin_type_t*) type2);
+               return builtin_types_equal(type1, type2);
        case TYPE_TYPEOF:
-               return typeof_types_equal((const typeof_type_t*) type1,
-                                         (const typeof_type_t*) type2);
+               return typeof_types_equal(type1, type2);
        case TYPE_TYPEDEF:
-               return typedef_types_equal((const typedef_type_t*) type1,
-                                          (const typedef_type_t*) type2);
+               return typedef_types_equal(type1, type2);
        }
 
        abort();
index 2e0ece2..4a0428c 100644 (file)
--- a/type_t.h
+++ b/type_t.h
@@ -66,76 +66,70 @@ 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 function_type_t {
-       type_t                type;
-       type_t               *result_type;
-       function_parameter_t *parameters;
-       bool                  variadic;
-       bool                  unspecified_parameters;
-};
-
-struct compound_type_t {
-       type_t         type;
-       /** the declaration of the compound type, its context field
-        * contains the compound entries. */
-       declaration_t *declaration;
-};
-
-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 type_t {
+       type_type_t       type;
+       type_qualifiers_t qualifiers;
 
-struct typedef_type_t {
-       type_t         type;
-       declaration_t *declaration;
-       type_t        *resolved_type;
-};
+       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 typeof_type_t {
-       type_t        type;
-       expression_t *expression;
-       type_t       *typeof_type;
-       type_t       *resolved_type;
+       ir_type          *firm_type;
 };
 
 type_t *make_atomic_type(atomic_type_type_t type, type_qualifiers_t qualifiers);
index 4ad6fc0..1213383 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 atomic_type_t *type)
+static void write_atomic_type(const type_t *type)
 {
-       fprintf(out, "%s", get_atomic_type_string(type->atype));
+       fprintf(out, "%s", get_atomic_type_string(type->v.atomic_type.atype));
 }
 
-static void write_pointer_type(const pointer_type_t *type)
+static void write_pointer_type(const type_t *type)
 {
-       write_type(type->points_to);
+       write_type(type->v.pointer_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 compound_type_t *type)
+static void write_compound_type(const type_t *type)
 {
-       declaration_t *declaration = find_typedef((const type_t*) type);
+       declaration_t *declaration = find_typedef(type);
        if(declaration != NULL) {
                fprintf(out, "%s", declaration->symbol->string);
                return;
        }
 
        /* does the struct have a name? */
-       symbol_t *symbol = type->declaration->symbol;
+       symbol_t *symbol = type->v.compound_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 compound_type_t *type)
        fprintf(out, "/* TODO anonymous struct */byte");
 }
 
-static void write_enum_type(const enum_type_t *type)
+static void write_enum_type(const type_t *type)
 {
-       declaration_t *declaration = find_typedef((const type_t*) type);
+       declaration_t *declaration = find_typedef(type);
        if(declaration != NULL) {
                fprintf(out, "%s", declaration->symbol->string);
                return;
        }
 
        /* does the enum have a name? */
-       symbol_t *symbol = type->declaration->symbol;
+       symbol_t *symbol = type->v.enum_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 enum_type_t *type)
        fprintf(out, "/* TODO anonymous enum */byte");
 }
 
-static void write_function_type(const function_type_t *type)
+static void write_function_type(const type_t *type)
 {
        fprintf(out, "(func(");
 
-       function_parameter_t *parameter = type->parameters;
+       function_parameter_t *parameter = type->v.function_type.parameters;
        int                   first     = 1;
        while(parameter != NULL) {
                if(!first) {
@@ -131,7 +131,7 @@ static void write_function_type(const function_type_t *type)
        }
 
        fprintf(out, ") : ");
-       write_type(type->result_type);
+       write_type(type->v.function_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((const atomic_type_t*) type);
+               write_atomic_type(type);
                return;
        case TYPE_POINTER:
-               write_pointer_type((const pointer_type_t*) type);
+               write_pointer_type(type);
                return;
        case TYPE_COMPOUND_UNION:
        case TYPE_COMPOUND_STRUCT:
-               write_compound_type((const compound_type_t*) type);
+               write_compound_type(type);
                return;
        case TYPE_ENUM:
-               write_enum_type((const enum_type_t*) type);
+               write_enum_type(type);
                return;
        case TYPE_FUNCTION:
-               write_function_type((const function_type_t*) type);
+               write_function_type(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 compound_type_t *type)
+static void write_struct(const symbol_t *symbol, const type_t *type)
 {
        fprintf(out, "struct %s:\n", symbol->string);
 
-       const declaration_t *declaration = type->declaration->context.declarations;
+       const declaration_t *declaration = type->v.compound_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 compound_type_t *type)
        fprintf(out, "\n");
 }
 
-static void write_union(const symbol_t *symbol, const compound_type_t *type)
+static void write_union(const symbol_t *symbol, const type_t *type)
 {
        fprintf(out, "union %s:\n", symbol->string);
 
-       const declaration_t *declaration = type->declaration->context.declarations;
+       const declaration_t *declaration = type->v.compound_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("unimeplemented unary expression found");
+               panic("unimplemented 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 enum_type_t *type)
+static void write_enum(const symbol_t *symbol, const type_t *type)
 {
        fprintf(out, "enum %s:\n", symbol->string);
 
-       declaration_t *entry = type->declaration->next;
+       declaration_t *entry = type->v.enum_type.declaration->next;
        for ( ; entry != NULL && entry->storage_class == STORAGE_CLASS_ENUM_ENTRY;
                        entry = entry->next) {
                fprintf(out, "\t%s", entry->symbol->string);
@@ -270,8 +270,7 @@ static void write_function(const declaration_t *declaration)
        fprintf(out, "func extern %s(",
                declaration->symbol->string);
 
-       const function_type_t *function_type
-               = (const function_type_t*) declaration->type;
+       const type_t *function_type = declaration->type;
 
        declaration_t *parameter = declaration->context.declarations;
        int            first     = 1;
@@ -288,7 +287,7 @@ static void write_function(const declaration_t *declaration)
                }
                write_type(parameter->type);
        }
-       if(function_type->variadic) {
+       if(function_type->v.function_type.variadic) {
                if(!first) {
                        fprintf(out, ", ");
                } else {
@@ -298,9 +297,9 @@ static void write_function(const declaration_t *declaration)
        }
        fprintf(out, ")");
 
-       const type_t *result_type = function_type->result_type;
+       const type_t *result_type = function_type->v.function_type.result_type;
        if(result_type->type != TYPE_ATOMIC ||
-                       ((const atomic_type_t*) result_type)->atype != ATOMIC_TYPE_VOID) {
+          result_type->v.atomic_type.atype != ATOMIC_TYPE_VOID) {
                fprintf(out, " : ");
                write_type(result_type);
        }
@@ -321,7 +320,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);
@@ -330,11 +329,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, (compound_type_t*) type);
+                       write_struct(declaration->symbol, type);
                } else if(type->type == TYPE_COMPOUND_UNION) {
-                       write_union(declaration->symbol, (compound_type_t*) type);
+                       write_union(declaration->symbol, type);
                } else if(type->type == TYPE_ENUM) {
-                       write_enum(declaration->symbol, (enum_type_t*) type);
+                       write_enum(declaration->symbol, type);
                }
        }