From 6535bf6175af32e2514faf75d2742424751a783b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 15 Apr 2015 14:10:50 +0200 Subject: New variables architecture Now operator[] is only used for lookup. --- build/scope.cxx | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'build/scope.cxx') diff --git a/build/scope.cxx b/build/scope.cxx index 6fb32b1..4503c6d 100644 --- a/build/scope.cxx +++ b/build/scope.cxx @@ -11,18 +11,35 @@ namespace build // scope // value_proxy scope:: - operator[] (const variable& var) + operator[] (const variable& var) const { - for (scope* s (this); s != nullptr; s = s->parent_scope ()) + for (const scope* s (this); s != nullptr; s = s->parent_scope ()) { - auto i (s->variables.find (var)); - if (i != s->variables.end ()) - return value_proxy (&i->second, s); + auto i (s->vars.find (var)); + if (i != s->vars.end ()) + // @@ Same issue as in variable_map: need ro_value_proxy. + return value_proxy (&const_cast (i->second), &s->vars); } return value_proxy (nullptr, nullptr); } + value_proxy scope:: + append (const variable& var) + { + value_proxy val (operator[] (var)); + + if (val && val.belongs (*this)) // Existing variable in this scope. + return val; + + value_proxy r (assign (var)); + + if (val) + r = val; // Copy value from the outer scope. + + return r; + } + // scope_map // scope_map scopes; -- cgit v1.1