aboutsummaryrefslogtreecommitdiff
path: root/build2/test/script/script.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-10-16 10:41:59 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-04 09:26:21 +0200
commitb9007109a1b6044f5b3239ccacc10946c94c46f4 (patch)
treedc47d05c21dd9684d7b7ab6f5756b775d3a75892 /build2/test/script/script.cxx
parente6932f85e8b20876f66968b31f84488eee31153d (diff)
Add notion of scope to testscript model
Diffstat (limited to 'build2/test/script/script.cxx')
-rw-r--r--build2/test/script/script.cxx23
1 files changed, 16 insertions, 7 deletions
diff --git a/build2/test/script/script.cxx b/build2/test/script/script.cxx
index 1b47846..b206e4f 100644
--- a/build2/test/script/script.cxx
+++ b/build2/test/script/script.cxx
@@ -43,11 +43,19 @@ namespace build2
}
}
- lookup script::
+ lookup scope::
find (const variable& var) const
{
- if (const value* v = vars.find (var))
- return lookup (v, &vars);
+ // Search script scopes until we hit the root.
+ //
+ const scope* p (this);
+
+ do
+ {
+ if (const value* v = p->vars.find (var))
+ return lookup (v, &p->vars);
+ }
+ while (p->parent != nullptr ? (p = p->parent) : nullptr);
// Switch to the corresponding buildfile variable. Note that we don't
// want to insert a new variable into the pool (we might be running
@@ -59,6 +67,7 @@ namespace build2
if (pvar == nullptr)
return lookup ();
+ const script& s (static_cast<const script&> (*p));
{
const variable& var (*pvar);
@@ -69,12 +78,12 @@ namespace build2
// value. In this case, presumably the override also affects the
// script target and we will pick it up there. A bit fuzzy.
//
- auto p (test_target.find_original (var, true));
+ auto p (s.test_target.find_original (var, true));
if (p.first)
{
if (var.override != nullptr)
- p = test_target.base_scope ().find_override (
+ p = s.test_target.base_scope ().find_override (
var, move (p), true);
return p.first;
@@ -86,11 +95,11 @@ namespace build2
// in different scopes which brings the question of which scopes we
// should search.
//
- return script_target[var];
+ return s.script_target[var];
}
}
- value& script::
+ value& scope::
append (const variable& var)
{
lookup l (find (var));