From 088a60c512aff26eeb026c516d0afe724880cb2b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 7 Apr 2015 10:47:28 +0200 Subject: Provide more convenient access to root scope --- build/scope | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'build/scope') diff --git a/build/scope b/build/scope index 0fa3025..057fbc1 100644 --- a/build/scope +++ b/build/scope @@ -29,7 +29,18 @@ namespace build src_path () const {return *src_path_;} // Corresponding src path. scope* - parent () const {return parent_;} + parent_scope () const {return parent_;} + + // Root scope of this scope or NULL if this scope is not (yet) + // in any (known) project. Note that if the scope itself is + // root, then this function return this. To get to the outer + // root, query the root scope of the parent. + // + scope* + root_scope () const {return root_;} + + bool + root () const {return root_ == this;} // Variable lookup. Note that this find, not find or insert like // in the variable_map, because we also search in outer scopes. @@ -44,19 +55,6 @@ namespace build const path_type* src_path_ {nullptr}; // Cached src_{root,base} var value. - private: - friend class scope_map; - - typedef path_map::const_iterator iterator; - - scope (): variables (*this) {} - - void - init (const iterator& i, scope* p) {i_ = i; parent_ = p;} - - void - parent (scope& p) {parent_ = &p;} - public: variable_map variables; prerequisite_set prerequisites; @@ -85,8 +83,14 @@ namespace build std::unordered_map triggers; private: + friend class scope_map; + typedef path_map::const_iterator iterator; + + scope (): variables (*this) {} + iterator i_; scope* parent_; + scope* root_; }; class scope_map: public path_map @@ -96,10 +100,10 @@ namespace build // of the global scope. // std::pair - insert (const path&); + insert (const path&, bool root); scope& - operator[] (const path& p) {return insert (p).first;} + operator[] (const path& p) {return insert (p, false).first;} // Find the most qualified scope that encompasses this path. // -- cgit v1.1