Fix overloading bug due to #import .; Add sys/wgl.odin

This commit is contained in:
Ginger Bill
2017-02-19 11:35:33 +00:00
parent 0c37aa9ea0
commit 758dd9ba16
7 changed files with 114 additions and 43 deletions
+21 -18
View File
@@ -2564,6 +2564,17 @@ bool check_index_value(Checker *c, AstNode *index_value, i64 max_count, i64 *val
return true;
}
isize procedure_overload_count(Scope *s, String name) {
isize overload_count = 0;
Entity *e = scope_lookup_entity(s, name);
if (e->kind == Entity_Procedure) {
HashKey key = hash_string(e->token.string);
// NOTE(bill): Overloads are only allowed with the same scope
overload_count = map_entity_multi_count(&s->elements, key);
}
return overload_count;
}
Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_hint) {
ast_node(se, SelectorExpr, node);
@@ -2596,15 +2607,17 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h
// It pretty much needs to be in this order and this way
// If you can clean this up, please do but be really careful
Scope *import_scope = e->ImportName.scope;
String sel_name = selector->Ident.string;
check_op_expr = false;
entity = scope_lookup_entity(e->ImportName.scope, sel_name);
entity = scope_lookup_entity(import_scope, sel_name);
bool is_declared = entity != NULL;
if (is_declared) {
if (entity->kind == Entity_Builtin) {
is_declared = false;
} else if (entity->scope->is_global && !e->ImportName.scope->is_global) {
} else if (entity->scope->is_global && !import_scope->is_global) {
is_declared = false;
}
}
@@ -2615,18 +2628,8 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h
check_entity_decl(c, entity, NULL, NULL);
GB_ASSERT(entity->type != NULL);
bool is_overloaded = false;
isize overload_count = 0;
HashKey key = {0};
if (entity->kind == Entity_Procedure) {
key = hash_string(entity->token.string);
// NOTE(bill): Overloads are only allowed with the same scope
Scope *s = entity->scope;
overload_count = map_entity_multi_count(&s->elements, key);
if (overload_count > 1) {
is_overloaded = true;
}
}
isize overload_count = procedure_overload_count(import_scope, entity->token.string);
bool is_overloaded = overload_count > 1;
bool implicit_is_found = map_bool_get(&e->ImportName.scope->implicit, hash_pointer(entity)) != NULL;
bool is_not_exported = !is_entity_exported(entity);
@@ -2645,12 +2648,13 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h
}
if (is_overloaded) {
Scope *s = entity->scope;
HashKey key = hash_string(entity->token.string);
Scope *s = import_scope;
bool skip = false;
Entity **procs = gb_alloc_array(heap_allocator(), Entity *, overload_count);
map_entity_multi_get_all(&s->elements, key, procs);
for (isize i = 0; i < overload_count; /**/) {
for (isize i = 0; i < overload_count; i++) {
Type *t = base_type(procs[i]->type);
if (t == t_invalid) {
continue;
@@ -2660,6 +2664,7 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h
if (map_bool_get(&e->ImportName.scope->implicit, hash_pointer(procs[i]))) {
gb_swap(Entity *, procs[i], procs[overload_count-1]);
overload_count--;
i--; // NOTE(bill): Counteract the post event
continue;
}
@@ -2673,8 +2678,6 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h
break;
}
}
i++;
}
if (overload_count > 0 && !skip) {
+14
View File
@@ -1715,6 +1715,12 @@ void check_import_entities(Checker *c, MapScope *file_scopes) {
continue;
}
if (id->is_import) {
// String gpa = str_lit("GetProcAddress");
// if (str_eq(e->token.string, gpa)) {
// Entity *f = scope_lookup_entity(parent_scope, gpa);
// gb_printf_err("%.*s %.*s %td\n", LIT(gpa), LIT(f->token.pos.file), entity_procedure_overload_count(f));
// }
if (is_entity_exported(e)) {
// TODO(bill): Should these entities be imported but cause an error when used?
bool ok = add_entity(c, parent_scope, NULL, e);
@@ -1722,6 +1728,12 @@ void check_import_entities(Checker *c, MapScope *file_scopes) {
map_bool_set(&parent_scope->implicit, hash_pointer(e), true);
}
}
// if (str_eq(e->token.string, gpa)) {
// Entity *f = scope_lookup_entity(parent_scope, gpa);
// gb_printf_err("%.*s %.*s %td\n", LIT(gpa), LIT(f->token.pos.file), entity_procedure_overload_count(f));
// }
} else {
add_entity(c, parent_scope, NULL, e);
}
@@ -1736,6 +1748,8 @@ void check_import_entities(Checker *c, MapScope *file_scopes) {
Entity *e = make_entity_import_name(c->allocator, parent_scope, id->import_name, t_invalid,
id->fullpath, id->import_name.string,
scope);
add_entity(c, parent_scope, NULL, e);
}
}
-7
View File
@@ -1102,13 +1102,6 @@ void ir_add_block_to_proc(irProcedure *proc, irBlock *b) {
b->index = proc->block_count++;
}
// irBlock *ir_add_block(irProcedure *proc, AstNode *node, char *label) {
// irBlock *block = ir_new_block(proc, node, label);
// ir_add_block_to_proc(proc, block);
// return block;
// }
void ir_start_block(irProcedure *proc, irBlock *block) {
proc->curr_block = block;
if (block != NULL) {