From e1d2e3b63934c1e193429f1d6c4e04abc0e85d56 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 26 Feb 2015 15:40:29 +0200 Subject: Support for scope parents, initial variable support --- build/scope | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'build/scope') diff --git a/build/scope b/build/scope index 58f7933..6d96b0a 100644 --- a/build/scope +++ b/build/scope @@ -7,6 +7,7 @@ #include #include +#include #include namespace build @@ -19,6 +20,9 @@ namespace build const path_type& path () const {return i_->first;} // Absolute and normalized. + scope& + parent () const {return *parent_;} + private: friend class scope_map; @@ -27,32 +31,41 @@ namespace build scope () = default; void - init (const iterator& i) {i_ = i;} + init (const iterator& i, scope* p) {i_ = i; parent_ = p;} + + void + parent (scope& p) {parent_ = &p;} public: + variable_map variables; prerequisite_set prerequisites; private: iterator i_; + scope* parent_; }; class scope_map: path_map { public: + // Note that we assume the first insertion into the map is that + // of the root scope. + // + scope& - operator[] (const path& k) - { - auto i (emplace (k, scope ())); - auto& r (i.first->second); + operator[] (const path&); - if (i.second) - r.init (i.first); + // Find the most qualified scope that encompasses this path. + // + scope& + find (const path&); - return r; - } + private: + typedef path_map base; }; extern scope_map scopes; + extern scope* root_scope; } #endif // BUILD_SCOPE -- cgit v1.1