summaryrefslogtreecommitdiffstats
path: root/Source/cmConditionEvaluator.cxx
diff options
context:
space:
mode:
authorAlex Turbov <i.zaufi@gmail.com>2021-07-26 20:07:12 (GMT)
committerBrad King <brad.king@kitware.com>2021-08-03 14:55:46 (GMT)
commit9721ab416f65edd969b756a501b5748d21d4f242 (patch)
treed6fe74a92c8d3764333d25f250f64814c52a98dc /Source/cmConditionEvaluator.cxx
parentd4d44e86f6a144bc849ffd1439a51a87cbb0cc12 (diff)
downloadCMake-9721ab416f65edd969b756a501b5748d21d4f242.zip
CMake-9721ab416f65edd969b756a501b5748d21d4f242.tar.gz
CMake-9721ab416f65edd969b756a501b5748d21d4f242.tar.bz2
Refactor: Reorder `MATCHES` handler from top below to the fail-fast
Diffstat (limited to 'Source/cmConditionEvaluator.cxx')
-rw-r--r--Source/cmConditionEvaluator.cxx36
1 files changed, 18 insertions, 18 deletions
diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx
index eea7bde..67556ef 100644
--- a/Source/cmConditionEvaluator.cxx
+++ b/Source/cmConditionEvaluator.cxx
@@ -508,9 +508,22 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
IncrementArguments(newArgs, argP1, argP2);
- if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
- this->IsKeyword(keyMATCHES, *argP1)) {
+ // NOTE Handle special case `if(... BLAH_BAH MATCHES)`
+ // (i.e., w/o regex to match which is possibly result of
+ // variable expansion to an empty string)
+ if (argP1 != newArgs.end() && this->IsKeyword(keyMATCHES, *arg)) {
+ *arg = cmExpandedCommandArgument("0", true);
+ newArgs.erase(argP1);
+ argP1 = arg;
+ IncrementArguments(newArgs, argP1, argP2);
+ }
+ // NOTE Fail fast: All the binary ops below require 2 arguments.
+ else if (argP1 == newArgs.end() || argP2 == newArgs.end()) {
+ continue;
+ }
+
+ else if (this->IsKeyword(keyMATCHES, *argP1)) {
cmProp def = this->GetDefinitionIfUnquoted(*arg);
std::string def_buf;
@@ -535,12 +548,11 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
return false;
}
- if (regEntry.find(*def)) {
+ const auto match = regEntry.find(*def);
+ if (match) {
this->Makefile.StoreMatches(regEntry);
- *arg = cmExpandedCommandArgument("1", true);
- } else {
- *arg = cmExpandedCommandArgument("0", true);
}
+ *arg = cmExpandedCommandArgument(std::to_string(int(match)), true);
newArgs.erase(argP2);
newArgs.erase(argP1);
@@ -548,18 +560,6 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
IncrementArguments(newArgs, argP1, argP2);
}
- else if (argP1 != newArgs.end() && this->IsKeyword(keyMATCHES, *arg)) {
- *arg = cmExpandedCommandArgument("0", true);
- newArgs.erase(argP1);
- argP1 = arg;
- IncrementArguments(newArgs, argP1, argP2);
- }
-
- // NOTE Fail fast: All the binary ops below require 2 arguments.
- else if (argP1 == newArgs.end() || argP2 == newArgs.end()) {
- continue;
- }
-
else if (this->IsKeyword(keyLESS, *argP1) ||
this->IsKeyword(keyLESS_EQUAL, *argP1) ||
this->IsKeyword(keyGREATER, *argP1) ||