aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/variable.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2019-08-22 14:38:57 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2019-08-22 16:16:32 +0200
commit4f5b6cb7ed4e05e98cce7e692462f49e24b7a39a (patch)
tree4184fa33e116ec74747feec0c15e30219c7d087b /libbuild2/variable.hxx
parent739f68b9e45c925ccc5a28b9b796030272575e2b (diff)
Targets, scopes, vars
Diffstat (limited to 'libbuild2/variable.hxx')
-rw-r--r--libbuild2/variable.hxx65
1 files changed, 37 insertions, 28 deletions
diff --git a/libbuild2/variable.hxx b/libbuild2/variable.hxx
index 9a106b5..d153cb0 100644
--- a/libbuild2/variable.hxx
+++ b/libbuild2/variable.hxx
@@ -16,6 +16,7 @@
#include <libbuild2/types.hxx>
#include <libbuild2/utility.hxx>
+#include <libbuild2/context.hxx>
#include <libbuild2/target-type.hxx>
#include <libbuild2/export.hxx>
@@ -1018,7 +1019,7 @@ namespace build2
// Variable pool.
//
- // The global version is protected by the phase mutex.
+ // The global (as in, context-wide) version is protected by the phase mutex.
//
class variable_pool
{
@@ -1175,9 +1176,12 @@ namespace build2
variable_pool&
rw (scope&) const {return const_cast<variable_pool&> (*this);}
- private:
- LIBBUILD2_SYMEXPORT static variable_pool instance;
+ // Entities that can access bypassing the lock proof.
+ //
+ friend class parser;
+ friend class scope;
+ private:
LIBBUILD2_SYMEXPORT variable&
insert (string name,
const value_type*,
@@ -1191,17 +1195,6 @@ namespace build2
const variable_visibility* = nullptr,
const bool* = nullptr) const;
- // Entities that can access bypassing the lock proof.
- //
- friend class parser;
- friend class scope;
- friend LIBBUILD2_SYMEXPORT variable_overrides reset (const strings&);
-
- public:
- // For var_pool initialization.
- //
- LIBBUILD2_SYMEXPORT static const variable_pool& cinstance;
-
// Variable map.
//
private:
@@ -1261,13 +1254,13 @@ namespace build2
// Global pool flag.
//
private:
+ friend class context;
+
explicit
variable_pool (bool global): global_ (global) {}
bool global_;
};
-
- LIBBUILD2_SYMEXPORT extern const variable_pool& var_pool;
}
// variable_map
@@ -1361,7 +1354,9 @@ namespace build2
lookup
operator[] (const string& name) const
{
- const variable* var (var_pool.find (name));
+ const variable* var (ctx != nullptr
+ ? ctx->var_pool.find (name)
+ : nullptr);
return var != nullptr ? operator[] (*var) : lookup ();
}
@@ -1402,7 +1397,7 @@ namespace build2
// Note that the variable is expected to have already been registered.
//
value&
- assign (const string& name) {return insert (var_pool[name]).first;}
+ assign (const string& name) {return insert (ctx->var_pool[name]).first;}
// As above but also return an indication of whether the new value (which
// will be NULL) was actually inserted. Similar to find(), if typed is
@@ -1436,11 +1431,18 @@ namespace build2
// (e.g., scopes, etc).
//
explicit
- variable_map (bool global = false): global_ (global) {}
+ variable_map (context& c, bool global = false)
+ : ctx (&c), global_ (global) {}
void
clear () {m_.clear ();}
+ // Implementation details.
+ //
+ public:
+ explicit
+ variable_map (context* c): ctx (c) {}
+
private:
friend class variable_type_map;
@@ -1448,10 +1450,13 @@ namespace build2
typify (const value_data&, const variable&) const;
private:
- bool global_;
+ context* ctx;
map_type m_;
+ bool global_;
};
+ extern const variable_map empty_variable_map;
+
// Value caching. Used for overrides as well as target type/pattern-specific
// append/prepend.
//
@@ -1528,13 +1533,13 @@ namespace build2
using const_iterator = map_type::const_iterator;
using const_reverse_iterator = map_type::const_reverse_iterator;
- explicit
- variable_pattern_map (bool global): global_ (global) {}
+ variable_pattern_map (context& c, bool global)
+ : ctx (c), global_ (global) {}
variable_map&
operator[] (const string& v)
{
- return map_.emplace (v, variable_map (global_)).first->second;
+ return map_.emplace (v, variable_map (ctx, global_)).first->second;
}
const_iterator begin () const {return map_.begin ();}
@@ -1544,8 +1549,10 @@ namespace build2
bool empty () const {return map_.empty ();}
private:
- bool global_;
+ context& ctx;
map_type map_;
+ bool global_;
+
};
class LIBBUILD2_SYMEXPORT variable_type_map
@@ -1555,13 +1562,13 @@ namespace build2
variable_pattern_map>;
using const_iterator = map_type::const_iterator;
- explicit
- variable_type_map (bool global): global_ (global) {}
+ variable_type_map (context& c, bool global): ctx (c), global_ (global) {}
variable_pattern_map&
operator[] (const target_type& t)
{
- return map_.emplace (t, variable_pattern_map (global_)).first->second;
+ return map_.emplace (
+ t, variable_pattern_map (ctx, global_)).first->second;
}
const_iterator begin () const {return map_.begin ();}
@@ -1585,8 +1592,10 @@ namespace build2
cache;
private:
- bool global_;
+ context& ctx;
map_type map_;
+ bool global_;
+
};
}