aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-03-15 18:30:39 +0000
committergingerBill <bill@gingerbill.org>2019-03-15 18:30:39 +0000
commitfdb60b2d511f99dd9b8b427d032333992b10fd6a (patch)
treef4149a91081cd71c13dca54d8f1e305a90456b48 /src
parent885c5dc8b75dd88d376627195a5468d12264bcc5 (diff)
Improve package strings
Diffstat (limited to 'src')
-rw-r--r--src/check_stmt.cpp3
-rw-r--r--src/checker.cpp19
2 files changed, 15 insertions, 7 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp
index cead61ce8..07de5dc2e 100644
--- a/src/check_stmt.cpp
+++ b/src/check_stmt.cpp
@@ -474,10 +474,11 @@ bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, b
case Entity_ImportName: {
Scope *scope = e->ImportName.scope;
for_array(i, scope->elements.entries) {
+ String name = scope->elements.entries[i].key.string;
Entity *decl = scope->elements.entries[i].value;
if (!is_entity_exported(decl)) continue;
- Entity *found = scope_insert(ctx->scope, decl);
+ Entity *found = scope_insert_with_name(ctx->scope, name, decl);
if (found != nullptr) {
gbString expr_str = expr_to_string(expr);
error(us->token,
diff --git a/src/checker.cpp b/src/checker.cpp
index 8e8afc621..887f1af67 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -388,8 +388,7 @@ Entity *scope_lookup(Scope *s, String name) {
-Entity *scope_insert(Scope *s, Entity *entity) {
- String name = entity->token.string;
+Entity *scope_insert_with_name(Scope *s, String name, Entity *entity) {
if (name == "") {
return nullptr;
}
@@ -406,6 +405,11 @@ Entity *scope_insert(Scope *s, Entity *entity) {
return nullptr;
}
+Entity *scope_insert(Scope *s, Entity *entity) {
+ String name = entity->token.string;
+ return scope_insert_with_name(s, name, entity);
+}
+
GB_COMPARE_PROC(entity_variable_pos_cmp) {
Entity *x = *cast(Entity **)a;
@@ -1023,11 +1027,10 @@ void add_entity_definition(CheckerInfo *i, Ast *identifier, Entity *entity) {
array_add(&i->definitions, entity);
}
-bool add_entity(Checker *c, Scope *scope, Ast *identifier, Entity *entity) {
+bool add_entity_with_name(Checker *c, Scope *scope, Ast *identifier, Entity *entity, String name) {
if (scope == nullptr) {
return false;
}
- String name = entity->token.string;
if (!is_blank_ident(name)) {
Entity *ie = scope_insert(scope, entity);
if (ie != nullptr) {
@@ -1063,6 +1066,9 @@ bool add_entity(Checker *c, Scope *scope, Ast *identifier, Entity *entity) {
}
return true;
}
+bool add_entity(Checker *c, Scope *scope, Ast *identifier, Entity *entity) {
+ return add_entity_with_name(c, scope, identifier, entity, entity->token.string);
+}
void add_entity_use(CheckerContext *c, Ast *identifier, Entity *entity) {
if (entity == nullptr) {
@@ -3050,12 +3056,13 @@ void check_add_import_decl(CheckerContext *ctx, Ast *decl) {
// NOTE(bill): Add imported entities to this file's scope
for_array(elem_index, scope->elements.entries) {
+ String name = scope->elements.entries[elem_index].key.string;
Entity *e = scope->elements.entries[elem_index].value;
if (e->scope == parent_scope) continue;
if (is_entity_exported(e)) {
- Entity *prev = scope_lookup(parent_scope, e->token.string);
- add_entity(ctx->checker, parent_scope, e->identifier, e);
+ Entity *prev = scope_lookup(parent_scope, name);
+ add_entity_with_name(ctx->checker, parent_scope, e->identifier, e, name);
}
}
}