diff --git a/src/Scope.cc b/src/Scope.cc index 4164bfb98e..ca2af6f73f 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -46,6 +46,19 @@ const IDPtr& Scope::Find(std::string_view name) const return ID::nil; } +void Scope::RemoveGlobal(std::string name, IDPtr /* gid */) + { + ASSERT(this == global_scope()); + + local.erase(name); + + // We could remove the identifier from ordered_vars, but for now + // we skip doing so because (1) the only removals we do are for global + // scope (per the method name), and the only use of ordered_vars is + // for traversing function parameters (i.e., non-global scope), and + // (2) it would be a pain to do so given the current data structure. + } + IDPtr Scope::GenerateTemporary(const char* name) { return make_intrusive(name, SCOPE_FUNCTION, false); diff --git a/src/Scope.h b/src/Scope.h index b84b5dbfb7..4545219346 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -37,12 +37,15 @@ public: const IDPtr& Find(std::string_view name) const; - template void Insert(N&& name, I&& id) + void Insert(std::string name, IDPtr id) { - local[std::forward(name)] = std::forward(id); - ordered_vars.push_back(std::forward(id)); + local[name] = id; + ordered_vars.push_back(id); } + // Must only be called for the global scope. + void RemoveGlobal(std::string name, IDPtr gid); + const IDPtr& GetID() const { return scope_id; } const std::unique_ptr>& Attrs() const { return attrs; }