8 assert(!scopes_.empty());
13 if (dbg.sym ==
'_')
return nullptr;
15 for (
auto& scope : scopes_ | std::ranges::views::reverse)
16 if (
auto i = scope.find(dbg.sym); i != scope.end())
return i->second.second;
22 if (dbg.sym ==
'_')
error(dbg.loc,
"the symbol '_' is special and never binds to anything");
23 if (
auto res =
query(dbg))
return res;
24 error(dbg.loc,
"'{}' not found", dbg.sym);
28 auto [loc, sym] = dbg;
29 if (sym ==
'_')
return;
32 (*scope)[sym] = std::pair(loc, def);
33 }
else if (
auto [i, ins] = scope->emplace(sym, std::pair(loc, def)); !ins) {
34 auto prev = i->second.first;
35 error(loc,
"redeclaration of '{}'; previous declaration here: {}", sym, prev);
const Def * query(Dbg) const
void bind(Scope *, Dbg, const Def *, bool rebind=false)
fe::SymMap< std::pair< Loc, const Def * > > Scope
const Def * find(Dbg) const
Same as Scopes::query but potentially raises an error.
void error(const Def *def, const char *fmt, Args &&... args)