diff options
author | Martin Duffy <martin.duffy@kitware.com> | 2023-09-11 13:36:12 (GMT) |
---|---|---|
committer | Martin Duffy <martin.duffy@kitware.com> | 2023-09-13 22:01:14 (GMT) |
commit | 634079b86d56e4d53240a52d80a2d3ba985ffb5f (patch) | |
tree | 790e931efd1dc5dd965bcea6309d4750250ff2a6 /Source | |
parent | 49e2a4a0a734f0e42e2d5717ab7c4bf4210af635 (diff) | |
download | CMake-634079b86d56e4d53240a52d80a2d3ba985ffb5f.zip CMake-634079b86d56e4d53240a52d80a2d3ba985ffb5f.tar.gz CMake-634079b86d56e4d53240a52d80a2d3ba985ffb5f.tar.bz2 |
cmGeneratorExpressionEvaluator: Short-circuit boolean operators
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGeneratorExpressionEvaluator.cxx | 10 | ||||
-rw-r--r-- | Source/cmGeneratorExpressionNode.cxx | 17 | ||||
-rw-r--r-- | Source/cmGeneratorExpressionNode.h | 6 |
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 30798a3..811d53b 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, |