diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-10-16 10:41:59 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-11-04 09:26:21 +0200 |
commit | b9007109a1b6044f5b3239ccacc10946c94c46f4 (patch) | |
tree | dc47d05c21dd9684d7b7ab6f5756b775d3a75892 | |
parent | e6932f85e8b20876f66968b31f84488eee31153d (diff) |
Add notion of scope to testscript model
-rw-r--r-- | build2/test/script/parser | 1 | ||||
-rw-r--r-- | build2/test/script/parser.cxx | 7 | ||||
-rw-r--r-- | build2/test/script/script | 27 | ||||
-rw-r--r-- | build2/test/script/script.cxx | 23 |
4 files changed, 42 insertions, 16 deletions
diff --git a/build2/test/script/parser b/build2/test/script/parser index 732b664..05b4d47 100644 --- a/build2/test/script/parser +++ b/build2/test/script/parser @@ -69,6 +69,7 @@ namespace build2 lexer* lexer_; script* script_; runner* runner_; + scope* scope_; }; } } diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx index 57068c6..7d234eb 100644 --- a/build2/test/script/parser.cxx +++ b/build2/test/script/parser.cxx @@ -28,6 +28,7 @@ namespace build2 script_ = &s; runner_ = &r; + scope_ = script_; token t; type tt; @@ -118,8 +119,8 @@ namespace build2 fail (t) << "unexpected " << t; value& lhs (kind == type::assign - ? script_->assign (var) - : script_->append (var)); + ? scope_->assign (var) + : scope_->append (var)); // @@ Need to adjust to make strings the default type. // @@ -604,7 +605,7 @@ namespace build2 fail (l) << "qualified variable name"; const variable& var (script_->var_pool.insert (move (name))); - return script_->find (var); + return scope_->find (var); } } } diff --git a/build2/test/script/script b/build2/test/script/script index f5e5ef0..005d6e5 100644 --- a/build2/test/script/script +++ b/build2/test/script/script @@ -57,20 +57,22 @@ namespace build2 command_exit exit; }; - class script + class scope { public: - script (target& test_target, target& script_target); + scope* parent; // NULL for the root (script) scope. - public: - target& test_target; // Target we are testing. - target& script_target; // Target of the testscript file. + scope (scope& p): parent (&p) {} + + protected: + scope (): parent (nullptr) {} // For the root (script) scope. + // Variables. + // public: // Note that if we pass the variable name as a string, then it will // be looked up in the wrong pool. // - variable_pool var_pool; variable_map vars; // Lookup the variable starting from this scope, continuing with outer @@ -97,6 +99,19 @@ namespace build2 value& append (const variable&); }; + + class script: public scope + { + public: + script (target& test_target, target& script_target); + + public: + target& test_target; // Target we are testing. + target& script_target; // Target of the testscript file. + + public: + variable_pool var_pool; + }; } } } 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)); |