diff options
| author | Ginger Bill <bill@gingerbill.org> | 2016-09-14 14:16:01 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2016-09-14 14:16:01 +0100 |
| commit | bb109b47d6b43547481a695ed9401aca95cbdf0e (patch) | |
| tree | a7fb5035b94e7da6517ba35988673580fa604b65 /src/checker/checker.cpp | |
| parent | a60e6bedd963b9de4207e5bf8dba13e5c596dd1b (diff) | |
Basic module system (only file namespacing)
Diffstat (limited to 'src/checker/checker.cpp')
| -rw-r--r-- | src/checker/checker.cpp | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/src/checker/checker.cpp b/src/checker/checker.cpp index c09e3f78d..19df9a1b4 100644 --- a/src/checker/checker.cpp +++ b/src/checker/checker.cpp @@ -117,6 +117,7 @@ struct Scope { b32 is_proc; b32 is_global; b32 is_file; + b32 is_init; }; enum ExprKind { @@ -819,6 +820,10 @@ void check_parsed_files(Checker *c) { scope = make_scope(c->global_scope, c->allocator); scope->is_global = f->is_global_scope; scope->is_file = true; + if (i == 0) { + // NOTE(bill): First file is always the initial file + scope->is_init = true; + } if (scope->is_global) { gb_array_append(c->global_scope->shared, scope); @@ -844,9 +849,6 @@ void check_parsed_files(Checker *c) { switch (decl->kind) { case_ast_node(bd, BadDecl, decl); case_end; - case_ast_node(ld, LoadDecl, decl); - // NOTE(bill): ignore - case_end; case_ast_node(id, ImportDecl, decl); // NOTE(bill): Handle later case_end; @@ -947,37 +949,34 @@ void check_parsed_files(Checker *c) { gb_for_array(decl_index, f->decls) { AstNode *decl = f->decls[decl_index]; - if (decl->kind != AstNode_ImportDecl) { - continue; - } - #if 1 - ast_node(id, ImportDecl, decl); - - HashKey key = hash_string(id->fullpath); - auto found = map_get(&file_scopes, key); - GB_ASSERT_MSG(found != NULL, "Unable to find scope for file: %.*s", LIT(id->fullpath)); - Scope *scope = *found; - b32 previously_added = false; - gb_for_array(import_index, file_scope->imported) { - Scope *prev = file_scope->imported[import_index]; - if (prev == scope) { - previously_added = true; - break; + switch (decl->kind) { + case_ast_node(id, ImportDecl, decl); + HashKey key = hash_string(id->fullpath); + auto found = map_get(&file_scopes, key); + GB_ASSERT_MSG(found != NULL, "Unable to find scope for file: %.*s", LIT(id->fullpath)); + Scope *scope = *found; + b32 previously_added = false; + gb_for_array(import_index, file_scope->imported) { + Scope *prev = file_scope->imported[import_index]; + if (prev == scope) { + previously_added = true; + break; + } + } + if (!previously_added) { + gb_array_append(file_scope->imported, scope); } - } - if (!previously_added) { - gb_array_append(file_scope->imported, scope); - } - // NOTE(bill): Add imported entities to this file's scope - gb_for_array(elem_index, scope->elements.entries) { - Entity *e = scope->elements.entries[elem_index].value; - // NOTE(bill): Do not add other imported entities - if (e->scope == scope) { - add_entity(c, file_scope, NULL, e); + // NOTE(bill): Add imported entities to this file's scope + gb_for_array(elem_index, scope->elements.entries) { + Entity *e = scope->elements.entries[elem_index].value; + // NOTE(bill): Do not add other imported entities + if (e->scope == scope) { + add_entity(c, file_scope, NULL, e); + } } + case_end; } - #endif } } |