mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-29 19:00:06 +00:00
Clean up import lookup code
This commit is contained in:
+1
-13
@@ -2590,22 +2590,10 @@ Entity *check_selector(CheckerContext *c, Operand *operand, Ast *node, Type *typ
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
check_entity_decl(c, entity, nullptr, nullptr);
|
||||
GB_ASSERT(entity->type != nullptr);
|
||||
|
||||
|
||||
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) {
|
||||
if (!is_entity_exported(entity)) {
|
||||
gbString sel_str = expr_to_string(selector);
|
||||
error(op_expr, "'%s' is not exported by '%.*s'", sel_str, LIT(import_name));
|
||||
gb_string_free(sel_str);
|
||||
|
||||
+2
-11
@@ -33,7 +33,6 @@ void scope_reset(Scope *scope) {
|
||||
scope->first_child = nullptr;
|
||||
scope->last_child = nullptr;
|
||||
map_clear (&scope->elements);
|
||||
ptr_set_clear(&scope->implicit);
|
||||
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);
|
||||
s->parent = parent;
|
||||
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);
|
||||
|
||||
s->delayed_imports.allocator = heap_allocator();
|
||||
@@ -301,7 +299,6 @@ void destroy_scope(Scope *scope) {
|
||||
map_destroy(&scope->elements);
|
||||
array_free(&scope->delayed_imports);
|
||||
array_free(&scope->delayed_directives);
|
||||
ptr_set_destroy(&scope->implicit);
|
||||
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)
|
||||
@@ -707,10 +704,6 @@ Entity *implicit_entity_of_node(Ast *clause) {
|
||||
}
|
||||
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
|
||||
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;
|
||||
if (e->scope == parent_scope) continue;
|
||||
|
||||
bool implicit_is_found = ptr_set_exists(&scope->implicit, e);
|
||||
if (is_entity_exported(e) && !implicit_is_found) {
|
||||
if (is_entity_exported(e)) {
|
||||
Entity *prev = scope_lookup(parent_scope, e->token.string);
|
||||
bool ok = add_entity(ctx->checker, parent_scope, e->identifier, e);
|
||||
if (ok) ptr_set_add(&parent_scope->implicit, e);
|
||||
add_entity(ctx->checker, parent_scope, e->identifier, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,8 +218,6 @@ struct Scope {
|
||||
Scope * first_child;
|
||||
Scope * last_child;
|
||||
Map<Entity *> elements; // Key: String
|
||||
PtrSet<Entity *> implicit;
|
||||
// Scope * shared;
|
||||
|
||||
Array<Ast *> delayed_directives;
|
||||
Array<Ast *> delayed_imports;
|
||||
|
||||
Reference in New Issue
Block a user