CMake/Source/cmConditionEvaluator.cxx

726 lines
25 KiB
C++

/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmConditionEvaluator.h"
#include <array>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iterator>
#include <sstream>
#include <utility>
#include <cm/string_view>
#include <cmext/algorithm>
#include "cmsys/RegularExpression.hxx"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmProperty.h"
#include "cmState.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmake.h"
namespace {
auto const keyAND = "AND"_s;
auto const keyCOMMAND = "COMMAND"_s;
auto const keyDEFINED = "DEFINED"_s;
auto const keyEQUAL = "EQUAL"_s;
auto const keyEXISTS = "EXISTS"_s;
auto const keyGREATER = "GREATER"_s;
auto const keyGREATER_EQUAL = "GREATER_EQUAL"_s;
auto const keyIN_LIST = "IN_LIST"_s;
auto const keyIS_ABSOLUTE = "IS_ABSOLUTE"_s;
auto const keyIS_DIRECTORY = "IS_DIRECTORY"_s;
auto const keyIS_NEWER_THAN = "IS_NEWER_THAN"_s;
auto const keyIS_SYMLINK = "IS_SYMLINK"_s;
auto const keyLESS = "LESS"_s;
auto const keyLESS_EQUAL = "LESS_EQUAL"_s;
auto const keyMATCHES = "MATCHES"_s;
auto const keyNOT = "NOT"_s;
auto const keyOR = "OR"_s;
auto const keyParenL = "("_s;
auto const keyParenR = ")"_s;
auto const keyPOLICY = "POLICY"_s;
auto const keySTREQUAL = "STREQUAL"_s;
auto const keySTRGREATER = "STRGREATER"_s;
auto const keySTRGREATER_EQUAL = "STRGREATER_EQUAL"_s;
auto const keySTRLESS = "STRLESS"_s;
auto const keySTRLESS_EQUAL = "STRLESS_EQUAL"_s;
auto const keyTARGET = "TARGET"_s;
auto const keyTEST = "TEST"_s;
auto const keyVERSION_EQUAL = "VERSION_EQUAL"_s;
auto const keyVERSION_GREATER = "VERSION_GREATER"_s;
auto const keyVERSION_GREATER_EQUAL = "VERSION_GREATER_EQUAL"_s;
auto const keyVERSION_LESS = "VERSION_LESS"_s;
auto const keyVERSION_LESS_EQUAL = "VERSION_LESS_EQUAL"_s;
std::string bool2string(bool const value)
{
return std::string(std::size_t(1), static_cast<char>('0' + int(value)));
}
void IncrementArguments(cmConditionEvaluator::cmArgumentList& newArgs,
cmConditionEvaluator::cmArgumentList::iterator& argP1)
{
using difference_type =
cmConditionEvaluator::cmArgumentList::difference_type;
std::advance(argP1, difference_type(argP1 != newArgs.end()));
}
void IncrementArguments(cmConditionEvaluator::cmArgumentList& newArgs,
cmConditionEvaluator::cmArgumentList::iterator& argP1,
cmConditionEvaluator::cmArgumentList::iterator& argP2)
{
IncrementArguments(newArgs, argP1);
argP2 = argP1;
using difference_type =
cmConditionEvaluator::cmArgumentList::difference_type;
std::advance(argP2, difference_type(argP1 != newArgs.end()));
}
void HandlePredicate(const bool value,
cmConditionEvaluator::cmArgumentList::iterator& arg,
cmConditionEvaluator::cmArgumentList& newArgs,
cmConditionEvaluator::cmArgumentList::iterator& argP1)
{
*arg = cmExpandedCommandArgument(bool2string(value), true);
newArgs.erase(argP1);
argP1 = arg;
IncrementArguments(newArgs, argP1);
}
void HandleBinaryOp(const bool value,
cmConditionEvaluator::cmArgumentList::iterator& arg,
cmConditionEvaluator::cmArgumentList& newArgs,
cmConditionEvaluator::cmArgumentList::iterator& argP1,
cmConditionEvaluator::cmArgumentList::iterator& argP2)
{
*arg = cmExpandedCommandArgument(bool2string(value), true);
newArgs.erase(argP2);
newArgs.erase(argP1);
argP1 = arg;
IncrementArguments(newArgs, argP1, argP2);
}
} // anonymous namespace
cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile,
cmListFileBacktrace bt)
: Makefile(makefile)
, Backtrace(std::move(bt))
, Policy12Status(makefile.GetPolicyStatus(cmPolicies::CMP0012))
, Policy54Status(makefile.GetPolicyStatus(cmPolicies::CMP0054))
, Policy57Status(makefile.GetPolicyStatus(cmPolicies::CMP0057))
, Policy64Status(makefile.GetPolicyStatus(cmPolicies::CMP0064))
{
}
//=========================================================================
// order of operations,
// 1. ( ) -- parenthetical groups
// 2. IS_DIRECTORY EXISTS COMMAND DEFINED etc predicates
// 3. MATCHES LESS GREATER EQUAL STRLESS STRGREATER STREQUAL etc binary ops
// 4. NOT
// 5. AND OR
//
// There is an issue on whether the arguments should be values of references,
// for example IF (FOO AND BAR) should that compare the strings FOO and BAR
// or should it really do IF (${FOO} AND ${BAR}) Currently IS_DIRECTORY
// EXISTS COMMAND and DEFINED all take values. EQUAL, LESS and GREATER can
// take numeric values or variable names. STRLESS and STRGREATER take
// variable names but if the variable name is not found it will use the name
// directly. AND OR take variables or the values 0 or 1.
bool cmConditionEvaluator::IsTrue(
const std::vector<cmExpandedCommandArgument>& args, std::string& errorString,
MessageType& status)
{
errorString.clear();
// handle empty invocation
if (args.empty()) {
return false;
}
// store the reduced args in this vector
cmArgumentList newArgs(args.begin(), args.end());
// now loop through the arguments and see if we can reduce any of them
// we do this multiple times. Once for each level of precedence
// parens
using handlerFn_t = bool (cmConditionEvaluator::*)(
cmArgumentList&, std::string&, MessageType&);
const std::array<handlerFn_t, 5> handlers = { {
&cmConditionEvaluator::HandleLevel0, // parenthesis
&cmConditionEvaluator::HandleLevel1, // predicates
&cmConditionEvaluator::HandleLevel2, // binary ops
&cmConditionEvaluator::HandleLevel3, // NOT
&cmConditionEvaluator::HandleLevel4 // AND OR
} };
for (auto fn : handlers) {
// Call the reducer 'till there is anything to reduce...
// (i.e., if after an iteration the size becomes smaller)
for (auto beginSize = newArgs.size();
(this->*fn)(newArgs, errorString, status) &&
newArgs.size() < beginSize;
beginSize = newArgs.size()) {
}
}
// now at the end there should only be one argument left
if (newArgs.size() != 1) {
errorString = "Unknown arguments specified";
status = MessageType::FATAL_ERROR;
return false;
}
return this->GetBooleanValueWithAutoDereference(newArgs.front(), errorString,
status, true);
}
//=========================================================================
cmProp cmConditionEvaluator::GetDefinitionIfUnquoted(
cmExpandedCommandArgument const& argument) const
{
if ((this->Policy54Status != cmPolicies::WARN &&
this->Policy54Status != cmPolicies::OLD) &&
argument.WasQuoted()) {
return nullptr;
}
cmProp def = this->Makefile.GetDefinition(argument.GetValue());
if (def && argument.WasQuoted() &&
this->Policy54Status == cmPolicies::WARN) {
if (!this->Makefile.HasCMP0054AlreadyBeenReported(this->Backtrace.Top())) {
std::ostringstream e;
// clang-format off
e << (cmPolicies::GetPolicyWarning(cmPolicies::CMP0054))
<< "\n"
"Quoted variables like \"" << argument.GetValue() << "\" "
"will no longer be dereferenced when the policy is set to NEW. "
"Since the policy is not set the OLD behavior will be used.";
// clang-format on
this->Makefile.GetCMakeInstance()->IssueMessage(
MessageType::AUTHOR_WARNING, e.str(), this->Backtrace);
}
}
return def;
}
//=========================================================================
cmProp cmConditionEvaluator::GetVariableOrString(
const cmExpandedCommandArgument& argument) const
{
cmProp def = this->GetDefinitionIfUnquoted(argument);
if (!def) {
def = &argument.GetValue();
}
return def;
}
//=========================================================================
bool cmConditionEvaluator::IsKeyword(cm::static_string_view keyword,
cmExpandedCommandArgument& argument) const
{
if ((this->Policy54Status != cmPolicies::WARN &&
this->Policy54Status != cmPolicies::OLD) &&
argument.WasQuoted()) {
return false;
}
const auto isKeyword = argument.GetValue() == keyword;
if (isKeyword && argument.WasQuoted() &&
this->Policy54Status == cmPolicies::WARN) {
if (!this->Makefile.HasCMP0054AlreadyBeenReported(this->Backtrace.Top())) {
std::ostringstream e;
// clang-format off
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0054)
<< "\n"
"Quoted keywords like \"" << argument.GetValue() << "\" "
"will no longer be interpreted as keywords "
"when the policy is set to NEW. "
"Since the policy is not set the OLD behavior will be used.";
// clang-format on
this->Makefile.GetCMakeInstance()->IssueMessage(
MessageType::AUTHOR_WARNING, e.str(), this->Backtrace);
}
}
return isKeyword;
}
//=========================================================================
bool cmConditionEvaluator::GetBooleanValue(
cmExpandedCommandArgument& arg) const
{
// Check basic constants.
if (arg == "0") {
return false;
}
if (arg == "1") {
return true;
}
// Check named constants.
if (cmIsOn(arg.GetValue())) {
return true;
}
if (cmIsOff(arg.GetValue())) {
return false;
}
// Check for numbers.
if (!arg.empty()) {
char* end;
const double d = std::strtod(arg.GetValue().c_str(), &end);
if (*end == '\0') {
// The whole string is a number. Use C conversion to bool.
return static_cast<bool>(d);
}
}
// Check definition.
cmProp def = this->GetDefinitionIfUnquoted(arg);
return !cmIsOff(def);
}
//=========================================================================
// Boolean value behavior from CMake 2.6.4 and below.
bool cmConditionEvaluator::GetBooleanValueOld(
cmExpandedCommandArgument const& arg, bool const one) const
{
if (one) {
// Old IsTrue behavior for single argument.
if (arg == "0") {
return false;
}
if (arg == "1") {
return true;
}
cmProp def = this->GetDefinitionIfUnquoted(arg);
return !cmIsOff(def);
}
// Old GetVariableOrNumber behavior.
cmProp def = this->GetDefinitionIfUnquoted(arg);
if (!def && std::atoi(arg.GetValue().c_str())) {
def = &arg.GetValue();
}
return !cmIsOff(def);
}
//=========================================================================
// returns the resulting boolean value
bool cmConditionEvaluator::GetBooleanValueWithAutoDereference(
cmExpandedCommandArgument& newArg, std::string& errorString,
MessageType& status, bool const oneArg) const
{
// Use the policy if it is set.
if (this->Policy12Status == cmPolicies::NEW) {
return this->GetBooleanValue(newArg);
}
if (this->Policy12Status == cmPolicies::OLD) {
return this->GetBooleanValueOld(newArg, oneArg);
}
// Check policy only if old and new results differ.
const auto newResult = this->GetBooleanValue(newArg);
const auto oldResult = this->GetBooleanValueOld(newArg, oneArg);
if (newResult != oldResult) {
switch (this->Policy12Status) {
case cmPolicies::WARN:
errorString = "An argument named \"" + newArg.GetValue() +
"\" appears in a conditional statement. " +
cmPolicies::GetPolicyWarning(cmPolicies::CMP0012);
status = MessageType::AUTHOR_WARNING;
CM_FALLTHROUGH;
case cmPolicies::OLD:
return oldResult;
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS: {
errorString = "An argument named \"" + newArg.GetValue() +
"\" appears in a conditional statement. " +
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0012);
status = MessageType::FATAL_ERROR;
}
case cmPolicies::NEW:
break;
}
}
return newResult;
}
//=========================================================================
// level 0 processes parenthetical expressions
bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs,
std::string& errorString,
MessageType& status)
{
for (auto arg = newArgs.begin(); arg != newArgs.end(); ++arg) {
if (this->IsKeyword(keyParenL, *arg)) {
// search for the closing paren for this opening one
auto depth = 1;
auto argClose = std::next(arg);
for (; argClose != newArgs.end() && depth; ++argClose) {
depth += int(this->IsKeyword(keyParenL, *argClose)) -
int(this->IsKeyword(keyParenR, *argClose));
}
if (depth) {
errorString = "mismatched parenthesis in condition";
status = MessageType::FATAL_ERROR;
return false;
}
// store the reduced args in this vector
auto argP1 = std::next(arg);
std::vector<cmExpandedCommandArgument> newArgs2{ argP1, argClose };
newArgs2.pop_back();
// now recursively invoke IsTrue to handle the values inside the
// parenthetical expression
const auto value = this->IsTrue(newArgs2, errorString, status);
*arg = cmExpandedCommandArgument(bool2string(value), true);
argP1 = std::next(arg);
// remove the now evaluated parenthetical expression
newArgs.erase(argP1, argClose);
}
}
return true;
}
//=========================================================================
// level one handles most predicates except for NOT
bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&,
MessageType&)
{
const auto policy64IsOld = this->Policy64Status == cmPolicies::OLD ||
this->Policy64Status == cmPolicies::WARN;
for (auto arg = newArgs.begin(), argP1 = arg; arg != newArgs.end();
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.";
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
if (argP1 == newArgs.end()) {
continue;
}
// does a file exist
if (this->IsKeyword(keyEXISTS, *arg)) {
HandlePredicate(cmSystemTools::FileExists(argP1->GetValue()), arg,
newArgs, argP1);
}
// does a directory with this name exist
else if (this->IsKeyword(keyIS_DIRECTORY, *arg)) {
HandlePredicate(cmSystemTools::FileIsDirectory(argP1->GetValue()), arg,
newArgs, argP1);
}
// does a symlink with this name exist
else if (this->IsKeyword(keyIS_SYMLINK, *arg)) {
HandlePredicate(cmSystemTools::FileIsSymlink(argP1->GetValue()), arg,
newArgs, argP1);
}
// is the given path an absolute path ?
else if (this->IsKeyword(keyIS_ABSOLUTE, *arg)) {
HandlePredicate(cmSystemTools::FileIsFullPath(argP1->GetValue()), arg,
newArgs, argP1);
}
// does a command exist
else if (this->IsKeyword(keyCOMMAND, *arg)) {
HandlePredicate(
this->Makefile.GetState()->GetCommand(argP1->GetValue()) != nullptr,
arg, newArgs, argP1);
}
// does a policy exist
else if (this->IsKeyword(keyPOLICY, *arg)) {
cmPolicies::PolicyID pid;
HandlePredicate(cmPolicies::GetPolicyID(argP1->GetValue().c_str(), pid),
arg, newArgs, argP1);
}
// does a target exist
else if (this->IsKeyword(keyTARGET, *arg)) {
HandlePredicate(this->Makefile.FindTargetToUse(argP1->GetValue()) !=
nullptr,
arg, newArgs, argP1);
}
// is a variable defined
else if (this->IsKeyword(keyDEFINED, *arg)) {
const auto argP1len = argP1->GetValue().size();
auto bdef = false;
if (argP1len > 4 && cmHasLiteralPrefix(argP1->GetValue(), "ENV{") &&
argP1->GetValue().operator[](argP1len - 1) == '}') {
const auto env = argP1->GetValue().substr(4, argP1len - 5);
bdef = cmSystemTools::HasEnv(env);
} else if (argP1len > 6 &&
cmHasLiteralPrefix(argP1->GetValue(), "CACHE{") &&
argP1->GetValue().operator[](argP1len - 1) == '}') {
const auto cache = argP1->GetValue().substr(6, argP1len - 7);
bdef = this->Makefile.GetState()->GetCacheEntryValue(cache) != nullptr;
} else {
bdef = this->Makefile.IsDefinitionSet(argP1->GetValue());
}
HandlePredicate(bdef, arg, newArgs, argP1);
}
// does a test exist
else if (this->IsKeyword(keyTEST, *arg)) {
if (policy64IsOld) {
continue;
}
HandlePredicate(this->Makefile.GetTest(argP1->GetValue()) != nullptr,
arg, newArgs, argP1);
}
}
return true;
}
//=========================================================================
// level two handles most binary operations except for AND OR
bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
std::string& errorString,
MessageType& status)
{
for (auto arg = newArgs.begin(), argP1 = arg, argP2 = arg;
arg != newArgs.end(); argP1 = ++arg) {
IncrementArguments(newArgs, argP1, argP2);
// 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;
if (!def) {
def = &arg->GetValue();
} else if (cmHasLiteralPrefix(arg->GetValue(), "CMAKE_MATCH_")) {
// The string to match is owned by our match result variables.
// Move it to our own buffer before clearing them.
def_buf = *def;
def = &def_buf;
}
this->Makefile.ClearMatches();
const auto& rex = argP2->GetValue();
cmsys::RegularExpression regEntry;
if (!regEntry.compile(rex)) {
std::ostringstream error;
error << "Regular expression \"" << rex << "\" cannot compile";
errorString = error.str();
status = MessageType::FATAL_ERROR;
return false;
}
const auto match = regEntry.find(*def);
if (match) {
this->Makefile.StoreMatches(regEntry);
}
*arg = cmExpandedCommandArgument(bool2string(match), true);
newArgs.erase(argP2);
newArgs.erase(argP1);
argP1 = arg;
IncrementArguments(newArgs, argP1, argP2);
}
else if (this->IsKeyword(keyLESS, *argP1) ||
this->IsKeyword(keyLESS_EQUAL, *argP1) ||
this->IsKeyword(keyGREATER, *argP1) ||
this->IsKeyword(keyGREATER_EQUAL, *argP1) ||
this->IsKeyword(keyEQUAL, *argP1)) {
cmProp def = this->GetVariableOrString(*arg);
cmProp def2 = this->GetVariableOrString(*argP2);
double lhs;
double rhs;
bool result;
if (std::sscanf(def->c_str(), "%lg", &lhs) != 1 ||
std::sscanf(def2->c_str(), "%lg", &rhs) != 1) {
result = false;
} else if (argP1->GetValue() == keyLESS) {
result = (lhs < rhs);
} else if (argP1->GetValue() == keyLESS_EQUAL) {
result = (lhs <= rhs);
} else if (argP1->GetValue() == keyGREATER) {
result = (lhs > rhs);
} else if (argP1->GetValue() == keyGREATER_EQUAL) {
result = (lhs >= rhs);
} else {
result = (lhs == rhs);
}
HandleBinaryOp(result, arg, newArgs, argP1, argP2);
}
else if (this->IsKeyword(keySTRLESS, *argP1) ||
this->IsKeyword(keySTRLESS_EQUAL, *argP1) ||
this->IsKeyword(keySTRGREATER, *argP1) ||
this->IsKeyword(keySTRGREATER_EQUAL, *argP1) ||
this->IsKeyword(keySTREQUAL, *argP1)) {
cmProp def = this->GetVariableOrString(*arg);
cmProp def2 = this->GetVariableOrString(*argP2);
const int val = (*def).compare(*def2);
bool result;
if (argP1->GetValue() == keySTRLESS) {
result = (val < 0);
} else if (argP1->GetValue() == keySTRLESS_EQUAL) {
result = (val <= 0);
} else if (argP1->GetValue() == keySTRGREATER) {
result = (val > 0);
} else if (argP1->GetValue() == keySTRGREATER_EQUAL) {
result = (val >= 0);
} else // strequal
{
result = (val == 0);
}
HandleBinaryOp(result, arg, newArgs, argP1, argP2);
}
else if (this->IsKeyword(keyVERSION_LESS, *argP1) ||
this->IsKeyword(keyVERSION_LESS_EQUAL, *argP1) ||
this->IsKeyword(keyVERSION_GREATER, *argP1) ||
this->IsKeyword(keyVERSION_GREATER_EQUAL, *argP1) ||
this->IsKeyword(keyVERSION_EQUAL, *argP1)) {
cmProp def = this->GetVariableOrString(*arg);
cmProp def2 = this->GetVariableOrString(*argP2);
cmSystemTools::CompareOp op;
if (argP1->GetValue() == keyVERSION_LESS) {
op = cmSystemTools::OP_LESS;
} else if (argP1->GetValue() == keyVERSION_LESS_EQUAL) {
op = cmSystemTools::OP_LESS_EQUAL;
} else if (argP1->GetValue() == keyVERSION_GREATER) {
op = cmSystemTools::OP_GREATER;
} else if (argP1->GetValue() == keyVERSION_GREATER_EQUAL) {
op = cmSystemTools::OP_GREATER_EQUAL;
} else { // version_equal
op = cmSystemTools::OP_EQUAL;
}
const auto result =
cmSystemTools::VersionCompare(op, def->c_str(), def2->c_str());
HandleBinaryOp(result, arg, newArgs, argP1, argP2);
}
// is file A newer than file B
else if (this->IsKeyword(keyIS_NEWER_THAN, *argP1)) {
auto fileIsNewer = 0;
cmsys::Status ftcStatus = cmSystemTools::FileTimeCompare(
arg->GetValue(), argP2->GetValue(), &fileIsNewer);
HandleBinaryOp((!ftcStatus || fileIsNewer == 1 || fileIsNewer == 0), arg,
newArgs, argP1, argP2);
}
else if (this->IsKeyword(keyIN_LIST, *argP1)) {
if (this->Policy57Status != cmPolicies::OLD &&
this->Policy57Status != cmPolicies::WARN) {
cmProp def = this->GetVariableOrString(*arg);
cmProp def2 = this->Makefile.GetDefinition(argP2->GetValue());
HandleBinaryOp(def2 && cm::contains(cmExpandedList(*def2, true), *def),
arg, newArgs, argP1, argP2);
} else if (this->Policy57Status == cmPolicies::WARN) {
std::ostringstream e;
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0057)
<< "\n"
"IN_LIST 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());
}
}
}
return true;
}
//=========================================================================
// level 3 handles NOT
bool cmConditionEvaluator::HandleLevel3(cmArgumentList& newArgs,
std::string& errorString,
MessageType& status)
{
for (auto arg = newArgs.begin(), argP1 = arg; arg != newArgs.end();
argP1 = ++arg) {
IncrementArguments(newArgs, argP1);
if (argP1 != newArgs.end() && this->IsKeyword(keyNOT, *arg)) {
const auto rhs =
this->GetBooleanValueWithAutoDereference(*argP1, errorString, status);
HandlePredicate(!rhs, arg, newArgs, argP1);
}
}
return true;
}
//=========================================================================
// level 4 handles AND OR
bool cmConditionEvaluator::HandleLevel4(cmArgumentList& newArgs,
std::string& errorString,
MessageType& status)
{
for (auto arg = newArgs.begin(), argP1 = arg, argP2 = arg;
arg != newArgs.end(); argP1 = ++arg) {
IncrementArguments(newArgs, argP1, argP2);
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
(this->IsKeyword(keyAND, *argP1) || this->IsKeyword(keyOR, *argP1))) {
const auto lhs =
this->GetBooleanValueWithAutoDereference(*arg, errorString, status);
const auto rhs =
this->GetBooleanValueWithAutoDereference(*argP2, errorString, status);
HandleBinaryOp(this->IsKeyword(keyAND, *argP1) ? (lhs && rhs)
: (lhs || rhs),
arg, newArgs, argP1, argP2);
}
}
return true;
}