BasicBlockId break_bb = new_bb ();
// We are still outside the loop block;
- ScopeId continue_scope = ctx.place_db.get_current_scope_id () + 1;
+ ScopeId continue_scope
+ = ctx.place_db.get_current_scope_id ().next_scope_id ();
ctx.loop_and_label_stack.emplace_back (true, label, label_var, break_bb,
continue_bb, continue_scope);
LoopAndLabelCtx info = cont.has_label () ? get_label_ctx (cont.get_label ())
: get_unnamed_loop_ctx ();
start_new_consecutive_bb ();
- unwind_until (info.continue_bb);
+ unwind_until (info.continue_scope);
push_goto (info.continue_bb);
// No code allowed after continue. Handled in BlockExpr.
}
}
};
-using ScopeId = uint32_t;
+struct ScopeId
+{
+ uint32_t value;
+ ScopeId next_scope_id () const { return {value + 1}; }
+ // some overloads for comparision
+ bool operator== (const ScopeId &rhs) const { return value == rhs.value; }
+ bool operator!= (const ScopeId &rhs) const { return !(operator== (rhs)); }
+ bool operator< (const ScopeId &rhs) const { return value < rhs.value; }
+ bool operator> (const ScopeId &rhs) const { return value > rhs.value; }
+ bool operator<= (const ScopeId &rhs) const { return !(operator> (rhs)); }
+ bool operator>= (const ScopeId &rhs) const { return !(operator< (rhs)); }
+};
-static constexpr ScopeId INVALID_SCOPE = std::numeric_limits<ScopeId>::max ();
+static constexpr ScopeId INVALID_SCOPE
+ = {std::numeric_limits<uint32_t>::max ()};
/** Arguments and return value are in the root scope. */
-static constexpr ScopeId ROOT_SCOPE = 0;
+static constexpr ScopeId ROOT_SCOPE = {0};
/** Top-level local variables are in the top-level scope. */
-static constexpr ScopeId TOP_LEVEL_SCOPE = 1;
+static constexpr ScopeId TOP_LEVEL_SCOPE = {1};
struct Scope
{
std::vector<Place> places;
std::unordered_map<TyTy::BaseType *, PlaceId> constants_lookup;
std::vector<Scope> scopes;
- ScopeId current_scope = 0;
+ ScopeId current_scope = ROOT_SCOPE;
std::vector<Loan> loans;
const std::vector<Scope> &get_scopes () const { return scopes; }
- const Scope &get_current_scope () const { return scopes[current_scope]; }
+ const Scope &get_current_scope () const
+ {
+ return scopes[current_scope.value];
+ }
- const Scope &get_scope (ScopeId id) const { return scopes[id]; }
+ const Scope &get_scope (ScopeId id) const { return scopes[id.value]; }
FreeRegion get_next_free_region ()
{
ScopeId push_new_scope ()
{
- ScopeId new_scope = scopes.size ();
+ ScopeId new_scope = {scopes.size ()};
scopes.emplace_back ();
- scopes[new_scope].parent = current_scope;
- scopes[current_scope].children.push_back (new_scope);
+ scopes[new_scope.value].parent = current_scope;
+ scopes[current_scope.value].children.push_back (new_scope);
current_scope = new_scope;
return new_scope;
}
ScopeId pop_scope ()
{
- current_scope = scopes[current_scope].parent;
+ current_scope = scopes[current_scope.value].parent;
return current_scope;
}
if (new_place_ref.kind == Place::VARIABLE
|| new_place_ref.kind == Place::TEMPORARY)
- scopes[current_scope].locals.push_back (new_place);
+ scopes[current_scope.value].locals.push_back (new_place);
auto variances = Resolver::TypeCheckContext::get ()
->get_variance_analysis_ctx ()
WARN_UNUSED_RESULT bool is_in_scope (PlaceId place) const
{
for (ScopeId scope = current_scope; scope != INVALID_SCOPE;
- scope = scopes[scope].parent)
+ scope = scopes[scope.value].parent)
{
- auto &scope_ref = scopes[scope];
+ auto &scope_ref = scopes[scope.value];
if (std::find (scope_ref.locals.begin (), scope_ref.locals.end (),
place)
!= scope_ref.locals.end ())