From ea55b08698329defe9155ba89f013efc9350a861 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 28 Jun 2024 11:19:23 -0400 Subject: shortcut push-pops; don't env-copy functions --- var.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'var.cpp') diff --git a/var.cpp b/var.cpp index c907d7a..f4d64fd 100644 --- a/var.cpp +++ b/var.cpp @@ -33,6 +33,23 @@ Var Var::lookup(const std::string& name, int skip) return {}; } +void Var::rename(const std::string& old, const std::string& neww, int skip) +{ + for (auto sc = vars.rbegin(); sc != vars.rend(); ++sc) { + if (skip > 0) { + --skip; + continue; + } + if (sc->contains(old)) { + auto it = sc->find(old); + (*sc)[neww] = it->second; + //it->second.value->setName(neww); + sc->erase(it); + break; + } + } +} + Var Var::lookupLocal(const std::string& name) { return vars.back().contains(name) ? vars.back()[name] : Var(); -- cgit v1.2.3