Skip to content

Commit

Permalink
refactor(name resolution): removing dead code and refactoring code wh…
Browse files Browse the repository at this point in the history
…en assigning names to symbols in namespaces
  • Loading branch information
SuperFola committed Dec 6, 2024
1 parent 00f4dd2 commit 1391c33
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
18 changes: 8 additions & 10 deletions src/arkreactor/Compiler/NameResolution/NameResolutionPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,18 +305,16 @@ namespace Ark::internal

if (!allowed)
{
std::string message;
if (fqn.ends_with("#hidden"))
throw CodeError(
fmt::format(
R"(Unbound variable "{}". However, it exists in a namespace as "{}", did you forget to add it to the symbol list while importing?)",
symbol.string(),
fqn.substr(0, fqn.find_first_of('#'))),
symbol.filename(),
symbol.line(),
symbol.col(),
symbol.repr());
message = fmt::format(
R"(Unbound variable "{}". However, it exists in a namespace as "{}", did you forget to add it to the symbol list while importing?)",
symbol.string(),
fqn.substr(0, fqn.find_first_of('#')));
else
message = fmt::format(R"(Unbound variable "{}". However, it exists in a namespace as "{}", did you forget to prefix it with its namespace?)", symbol.string(), fqn);
throw CodeError(
fmt::format(R"(Unbound variable "{}". However, it exists in a namespace as "{}", did you forget to prefix it with its namespace?)", symbol.string(), fqn),
message,
symbol.filename(),
symbol.line(),
symbol.col(),
Expand Down
11 changes: 1 addition & 10 deletions src/arkreactor/Compiler/NameResolution/StaticScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace Ark::internal
std::string fqn = fullyQualifiedName(name);
std::string unprefixed_name = starts_with_prefix ? name.substr(name.find_first_of(':') + 1) : name;

if (!m_symbols.empty() && std::ranges::find(m_symbols, unprefixed_name) == m_symbols.end())
if (!m_symbols.empty() && !hasSymbol(unprefixed_name))
return m_vars.emplace(fqn + "#hidden", fqn, is_mutable).first->name;
return m_vars.emplace(fqn, fqn, is_mutable).first->name;
}
Expand All @@ -86,16 +86,7 @@ namespace Ark::internal
if ((m_is_glob || hasSymbol(name) || m_with_prefix) && it != m_vars.end())
return *it;
if (!m_symbols.empty() && it_original != m_vars.end())
{
// hide the name
if (it_original->name == it_original->original_name)
{
bool is_mutable = it_original->is_mutable;
m_vars.erase(it_original);
return *std::get<0>(m_vars.emplace(fullyQualifiedName(name) + "#hidden", name, is_mutable));
}
return *it_original;
}
}
// lookup in the additional saved namespaces
if (extensive_lookup)
Expand Down

0 comments on commit 1391c33

Please sign in to comment.