From 68f96f9213e849d0d7c4cedf3edeaec99743ee27 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 24 Aug 2015 09:51:15 +0200 Subject: New variable architecture --- build/scope.cxx | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'build/scope.cxx') diff --git a/build/scope.cxx b/build/scope.cxx index d878726..e6d165e 100644 --- a/build/scope.cxx +++ b/build/scope.cxx @@ -12,30 +12,33 @@ namespace build { // scope // - value_proxy scope:: + lookup scope:: operator[] (const variable& var) const { - for (const scope* s (this); s != nullptr; s = s->parent_scope ()) + const value* r (nullptr); + const scope* s (this); + + for (; s != nullptr; s = s->parent_scope ()) { - if (const value_ptr* v = s->vars.find (var)) - return value_proxy (v, &s->vars); + if ((r = s->vars.find (var)) != nullptr) + break; } - return value_proxy (); + return lookup (r, &s->vars); } - value_proxy scope:: + value& scope:: append (const variable& var) { - value_proxy val (operator[] (var)); + auto l (operator[] (var)); - if (val && val.belongs (*this)) // Existing variable in this scope. - return val; + if (l && l.belongs (*this)) // Existing variable in this scope. + return const_cast (*l); - value_proxy r (assign (var)); + value& r (assign (var)); - if (val) - r = val; // Copy value from the outer scope. + if (l) + r = *l; // Copy value from the outer scope. return r; } -- cgit v1.1