From 6535bf6175af32e2514faf75d2742424751a783b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 15 Apr 2015 14:10:50 +0200 Subject: New variables architecture Now operator[] is only used for lookup. --- build/variable | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'build/variable') diff --git a/build/variable b/build/variable index 6c14477..48fc519 100644 --- a/build/variable +++ b/build/variable @@ -7,6 +7,7 @@ #include #include // unique_ptr +#include // nullptr_t #include // move() #include #include // hash @@ -19,7 +20,6 @@ namespace build { - class scope; struct value; struct value_type @@ -87,10 +87,10 @@ namespace build // // A variable can be undefined, null, or contain some actual value. // + struct variable_map; + struct value_proxy { - typedef build::scope scope_type; - bool defined () const {return p != nullptr;} @@ -100,8 +100,6 @@ namespace build explicit operator bool () const {return defined () && !null ();} explicit operator value_ptr& () const {return *p;} - scope_type* scope; // If NULL, then this is a target variable. - // Get interface. See available specializations below. // template @@ -127,9 +125,20 @@ namespace build const value_proxy& operator= (dir_path) const; + const value_proxy& + operator= (nullptr_t) const; + + // Return true if this value belongs to the specified scope or target. + // + template + bool + belongs (const T& x) const {return map == &x.vars;} + // Implementation details. // - value_proxy (value_ptr* p, scope_type* s): p (p), scope (s) {} + const variable_map* map; // Variable map to which this value belongs. + + value_proxy (value_ptr* p, const variable_map* m): map (m), p (p) {} private: value_ptr* p; @@ -215,32 +224,32 @@ namespace build typedef prefix_map base; value_proxy - operator[] (const std::string& v) + operator[] (const variable& var) const { - return operator[] (variable_pool.find (v)); + auto i (find (var)); + return i != end () + // @@ To do this properly we seem to need ro_value_proxy. + // + ? value_proxy (&const_cast (i->second), this) + : value_proxy (nullptr, nullptr); } value_proxy - operator[] (const variable& v) + operator[] (const std::string& name) const { - return value_proxy (&base::operator[] (v), scope_); + return operator[] (variable_pool.find (name)); } value_proxy - operator[] (const std::string& v) const + assign (const variable& var) { - return operator[] (variable_pool.find (v)); + return value_proxy (&base::operator[] (var), this); } value_proxy - operator[] (const variable& v) const + assign (const std::string& name) { - auto i (find (v)); - return i != end () - // @@ To do this properly we seem to need ro_value_proxy. - // - ? value_proxy (&const_cast (i->second), scope_) - : value_proxy (nullptr, nullptr); + return assign (variable_pool.find (name)); } std::pair @@ -254,13 +263,6 @@ namespace build { return find_prefix (variable_pool.find (ns)); } - - explicit - variable_map (scope* s): scope_ (s) {} - - private: - scope* scope_; // Scope to which this map belongs or NULL if this - // is a target variable map. }; } -- cgit v1.1