16 if (std::ranges::find(scope.data, name) == scope.data.end())
17 scope.data.push_back(name);
22 auto& [data, type] =
m_scopes.back();
27 if (
const auto it = std::ranges::find(data, name); it != data.end())
28 return static_cast<std::size_t
>(std::distance(it, data.end())) - 1;
57 if (back.data.size() > old_length)
59 back.data.begin() +
static_cast<decltype(back.data)::difference_type
>(old_length),
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...
void 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.