From 314538703a4c70a45dc7679af6eb0c46f39ee3e4 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sun, 25 Jul 2021 03:50:52 +0300 Subject: Refactor: Deduplicate code for `AND` and `OR` handling in `if()` command Signed-off-by: Alex Turbov --- Source/cmConditionEvaluator.cxx | 25 +++++++++---------------- 1 file 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); -- cgit v0.12