aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-01-30 15:37:10 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-02-13 12:42:41 +0200
commit450c5c09ed7898a800bf5c9328799a43aba78e48 (patch)
tree684d82e370570bd80b0c2f377b2fbe3b922d007f
parent1f543f6eb368c3b23aa1f9cd2d23f0dba1456dec (diff)
Add global flag to variable_map
-rw-r--r--build2/scope4
-rw-r--r--build2/scope.cxx2
-rw-r--r--build2/target4
-rw-r--r--build2/variable63
-rw-r--r--build2/variable.cxx2
5 files changed, 67 insertions, 8 deletions
diff --git a/build2/scope b/build2/scope
index 16ddfbb..8c5ec00 100644
--- a/build2/scope
+++ b/build2/scope
@@ -253,7 +253,8 @@ namespace build2
friend void create_bootstrap_outer (scope&);
friend scope& create_bootstrap_inner (scope&, const dir_path&);
- scope () = default;
+ explicit
+ scope (bool global): vars (global), target_vars (global) {}
scope* parent_;
scope* root_;
@@ -273,6 +274,7 @@ namespace build2
{
public:
temp_scope (scope& p)
+ : scope (false) // Not global.
{
out_path_ = p.out_path_;
src_path_ = p.src_path_;
diff --git a/build2/scope.cxx b/build2/scope.cxx
index 8d0841b..9514817 100644
--- a/build2/scope.cxx
+++ b/build2/scope.cxx
@@ -701,7 +701,7 @@ namespace build2
{
scope_map_base& m (*this);
- auto er (m.emplace (k, scope ()));
+ auto er (m.emplace (k, scope (true))); // Global.
scope& s (er.first->second);
// If this is a new scope, update the parent chain.
diff --git a/build2/target b/build2/target
index 0dec5d4..8733a59 100644
--- a/build2/target
+++ b/build2/target
@@ -549,7 +549,9 @@ namespace build2
//
public:
target (dir_path d, dir_path o, string n, optional<string> e)
- : dir (move (d)), out (move (o)), name (move (n)), ext (move (e)) {}
+ : dir (move (d)), out (move (o)), name (move (n)), ext (move (e)),
+ vars (true) // Global.
+ {}
};
// All targets are from the targets set below.
diff --git a/build2/variable b/build2/variable
index e60c7a1..0df28d8 100644
--- a/build2/variable
+++ b/build2/variable
@@ -1102,18 +1102,67 @@ namespace build2
size_type
size () const {return m_.size ();}
+ public:
+ // Global should be true if this map is part of the global (model) state
+ // (e.g., scope, target, etc).
+ //
+ explicit
+ variable_map (bool global = false): global_ (global) {}
+
private:
+ bool global_;
map_type m_;
};
// Target type/pattern-specific variables.
//
- using variable_pattern_map = std::map<string, variable_map>;
- using variable_type_map_base = std::map<reference_wrapper<const target_type>,
- variable_pattern_map>;
+ class variable_pattern_map
+ {
+ public:
+ using map_type = std::map<string, variable_map>;
+ using const_iterator = map_type::const_iterator;
+ using const_reverse_iterator = map_type::const_reverse_iterator;
- struct variable_type_map: variable_type_map_base
+ explicit
+ variable_pattern_map (bool global): global_ (global) {}
+
+ variable_map&
+ operator[] (const string& v)
+ {
+ return map_.emplace (v, variable_map (global_)).first->second;
+ }
+
+ const_iterator begin () const {return map_.begin ();}
+ const_iterator end () const {return map_.end ();}
+ const_reverse_iterator rbegin () const {return map_.rbegin ();}
+ const_reverse_iterator rend () const {return map_.rend ();}
+ bool empty () const {return map_.empty ();}
+
+ private:
+ bool global_;
+ map_type map_;
+ };
+
+ class variable_type_map
{
+ public:
+ using map_type = std::map<reference_wrapper<const target_type>,
+ variable_pattern_map>;
+ using const_iterator = map_type::const_iterator;
+
+ explicit
+ variable_type_map (bool global): global_ (global) {}
+
+ variable_pattern_map&
+ operator[] (const target_type& t)
+ {
+ return map_.emplace (t, variable_pattern_map (global_)).first->second;
+ }
+
+ const_iterator begin () const {return map_.begin ();}
+ const_iterator end () const {return map_.end ();}
+ bool empty () const {return map_.empty ();}
+
lookup
find (const target_type&, const string& tname, const variable&) const;
@@ -1127,8 +1176,14 @@ namespace build2
// (as target type and target name). The target name, unfortunately, has
// to be stored by value (maybe will pool them at some point).
//
+ // @@ MT
+ //
mutable
std::map<tuple<const value*, const target_type*, string>, value> cache;
+
+ private:
+ bool global_;
+ map_type map_;
};
}
diff --git a/build2/variable.cxx b/build2/variable.cxx
index 16fbe74..1cdde5e 100644
--- a/build2/variable.cxx
+++ b/build2/variable.cxx
@@ -1138,7 +1138,7 @@ namespace build2
//
for (auto tt (&type); tt != nullptr; tt = tt->base)
{
- auto i (variable_type_map_base::find (*tt));
+ auto i (map_.find (*tt));
if (i == end ())
continue;