summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-09-26 13:31:34 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-09-26 13:31:42 (GMT)
commitb8151299dee511eda187b4a53e4ffb7aaafb972f (patch)
treef1334e1506ddd1b6c66883377b8f5c9e07fe06c4 /Source
parentdd1722d573502060e230287e6a27bfc090666175 (diff)
parent634079b86d56e4d53240a52d80a2d3ba985ffb5f (diff)
downloadCMake-b8151299dee511eda187b4a53e4ffb7aaafb972f.zip
CMake-b8151299dee511eda187b4a53e4ffb7aaafb972f.tar.gz
CMake-b8151299dee511eda187b4a53e4ffb7aaafb972f.tar.bz2
Merge topic 'genexp-no-eval'
634079b86d cmGeneratorExpressionEvaluator: Short-circuit boolean operators Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: scivision <michael@scivision.dev> Acked-by: Pavel Solodovnikov <hellyeahdominate@gmail.com> Merge-request: !8791
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGeneratorExpressionEvaluator.cxx10
-rw-r--r--Source/cmGeneratorExpressionNode.cxx17
-rw-r--r--Source/cmGeneratorExpressionNode.h6
3 files changed, 29 insertions, 4 deletions
diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx
index b239408..50334ef 100644
--- a/Source/cmGeneratorExpressionEvaluator.cxx
+++ b/Source/cmGeneratorExpressionEvaluator.cxx
@@ -153,10 +153,12 @@ std::string GeneratorExpressionContent::EvaluateParameters(
return std::string();
}
std::string parameter;
- for (const auto& pExprEval : *pit) {
- parameter += pExprEval->Evaluate(context, dagChecker);
- if (context->HadError) {
- return std::string();
+ if (node->ShouldEvaluateNextParameter(parameters, parameter)) {
+ for (const auto& pExprEval : *pit) {
+ parameter += pExprEval->Evaluate(context, dagChecker);
+ if (context->HadError) {
+ return std::string();
+ }
}
}
parameters.push_back(std::move(parameter));
diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx
index 745a749..57beb72 100644
--- a/Source/cmGeneratorExpressionNode.cxx
+++ b/Source/cmGeneratorExpressionNode.cxx
@@ -128,6 +128,16 @@ struct BooleanOpNode : public cmGeneratorExpressionNode
int NumExpectedParameters() const override { return OneOrMoreParameters; }
+ bool ShouldEvaluateNextParameter(const std::vector<std::string>& parameters,
+ std::string& def_value) const override
+ {
+ if (!parameters.empty() && parameters[0] == failureVal) {
+ def_value = failureVal;
+ return false;
+ }
+ return true;
+ }
+
std::string Evaluate(const std::vector<std::string>& parameters,
cmGeneratorExpressionContext* context,
const GeneratorExpressionContent* content,
@@ -195,6 +205,13 @@ static const struct IfNode : public cmGeneratorExpressionNode
int NumExpectedParameters() const override { return 3; }
+ bool ShouldEvaluateNextParameter(const std::vector<std::string>& parameters,
+ std::string&) const override
+ {
+ return (parameters.empty() ||
+ parameters[0] != cmStrCat(parameters.size() - 1, ""));
+ }
+
std::string Evaluate(const std::vector<std::string>& parameters,
cmGeneratorExpressionContext* context,
const GeneratorExpressionContent* content,
diff --git a/Source/cmGeneratorExpressionNode.h b/Source/cmGeneratorExpressionNode.h
index f068b02..7a76289 100644
--- a/Source/cmGeneratorExpressionNode.h
+++ b/Source/cmGeneratorExpressionNode.h
@@ -33,6 +33,12 @@ struct cmGeneratorExpressionNode
virtual int NumExpectedParameters() const { return 1; }
+ virtual bool ShouldEvaluateNextParameter(const std::vector<std::string>&,
+ std::string&) const
+ {
+ return true;
+ }
+
virtual std::string Evaluate(
const std::vector<std::string>& parameters,
cmGeneratorExpressionContext* context,