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/scope | 52 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 11 deletions(-) (limited to 'build/scope') diff --git a/build/scope b/build/scope index e4a8a7d..e3c8776 100644 --- a/build/scope +++ b/build/scope @@ -26,6 +26,8 @@ namespace build const dir_path& src_path () const {return *src_path_;} // Corresponding src path. + const dir_path* src_path_ {nullptr}; // Cached src_{root,base} var value. + scope* parent_scope () const {return parent_;} @@ -40,28 +42,56 @@ namespace build bool root () const {return root_ == this;} - // Variable lookup. Note that this is find, not find or insert like - // in the variable_map, because we also search in outer scopes. For - // the latter use the variables map directly. + // Variables. // public: + variable_map vars; + + // Lookup, including in outer scopes. If you only want to lookup + // in this scope, do it on the the variables map directly. + // value_proxy - operator[] (const variable&); + operator[] (const variable&) const; value_proxy - operator[] (const std::string& name) + operator[] (const std::string& name) const { return operator[] (variable_pool.find (name)); } - const dir_path* src_path_ {nullptr}; // Cached src_{root,base} var value. + // Return a value_proxy suitable for assignment. If the variable + // does not exist in this scope's map, then a new one with the + // NULL value is added and returned. Otherwise the existing value + // if returned. + // + value_proxy + assign (const variable& var) + { + return vars.assign (var); + } - public: - variable_map variables; + value_proxy + assign (const std::string& name) + { + return assign (variable_pool.find (name)); + } + + // Return a value_proxy suitable for appending. If the variable + // does not exist in this scope's map, then outer scopes are + // searched for the same variable. If found then a new variable + // with the found value is added to this scope and returned. + // Otherwise this function proceeds as assign(). + // + value_proxy + append (const variable&); - const variable_map& - ro_variables () const {return variables;} + value_proxy + append (const std::string& name) + { + return append (variable_pool.find (name)); + } + public: prerequisite_set prerequisites; // Meta/operations supported by this project (set on the root @@ -95,7 +125,7 @@ namespace build typedef dir_path_map::const_iterator iterator; - scope (): variables (this) {} + scope () = default; iterator i_; scope* parent_; -- cgit v1.1