Add debug info for types
authorMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Wed, 19 Dec 2007 15:08:14 +0000 (15:08 +0000)
committerMichael Beck <beck@ipd.info.uni-karlsruhe.de>
Wed, 19 Dec 2007 15:08:14 +0000 (15:08 +0000)
[r18804]

ast2firm.c
lexer.c
parser.c
type_t.h
types.c

index 7c030b0..c479e98 100644 (file)
@@ -359,9 +359,10 @@ static long fold_constant(const expression_t *expression);
 
 static ir_type *create_atomic_type(const atomic_type_t *type)
 {
+       dbg_info *dbgi  = get_dbg_info(&type->type.source_position);
        ir_mode *mode   = get_atomic_mode(type);
        ident   *id     = get_mode_ident(mode);
-       ir_type *irtype = new_type_primitive(id, mode);
+       ir_type *irtype = new_d_type_primitive(id, mode, dbgi);
 
        if(type->akind == ATOMIC_TYPE_LONG_DOUBLE
                        || type->akind == ATOMIC_TYPE_DOUBLE) {
@@ -378,7 +379,8 @@ static ir_type *create_method_type(const function_type_t *function_type)
        ident   *id           = unique_ident("functiontype");
        int      n_parameters = count_parameters(function_type);
        int      n_results    = return_type == type_void ? 0 : 1;
-       ir_type *irtype       = new_type_method(id, n_parameters, n_results);
+       dbg_info *dbgi        = get_dbg_info(&function_type->type.source_position);
+       ir_type *irtype       = new_d_type_method(id, n_parameters, n_results, dbgi);
 
        if(return_type != type_void) {
                ir_type *restype = get_ir_type(return_type);
@@ -408,8 +410,9 @@ static ir_type *create_pointer_type(pointer_type_t *type)
         * again (might be a struct). We therefore first create a void* pointer
         * and then set the real points_to type
         */
-       ir_type *ir_type = new_type_pointer(unique_ident("pointer"),
-                                           ir_type_void, mode_P_data);
+       dbg_info *dbgi   = get_dbg_info(&type->type.source_position);
+       ir_type *ir_type = new_d_type_pointer(unique_ident("pointer"),
+                                           ir_type_void, mode_P_data, dbgi);
        type->type.firm_type  = ir_type;
 
        ir_points_to = get_ir_type(points_to);
@@ -424,7 +427,8 @@ static ir_type *create_array_type(array_type_t *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);
+       dbg_info *dbgi   = get_dbg_info(&type->type.source_position);
+       ir_type *ir_type = new_d_type_array(id, 1, ir_element_type, dbgi);
 
        if(type->size != NULL) {
                int n_elements = fold_constant(type->size);
@@ -474,7 +478,8 @@ static ir_type *get_signed_int_type_for_bit_size(ir_type *base_tp,
        char name[32];
        snprintf(name, sizeof(name), "I%u", size);
        ident *id = new_id_from_str(name);
-       res = new_type_primitive(mangle_u(get_type_ident(base_tp), id), mode);
+       dbg_info *dbgi = get_dbg_info(&builtin_source_position);
+       res = new_d_type_primitive(mangle_u(get_type_ident(base_tp), id), mode, dbgi);
        set_primitive_base_type(res, base_tp);
 
        return res;
@@ -509,7 +514,8 @@ static ir_type *get_unsigned_int_type_for_bit_size(ir_type *base_tp,
 
        snprintf(name, sizeof(name), "U%u", size);
        ident *id = new_id_from_str(name);
-       res = new_type_primitive(mangle_u(get_type_ident(base_tp), id), mode);
+       dbg_info *dbgi = get_dbg_info(&builtin_source_position);
+       res = new_d_type_primitive(mangle_u(get_type_ident(base_tp), id), mode, dbgi);
        set_primitive_base_type(res, base_tp);
 
        return res;
@@ -542,7 +548,8 @@ static ir_type *create_struct_type(compound_type_t *type)
        } else {
                id = unique_ident("__anonymous_struct");
        }
-       ir_type *irtype = new_type_struct(id);
+       dbg_info *dbgi  = get_dbg_info(&type->type.source_position);
+       ir_type *irtype = new_d_type_struct(id, dbgi);
 
        type->type.firm_type = irtype;
 
@@ -621,6 +628,7 @@ static ir_type *create_struct_type(compound_type_t *type)
                                                         (unsigned char) bits_remainder);
                        add_struct_member(irtype, entity);
                        entry->declaration_kind = DECLARATION_KIND_COMPOUND_MEMBER;
+                       assert(entry->v.entity == NULL);
                        entry->v.entity         = entity;
                }
        }
@@ -646,7 +654,8 @@ static ir_type *create_union_type(compound_type_t *type)
        } else {
                id = unique_ident("__anonymous_union");
        }
-       ir_type *irtype = new_type_union(id);
+       dbg_info *dbgi  = get_dbg_info(&type->type.source_position);
+       ir_type *irtype = new_d_type_union(id, dbgi);
 
        type->type.firm_type = irtype;
 
@@ -967,11 +976,11 @@ static ir_node *string_to_firm(const source_position_t *const src_pos,
                                const string_t *const value)
 {
        ir_type *const global_type = get_glob_type();
-       ir_type *const type        = new_type_array(unique_ident("strtype"), 1,
-                                                   ir_type_const_char);
+       dbg_info *const dbgi       = get_dbg_info(src_pos);
+       ir_type *const type        = new_d_type_array(unique_ident("strtype"), 1,
+                                                   ir_type_const_char, dbgi);
 
        ident     *const id     = unique_ident(id_prefix);
-       dbg_info  *const dbgi   = get_dbg_info(src_pos);
        ir_entity *const entity = new_d_entity(global_type, id, type, dbgi);
        set_entity_ld_ident(entity, id);
        set_entity_variability(entity, variability_constant);
@@ -1011,11 +1020,11 @@ static ir_node *wide_string_literal_to_firm(
 {
        ir_type *const global_type = get_glob_type();
        ir_type *const elem_type   = ir_type_wchar_t;
-       ir_type *const type        = new_type_array(unique_ident("strtype"), 1,
-                                                   elem_type);
+       dbg_info *const dbgi       = get_dbg_info(&literal->base.source_position);
+       ir_type *const type        = new_d_type_array(unique_ident("strtype"), 1,
+                                                   elem_type, dbgi);
 
        ident     *const id     = unique_ident("Lstr");
-       dbg_info  *const dbgi   = get_dbg_info(&literal->base.source_position);
        ir_entity *const entity = new_d_entity(global_type, id, type, dbgi);
        set_entity_ld_ident(entity, id);
        set_entity_variability(entity, variability_constant);
@@ -1279,8 +1288,9 @@ static ir_node *call_expression_to_firm(const call_expression_t *call)
                /* we need to construct a new method type matching the call
                 * arguments... */
                int n_res       = get_method_n_ress(ir_method_type);
-               new_method_type = new_type_method(unique_ident("calltype"),
-                                                 n_parameters, n_res);
+               dbg_info *dbgi  = get_dbg_info(&call->base.source_position);
+               new_method_type = new_d_type_method(unique_ident("calltype"),
+                                                 n_parameters, n_res, dbgi);
                set_method_calling_convention(new_method_type,
                               get_method_calling_convention(ir_method_type));
                set_method_additional_properties(new_method_type,
diff --git a/lexer.c b/lexer.c
index d7b2809..45327f6 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -917,6 +917,12 @@ static void skip_multiline_comment(void)
 
        while(1) {
                switch(c) {
+               case '/':
+                       next_char();
+                       if (c == '*') {
+                               /* TODO: nested comment, warn here */
+                       }
+                       break;
                case '*':
                        next_char();
                        if(c == '/') {
index 07e93ac..daa9c5b 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -274,13 +274,14 @@ static size_t get_type_struct_size(type_kind_t kind)
  * Allocate a type node of given kind and initialize all
  * fields with zero.
  */
-static type_t *allocate_type_zero(type_kind_t kind)
+static type_t *allocate_type_zero(type_kind_t kind, source_position_t source_position)
 {
        size_t  size = get_type_struct_size(kind);
        type_t *res  = obstack_alloc(type_obst, size);
        memset(res, 0, size);
 
-       res->base.kind = kind;
+       res->base.kind            = kind;
+       res->base.source_position = source_position;
        return res;
 }
 
@@ -806,7 +807,7 @@ static type_t *make_global_typedef(const char *name, type_t *type)
 
        record_declaration(declaration);
 
-       type_t *typedef_type               = allocate_type_zero(TYPE_TYPEDEF);
+       type_t *typedef_type               = allocate_type_zero(TYPE_TYPEDEF, builtin_source_position);
        typedef_type->typedeft.declaration = declaration;
 
        return typedef_type;
@@ -1380,7 +1381,7 @@ static type_t *parse_enum_specifier(void)
                declaration->parent_scope  = scope;
        }
 
-       type_t *const type      = allocate_type_zero(TYPE_ENUM);
+       type_t *const type      = allocate_type_zero(TYPE_ENUM, declaration->source_position);
        type->enumt.declaration = declaration;
 
        if(token.type == '{') {
@@ -1453,7 +1454,7 @@ restart:
 
        expect(')');
 
-       type_t *typeof_type              = allocate_type_zero(TYPE_TYPEOF);
+       type_t *typeof_type              = allocate_type_zero(TYPE_TYPEOF, expression->base.source_position);
        typeof_type->typeoft.expression  = expression;
        typeof_type->typeoft.typeof_type = type;
 
@@ -1481,7 +1482,7 @@ typedef enum {
 static type_t *create_builtin_type(symbol_t *const symbol,
                                    type_t *const real_type)
 {
-       type_t *type            = allocate_type_zero(TYPE_BUILTIN);
+       type_t *type            = allocate_type_zero(TYPE_BUILTIN, builtin_source_position);
        type->builtin.symbol    = symbol;
        type->builtin.real_type = real_type;
 
@@ -1500,7 +1501,7 @@ static type_t *get_typedef_type(symbol_t *symbol)
                        || declaration->storage_class != STORAGE_CLASS_TYPEDEF)
                return NULL;
 
-       type_t *type               = allocate_type_zero(TYPE_TYPEDEF);
+       type_t *type               = allocate_type_zero(TYPE_TYPEDEF, declaration->source_position);
        type->typedeft.declaration = declaration;
 
        return type;
@@ -1618,13 +1619,13 @@ static void parse_declaration_specifiers(declaration_specifiers_t *specifiers)
                /* TODO: if is_type_valid(type) for the following rules should issue
                 * an error */
                case T_struct: {
-                       type = allocate_type_zero(TYPE_COMPOUND_STRUCT);
+                       type = allocate_type_zero(TYPE_COMPOUND_STRUCT, HERE);
 
                        type->compound.declaration = parse_compound_type_specifier(true);
                        break;
                }
                case T_union: {
-                       type = allocate_type_zero(TYPE_COMPOUND_UNION);
+                       type = allocate_type_zero(TYPE_COMPOUND_UNION, HERE);
 
                        type->compound.declaration = parse_compound_type_specifier(false);
                        break;
@@ -1777,7 +1778,7 @@ finish_specifiers:
                        atomic_type = ATOMIC_TYPE_INVALID;
                }
 
-               type               = allocate_type_zero(TYPE_ATOMIC);
+               type               = allocate_type_zero(TYPE_ATOMIC, builtin_source_position);
                type->atomic.akind = atomic_type;
                newtype            = 1;
        } else {
@@ -1949,11 +1950,11 @@ typedef enum {
        CONSTRUCT_POINTER,
        CONSTRUCT_FUNCTION,
        CONSTRUCT_ARRAY
-} construct_type_type_t;
+} construct_type_kind_t;
 
 typedef struct construct_type_t construct_type_t;
 struct construct_type_t {
-       construct_type_type_t  type;
+       construct_type_kind_t  kind;
        construct_type_t      *next;
 };
 
@@ -1990,7 +1991,7 @@ static construct_type_t *parse_pointer_declarator(void)
 
        parsed_pointer_t *pointer = obstack_alloc(&temp_obst, sizeof(pointer[0]));
        memset(pointer, 0, sizeof(pointer[0]));
-       pointer->construct_type.type = CONSTRUCT_POINTER;
+       pointer->construct_type.kind = CONSTRUCT_POINTER;
        pointer->type_qualifiers     = parse_type_qualifiers();
 
        return (construct_type_t*) pointer;
@@ -2002,7 +2003,7 @@ static construct_type_t *parse_array_declarator(void)
 
        parsed_array_t *array = obstack_alloc(&temp_obst, sizeof(array[0]));
        memset(array, 0, sizeof(array[0]));
-       array->construct_type.type = CONSTRUCT_ARRAY;
+       array->construct_type.kind = CONSTRUCT_ARRAY;
 
        if(token.type == T_static) {
                array->is_static = true;
@@ -2034,7 +2035,7 @@ static construct_type_t *parse_function_declarator(declaration_t *declaration)
 {
        eat('(');
 
-       type_t *type = allocate_type_zero(TYPE_FUNCTION);
+       type_t *type = allocate_type_zero(TYPE_FUNCTION, declaration->source_position);
 
        declaration_t *parameters = parse_parameters(&type->function);
        if(declaration != NULL) {
@@ -2044,7 +2045,7 @@ static construct_type_t *parse_function_declarator(declaration_t *declaration)
        construct_function_type_t *construct_function_type =
                obstack_alloc(&temp_obst, sizeof(construct_function_type[0]));
        memset(construct_function_type, 0, sizeof(construct_function_type[0]));
-       construct_function_type->construct_type.type = CONSTRUCT_FUNCTION;
+       construct_function_type->construct_type.kind = CONSTRUCT_FUNCTION;
        construct_function_type->function_type       = type;
 
        expect(')');
@@ -2155,7 +2156,7 @@ static type_t *construct_declarator_type(construct_type_t *construct_list,
 {
        construct_type_t *iter = construct_list;
        for( ; iter != NULL; iter = iter->next) {
-               switch(iter->type) {
+               switch(iter->kind) {
                case CONSTRUCT_INVALID:
                        panic("invalid type construction found");
                case CONSTRUCT_FUNCTION: {
@@ -2181,7 +2182,7 @@ static type_t *construct_declarator_type(construct_type_t *construct_list,
 
                case CONSTRUCT_POINTER: {
                        parsed_pointer_t *parsed_pointer = (parsed_pointer_t*) iter;
-                       type_t           *pointer_type   = allocate_type_zero(TYPE_POINTER);
+                       type_t           *pointer_type   = allocate_type_zero(TYPE_POINTER, (source_position_t){NULL, 0});
                        pointer_type->pointer.points_to  = type;
                        pointer_type->base.qualifiers    = parsed_pointer->type_qualifiers;
 
@@ -2191,7 +2192,7 @@ static type_t *construct_declarator_type(construct_type_t *construct_list,
 
                case CONSTRUCT_ARRAY: {
                        parsed_array_t *parsed_array  = (parsed_array_t*) iter;
-                       type_t         *array_type    = allocate_type_zero(TYPE_ARRAY);
+                       type_t         *array_type    = allocate_type_zero(TYPE_ARRAY, (source_position_t){NULL, 0});
 
                        array_type->base.qualifiers    = parsed_array->type_qualifiers;
                        array_type->array.element_type = type;
@@ -2214,7 +2215,7 @@ static type_t *construct_declarator_type(construct_type_t *construct_list,
                if(hashed_type != type) {
                        /* the function type was constructed earlier freeing it here will
                         * destroy other types... */
-                       if(iter->type != CONSTRUCT_FUNCTION) {
+                       if(iter->kind != CONSTRUCT_FUNCTION) {
                                free_type(type);
                        }
                        type = hashed_type;
@@ -2934,9 +2935,9 @@ end_of_parse_external_declaration:
        environment_pop_to(top);
 }
 
-static type_t *make_bitfield_type(type_t *base, expression_t *size)
+static type_t *make_bitfield_type(type_t *base, expression_t *size, source_position_t source_position)
 {
-       type_t *type        = allocate_type_zero(TYPE_BITFIELD);
+       type_t *type        = allocate_type_zero(TYPE_BITFIELD, source_position);
        type->bitfield.base = base;
        type->bitfield.size = size;
 
@@ -2957,6 +2958,7 @@ static void parse_compound_declarators(declaration_t *struct_declaration,
                declaration_t *declaration;
 
                if(token.type == ':') {
+                       source_position_t source_position = HERE;
                        next_token();
 
                        type_t *base_type = specifiers->type;
@@ -2967,12 +2969,12 @@ static void parse_compound_declarators(declaration_t *struct_declaration,
                                       base_type);
                        }
 
-                       type_t *type = make_bitfield_type(base_type, size);
+                       type_t *type = make_bitfield_type(base_type, size, source_position);
 
                        declaration                  = allocate_declaration_zero();
                        declaration->namespc         = NAMESPACE_NORMAL;
                        declaration->storage_class   = STORAGE_CLASS_NONE;
-                       declaration->source_position = token.source_position;
+                       declaration->source_position = source_position;
                        declaration->modifiers       = specifiers->decl_modifiers;
                        declaration->type            = type;
                } else {
@@ -2982,6 +2984,7 @@ static void parse_compound_declarators(declaration_t *struct_declaration,
                        type_t *type      = skip_typeref(orig_type);
 
                        if(token.type == ':') {
+                               source_position_t source_position = HERE;
                                next_token();
                                expression_t *size = parse_constant_expression();
 
@@ -2990,7 +2993,7 @@ static void parse_compound_declarators(declaration_t *struct_declaration,
                                               "integer type", orig_type);
                                }
 
-                               type_t *bitfield_type = make_bitfield_type(orig_type, size);
+                               type_t *bitfield_type = make_bitfield_type(orig_type, size, source_position);
                                declaration->type = bitfield_type;
                        } else {
                                /* TODO we ignore arrays for now... what is missing is a check
@@ -3166,7 +3169,7 @@ static expression_t *parse_float_const(void)
 static declaration_t *create_implicit_function(symbol_t *symbol,
                const source_position_t source_position)
 {
-       type_t *ntype                          = allocate_type_zero(TYPE_FUNCTION);
+       type_t *ntype                          = allocate_type_zero(TYPE_FUNCTION, source_position);
        ntype->function.return_type            = type_int;
        ntype->function.unspecified_parameters = true;
 
@@ -3210,7 +3213,7 @@ static type_t *make_function_1_type(type_t *return_type, type_t *argument_type)
        memset(parameter, 0, sizeof(parameter[0]));
        parameter->type = argument_type;
 
-       type_t *type               = allocate_type_zero(TYPE_FUNCTION);
+       type_t *type               = allocate_type_zero(TYPE_FUNCTION, builtin_source_position);
        type->function.return_type = return_type;
        type->function.parameters  = parameter;
 
index a31aa5d..f745e4f 100644 (file)
--- a/type_t.h
+++ b/type_t.h
@@ -73,6 +73,7 @@ typedef unsigned int type_qualifiers_t;
 struct type_base_t {
        type_kind_t       kind;
        type_qualifiers_t qualifiers;
+       source_position_t source_position;
 
        ir_type          *firm_type;
 };
diff --git a/types.c b/types.c
index c229827..ff45f8a 100644 (file)
--- a/types.c
+++ b/types.c
@@ -45,7 +45,7 @@ type_t *type_wchar_t_ptr;
 
 void init_basic_types(void)
 {
-       static const type_base_t error = { TYPE_ERROR, TYPE_QUALIFIER_NONE, NULL };
+       static const type_base_t error = { TYPE_ERROR, TYPE_QUALIFIER_NONE, { NULL, 0 }, NULL };
 
        type_error_type         = (type_t*)&error;
        type_signed_char        = make_atomic_type(ATOMIC_TYPE_SCHAR,       TYPE_QUALIFIER_NONE);