diff options
| author | Ginger Bill <bill@gingerbill.org> | 2016-09-16 19:46:48 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2016-09-16 19:46:48 +0100 |
| commit | eb424bb315a880bf52fe843733445dfb502c1525 (patch) | |
| tree | 70b625ca5169448662573ec7da75622013b247fc /src/checker/checker.cpp | |
| parent | 968de5aae886e87f395533283c17d77f31eabd0d (diff) | |
#import and #load
#import - imported entities will not get exported
#load - loaded entities will get exported
Diffstat (limited to 'src/checker/checker.cpp')
| -rw-r--r-- | src/checker/checker.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/checker/checker.cpp b/src/checker/checker.cpp index f6fb6a381..0f2ccc8b1 100644 --- a/src/checker/checker.cpp +++ b/src/checker/checker.cpp @@ -111,6 +111,7 @@ struct Scope { Scope *prev, *next; Scope *first_child, *last_child; Map<Entity *> elements; // Key: String + Map<Entity *> implicit; // Key: String gbArray(Scope *) shared; gbArray(Scope *) imported; @@ -216,6 +217,7 @@ struct CheckerInfo { Map<DeclInfo *> entities; // Key: Entity * Map<Entity *> foreign_procs; // Key: String Map<isize> type_info_map; // Key: Type * + Map<AstFile *> files; // Key: String isize type_info_index; }; @@ -261,8 +263,10 @@ Scope *make_scope(Scope *parent, gbAllocator allocator) { Scope *s = gb_alloc_item(allocator, Scope); s->parent = parent; map_init(&s->elements, gb_heap_allocator()); + map_init(&s->implicit, gb_heap_allocator()); gb_array_init(s->shared, gb_heap_allocator()); gb_array_init(s->imported, gb_heap_allocator()); + if (parent != NULL && parent != universal_scope) { DLIST_APPEND(parent->first_child, parent->last_child, s); } @@ -286,6 +290,7 @@ void destroy_scope(Scope *scope) { } map_destroy(&scope->elements); + map_destroy(&scope->implicit); gb_array_free(scope->shared); gb_array_free(scope->imported); @@ -397,8 +402,9 @@ Entity *scope_insert_entity(Scope *s, Entity *entity) { if (found) return *found; map_set(&s->elements, key, entity); - if (entity->scope == NULL) + if (entity->scope == NULL) { entity->scope = s; + } return NULL; } @@ -506,6 +512,7 @@ void init_checker_info(CheckerInfo *i) { map_init(&i->untyped, a); map_init(&i->foreign_procs, a); map_init(&i->type_info_map, a); + map_init(&i->files, a); i->type_info_index = 0; } @@ -519,6 +526,8 @@ void destroy_checker_info(CheckerInfo *i) { map_destroy(&i->untyped); map_destroy(&i->foreign_procs); map_destroy(&i->type_info_map); + map_destroy(&i->files); + } @@ -889,6 +898,7 @@ void check_parsed_files(Checker *c) { f->scope = scope; HashKey key = hash_string(f->tokenizer.fullpath); map_set(&file_scopes, key, scope); + map_set(&c->info.files, key, f); } // Collect Entities @@ -1032,10 +1042,17 @@ void check_parsed_files(Checker *c) { // 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; + if (e->scope == file_scope) { + continue; + } // NOTE(bill): Do not add other imported entities - if (e->scope == scope && e->kind != Entity_ImportName) { + if (e->kind != Entity_ImportName) { if (is_entity_exported(e)) { add_entity(c, file_scope, NULL, e); + if (!id->is_load) { + HashKey key = hash_string(e->token.string); + map_set(&file_scope->implicit, key, e); + } } } } |