From 333b13f697dfe04d5f2515c03baa1c4f5eccbe48 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 18 May 2020 12:08:33 +0200 Subject: Make build script variable pool local to execution environment --- libbuild2/script/parser.cxx | 24 +++++++++++++++++++++--- libbuild2/script/parser.hxx | 8 +++++++- 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'libbuild2/script') diff --git a/libbuild2/script/parser.cxx b/libbuild2/script/parser.cxx index 5c7510b..160374d 100644 --- a/libbuild2/script/parser.cxx +++ b/libbuild2/script/parser.cxx @@ -3,6 +3,7 @@ #include +#include #include // exit #include @@ -1716,7 +1717,8 @@ namespace build2 const function& exec_set, const function& exec_cmd, const function& exec_if, - size_t& li) + size_t& li, + variable_pool* var_pool) { try { @@ -1743,7 +1745,20 @@ namespace build2 { case line_type::var: { - exec_set (*ln.var, t, tt, ll); + // Enter the variable into the pool if this is not done during + // the script parsing. Note that in this case the pool is + // expected to be provided. + // + const variable* var (ln.var); + + if (var == nullptr) + { + assert (var_pool != nullptr); + + var = &var_pool->insert (t.value); + } + + exec_set (*var, t, tt, ll); replay_stop (); break; @@ -1861,7 +1876,10 @@ namespace build2 // Next if-else. // lines::const_iterator j (next (i, false, false)); - if (!exec_lines (i + 1, j, exec_set, exec_cmd, exec_if, li)) + if (!exec_lines (i + 1, j, + exec_set, exec_cmd, exec_if, + li, + var_pool)) return false; i = j->type == line_type::cmd_end ? j : next (j, true, true); diff --git a/libbuild2/script/parser.hxx b/libbuild2/script/parser.hxx index 850794e..ecd9f5a 100644 --- a/libbuild2/script/parser.hxx +++ b/libbuild2/script/parser.hxx @@ -146,12 +146,18 @@ namespace build2 size_t li, const location&); + // If a parser implementation doesn't pre-enter variables into a pool + // during the pre-parsing phase, then they are entered during the + // execution phase and so the variable pool must be provided. Note that + // in this case the variable pool insertions are not MT-safe. + // bool exec_lines (lines::const_iterator b, lines::const_iterator e, const function&, const function&, const function&, - size_t& li); + size_t& li, + variable_pool* = nullptr); // Set lexer pointers for both the current and the base classes. // -- cgit v1.1