aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2022-10-14 16:06:35 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2022-10-14 17:30:12 +0300
commit63b5b6416c6bde16560eb9b83a9e3122599369d5 (patch)
tree82c0f624aedebf6917aeb4c9b6648f8cdb9d3fc1 /libbuild2
parentfbe94f38ee51e705202a2d5cf1f45b5e8a08d8c7 (diff)
Fix 'for [<attrs>] x: ...' to treat <attrs> as value attributes
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/build/script/parser+for.test.testscript19
-rw-r--r--libbuild2/build/script/parser.cxx11
-rw-r--r--libbuild2/parser.cxx12
-rw-r--r--libbuild2/parser.hxx12
-rw-r--r--libbuild2/script/parser.cxx9
-rw-r--r--libbuild2/script/parser.hxx1
-rw-r--r--libbuild2/test/script/parser+for.test.testscript19
-rw-r--r--libbuild2/test/script/parser.cxx11
8 files changed, 37 insertions, 57 deletions
diff --git a/libbuild2/build/script/parser+for.test.testscript b/libbuild2/build/script/parser+for.test.testscript
index c5f6587..cbcaf14 100644
--- a/libbuild2/build/script/parser+for.test.testscript
+++ b/libbuild2/build/script/parser+for.test.testscript
@@ -58,7 +58,7 @@
cmd b
EOO
- : typed-value
+ : typed-values
:
$* <<EOI >>~%EOO%
for x: [dir_paths] a b
@@ -69,7 +69,7 @@
%cmd (b/|'b\\')%
EOO
- : typed-var
+ : typed-var-value
:
$* <<EOI >>~%EOO%
for [dir_path] x: a b
@@ -80,15 +80,16 @@
%cmd (b/|'b\\')%
EOO
- : type-mismatch
+ : typed-values-var-value
:
- $* <<EOI 2>>EOE != 0
- for [string] x: [dir_paths] a b
+ $* <<EOI >>~%EOO%
+ for [dir_path] x: [strings] a b
cmd $x
end
EOI
- buildfile:11:1: error: conflicting variable x type string and value type dir_path
- EOE
+ %cmd (a/|'a\\')%
+ %cmd (b/|'b\\')%
+ EOO
: defined-var
:
@@ -340,7 +341,7 @@
echo a b | for x
EOO
- : typed-var
+ : typed-var-value
:
$* <<EOI >>EOO
echo 'a b' | for -w [dir_paths] x
@@ -563,7 +564,7 @@
for x b <a
EOO
- : typed-var
+ : typed-var-value
:
$* <<EOI >>EOO
for -w [dir_path] x <'a b'
diff --git a/libbuild2/build/script/parser.cxx b/libbuild2/build/script/parser.cxx
index 035ab6b..3098bc9 100644
--- a/libbuild2/build/script/parser.cxx
+++ b/libbuild2/build/script/parser.cxx
@@ -1455,15 +1455,14 @@ namespace build2
auto exec_for = [this] (const variable& var,
value&& val,
- const location& l)
+ const attributes& val_attrs,
+ const location&)
{
value& lhs (environment_->assign (var));
- // To match the function semantics also pass the value's type
- // attribute, restoring it from RHS. Note that the value can't be
- // NULL.
- //
- apply_value (&var, lhs, move (val), type::assign, l, val.type);
+ attributes_.push_back (move (val_attrs));
+
+ apply_value_attributes (&var, lhs, move (val), type::assign);
};
build2::script::parser::exec_lines (
diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx
index 184fa01..a13dc41 100644
--- a/libbuild2/parser.cxx
+++ b/libbuild2/parser.cxx
@@ -5067,18 +5067,6 @@ namespace build2
fail (l) << "unexpected value in attribute " << a;
}
- apply_value (var, v, move (rhs), kind, l, type, null);
- }
-
- void parser::
- apply_value (const variable* var,
- value& v,
- value&& rhs,
- type kind,
- const location& l,
- const value_type* type,
- bool null)
- {
// When do we set the type and when do we keep the original? This gets
// tricky for append/prepend where both values contribute. The guiding
// rule here is that if the user specified the type, then they reasonable
diff --git a/libbuild2/parser.hxx b/libbuild2/parser.hxx
index 02d4f74..0d1e9e2 100644
--- a/libbuild2/parser.hxx
+++ b/libbuild2/parser.hxx
@@ -304,18 +304,6 @@ namespace build2
value&& rhs,
token_type assign_kind);
- void
- apply_value (const variable*, // Optional.
- value& lhs,
- value&& rhs,
- token_type assign_kind,
- const location&,
- //
- // Attributes:
- //
- const value_type* = nullptr,
- bool null = false);
-
// Return the value pack (values can be NULL/typed). Note that for an
// empty eval context ('()' potentially with whitespaces in between) the
// result is an empty pack, not a pack of one empty.
diff --git a/libbuild2/script/parser.cxx b/libbuild2/script/parser.cxx
index a2e0819..87a51d8 100644
--- a/libbuild2/script/parser.cxx
+++ b/libbuild2/script/parser.cxx
@@ -2587,6 +2587,11 @@ namespace build2
next_with_attributes (t, tt);
attributes_push (t, tt);
+ // @@ TMP Currently we assume that these are the value (rather
+ // than the variable) attributes.
+ //
+ attributes val_attrs (attributes_pop ());
+
assert (tt == type::word && t.qtype == quote_type::unquoted);
string vn (move (t.value));
@@ -2604,8 +2609,6 @@ namespace build2
var = &var_pool->insert (move (vn));
}
- apply_variable_attributes (*var);
-
next (t, tt); // Skip the colon.
assert (tt == type::colon);
@@ -2664,7 +2667,7 @@ namespace build2
if (etype != nullptr)
typify (v, *etype, var);
- exec_for (*var, move (v), ll);
+ exec_for (*var, move (v), val_attrs, ll);
// Find the construct end, if it is not found yet.
//
diff --git a/libbuild2/script/parser.hxx b/libbuild2/script/parser.hxx
index c402d3e..91f50bf 100644
--- a/libbuild2/script/parser.hxx
+++ b/libbuild2/script/parser.hxx
@@ -202,6 +202,7 @@ namespace build2
using exec_for_function = void (const variable&,
value&&,
+ const attributes& value_attrs,
const location&);
// If a parser implementation doesn't pre-enter variables into a pool
diff --git a/libbuild2/test/script/parser+for.test.testscript b/libbuild2/test/script/parser+for.test.testscript
index 426a39b..9d70886 100644
--- a/libbuild2/test/script/parser+for.test.testscript
+++ b/libbuild2/test/script/parser+for.test.testscript
@@ -58,7 +58,7 @@
cmd b
EOO
- : typed-value
+ : typed-values
:
$* <<EOI >>~%EOO%
for x: [dir_paths] a b
@@ -69,7 +69,7 @@
%cmd (b/|'b\\')%
EOO
- : typed-var
+ : typed-var-value
:
$* <<EOI >>~%EOO%
for [dir_path] x: a b
@@ -80,15 +80,16 @@
%cmd (b/|'b\\')%
EOO
- : type-mismatch
+ : typed-values-var-value
:
- $* <<EOI 2>>EOE != 0
- for [string] x: [dir_paths] a b
+ $* <<EOI >>~%EOO%
+ for [dir_path] x: [strings] a b
cmd $x
end
EOI
- testscript:1:1: error: conflicting variable x type string and value type dir_path
- EOE
+ %cmd (a/|'a\\')%
+ %cmd (b/|'b\\')%
+ EOO
: scope-var
:
@@ -471,7 +472,7 @@
echo a b | for x
EOO
- : typed-var
+ : typed-var-value
:
$* <<EOI >>EOO
echo 'a b' | for -w [dir_path] x
@@ -821,7 +822,7 @@
for x b <a
EOO
- : typed-var
+ : typed-var-value
:
$* <<EOI >>EOO
for -w [dir_path] x <'a b'
diff --git a/libbuild2/test/script/parser.cxx b/libbuild2/test/script/parser.cxx
index f85b185..a30f666 100644
--- a/libbuild2/test/script/parser.cxx
+++ b/libbuild2/test/script/parser.cxx
@@ -1666,15 +1666,14 @@ namespace build2
auto exec_for = [this] (const variable& var,
value&& val,
- const location& l)
+ const attributes& val_attrs,
+ const location&)
{
value& lhs (scope_->assign (var));
- // To match the function semantics also pass the value's type
- // attribute, restoring it from RHS. Note that the value can't be
- // NULL.
- //
- apply_value (&var, lhs, move (val), type::assign, l, val.type);
+ attributes_.push_back (val_attrs);
+
+ apply_value_attributes (&var, lhs, move (val), type::assign);
if (script_->test_command_var (var.name))
scope_->reset_special ();