aboutsummaryrefslogtreecommitdiff
path: root/build/scope
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-04-15 14:10:50 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-04-15 14:10:50 +0200
commit6535bf6175af32e2514faf75d2742424751a783b (patch)
tree21312b28ffe2bbb459a57e80a1f8eec498327d9f /build/scope
parentad720fabd468974e3909f62a0f4e4e3cf0d03aef (diff)
New variables architecture
Now operator[] is only used for lookup.
Diffstat (limited to 'build/scope')
-rw-r--r--build/scope52
1 files changed, 41 insertions, 11 deletions
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<scope>::const_iterator iterator;
- scope (): variables (this) {}
+ scope () = default;
iterator i_;
scope* parent_;