diff options
author | Alex Turbov <i.zaufi@gmail.com> | 2021-07-26 18:56:52 (GMT) |
---|---|---|
committer | Alex Turbov <i.zaufi@gmail.com> | 2021-07-26 20:40:18 (GMT) |
commit | 18bd6c98ea70adf3067539266fdb782e910fb3cc (patch) | |
tree | ecdd67c9d33f5df577d17310802eb5c6ecccb9a3 /Source/cmConditionEvaluator.cxx | |
parent | 8bc4a740d648e59d6712bbaea0cae8e03fc97a25 (diff) | |
download | CMake-18bd6c98ea70adf3067539266fdb782e910fb3cc.zip CMake-18bd6c98ea70adf3067539266fdb782e910fb3cc.tar.gz CMake-18bd6c98ea70adf3067539266fdb782e910fb3cc.tar.bz2 |
Refactor: Generalize policy checking in `HandleLevel1`
Also, move OLD policy checking out of the loop to evaluate it once.
Diffstat (limited to 'Source/cmConditionEvaluator.cxx')
-rw-r--r-- | Source/cmConditionEvaluator.cxx | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx index c4d945b..99927d7 100644 --- a/Source/cmConditionEvaluator.cxx +++ b/Source/cmConditionEvaluator.cxx @@ -400,6 +400,9 @@ bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs, bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&, MessageType&) { + const auto policy64IsOld = this->Policy64Status == cmPolicies::OLD || + this->Policy64Status == cmPolicies::WARN; + bool reducible; do { reducible = false; @@ -407,20 +410,24 @@ bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&, argP1 = ++arg) { IncrementArguments(newArgs, argP1); + auto policyCheck = [&, this](const cmPolicies::PolicyID id, + const cmPolicies::PolicyStatus status, + const cm::static_string_view kw) { + if (status == cmPolicies::WARN && this->IsKeyword(kw, *arg)) { + std::ostringstream e; + e << cmPolicies::GetPolicyWarning(id) << "\n" + << kw + << " will be interpreted as an operator " + "when the policy is set to NEW. " + "Since the policy is not set the OLD behavior will be used."; - // NOTE This is the only predicate that dones't need the next argument... - // Check it first! - // does a test exist (CMP0064 == WARN case) - if (this->Policy64Status == cmPolicies::WARN && - this->IsKeyword(keyTEST, *arg)) { - std::ostringstream e; - e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0064) << "\n"; - e << "TEST will be interpreted as an operator " - "when the policy is set to NEW. " - "Since the policy is not set the OLD behavior will be used."; - - this->Makefile.IssueMessage(MessageType::AUTHOR_WARNING, e.str()); - } + this->Makefile.IssueMessage(MessageType::AUTHOR_WARNING, e.str()); + } + }; + + // NOTE Checking policies for warnings are not require an access to the + // next arg. Check them first! + policyCheck(cmPolicies::CMP0064, this->Policy64Status, keyTEST); // NOTE Fail fast: All the predicates below require the next arg to be // valid @@ -487,12 +494,12 @@ bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&, HandlePredicate(bdef, reducible, arg, newArgs, argP1); } // does a test exist - else if (this->Policy64Status != cmPolicies::OLD && - this->Policy64Status != cmPolicies::WARN) { - if (this->IsKeyword(keyTEST, *arg)) { - HandlePredicate(this->Makefile.GetTest(argP1->GetValue()) != nullptr, - reducible, arg, newArgs, argP1); + else if (this->IsKeyword(keyTEST, *arg)) { + if (policy64IsOld) { + continue; } + HandlePredicate(this->Makefile.GetTest(argP1->GetValue()) != nullptr, + reducible, arg, newArgs, argP1); } } } while (reducible); |