aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/variable.txx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-05-24 16:51:24 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-05-28 10:10:44 +0200
commitaf5fa9e744acf6da12f2eab7f44810195c0d3ecd (patch)
tree3685dda19882b79a20235286f2c8593797d55de6 /libbuild2/variable.txx
parent9c3e14bb61d6fb1da6ada3213e2c4d566ddd5e33 (diff)
Ban conversion of patterns to values
Also improve conversion diagnostic.
Diffstat (limited to 'libbuild2/variable.txx')
-rw-r--r--libbuild2/variable.txx133
1 files changed, 71 insertions, 62 deletions
diff --git a/libbuild2/variable.txx b/libbuild2/variable.txx
index 3e4a9f3..b1c4112 100644
--- a/libbuild2/variable.txx
+++ b/libbuild2/variable.txx
@@ -128,6 +128,7 @@ namespace build2
{
size_t n (ns.size ());
+ diag_record dr;
if (value_traits<T>::empty_value ? n <= 1 : n == 1)
{
try
@@ -137,19 +138,23 @@ namespace build2
(n == 0
? T ()
: value_traits<T>::convert (move (ns.front ()), nullptr)));
-
- return;
}
- catch (const invalid_argument&) {} // Fall through.
+ catch (const invalid_argument& e)
+ {
+ dr << fail << e;
+ }
}
+ else
+ dr << fail << "invalid " << value_traits<T>::value_type.name
+ << " value: " << (n == 0 ? "empty" : "multiple names");
- diag_record dr (fail);
-
- dr << "invalid " << value_traits<T>::value_type.name
- << " value '" << ns << "'";
+ if (!dr.empty ())
+ {
+ if (var != nullptr)
+ dr << " in variable " << var->name;
- if (var != nullptr)
- dr << " in variable " << var->name;
+ dr << info << "while converting '" << ns << "'";
+ }
}
template <typename T>
@@ -158,6 +163,7 @@ namespace build2
{
size_t n (ns.size ());
+ diag_record dr;
if (value_traits<T>::empty_value ? n <= 1 : n == 1)
{
try
@@ -167,19 +173,23 @@ namespace build2
(n == 0
? T ()
: value_traits<T>::convert (move (ns.front ()), nullptr)));
-
- return;
}
- catch (const invalid_argument&) {} // Fall through.
+ catch (const invalid_argument& e)
+ {
+ dr << fail << e;
+ }
}
+ else
+ dr << fail << "invalid " << value_traits<T>::value_type.name
+ << " value: " << (n == 0 ? "empty" : "multiple names");
- diag_record dr (fail);
-
- dr << "invalid " << value_traits<T>::value_type.name
- << " value '" << ns << "'";
+ if (!dr.empty ())
+ {
+ if (var != nullptr)
+ dr << " in variable " << var->name;
- if (var != nullptr)
- dr << " in variable " << var->name;
+ dr << info << "while converting '" << ns << "'";
+ }
}
template <typename T>
@@ -188,6 +198,7 @@ namespace build2
{
size_t n (ns.size ());
+ diag_record dr;
if (value_traits<T>::empty_value ? n <= 1 : n == 1)
{
try
@@ -197,19 +208,23 @@ namespace build2
(n == 0
? T ()
: value_traits<T>::convert (move (ns.front ()), nullptr)));
-
- return;
}
- catch (const invalid_argument&) {} // Fall through.
+ catch (const invalid_argument& e)
+ {
+ dr << fail << e;
+ }
}
+ else
+ dr << fail << "invalid " << value_traits<T>::value_type.name
+ << " value: " << (n == 0 ? "empty" : "multiple names");
- diag_record dr (fail);
-
- dr << "invalid " << value_traits<T>::value_type.name
- << " value '" << ns << "'";
+ if (!dr.empty ())
+ {
+ if (var != nullptr)
+ dr << " in variable " << var->name;
- if (var != nullptr)
- dr << " in variable " << var->name;
+ dr << info << "while converting '" << ns << "'";
+ }
}
template <typename T>
@@ -282,30 +297,28 @@ namespace build2
return pair<F, S> (move (f), move (s));
}
- catch (const invalid_argument&)
+ catch (const invalid_argument& e)
{
diag_record dr (fail);
- dr << "invalid " << value_traits<S>::value_type.name
- << " second have of pair '" << *r << "'";
-
+ dr << e;
if (var != nullptr)
dr << " in variable " << var->name;
- dr << endf;
+ dr << info << "while converting second have of pair '" << *r << "'"
+ << endf;
}
}
- catch (const invalid_argument&)
+ catch (const invalid_argument& e)
{
diag_record dr (fail);
- dr << "invalid " << value_traits<F>::value_type.name
- << " first have of pair '" << l << "'";
-
+ dr << e;
if (var != nullptr)
dr << " in variable " << var->name;
- dr << endf;
+ dr << info << "while converting first have of pair '" << l << "'"
+ << endf;
}
}
@@ -340,30 +353,28 @@ namespace build2
return pair<F, optional<S>> (move (f), move (s));
}
- catch (const invalid_argument&)
+ catch (const invalid_argument& e)
{
diag_record dr (fail);
- dr << "invalid " << value_traits<S>::value_type.name
- << " second have of pair '" << *r << "'";
-
+ dr << e;
if (var != nullptr)
dr << " in variable " << var->name;
- dr << endf;
+ dr << info << "while converting second have of pair '" << *r << "'"
+ << endf;
}
}
- catch (const invalid_argument&)
+ catch (const invalid_argument& e)
{
diag_record dr (fail);
- dr << "invalid " << value_traits<F>::value_type.name
- << " first have of pair '" << l << "'";
-
+ dr << e;
if (var != nullptr)
dr << " in variable " << var->name;
- dr << endf;
+ dr << info << "while converting first have of pair '" << l << "'"
+ << endf;
}
}
@@ -401,30 +412,28 @@ namespace build2
return pair<optional<F>, S> (move (f), move (s));
}
- catch (const invalid_argument&)
+ catch (const invalid_argument& e)
{
diag_record dr (fail);
- dr << "invalid " << value_traits<S>::value_type.name
- << " second have of pair '" << l << "'";
-
+ dr << e;
if (var != nullptr)
dr << " in variable " << var->name;
- dr << endf;
+ dr << info << "while converting second have of pair '" << *r << "'"
+ << endf;
}
}
- catch (const invalid_argument&)
+ catch (const invalid_argument& e)
{
diag_record dr (fail);
- dr << "invalid " << value_traits<F>::value_type.name
- << " first have of pair '" << l << "'";
-
+ dr << e;
if (var != nullptr)
dr << " in variable " << var->name;
- dr << endf;
+ dr << info << "while converting first have of pair '" << l << "'"
+ << endf;
}
}
@@ -528,19 +537,19 @@ namespace build2
{
p.push_back (value_traits<T>::convert (move (n), r));
}
- catch (const invalid_argument&)
+ catch (const invalid_argument& e)
{
diag_record dr (fail);
- dr << "invalid " << value_traits<T>::value_type.name;
+ dr << e;
+ if (var != nullptr)
+ dr << " in variable " << var->name;
+ dr << info << "while converting ";
if (n.pair)
dr << " element pair '" << n << "'@'" << *r << "'";
else
dr << " element '" << n << "'";
-
- if (var != nullptr)
- dr << " in variable " << var->name;
}
}
}