From 7eed858cac7e8ff78626bdc5d63a7f36ca8f8010 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 4 Mar 2015 16:33:51 +0200 Subject: Move roots and bases to appropriate scopes --- build/scope.cxx | 54 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'build/scope.cxx') diff --git a/build/scope.cxx b/build/scope.cxx index 9013e12..b9b576e 100644 --- a/build/scope.cxx +++ b/build/scope.cxx @@ -10,24 +10,24 @@ namespace build { // scope // - value* scope:: + value_proxy scope:: operator[] (const string& name) { const variable& var (variable_pool.find (name)); - return (*this)[var]; + return operator[] (var); } - value* scope:: + value_proxy 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 value_proxy (&i->second, s); } - return nullptr; + return value_proxy (nullptr, nullptr); } // scope_map @@ -45,31 +45,37 @@ namespace build { scope* p (nullptr); - // Update scopes of which we are a new parent. + // Update scopes of which we are a new parent (unless this is the + // root scope). // - for (auto r (find_prefix (k)); r.first != r.second; ++r.first) + if (size () > 1) { - scope& c (r.first->second); - - // The first scope of which we are a parent is the least - // (shortest) one which means there is no other scope - // between it and our parent. + // The first entry is ourselves. + // + auto r (find_prefix (k)); + for (++r.first; r.first != r.second; ++r.first) + { + scope& c (r.first->second); + + // The first scope of which we are a parent is the least + // (shortest) one which means there is no other scope + // between it and our parent. + // + if (p == nullptr) + p = c.parent (); + else if (p != c.parent ()) // A scope with an intermediate parent. + continue; + + c.parent (s); + } + + // We couldn't get the parent from one of its old children + // so we have to find it ourselves. // if (p == nullptr) - p = c.parent (); - else if (p != c.parent ()) // A scope with an intermediate parent. - continue; - - c.parent (s); + p = &find (k.directory ()); } - // We couldn't get the parent from one of its old children - // so we have to find it ourselves (unless this is is the - // root scope). - // - if (p == nullptr && size () != 1) - p = &find (k.directory ()); - s.init (er.first, p); } -- cgit v1.1