summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorAlex Turbov <i.zaufi@gmail.com>2021-07-24 18:10:06 (GMT)
committerAlex Turbov <i.zaufi@gmail.com>2021-07-26 20:40:18 (GMT)
commit961df6cde60763dc77cafe6bf3a2704b52394a20 (patch)
tree6599c98d4f50521ac01e964cc6b36f9df611601c /Source
parent0f65d0cd837c2c12f04e8e10cec6c49eade08f1d (diff)
downloadCMake-961df6cde60763dc77cafe6bf3a2704b52394a20.zip
CMake-961df6cde60763dc77cafe6bf3a2704b52394a20.tar.gz
CMake-961df6cde60763dc77cafe6bf3a2704b52394a20.tar.bz2
Refactor: Make `IncrementArguments()` the free function
Signed-off-by: Alex Turbov <i.zaufi@gmail.com>
Diffstat (limited to 'Source')
-rw-r--r--Source/cmConditionEvaluator.cxx43
-rw-r--r--Source/cmConditionEvaluator.h4
2 files changed, 22 insertions, 25 deletions
diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx
index ef51729..50e7655 100644
--- a/Source/cmConditionEvaluator.cxx
+++ b/Source/cmConditionEvaluator.cxx
@@ -6,6 +6,7 @@
#include <cstdio>
#include <cstdlib>
#include <functional>
+#include <iterator>
#include <sstream>
#include <utility>
@@ -60,6 +61,19 @@ auto const keyVERSION_LESS_EQUAL = "VERSION_LESS_EQUAL"_s;
std::array<const char* const, 2> const ZERO_ONE_XLAT = { "0", "1" };
+inline void IncrementArguments(
+ cmConditionEvaluator::cmArgumentList& newArgs,
+ cmConditionEvaluator::cmArgumentList::iterator& argP1,
+ cmConditionEvaluator::cmArgumentList::iterator& argP2)
+{
+ if (argP1 != newArgs.end()) {
+ argP2 = ++argP1;
+ using difference_type =
+ cmConditionEvaluator::cmArgumentList::difference_type;
+ std::advance(argP2, difference_type(argP1 != newArgs.end()));
+ }
+}
+
} // anonymous namespace
cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile,
@@ -312,19 +326,6 @@ bool cmConditionEvaluator::GetBooleanValueWithAutoDereference(
}
//=========================================================================
-void cmConditionEvaluator::IncrementArguments(
- cmArgumentList& newArgs, cmArgumentList::iterator& argP1,
- cmArgumentList::iterator& argP2) const
-{
- if (argP1 != newArgs.end()) {
- argP2 = ++argP1;
- if (argP1 != newArgs.end()) {
- ++argP2;
- }
- }
-}
-
-//=========================================================================
// helper function to reduce code duplication
void cmConditionEvaluator::HandlePredicate(
const bool value, bool& reducible, cmArgumentList::iterator& arg,
@@ -334,7 +335,7 @@ void cmConditionEvaluator::HandlePredicate(
*arg = cmExpandedCommandArgument(ZERO_ONE_XLAT[value], true);
newArgs.erase(argP1);
argP1 = arg;
- this->IncrementArguments(newArgs, argP1, argP2);
+ IncrementArguments(newArgs, argP1, argP2);
reducible = true;
}
@@ -350,7 +351,7 @@ void cmConditionEvaluator::HandleBinaryOp(const bool value, bool& reducible,
newArgs.erase(argP2);
newArgs.erase(argP1);
argP1 = arg;
- this->IncrementArguments(newArgs, argP1, argP2);
+ IncrementArguments(newArgs, argP1, argP2);
reducible = true;
}
@@ -416,7 +417,7 @@ bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&,
reducible = false;
for (auto arg = newArgs.begin(), argP1 = arg, argP2 = arg;
arg != newArgs.end(); argP1 = ++arg) {
- this->IncrementArguments(newArgs, argP1, argP2);
+ IncrementArguments(newArgs, argP1, argP2);
// does a file exist
if (this->IsKeyword(keyEXISTS, *arg) && argP1 != newArgs.end()) {
this->HandlePredicate(cmSystemTools::FileExists(argP1->GetValue()),
@@ -514,7 +515,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
reducible = false;
for (auto arg = newArgs.begin(), argP1 = arg, argP2 = arg;
arg != newArgs.end(); argP1 = ++arg) {
- this->IncrementArguments(newArgs, argP1, argP2);
+ IncrementArguments(newArgs, argP1, argP2);
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
this->IsKeyword(keyMATCHES, *argP1)) {
def = this->GetDefinitionIfUnquoted(*arg);
@@ -545,7 +546,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
newArgs.erase(argP2);
newArgs.erase(argP1);
argP1 = arg;
- this->IncrementArguments(newArgs, argP1, argP2);
+ IncrementArguments(newArgs, argP1, argP2);
reducible = true;
}
@@ -553,7 +554,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
*arg = cmExpandedCommandArgument("0", true);
newArgs.erase(argP1);
argP1 = arg;
- this->IncrementArguments(newArgs, argP1, argP2);
+ IncrementArguments(newArgs, argP1, argP2);
reducible = true;
}
@@ -687,7 +688,7 @@ bool cmConditionEvaluator::HandleLevel3(cmArgumentList& newArgs,
reducible = false;
for (auto arg = newArgs.begin(), argP1 = arg, argP2 = arg;
arg != newArgs.end(); argP1 = ++arg) {
- this->IncrementArguments(newArgs, argP1, argP2);
+ IncrementArguments(newArgs, argP1, argP2);
if (argP1 != newArgs.end() && this->IsKeyword(keyNOT, *arg)) {
bool rhs = this->GetBooleanValueWithAutoDereference(
*argP1, errorString, status);
@@ -711,7 +712,7 @@ bool cmConditionEvaluator::HandleLevel4(cmArgumentList& newArgs,
reducible = false;
for (auto arg = newArgs.begin(), argP1 = arg, argP2 = arg;
arg != newArgs.end(); argP1 = ++arg) {
- this->IncrementArguments(newArgs, argP1, argP2);
+ IncrementArguments(newArgs, argP1, argP2);
if (argP1 != newArgs.end() && this->IsKeyword(keyAND, *argP1) &&
argP2 != newArgs.end()) {
lhs =
diff --git a/Source/cmConditionEvaluator.h b/Source/cmConditionEvaluator.h
index 5d48ee8..74652a0 100644
--- a/Source/cmConditionEvaluator.h
+++ b/Source/cmConditionEvaluator.h
@@ -51,10 +51,6 @@ private:
MessageType& status,
bool oneArg = false) const;
- void IncrementArguments(cmArgumentList& newArgs,
- cmArgumentList::iterator& argP1,
- cmArgumentList::iterator& argP2) const;
-
void HandlePredicate(bool value, bool& reducible,
cmArgumentList::iterator& arg, cmArgumentList& newArgs,
cmArgumentList::iterator& argP1,