diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-08-24 09:51:15 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-08-24 14:52:43 +0200 |
commit | 68f96f9213e849d0d7c4cedf3edeaec99743ee27 (patch) | |
tree | 271913d74c906971cac555319f5e14d0c66e0c16 /build/scope.cxx | |
parent | 0d5234f4aefd3cc5b5948cc1b9dd009e50046f5e (diff) |
New variable architecture
Diffstat (limited to 'build/scope.cxx')
-rw-r--r-- | build/scope.cxx | 27 |
1 files changed, 15 insertions, 12 deletions
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<const value> 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<const value> (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<value&> (*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; } |