16 if (std::ranges::find_if(
19 return name == v.name;
20 }) == scope.data.end())
21 scope.data.push_back(
Scope::Var { .name = name, .unreachable =
false });
26 auto& [data, type] =
m_scopes.back();
31 for (
auto it = data.rbegin(); it != data.rend(); ++it)
37 return static_cast<std::size_t
>(std::distance(data.rbegin(), it));
67 if (back.data.size() > old_length)
70 back.data.begin() +
static_cast<decltype(back.data)::difference_type
>(old_length),
80 m_scopes.back().data.back().unreachable =
true;
void saveScopeLengthForBranch()
Save the current scope length before entering a branch, so that we can ignore variable definitions in...
std::vector< Scope > m_scopes
std::vector< std::size_t > m_drop_for_conds
Needed to drop variables inside if/else branches since they don't have their own scope.
std::optional< std::size_t > lookupLastScopeByName(const std::string &name)
Search for a local in the current scope. Returns std::nullopt in case of closure scopes or if the var...
bool dropVarsForBranch()
Drop potentially defined variables in the last saved branch.
void deleteScope()
Delete the last scope.
void addLocal(const std::string &name)
Register a local in the current scope, triggered by a STORE instruction. If the local already exists,...
LocalsLocator()
Create a new LocalsLocator to track the position of variables in the scope stack.
void createScope(ScopeType type=ScopeType::Default)
Create a new scope.
void markLastLocalAsUnreachable()
Mark the last variable of a scope as unreachable, blocking lookupLastScopeByName(....