diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-02-27 16:57:34 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-02-27 16:57:34 +0200 |
commit | 4372f041bb7401c3adc2d5710566b13f64722102 (patch) | |
tree | 5f37f6e69e5529d3628b7611bb642dba15d885c0 /build/scope.cxx | |
parent | e1d2e3b63934c1e193429f1d6c4e04abc0e85d56 (diff) |
Variable assignment, appending support
Diffstat (limited to 'build/scope.cxx')
-rw-r--r-- | build/scope.cxx | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/build/scope.cxx b/build/scope.cxx index 7165663..9013e12 100644 --- a/build/scope.cxx +++ b/build/scope.cxx @@ -8,6 +8,30 @@ using namespace std; namespace build { + // scope + // + value* scope:: + operator[] (const string& name) + { + const variable& var (variable_pool.find (name)); + return (*this)[var]; + } + + value* scope:: + operator[] (const variable& var) + { + for (scope* s (this); s != nullptr; s = s->parent ()) + { + auto i (s->variables.find (var)); + if (i != s->variables.end ()) + return i->second.get (); + } + + return nullptr; + } + + // scope_map + // scope_map scopes; scope* root_scope; @@ -32,8 +56,8 @@ namespace build // between it and our parent. // if (p == nullptr) - p = &c; - else if (p != &c) // A scope with an intermediate parent. + p = c.parent (); + else if (p != c.parent ()) // A scope with an intermediate parent. continue; c.parent (s); @@ -44,7 +68,7 @@ namespace build // root scope). // if (p == nullptr && size () != 1) - p = &find (k); + p = &find (k.directory ()); s.init (er.first, p); } @@ -67,12 +91,12 @@ namespace build for (path d (k.directory ());; d = d.directory ()) { - auto i (base::find (k)); + auto i (base::find (d)); if (i != end ()) return i->second; - assert (d.empty ()); // We should have the root scope. + assert (!d.empty ()); // We should have the root scope. } } } |