diff options
-rw-r--r-- | build2/context.cxx | 2 | ||||
-rw-r--r-- | build2/file.cxx | 10 | ||||
-rw-r--r-- | build2/parser | 6 | ||||
-rw-r--r-- | build2/parser.cxx | 23 |
4 files changed, 21 insertions, 20 deletions
diff --git a/build2/context.cxx b/build2/context.cxx index 96532c4..0988f79 100644 --- a/build2/context.cxx +++ b/build2/context.cxx @@ -101,7 +101,7 @@ namespace build2 } parser p; - t = p.parse_variable (l, gs, t.value, tt); + t = p.parse_variable (l, gs, var_pool.find (t.value), tt); if (t.type != token_type::eos) fail << "unexpected " << t << " in variable assignment '" << v << "'"; diff --git a/build2/file.cxx b/build2/file.cxx index 9097703..90d584d 100644 --- a/build2/file.cxx +++ b/build2/file.cxx @@ -264,7 +264,7 @@ namespace build2 // any variable expansion other than those from the global scope. // static value - extract_variable (const path& bf, const char* var) + extract_variable (const path& bf, const char* name) { try { @@ -278,18 +278,20 @@ namespace build2 token t (lex.next ()); token_type tt; - if (t.type != token_type::name || t.value != var || + if (t.type != token_type::name || t.value != name || ((tt = lex.next ().type) != token_type::assign && tt != token_type::prepend && tt != token_type::append)) { - error << "variable '" << var << "' expected as first line in " << bf; + error << "variable '" << name << "' expected as first line in " << bf; throw failed (); // Suppress "used uninitialized" warning. } + const variable& var (var_pool.find (move (t.value))); + parser p; temp_scope tmp (*global_scope); - p.parse_variable (lex, tmp, t.value, tt); + p.parse_variable (lex, tmp, var, tt); auto l (tmp.vars[var]); assert (l.defined ()); diff --git a/build2/parser b/build2/parser index 201e8ed..f3413a3 100644 --- a/build2/parser +++ b/build2/parser @@ -11,13 +11,13 @@ #include <build2/spec> #include <build2/lexer> #include <build2/token> -#include <build2/variable> // list_value #include <build2/diagnostics> namespace build2 { class scope; class target; + struct variable; class parser { @@ -39,7 +39,7 @@ namespace build2 parse_buildspec (istream&, const path& name); token - parse_variable (lexer&, scope&, string var_name, token_type kind); + parse_variable (lexer&, scope&, const variable_type&, token_type kind); names_type parse_export_stub (istream& is, const path& p, scope& r, scope& b) @@ -79,7 +79,7 @@ namespace build2 if_else (token&, token_type&); void - variable (token&, token_type&, string name, token_type kind); + variable (token&, token_type&, const variable_type&, token_type kind); string variable_name (names_type&&, const location&); diff --git a/build2/parser.cxx b/build2/parser.cxx index b19fcb3..f9391f8 100644 --- a/build2/parser.cxx +++ b/build2/parser.cxx @@ -55,7 +55,7 @@ namespace build2 } token parser:: - parse_variable (lexer& l, scope& s, string name, type kind) + parse_variable (lexer& l, scope& s, const variable_type& var, type kind) { path_ = &l.name (); lexer_ = &l; @@ -64,7 +64,7 @@ namespace build2 type tt; token t (type::eos, false, 0, 0); - variable (t, tt, move (name), kind); + variable (t, tt, var, kind); return t; } @@ -301,7 +301,9 @@ namespace build2 token at (t); type att (tt); - string v (variable_name (move (pns), ploc)); + const variable_type& var ( + var_pool.find ( + variable_name (move (pns), ploc))); // If we have multiple targets/scopes, then we save the value // tokens when parsing the first one and then replay them for @@ -331,7 +333,7 @@ namespace build2 scope* ocs (scope_); switch_scope (p); - variable (t, tt, v, att); + variable (t, tt, var, att); scope_ = ocs; root_ = ors; @@ -347,7 +349,7 @@ namespace build2 { target* ot (target_); target_ = &enter_target (move (n)); - variable (t, tt, v, att); + variable (t, tt, var, att); target_ = ot; } else @@ -374,18 +376,16 @@ namespace build2 if (att == type::prepend) fail (at) << "prepend to target type/pattern-specific " - << "variable " << v; + << "variable " << var.name; if (att == type::append) fail (at) << "append to target type/pattern-specific " - << "variable " << v; + << "variable " << var.name; // Note: expanding variables in the value in the context of // the scope. // names_type vns (variable_value (t, tt)); - - const auto& var (var_pool.find (v)); value& val (scope_->target_vars[*ti][move (n.value)].assign ( var).first); val.assign (move (vns), var); @@ -465,7 +465,7 @@ namespace build2 // if (tt == type::assign || tt == type::prepend || tt == type::append) { - variable (t, tt, variable_name (move (ns), nloc), tt); + variable (t, tt, var_pool.find (variable_name (move (ns), nloc)), tt); if (tt == type::newline) next (t, tt); @@ -1165,10 +1165,9 @@ namespace build2 } void parser:: - variable (token& t, type& tt, string name, type kind) + variable (token& t, type& tt, const variable_type& var, type kind) { names_type vns (variable_value (t, tt)); - const auto& var (var_pool.find (move (name))); if (kind == type::assign) { |