aboutsummaryrefslogtreecommitdiff
path: root/build/scope.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-04-15 14:10:50 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-04-15 14:10:50 +0200
commit6535bf6175af32e2514faf75d2742424751a783b (patch)
tree21312b28ffe2bbb459a57e80a1f8eec498327d9f /build/scope.cxx
parentad720fabd468974e3909f62a0f4e4e3cf0d03aef (diff)
New variables architecture
Now operator[] is only used for lookup.
Diffstat (limited to 'build/scope.cxx')
-rw-r--r--build/scope.cxx27
1 files changed, 22 insertions, 5 deletions
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<value_ptr&> (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;