Fix missing type_info with manual linear search

This commit is contained in:
Ginger Bill
2016-09-08 00:23:14 +01:00
parent 3d02f8a5fd
commit c6d02e4778
13 changed files with 55 additions and 79 deletions
+2 -1
View File
@@ -866,7 +866,7 @@ void check_parsed_files(Checker *c) {
t_type_info_ptr = make_type_pointer(c->allocator, t_type_info);
auto *record = &get_base_type(e->type)->Record;
GB_ASSERT(record->field_count == 15);
GB_ASSERT_MSG(record->field_count == 15, "Internal Compiler Error: Invalid `Type_Info` layout");
t_type_info_named = record->fields[ 1]->type;
t_type_info_integer = record->fields[ 2]->type;
t_type_info_float = record->fields[ 3]->type;
@@ -881,6 +881,7 @@ void check_parsed_files(Checker *c) {
t_type_info_union = record->fields[12]->type;
t_type_info_raw_union = record->fields[13]->type;
t_type_info_enum = record->fields[14]->type;
// t_type_info_any = record->fields[15]->type;
}
check_global_entity(c, Entity_Constant);
+6 -4
View File
@@ -6,7 +6,6 @@ enum BuiltinProcId;
ENTITY_KIND(Invalid), \
ENTITY_KIND(Constant), \
ENTITY_KIND(Variable), \
ENTITY_KIND(UsingVariable), \
ENTITY_KIND(TypeName), \
ENTITY_KIND(Procedure), \
ENTITY_KIND(Builtin), \
@@ -46,10 +45,12 @@ struct Entity {
b8 used; // Variable is used
b8 is_field; // Is struct field
b8 anonymous; // Variable is an anonymous
b8 is_using; // `using` variable
} Variable;
struct {} UsingVariable;
struct {} TypeName;
struct { b8 used; } Procedure;
struct {
b8 pure;
} Procedure;
struct { BuiltinProcId id; } Builtin;
};
};
@@ -77,8 +78,9 @@ Entity *make_entity_variable(gbAllocator a, Scope *scope, Token token, Type *typ
Entity *make_entity_using_variable(gbAllocator a, Entity *parent, Token token, Type *type) {
GB_ASSERT(parent != NULL);
Entity *entity = alloc_entity(a, Entity_UsingVariable, parent->scope, token, type);
Entity *entity = alloc_entity(a, Entity_Variable, parent->scope, token, type);
entity->using_parent = parent;
entity->Variable.is_using = true;
return entity;
}
+1 -7
View File
@@ -91,8 +91,6 @@ b32 check_is_assignable_to(Checker *c, Operand *operand, Type *type, b32 is_argu
Type *s = operand->type;
if (are_types_identical(s, type)) {
return true;
}
@@ -179,6 +177,7 @@ void check_assignment(Checker *c, Operand *operand, Type *type, String context_n
Type *target_type = type;
if (type == NULL || is_type_any(type)) {
add_type_info_type(c, type);
target_type = default_type(operand->type);
}
convert_to_typed(c, operand, target_type);
@@ -795,11 +794,6 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type, Cycl
o->mode = Addressing_Builtin;
break;
case Entity_UsingVariable:
// TODO(bill): Entity_UsingVariable: is this correct?
o->mode = Addressing_Variable;
break;
default:
GB_PANIC("Compiler error: Unknown EntityKind");
break;
+2 -2
View File
@@ -452,6 +452,7 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d, b32 check_body_later) {
b32 is_foreign = (pd->tags & ProcTag_foreign) != 0;
b32 is_inline = (pd->tags & ProcTag_inline) != 0;
b32 is_no_inline = (pd->tags & ProcTag_no_inline) != 0;
b32 is_pure = (pd->tags & ProcTag_pure) != 0;
@@ -1283,8 +1284,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
error(&c->error_collector, us->token, "`using` cannot be applied to a procedure");
break;
case Entity_Variable:
case Entity_UsingVariable: {
case Entity_Variable: {
Type *t = get_base_type(type_deref(e->type));
if (is_type_struct(t) || is_type_raw_union(t)) {
Scope **found = map_get(&c->info.scopes, hash_pointer(t->Record.node));
+1
View File
@@ -369,6 +369,7 @@ gb_global Type *t_type_info_struct = NULL;
gb_global Type *t_type_info_union = NULL;
gb_global Type *t_type_info_raw_union = NULL;
gb_global Type *t_type_info_enum = NULL;
gb_global Type *t_type_info_any = NULL;