summaryrefslogtreecommitdiffstats
path: root/Source/cmConditionEvaluator.cxx
diff options
context:
space:
mode:
authorAlex Turbov <i.zaufi@gmail.com>2021-07-25 00:50:52 (GMT)
committerAlex Turbov <i.zaufi@gmail.com>2021-07-26 20:40:18 (GMT)
commit314538703a4c70a45dc7679af6eb0c46f39ee3e4 (patch)
tree531d7ea0cb72b47738460cdcc670044ab84c7462 /Source/cmConditionEvaluator.cxx
parent95fc27cedde069c884d151644bf1e7ef105dc7da (diff)
downloadCMake-314538703a4c70a45dc7679af6eb0c46f39ee3e4.zip
CMake-314538703a4c70a45dc7679af6eb0c46f39ee3e4.tar.gz
CMake-314538703a4c70a45dc7679af6eb0c46f39ee3e4.tar.bz2
Refactor: Deduplicate code for `AND` and `OR` handling in `if()` command
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
Diffstat (limited to 'Source/cmConditionEvaluator.cxx')
-rw-r--r--Source/cmConditionEvaluator.cxx25
1 files changed, 9 insertions, 16 deletions
diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx
index ef05560..3def347 100644
--- a/Source/cmConditionEvaluator.cxx
+++ b/Source/cmConditionEvaluator.cxx
@@ -687,29 +687,22 @@ bool cmConditionEvaluator::HandleLevel4(cmArgumentList& newArgs,
MessageType& status)
{
bool reducible;
- bool lhs;
- bool rhs;
do {
reducible = false;
for (auto arg = newArgs.begin(), argP1 = arg, argP2 = arg;
arg != newArgs.end(); argP1 = ++arg) {
IncrementArguments(newArgs, argP1, argP2);
- if (argP1 != newArgs.end() && this->IsKeyword(keyAND, *argP1) &&
+ if (argP1 != newArgs.end() &&
+ (this->IsKeyword(keyAND, *argP1) ||
+ this->IsKeyword(keyOR, *argP1)) &&
argP2 != newArgs.end()) {
- lhs =
+ const auto lhs =
this->GetBooleanValueWithAutoDereference(*arg, errorString, status);
- rhs = this->GetBooleanValueWithAutoDereference(*argP2, errorString,
- status);
- HandleBinaryOp((lhs && rhs), reducible, arg, newArgs, argP1, argP2);
- }
-
- if (argP1 != newArgs.end() && this->IsKeyword(keyOR, *argP1) &&
- argP2 != newArgs.end()) {
- lhs =
- this->GetBooleanValueWithAutoDereference(*arg, errorString, status);
- rhs = this->GetBooleanValueWithAutoDereference(*argP2, errorString,
- status);
- HandleBinaryOp((lhs || rhs), reducible, arg, newArgs, argP1, argP2);
+ const auto rhs = this->GetBooleanValueWithAutoDereference(
+ *argP2, errorString, status);
+ HandleBinaryOp(this->IsKeyword(keyAND, *argP1) ? (lhs && rhs)
+ : (lhs || rhs),
+ reducible, arg, newArgs, argP1, argP2);
}
}
} while (reducible);