aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/build/script
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-10-10 18:22:31 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-10-10 18:22:31 +0200
commit19af3f6b0873a92582e4787a87a6f14df53ff6ae (patch)
tree7545e80d9348eb7808e1c894cd111ab46cc8a9a5 /libbuild2/build/script
parent9f95a23eae04680559a9cb943fdfaa00f52cd66e (diff)
Preparatory work for public/private variable distinction
We still always use the public var_pool from context but where required, all access now goes through scope::var_pool().
Diffstat (limited to 'libbuild2/build/script')
-rw-r--r--libbuild2/build/script/parser.cxx6
-rw-r--r--libbuild2/build/script/parser.test.cxx8
-rw-r--r--libbuild2/build/script/script.cxx6
-rw-r--r--libbuild2/build/script/script.hxx7
4 files changed, 16 insertions, 11 deletions
diff --git a/libbuild2/build/script/parser.cxx b/libbuild2/build/script/parser.cxx
index 788a782..bcea7e0 100644
--- a/libbuild2/build/script/parser.cxx
+++ b/libbuild2/build/script/parser.cxx
@@ -2526,10 +2526,8 @@ namespace build2
{
if (pre_parse_suspended_)
{
- const variable* pvar (scope_->ctx.var_pool.find (name));
-
- if (pvar != nullptr)
- r = (*scope_)[*pvar];
+ if (const variable* var = scope_->var_pool ().find (name))
+ r = (*scope_)[*var];
}
if (!depdb_clear_)
diff --git a/libbuild2/build/script/parser.test.cxx b/libbuild2/build/script/parser.test.cxx
index f8c2696..061f3f8 100644
--- a/libbuild2/build/script/parser.test.cxx
+++ b/libbuild2/build/script/parser.test.cxx
@@ -232,6 +232,8 @@ namespace build2
tt.path (path ("driver"));
+ const scope& bs (tt.base_scope ());
+
small_vector<action, 1> acts {perform_update_id};
// Parse and run.
@@ -239,7 +241,7 @@ namespace build2
parser p (ctx);
path_name nm ("buildfile");
- script s (p.pre_parse (tt.base_scope (), tt.type (), acts,
+ script s (p.pre_parse (bs, tt.type (), acts,
cin, nm,
11 /* line */,
(m != mode::diag
@@ -251,7 +253,7 @@ namespace build2
{
case mode::run:
{
- environment e (perform_update_id, tt, s.body_temp_dir);
+ environment e (perform_update_id, tt, bs, s.body_temp_dir);
print_runner r (print_line, print_iterations);
p.execute_body (ctx.global_scope, ctx.global_scope, e, s, r);
break;
@@ -266,7 +268,7 @@ namespace build2
{
assert (s.diag_line);
- environment e (perform_update_id, tt, false /* temp_dir */);
+ environment e (perform_update_id, tt, bs, false /* temp_dir */);
cout << "diag: " << p.execute_special (ctx.global_scope,
ctx.global_scope,
diff --git a/libbuild2/build/script/script.cxx b/libbuild2/build/script/script.cxx
index a557065..2e777b4 100644
--- a/libbuild2/build/script/script.cxx
+++ b/libbuild2/build/script/script.cxx
@@ -28,6 +28,7 @@ namespace build2
environment::
environment (action a,
const target_type& t,
+ const scope_type& s,
bool temp,
const optional<timestamp>& dl)
: build2::script::environment (
@@ -39,7 +40,8 @@ namespace build2
redirect (redirect_type::merge, 2),
redirect (redirect_type::pass)),
target (t),
- vars (context, false /* global */),
+ scope (s),
+ vars (context, false /* shared */), // Note: managed.
var_ts (var_pool.insert (">")),
var_ps (var_pool.insert ("<")),
script_deadline (to_deadline (dl, false /* success */))
@@ -233,7 +235,7 @@ namespace build2
// in parallel). Plus, if there is no such variable, then we cannot
// possibly find any value.
//
- const variable* pvar (context.var_pool.find (n));
+ const variable* pvar (scope.var_pool ().find (n));
if (pvar == nullptr)
return lookup_type ();
diff --git a/libbuild2/build/script/script.hxx b/libbuild2/build/script/script.hxx
index f8df204..2c5e6e0 100644
--- a/libbuild2/build/script/script.hxx
+++ b/libbuild2/build/script/script.hxx
@@ -89,10 +89,12 @@ namespace build2
class environment: public build2::script::environment
{
public:
+ using scope_type = build2::scope;
using target_type = build2::target;
environment (action,
const target_type&,
+ const scope_type&,
bool temp_dir,
const optional<timestamp>& deadline = nullopt);
@@ -113,11 +115,12 @@ namespace build2
environment& operator= (const environment&) = delete;
public:
- // Primary target this environment is for.
+ // Primary target this environment is for and its base scope;
//
const target_type& target;
+ const scope_type& scope;
- // Script-local variable pool and map.
+ // Script-private variable pool and map.
//
// Note that it may be tempting to reuse the rule-specific variables
// for this but they should not be modified during execution (i.e.,