Clean up import lookup code

This commit is contained in:
gingerBill
2018-06-17 21:50:40 +01:00
parent 5fe4c33d0e
commit a99cc2fd70
4 changed files with 27 additions and 49 deletions
+24 -23
View File
@@ -1,33 +1,34 @@
package c package c
import b "core:builtin"
import "core:os" import "core:os"
CHAR_BIT :: 8; CHAR_BIT :: 8;
c_bool :: bool; bool :: b.bool;
c_char :: u8; char :: b.u8;
c_byte :: u8; byte :: b.byte;
c_schar :: i8; schar :: b.i8;
c_uchar :: u8; uchar :: b.u8;
c_short :: i16; short :: b.i16;
c_ushort :: u16; ushort :: b.u16;
c_int :: i32; int :: b.i32;
c_uint :: u32; uint :: b.u32;
c_long :: (os.OS == "windows" || size_of(rawptr) == 4) ? i32 : i64; long :: (os.OS == "windows" || size_of(b.rawptr) == 4) ? b.i32 : b.i64;
c_ulong :: (os.OS == "windows" || size_of(rawptr) == 4) ? u32 : u64; ulong :: (os.OS == "windows" || size_of(b.rawptr) == 4) ? b.u32 : b.u64;
c_longlong :: i64; longlong :: b.i64;
c_ulonglong :: u64; ulonglong :: b.u64;
c_float :: f32; float :: b.f32;
c_double :: f64; double :: b.f64;
c_complex_float :: complex64; complex_float :: b.complex64;
c_complex_double :: complex128; complex_double :: b.complex128;
#assert(size_of(uintptr) == size_of(int)); #assert(size_of(b.uintptr) == size_of(b.int));
c_size_t :: uint; size_t :: b.uint;
c_ssize_t :: int; ssize_t :: b.int;
c_ptrdiff_t :: int; ptrdiff_t :: b.int;
c_uintptr_t :: uintptr; uintptr_t :: b.uintptr;
c_intptr_t :: int; intptr_t :: b.int;
+1 -13
View File
@@ -2590,22 +2590,10 @@ Entity *check_selector(CheckerContext *c, Operand *operand, Ast *node, Type *typ
return nullptr; return nullptr;
} }
check_entity_decl(c, entity, nullptr, nullptr); check_entity_decl(c, entity, nullptr, nullptr);
GB_ASSERT(entity->type != nullptr); GB_ASSERT(entity->type != nullptr);
if (!is_entity_exported(entity)) {
bool implicit_is_found = is_entity_implicitly_imported(e, entity);
bool is_not_exported = !is_entity_exported(entity);
if (entity->kind == Entity_ImportName) {
is_not_exported = true;
} else if (implicit_is_found) {
is_not_exported = true;
}
if (is_not_exported) {
gbString sel_str = expr_to_string(selector); gbString sel_str = expr_to_string(selector);
error(op_expr, "'%s' is not exported by '%.*s'", sel_str, LIT(import_name)); error(op_expr, "'%s' is not exported by '%.*s'", sel_str, LIT(import_name));
gb_string_free(sel_str); gb_string_free(sel_str);
+2 -11
View File
@@ -33,7 +33,6 @@ void scope_reset(Scope *scope) {
scope->first_child = nullptr; scope->first_child = nullptr;
scope->last_child = nullptr; scope->last_child = nullptr;
map_clear (&scope->elements); map_clear (&scope->elements);
ptr_set_clear(&scope->implicit);
ptr_set_clear(&scope->imported); ptr_set_clear(&scope->imported);
} }
@@ -222,7 +221,6 @@ Scope *create_scope(Scope *parent, gbAllocator allocator, isize init_elements_ca
Scope *s = gb_alloc_item(allocator, Scope); Scope *s = gb_alloc_item(allocator, Scope);
s->parent = parent; s->parent = parent;
map_init(&s->elements, heap_allocator(), init_elements_capacity); map_init(&s->elements, heap_allocator(), init_elements_capacity);
ptr_set_init(&s->implicit, heap_allocator(), 0);
ptr_set_init(&s->imported, heap_allocator(), 0); ptr_set_init(&s->imported, heap_allocator(), 0);
s->delayed_imports.allocator = heap_allocator(); s->delayed_imports.allocator = heap_allocator();
@@ -301,7 +299,6 @@ void destroy_scope(Scope *scope) {
map_destroy(&scope->elements); map_destroy(&scope->elements);
array_free(&scope->delayed_imports); array_free(&scope->delayed_imports);
array_free(&scope->delayed_directives); array_free(&scope->delayed_directives);
ptr_set_destroy(&scope->implicit);
ptr_set_destroy(&scope->imported); ptr_set_destroy(&scope->imported);
// NOTE(bill): No need to free scope as it "should" be allocated in an arena (except for the global scope) // NOTE(bill): No need to free scope as it "should" be allocated in an arena (except for the global scope)
@@ -707,10 +704,6 @@ Entity *implicit_entity_of_node(Ast *clause) {
} }
return nullptr; return nullptr;
} }
bool is_entity_implicitly_imported(Entity *import_name, Entity *e) {
GB_ASSERT(import_name->kind == Entity_ImportName);
return ptr_set_exists(&import_name->ImportName.scope->implicit, e);
}
// Will return nullptr if not found // Will return nullptr if not found
Entity *entity_of_node(CheckerInfo *i, Ast *expr) { Entity *entity_of_node(CheckerInfo *i, Ast *expr) {
@@ -2600,11 +2593,9 @@ void check_add_import_decl(CheckerContext *ctx, Ast *decl) {
Entity *e = scope->elements.entries[elem_index].value; Entity *e = scope->elements.entries[elem_index].value;
if (e->scope == parent_scope) continue; if (e->scope == parent_scope) continue;
bool implicit_is_found = ptr_set_exists(&scope->implicit, e); if (is_entity_exported(e)) {
if (is_entity_exported(e) && !implicit_is_found) {
Entity *prev = scope_lookup(parent_scope, e->token.string); Entity *prev = scope_lookup(parent_scope, e->token.string);
bool ok = add_entity(ctx->checker, parent_scope, e->identifier, e); add_entity(ctx->checker, parent_scope, e->identifier, e);
if (ok) ptr_set_add(&parent_scope->implicit, e);
} }
} }
} }
-2
View File
@@ -218,8 +218,6 @@ struct Scope {
Scope * first_child; Scope * first_child;
Scope * last_child; Scope * last_child;
Map<Entity *> elements; // Key: String Map<Entity *> elements; // Key: String
PtrSet<Entity *> implicit;
// Scope * shared;
Array<Ast *> delayed_directives; Array<Ast *> delayed_directives;
Array<Ast *> delayed_imports; Array<Ast *> delayed_imports;