mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-13 01:21:38 -07:00
Clean up import lookup code
This commit is contained in:
+24
-23
@@ -1,33 +1,34 @@
|
||||
package c
|
||||
|
||||
import b "core:builtin"
|
||||
import "core:os"
|
||||
|
||||
CHAR_BIT :: 8;
|
||||
|
||||
c_bool :: bool;
|
||||
c_char :: u8;
|
||||
c_byte :: u8;
|
||||
c_schar :: i8;
|
||||
c_uchar :: u8;
|
||||
c_short :: i16;
|
||||
c_ushort :: u16;
|
||||
c_int :: i32;
|
||||
c_uint :: u32;
|
||||
bool :: b.bool;
|
||||
char :: b.u8;
|
||||
byte :: b.byte;
|
||||
schar :: b.i8;
|
||||
uchar :: b.u8;
|
||||
short :: b.i16;
|
||||
ushort :: b.u16;
|
||||
int :: b.i32;
|
||||
uint :: b.u32;
|
||||
|
||||
c_long :: (os.OS == "windows" || size_of(rawptr) == 4) ? i32 : i64;
|
||||
c_ulong :: (os.OS == "windows" || size_of(rawptr) == 4) ? u32 : u64;
|
||||
long :: (os.OS == "windows" || size_of(b.rawptr) == 4) ? b.i32 : b.i64;
|
||||
ulong :: (os.OS == "windows" || size_of(b.rawptr) == 4) ? b.u32 : b.u64;
|
||||
|
||||
c_longlong :: i64;
|
||||
c_ulonglong :: u64;
|
||||
c_float :: f32;
|
||||
c_double :: f64;
|
||||
c_complex_float :: complex64;
|
||||
c_complex_double :: complex128;
|
||||
longlong :: b.i64;
|
||||
ulonglong :: b.u64;
|
||||
float :: b.f32;
|
||||
double :: b.f64;
|
||||
complex_float :: b.complex64;
|
||||
complex_double :: b.complex128;
|
||||
|
||||
#assert(size_of(uintptr) == size_of(int));
|
||||
#assert(size_of(b.uintptr) == size_of(b.int));
|
||||
|
||||
c_size_t :: uint;
|
||||
c_ssize_t :: int;
|
||||
c_ptrdiff_t :: int;
|
||||
c_uintptr_t :: uintptr;
|
||||
c_intptr_t :: int;
|
||||
size_t :: b.uint;
|
||||
ssize_t :: b.int;
|
||||
ptrdiff_t :: b.int;
|
||||
uintptr_t :: b.uintptr;
|
||||
intptr_t :: b.int;
|
||||
|
||||
+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