2014-09-11 21:50:51 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2014 Kitware, Inc., Insight Software Consortium
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
|
|
|
|
#include "cmConditionEvaluator.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2016-02-01 17:49:08 +03:00
|
|
|
#include "cmAlgorithms.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmOutputConverter.h"
|
2014-09-11 21:50:51 +04:00
|
|
|
|
2016-03-29 17:31:21 +03:00
|
|
|
static std::string const keyAND = "AND";
|
|
|
|
static std::string const keyCOMMAND = "COMMAND";
|
|
|
|
static std::string const keyDEFINED = "DEFINED";
|
|
|
|
static std::string const keyEQUAL = "EQUAL";
|
|
|
|
static std::string const keyEXISTS = "EXISTS";
|
|
|
|
static std::string const keyGREATER = "GREATER";
|
|
|
|
static std::string const keyIN_LIST = "IN_LIST";
|
|
|
|
static std::string const keyIS_ABSOLUTE = "IS_ABSOLUTE";
|
|
|
|
static std::string const keyIS_DIRECTORY = "IS_DIRECTORY";
|
|
|
|
static std::string const keyIS_NEWER_THAN = "IS_NEWER_THAN";
|
|
|
|
static std::string const keyIS_SYMLINK = "IS_SYMLINK";
|
|
|
|
static std::string const keyLESS = "LESS";
|
|
|
|
static std::string const keyMATCHES = "MATCHES";
|
|
|
|
static std::string const keyNOT = "NOT";
|
|
|
|
static std::string const keyOR = "OR";
|
|
|
|
static std::string const keyParenL = "(";
|
|
|
|
static std::string const keyParenR = ")";
|
|
|
|
static std::string const keyPOLICY = "POLICY";
|
|
|
|
static std::string const keySTREQUAL = "STREQUAL";
|
|
|
|
static std::string const keySTRGREATER = "STRGREATER";
|
|
|
|
static std::string const keySTRLESS = "STRLESS";
|
|
|
|
static std::string const keyTARGET = "TARGET";
|
|
|
|
static std::string const keyTEST = "TEST";
|
|
|
|
static std::string const keyVERSION_EQUAL = "VERSION_EQUAL";
|
|
|
|
static std::string const keyVERSION_GREATER = "VERSION_GREATER";
|
|
|
|
static std::string const keyVERSION_LESS = "VERSION_LESS";
|
|
|
|
|
2015-10-20 20:13:52 +03:00
|
|
|
cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile,
|
2016-05-16 17:34:04 +03:00
|
|
|
const cmListFileContext& context,
|
|
|
|
const cmListFileBacktrace& bt)
|
|
|
|
: Makefile(makefile)
|
|
|
|
, ExecutionContext(context)
|
|
|
|
, Backtrace(bt)
|
|
|
|
, Policy12Status(makefile.GetPolicyStatus(cmPolicies::CMP0012))
|
|
|
|
, Policy54Status(makefile.GetPolicyStatus(cmPolicies::CMP0054))
|
|
|
|
, Policy57Status(makefile.GetPolicyStatus(cmPolicies::CMP0057))
|
|
|
|
, Policy64Status(makefile.GetPolicyStatus(cmPolicies::CMP0064))
|
2014-09-11 21:50:51 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// 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(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::vector<cmExpandedCommandArgument>& args, std::string& errorString,
|
|
|
|
cmake::MessageType& status)
|
2014-09-11 21:50:51 +04:00
|
|
|
{
|
|
|
|
errorString = "";
|
|
|
|
|
|
|
|
// handle empty invocation
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() < 1) {
|
2014-09-11 21:50:51 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
|
|
|
// store the reduced args in this vector
|
|
|
|
cmArgumentList newArgs;
|
|
|
|
|
|
|
|
// copy to the list structure
|
2014-11-22 13:00:45 +03:00
|
|
|
newArgs.insert(newArgs.end(), args.begin(), args.end());
|
2014-09-11 21:50:51 +04:00
|
|
|
|
|
|
|
// 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
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->HandleLevel0(newArgs, errorString, status)) {
|
2014-09-11 21:50:51 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
// predicates
|
|
|
|
if (!this->HandleLevel1(newArgs, errorString, status)) {
|
2014-09-11 21:50:51 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
// binary ops
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->HandleLevel2(newArgs, errorString, status)) {
|
2014-09-11 21:50:51 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
|
|
|
// NOT
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->HandleLevel3(newArgs, errorString, status)) {
|
2014-09-11 21:50:51 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
// AND OR
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->HandleLevel4(newArgs, errorString, status)) {
|
2014-09-11 21:50:51 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
|
|
|
// now at the end there should only be one argument left
|
2016-05-16 17:34:04 +03:00
|
|
|
if (newArgs.size() != 1) {
|
2014-09-11 21:50:51 +04:00
|
|
|
errorString = "Unknown arguments specified";
|
|
|
|
status = cmake::FATAL_ERROR;
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
|
|
|
return this->GetBooleanValueWithAutoDereference(*(newArgs.begin()),
|
2016-05-16 17:34:04 +03:00
|
|
|
errorString, status, true);
|
2014-09-11 21:50:51 +04:00
|
|
|
}
|
|
|
|
|
2014-09-04 22:21:28 +04:00
|
|
|
//=========================================================================
|
|
|
|
const char* cmConditionEvaluator::GetDefinitionIfUnquoted(
|
|
|
|
cmExpandedCommandArgument const& argument) const
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((this->Policy54Status != cmPolicies::WARN &&
|
|
|
|
this->Policy54Status != cmPolicies::OLD) &&
|
|
|
|
argument.WasQuoted()) {
|
2016-06-27 23:44:16 +03:00
|
|
|
return CM_NULLPTR;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-04 22:21:28 +04:00
|
|
|
|
|
|
|
const char* def = this->Makefile.GetDefinition(argument.GetValue());
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (def && argument.WasQuoted() &&
|
|
|
|
this->Policy54Status == cmPolicies::WARN) {
|
|
|
|
if (!this->Makefile.HasCMP0054AlreadyBeenReported(
|
|
|
|
this->ExecutionContext)) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2015-05-03 11:12:10 +03:00
|
|
|
e << (cmPolicies::GetPolicyWarning(cmPolicies::CMP0054)) << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
e << "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.";
|
|
|
|
|
|
|
|
this->Makefile.GetCMakeInstance()->IssueMessage(
|
|
|
|
cmake::AUTHOR_WARNING, e.str(), this->Backtrace);
|
2014-09-04 22:21:28 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-04 22:21:28 +04:00
|
|
|
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:50:51 +04:00
|
|
|
//=========================================================================
|
|
|
|
const char* cmConditionEvaluator::GetVariableOrString(
|
2016-05-16 17:34:04 +03:00
|
|
|
const cmExpandedCommandArgument& argument) const
|
2014-09-11 21:50:51 +04:00
|
|
|
{
|
2014-09-04 22:21:28 +04:00
|
|
|
const char* def = this->GetDefinitionIfUnquoted(argument);
|
2014-09-11 21:50:51 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!def) {
|
2014-09-04 22:21:28 +04:00
|
|
|
def = argument.c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2014-09-04 22:21:28 +04:00
|
|
|
//=========================================================================
|
|
|
|
bool cmConditionEvaluator::IsKeyword(std::string const& keyword,
|
2016-05-16 17:34:04 +03:00
|
|
|
cmExpandedCommandArgument& argument) const
|
2014-09-04 22:21:28 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((this->Policy54Status != cmPolicies::WARN &&
|
|
|
|
this->Policy54Status != cmPolicies::OLD) &&
|
|
|
|
argument.WasQuoted()) {
|
2014-09-04 22:21:28 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-04 22:21:28 +04:00
|
|
|
|
|
|
|
bool isKeyword = argument.GetValue() == keyword;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (isKeyword && argument.WasQuoted() &&
|
|
|
|
this->Policy54Status == cmPolicies::WARN) {
|
|
|
|
if (!this->Makefile.HasCMP0054AlreadyBeenReported(
|
|
|
|
this->ExecutionContext)) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2015-05-03 11:12:10 +03:00
|
|
|
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0054) << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
e << "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.";
|
|
|
|
|
|
|
|
this->Makefile.GetCMakeInstance()->IssueMessage(
|
|
|
|
cmake::AUTHOR_WARNING, e.str(), this->Backtrace);
|
2014-09-04 22:21:28 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-04 22:21:28 +04:00
|
|
|
|
|
|
|
return isKeyword;
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:50:51 +04:00
|
|
|
//=========================================================================
|
|
|
|
bool cmConditionEvaluator::GetBooleanValue(
|
2014-09-04 22:21:28 +04:00
|
|
|
cmExpandedCommandArgument& arg) const
|
2014-09-11 21:50:51 +04:00
|
|
|
{
|
|
|
|
// Check basic constants.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (arg == "0") {
|
2014-09-11 21:50:51 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (arg == "1") {
|
2014-09-11 21:50:51 +04:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
|
|
|
// Check named constants.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::IsOn(arg.c_str())) {
|
2014-09-11 21:50:51 +04:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (cmSystemTools::IsOff(arg.c_str())) {
|
2014-09-11 21:50:51 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
|
|
|
// Check for numbers.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!arg.empty()) {
|
2014-09-11 21:50:51 +04:00
|
|
|
char* end;
|
|
|
|
double d = strtod(arg.c_str(), &end);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (*end == '\0') {
|
2014-09-11 21:50:51 +04:00
|
|
|
// The whole string is a number. Use C conversion to bool.
|
2016-05-16 17:34:04 +03:00
|
|
|
return d ? true : false;
|
2014-09-11 21:50:51 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
|
|
|
// Check definition.
|
2014-09-04 22:21:28 +04:00
|
|
|
const char* def = this->GetDefinitionIfUnquoted(arg);
|
2014-09-11 21:50:51 +04:00
|
|
|
return !cmSystemTools::IsOff(def);
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// Boolean value behavior from CMake 2.6.4 and below.
|
|
|
|
bool cmConditionEvaluator::GetBooleanValueOld(
|
2014-09-04 22:21:28 +04:00
|
|
|
cmExpandedCommandArgument const& arg, bool one) const
|
2014-09-11 21:50:51 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (one) {
|
2014-09-11 21:50:51 +04:00
|
|
|
// Old IsTrue behavior for single argument.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (arg == "0") {
|
|
|
|
return false;
|
|
|
|
} else if (arg == "1") {
|
|
|
|
return true;
|
|
|
|
} else {
|
2014-09-04 22:21:28 +04:00
|
|
|
const char* def = this->GetDefinitionIfUnquoted(arg);
|
|
|
|
return !cmSystemTools::IsOff(def);
|
2014-09-11 21:50:51 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-09-11 21:50:51 +04:00
|
|
|
// Old GetVariableOrNumber behavior.
|
2014-09-04 22:21:28 +04:00
|
|
|
const char* def = this->GetDefinitionIfUnquoted(arg);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!def && atoi(arg.c_str())) {
|
2014-09-11 21:50:51 +04:00
|
|
|
def = arg.c_str();
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return !cmSystemTools::IsOff(def);
|
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// returns the resulting boolean value
|
|
|
|
bool cmConditionEvaluator::GetBooleanValueWithAutoDereference(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmExpandedCommandArgument& newArg, std::string& errorString,
|
|
|
|
cmake::MessageType& status, bool oneArg) const
|
2014-09-11 21:50:51 +04:00
|
|
|
{
|
|
|
|
// Use the policy if it is set.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Policy12Status == cmPolicies::NEW) {
|
2014-09-11 21:50:51 +04:00
|
|
|
return GetBooleanValue(newArg);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->Policy12Status == cmPolicies::OLD) {
|
2014-09-11 21:50:51 +04:00
|
|
|
return GetBooleanValueOld(newArg, oneArg);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
|
|
|
// Check policy only if old and new results differ.
|
|
|
|
bool newResult = this->GetBooleanValue(newArg);
|
|
|
|
bool oldResult = this->GetBooleanValueOld(newArg, oneArg);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (newResult != oldResult) {
|
|
|
|
switch (this->Policy12Status) {
|
|
|
|
case cmPolicies::WARN: {
|
|
|
|
errorString = "An argument named \"" + newArg.GetValue() +
|
|
|
|
"\" appears in a conditional statement. " +
|
|
|
|
cmPolicies::GetPolicyWarning(cmPolicies::CMP0012);
|
2014-09-11 21:50:51 +04:00
|
|
|
status = cmake::AUTHOR_WARNING;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
case cmPolicies::OLD:
|
|
|
|
return oldResult;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
2016-05-16 17:34:04 +03:00
|
|
|
case cmPolicies::REQUIRED_ALWAYS: {
|
|
|
|
errorString = "An argument named \"" + newArg.GetValue() +
|
|
|
|
"\" appears in a conditional statement. " +
|
|
|
|
cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0012);
|
2014-09-11 21:50:51 +04:00
|
|
|
status = cmake::FATAL_ERROR;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
case cmPolicies::NEW:
|
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
return newResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmConditionEvaluator::IncrementArguments(
|
|
|
|
cmArgumentList& newArgs, cmArgumentList::iterator& argP1,
|
|
|
|
cmArgumentList::iterator& argP2) const
|
2014-09-11 21:50:51 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (argP1 != newArgs.end()) {
|
2014-09-11 21:50:51 +04:00
|
|
|
argP1++;
|
|
|
|
argP2 = argP1;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (argP1 != newArgs.end()) {
|
2014-09-11 21:50:51 +04:00
|
|
|
argP2++;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// helper function to reduce code duplication
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmConditionEvaluator::HandlePredicate(
|
|
|
|
bool value, int& reducible, cmArgumentList::iterator& arg,
|
|
|
|
cmArgumentList& newArgs, cmArgumentList::iterator& argP1,
|
|
|
|
cmArgumentList::iterator& argP2) const
|
2014-09-11 21:50:51 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (value) {
|
2014-09-04 22:21:28 +04:00
|
|
|
*arg = cmExpandedCommandArgument("1", true);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-09-04 22:21:28 +04:00
|
|
|
*arg = cmExpandedCommandArgument("0", true);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
newArgs.erase(argP1);
|
|
|
|
argP1 = arg;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->IncrementArguments(newArgs, argP1, argP2);
|
2014-09-11 21:50:51 +04:00
|
|
|
reducible = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// helper function to reduce code duplication
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmConditionEvaluator::HandleBinaryOp(bool value, int& reducible,
|
|
|
|
cmArgumentList::iterator& arg,
|
|
|
|
cmArgumentList& newArgs,
|
|
|
|
cmArgumentList::iterator& argP1,
|
|
|
|
cmArgumentList::iterator& argP2)
|
2014-09-11 21:50:51 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (value) {
|
2014-09-04 22:21:28 +04:00
|
|
|
*arg = cmExpandedCommandArgument("1", true);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-09-04 22:21:28 +04:00
|
|
|
*arg = cmExpandedCommandArgument("0", true);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
newArgs.erase(argP2);
|
|
|
|
newArgs.erase(argP1);
|
|
|
|
argP1 = arg;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->IncrementArguments(newArgs, argP1, argP2);
|
2014-09-11 21:50:51 +04:00
|
|
|
reducible = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// level 0 processes parenthetical expressions
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs,
|
|
|
|
std::string& errorString,
|
|
|
|
cmake::MessageType& status)
|
2014-09-11 21:50:51 +04:00
|
|
|
{
|
|
|
|
int reducible;
|
2016-05-16 17:34:04 +03:00
|
|
|
do {
|
2014-09-11 21:50:51 +04:00
|
|
|
reducible = 0;
|
2014-09-04 22:21:28 +04:00
|
|
|
cmArgumentList::iterator arg = newArgs.begin();
|
2016-05-16 17:34:04 +03:00
|
|
|
while (arg != newArgs.end()) {
|
|
|
|
if (IsKeyword(keyParenL, *arg)) {
|
2014-09-11 21:50:51 +04:00
|
|
|
// search for the closing paren for this opening one
|
2014-09-04 22:21:28 +04:00
|
|
|
cmArgumentList::iterator argClose;
|
2014-09-11 21:50:51 +04:00
|
|
|
argClose = arg;
|
|
|
|
argClose++;
|
|
|
|
unsigned int depth = 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (argClose != newArgs.end() && depth) {
|
|
|
|
if (this->IsKeyword(keyParenL, *argClose)) {
|
|
|
|
depth++;
|
|
|
|
}
|
|
|
|
if (this->IsKeyword(keyParenR, *argClose)) {
|
|
|
|
depth--;
|
2014-09-11 21:50:51 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
argClose++;
|
|
|
|
}
|
|
|
|
if (depth) {
|
2014-09-11 21:50:51 +04:00
|
|
|
errorString = "mismatched parenthesis in condition";
|
|
|
|
status = cmake::FATAL_ERROR;
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
// store the reduced args in this vector
|
2014-09-04 22:21:28 +04:00
|
|
|
std::vector<cmExpandedCommandArgument> newArgs2;
|
2014-09-11 21:50:51 +04:00
|
|
|
|
|
|
|
// copy to the list structure
|
2014-09-04 22:21:28 +04:00
|
|
|
cmArgumentList::iterator argP1 = arg;
|
2014-09-11 21:50:51 +04:00
|
|
|
argP1++;
|
2014-11-22 13:00:45 +03:00
|
|
|
newArgs2.insert(newArgs2.end(), argP1, argClose);
|
2014-09-11 21:50:51 +04:00
|
|
|
newArgs2.pop_back();
|
|
|
|
// now recursively invoke IsTrue to handle the values inside the
|
|
|
|
// parenthetical expression
|
2016-05-16 17:34:04 +03:00
|
|
|
bool value = this->IsTrue(newArgs2, errorString, status);
|
|
|
|
if (value) {
|
2014-09-04 22:21:28 +04:00
|
|
|
*arg = cmExpandedCommandArgument("1", true);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-09-04 22:21:28 +04:00
|
|
|
*arg = cmExpandedCommandArgument("0", true);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
argP1 = arg;
|
|
|
|
argP1++;
|
|
|
|
// remove the now evaluated parenthetical expression
|
2016-05-16 17:34:04 +03:00
|
|
|
newArgs.erase(argP1, argClose);
|
2014-09-11 21:50:51 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
++arg;
|
2014-09-11 21:50:51 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} while (reducible);
|
2014-09-11 21:50:51 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// level one handles most predicates except for NOT
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&,
|
|
|
|
cmake::MessageType&)
|
2014-09-11 21:50:51 +04:00
|
|
|
{
|
|
|
|
int reducible;
|
2016-05-16 17:34:04 +03:00
|
|
|
do {
|
2014-09-11 21:50:51 +04:00
|
|
|
reducible = 0;
|
2014-09-04 22:21:28 +04:00
|
|
|
cmArgumentList::iterator arg = newArgs.begin();
|
|
|
|
cmArgumentList::iterator argP1;
|
|
|
|
cmArgumentList::iterator argP2;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (arg != newArgs.end()) {
|
2014-09-11 21:50:51 +04:00
|
|
|
argP1 = arg;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->IncrementArguments(newArgs, argP1, argP2);
|
2014-09-11 21:50:51 +04:00
|
|
|
// does a file exist
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsKeyword(keyEXISTS, *arg) && argP1 != newArgs.end()) {
|
|
|
|
this->HandlePredicate(cmSystemTools::FileExists(argP1->c_str()),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
// does a directory with this name exist
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsKeyword(keyIS_DIRECTORY, *arg) && argP1 != newArgs.end()) {
|
|
|
|
this->HandlePredicate(cmSystemTools::FileIsDirectory(argP1->c_str()),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
// does a symlink with this name exist
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsKeyword(keyIS_SYMLINK, *arg) && argP1 != newArgs.end()) {
|
|
|
|
this->HandlePredicate(cmSystemTools::FileIsSymlink(argP1->c_str()),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
// is the given path an absolute path ?
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsKeyword(keyIS_ABSOLUTE, *arg) && argP1 != newArgs.end()) {
|
|
|
|
this->HandlePredicate(cmSystemTools::FileIsFullPath(argP1->c_str()),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
// does a command exist
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsKeyword(keyCOMMAND, *arg) && argP1 != newArgs.end()) {
|
2015-04-11 13:52:14 +03:00
|
|
|
cmCommand* command =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile.GetState()->GetCommand(argP1->c_str());
|
|
|
|
this->HandlePredicate(command ? true : false, reducible, arg, newArgs,
|
|
|
|
argP1, argP2);
|
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
// does a policy exist
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsKeyword(keyPOLICY, *arg) && argP1 != newArgs.end()) {
|
2014-09-11 21:50:51 +04:00
|
|
|
cmPolicies::PolicyID pid;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->HandlePredicate(cmPolicies::GetPolicyID(argP1->c_str(), pid),
|
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
// does a target exist
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsKeyword(keyTARGET, *arg) && argP1 != newArgs.end()) {
|
2014-09-11 21:50:51 +04:00
|
|
|
this->HandlePredicate(
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile.FindTargetToUse(argP1->GetValue()) ? true : false,
|
2014-09-11 21:50:51 +04:00
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-12-30 04:47:48 +03:00
|
|
|
// does a test exist
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Policy64Status != cmPolicies::OLD &&
|
|
|
|
this->Policy64Status != cmPolicies::WARN) {
|
|
|
|
if (this->IsKeyword(keyTEST, *arg) && argP1 != newArgs.end()) {
|
2014-12-30 04:47:48 +03:00
|
|
|
const cmTest* haveTest = this->Makefile.GetTest(argP1->c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
this->HandlePredicate(haveTest ? true : false, reducible, arg,
|
|
|
|
newArgs, argP1, argP2);
|
2014-12-30 04:47:48 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->Policy64Status == cmPolicies::WARN &&
|
|
|
|
this->IsKeyword(keyTEST, *arg)) {
|
2014-12-30 04:47:48 +03:00
|
|
|
std::ostringstream e;
|
|
|
|
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0064) << "\n";
|
|
|
|
e << "TEST will be interpreted as an operator "
|
2016-05-16 17:34:04 +03:00
|
|
|
"when the policy is set to NEW. "
|
|
|
|
"Since the policy is not set the OLD behavior will be used.";
|
2014-12-30 04:47:48 +03:00
|
|
|
|
|
|
|
this->Makefile.IssueMessage(cmake::AUTHOR_WARNING, e.str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
// is a variable defined
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->IsKeyword(keyDEFINED, *arg) && argP1 != newArgs.end()) {
|
2014-09-04 22:21:28 +04:00
|
|
|
size_t argP1len = argP1->GetValue().size();
|
2014-09-11 21:50:51 +04:00
|
|
|
bool bdef = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (argP1len > 4 && argP1->GetValue().substr(0, 4) == "ENV{" &&
|
|
|
|
argP1->GetValue().operator[](argP1len - 1) == '}') {
|
|
|
|
std::string env = argP1->GetValue().substr(4, argP1len - 5);
|
|
|
|
bdef = cmSystemTools::GetEnv(env.c_str()) ? true : false;
|
|
|
|
} else {
|
2014-09-04 22:21:28 +04:00
|
|
|
bdef = this->Makefile.IsDefinitionSet(argP1->GetValue());
|
2014-09-11 21:50:51 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->HandlePredicate(bdef, reducible, arg, newArgs, argP1, argP2);
|
2014-09-11 21:50:51 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
++arg;
|
2014-09-11 21:50:51 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} while (reducible);
|
2014-09-11 21:50:51 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// level two handles most binary operations except for AND OR
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs,
|
|
|
|
std::string& errorString,
|
|
|
|
cmake::MessageType& status)
|
2014-09-11 21:50:51 +04:00
|
|
|
{
|
|
|
|
int reducible;
|
2016-02-01 17:49:08 +03:00
|
|
|
std::string def_buf;
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* def;
|
|
|
|
const char* def2;
|
|
|
|
do {
|
2014-09-11 21:50:51 +04:00
|
|
|
reducible = 0;
|
2014-09-04 22:21:28 +04:00
|
|
|
cmArgumentList::iterator arg = newArgs.begin();
|
|
|
|
cmArgumentList::iterator argP1;
|
|
|
|
cmArgumentList::iterator argP2;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (arg != newArgs.end()) {
|
2014-09-11 21:50:51 +04:00
|
|
|
argP1 = arg;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->IncrementArguments(newArgs, argP1, argP2);
|
2014-09-11 21:50:51 +04:00
|
|
|
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
|
2016-05-16 17:34:04 +03:00
|
|
|
IsKeyword(keyMATCHES, *argP1)) {
|
2014-09-11 21:50:51 +04:00
|
|
|
def = this->GetVariableOrString(*arg);
|
2016-02-01 17:49:08 +03:00
|
|
|
if (def != arg->c_str() // yes, we compare the pointer value
|
2016-05-16 17:34:04 +03:00
|
|
|
&& cmHasLiteralPrefix(arg->GetValue(), "CMAKE_MATCH_")) {
|
2016-02-01 17:49:08 +03:00
|
|
|
// 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.c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-04 22:21:28 +04:00
|
|
|
const char* rex = argP2->c_str();
|
2014-12-01 18:51:49 +03:00
|
|
|
this->Makefile.ClearMatches();
|
2014-09-11 21:50:51 +04:00
|
|
|
cmsys::RegularExpression regEntry;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!regEntry.compile(rex)) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream error;
|
2014-09-11 21:50:51 +04:00
|
|
|
error << "Regular expression \"" << rex << "\" cannot compile";
|
|
|
|
errorString = error.str();
|
|
|
|
status = cmake::FATAL_ERROR;
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (regEntry.find(def)) {
|
2014-12-01 18:51:49 +03:00
|
|
|
this->Makefile.StoreMatches(regEntry);
|
2014-09-04 22:21:28 +04:00
|
|
|
*arg = cmExpandedCommandArgument("1", true);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-09-04 22:21:28 +04:00
|
|
|
*arg = cmExpandedCommandArgument("0", true);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
newArgs.erase(argP2);
|
|
|
|
newArgs.erase(argP1);
|
|
|
|
argP1 = arg;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->IncrementArguments(newArgs, argP1, argP2);
|
2014-09-11 21:50:51 +04:00
|
|
|
reducible = 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (argP1 != newArgs.end() && this->IsKeyword(keyMATCHES, *arg)) {
|
2014-09-04 22:21:28 +04:00
|
|
|
*arg = cmExpandedCommandArgument("0", true);
|
2014-09-11 21:50:51 +04:00
|
|
|
newArgs.erase(argP1);
|
|
|
|
argP1 = arg;
|
2016-05-16 17:34:04 +03:00
|
|
|
this->IncrementArguments(newArgs, argP1, argP2);
|
2014-09-11 21:50:51 +04:00
|
|
|
reducible = 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
|
|
|
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
|
2016-05-16 17:34:04 +03:00
|
|
|
(this->IsKeyword(keyLESS, *argP1) ||
|
|
|
|
this->IsKeyword(keyGREATER, *argP1) ||
|
|
|
|
this->IsKeyword(keyEQUAL, *argP1))) {
|
2014-09-11 21:50:51 +04:00
|
|
|
def = this->GetVariableOrString(*arg);
|
|
|
|
def2 = this->GetVariableOrString(*argP2);
|
|
|
|
double lhs;
|
|
|
|
double rhs;
|
|
|
|
bool result;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (sscanf(def, "%lg", &lhs) != 1 || sscanf(def2, "%lg", &rhs) != 1) {
|
2014-09-11 21:50:51 +04:00
|
|
|
result = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (*(argP1) == keyLESS) {
|
2014-09-11 21:50:51 +04:00
|
|
|
result = (lhs < rhs);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (*(argP1) == keyGREATER) {
|
2014-09-11 21:50:51 +04:00
|
|
|
result = (lhs > rhs);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-09-11 21:50:51 +04:00
|
|
|
result = (lhs == rhs);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->HandleBinaryOp(result, reducible, arg, newArgs, argP1, argP2);
|
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
|
|
|
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
|
2016-05-16 17:34:04 +03:00
|
|
|
(this->IsKeyword(keySTRLESS, *argP1) ||
|
|
|
|
this->IsKeyword(keySTREQUAL, *argP1) ||
|
|
|
|
this->IsKeyword(keySTRGREATER, *argP1))) {
|
2014-09-11 21:50:51 +04:00
|
|
|
def = this->GetVariableOrString(*arg);
|
|
|
|
def2 = this->GetVariableOrString(*argP2);
|
2016-05-16 17:34:04 +03:00
|
|
|
int val = strcmp(def, def2);
|
2014-09-11 21:50:51 +04:00
|
|
|
bool result;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (*(argP1) == keySTRLESS) {
|
2014-09-11 21:50:51 +04:00
|
|
|
result = (val < 0);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (*(argP1) == keySTRGREATER) {
|
2014-09-11 21:50:51 +04:00
|
|
|
result = (val > 0);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else // strequal
|
|
|
|
{
|
2014-09-11 21:50:51 +04:00
|
|
|
result = (val == 0);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
this->HandleBinaryOp(result, reducible, arg, newArgs, argP1, argP2);
|
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
|
|
|
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
|
2016-05-16 17:34:04 +03:00
|
|
|
(this->IsKeyword(keyVERSION_LESS, *argP1) ||
|
|
|
|
this->IsKeyword(keyVERSION_GREATER, *argP1) ||
|
|
|
|
this->IsKeyword(keyVERSION_EQUAL, *argP1))) {
|
2014-09-11 21:50:51 +04:00
|
|
|
def = this->GetVariableOrString(*arg);
|
|
|
|
def2 = this->GetVariableOrString(*argP2);
|
|
|
|
cmSystemTools::CompareOp op = cmSystemTools::OP_EQUAL;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (*argP1 == keyVERSION_LESS) {
|
2014-09-11 21:50:51 +04:00
|
|
|
op = cmSystemTools::OP_LESS;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (*argP1 == keyVERSION_GREATER) {
|
2014-09-11 21:50:51 +04:00
|
|
|
op = cmSystemTools::OP_GREATER;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
bool result = cmSystemTools::VersionCompare(op, def, def2);
|
|
|
|
this->HandleBinaryOp(result, reducible, arg, newArgs, argP1, argP2);
|
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
|
|
|
// is file A newer than file B
|
|
|
|
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
|
2016-05-16 17:34:04 +03:00
|
|
|
this->IsKeyword(keyIS_NEWER_THAN, *argP1)) {
|
|
|
|
int fileIsNewer = 0;
|
|
|
|
bool success = cmSystemTools::FileTimeCompare(
|
|
|
|
arg->GetValue(), (argP2)->GetValue(), &fileIsNewer);
|
2014-09-11 21:50:51 +04:00
|
|
|
this->HandleBinaryOp(
|
2016-05-16 17:34:04 +03:00
|
|
|
(success == false || fileIsNewer == 1 || fileIsNewer == 0),
|
2014-09-11 21:50:51 +04:00
|
|
|
reducible, arg, newArgs, argP1, argP2);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
2015-04-29 18:25:13 +03:00
|
|
|
if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
|
2016-05-16 17:34:04 +03:00
|
|
|
this->IsKeyword(keyIN_LIST, *argP1)) {
|
|
|
|
if (this->Policy57Status != cmPolicies::OLD &&
|
|
|
|
this->Policy57Status != cmPolicies::WARN) {
|
2015-04-29 18:25:13 +03:00
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
def = this->GetVariableOrString(*arg);
|
|
|
|
def2 = this->Makefile.GetDefinition(argP2->GetValue());
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (def2) {
|
2015-04-29 18:25:13 +03:00
|
|
|
std::vector<std::string> list;
|
|
|
|
cmSystemTools::ExpandListArgument(def2, list, true);
|
|
|
|
|
|
|
|
result = std::find(list.begin(), list.end(), def) != list.end();
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
|
|
|
|
this->HandleBinaryOp(result, reducible, arg, newArgs, argP1, argP2);
|
|
|
|
} else if (this->Policy57Status == cmPolicies::WARN) {
|
|
|
|
std::ostringstream e;
|
|
|
|
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0057) << "\n";
|
|
|
|
e << "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(cmake::AUTHOR_WARNING, e.str());
|
2015-04-29 18:25:13 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-04-29 18:25:13 +03:00
|
|
|
|
2014-09-11 21:50:51 +04:00
|
|
|
++arg;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} while (reducible);
|
2014-09-11 21:50:51 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// level 3 handles NOT
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmConditionEvaluator::HandleLevel3(cmArgumentList& newArgs,
|
|
|
|
std::string& errorString,
|
|
|
|
cmake::MessageType& status)
|
2014-09-11 21:50:51 +04:00
|
|
|
{
|
|
|
|
int reducible;
|
2016-05-16 17:34:04 +03:00
|
|
|
do {
|
2014-09-11 21:50:51 +04:00
|
|
|
reducible = 0;
|
2014-09-04 22:21:28 +04:00
|
|
|
cmArgumentList::iterator arg = newArgs.begin();
|
|
|
|
cmArgumentList::iterator argP1;
|
|
|
|
cmArgumentList::iterator argP2;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (arg != newArgs.end()) {
|
2014-09-11 21:50:51 +04:00
|
|
|
argP1 = arg;
|
2016-05-16 17:34:04 +03:00
|
|
|
IncrementArguments(newArgs, argP1, argP2);
|
|
|
|
if (argP1 != newArgs.end() && IsKeyword(keyNOT, *arg)) {
|
|
|
|
bool rhs = this->GetBooleanValueWithAutoDereference(
|
|
|
|
*argP1, errorString, status);
|
2014-09-11 21:50:51 +04:00
|
|
|
this->HandlePredicate(!rhs, reducible, arg, newArgs, argP1, argP2);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
++arg;
|
2014-09-11 21:50:51 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} while (reducible);
|
2014-09-11 21:50:51 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=========================================================================
|
|
|
|
// level 4 handles AND OR
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmConditionEvaluator::HandleLevel4(cmArgumentList& newArgs,
|
|
|
|
std::string& errorString,
|
|
|
|
cmake::MessageType& status)
|
2014-09-11 21:50:51 +04:00
|
|
|
{
|
|
|
|
int reducible;
|
|
|
|
bool lhs;
|
|
|
|
bool rhs;
|
2016-05-16 17:34:04 +03:00
|
|
|
do {
|
2014-09-11 21:50:51 +04:00
|
|
|
reducible = 0;
|
2014-09-04 22:21:28 +04:00
|
|
|
cmArgumentList::iterator arg = newArgs.begin();
|
|
|
|
cmArgumentList::iterator argP1;
|
|
|
|
cmArgumentList::iterator argP2;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (arg != newArgs.end()) {
|
2014-09-11 21:50:51 +04:00
|
|
|
argP1 = arg;
|
2016-05-16 17:34:04 +03:00
|
|
|
IncrementArguments(newArgs, argP1, argP2);
|
2016-03-29 17:31:21 +03:00
|
|
|
if (argP1 != newArgs.end() && IsKeyword(keyAND, *argP1) &&
|
2016-05-16 17:34:04 +03:00
|
|
|
argP2 != newArgs.end()) {
|
|
|
|
lhs =
|
|
|
|
this->GetBooleanValueWithAutoDereference(*arg, errorString, status);
|
|
|
|
rhs = this->GetBooleanValueWithAutoDereference(*argP2, errorString,
|
|
|
|
status);
|
|
|
|
this->HandleBinaryOp((lhs && rhs), reducible, arg, newArgs, argP1,
|
|
|
|
argP2);
|
|
|
|
}
|
2014-09-11 21:50:51 +04:00
|
|
|
|
2016-03-29 17:31:21 +03:00
|
|
|
if (argP1 != newArgs.end() && this->IsKeyword(keyOR, *argP1) &&
|
2016-05-16 17:34:04 +03:00
|
|
|
argP2 != newArgs.end()) {
|
|
|
|
lhs =
|
|
|
|
this->GetBooleanValueWithAutoDereference(*arg, errorString, status);
|
|
|
|
rhs = this->GetBooleanValueWithAutoDereference(*argP2, errorString,
|
|
|
|
status);
|
|
|
|
this->HandleBinaryOp((lhs || rhs), reducible, arg, newArgs, argP1,
|
|
|
|
argP2);
|
2014-09-11 21:50:51 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
++arg;
|
2014-09-11 21:50:51 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} while (reducible);
|
2014-09-11 21:50:51 +04:00
|
|
|
return true;
|
|
|
|
}
|