diff options
Diffstat (limited to 'Source/cmConditionEvaluator.cxx')
-rw-r--r-- | Source/cmConditionEvaluator.cxx | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx index 7a3a3e8..14f10bd74 100644 --- a/Source/cmConditionEvaluator.cxx +++ b/Source/cmConditionEvaluator.cxx @@ -4,7 +4,6 @@ #include <cstdio> #include <cstdlib> -#include <cstring> #include <functional> #include <sstream> #include <utility> @@ -15,6 +14,7 @@ #include "cmMakefile.h" #include "cmMessageType.h" +#include "cmProperty.h" #include "cmState.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" @@ -56,10 +56,8 @@ static std::string const keyVERSION_LESS = "VERSION_LESS"; static std::string const keyVERSION_LESS_EQUAL = "VERSION_LESS_EQUAL"; cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile, - cmListFileContext context, cmListFileBacktrace bt) : Makefile(makefile) - , ExecutionContext(std::move(context)) , Backtrace(std::move(bt)) , Policy12Status(makefile.GetPolicyStatus(cmPolicies::CMP0012)) , Policy54Status(makefile.GetPolicyStatus(cmPolicies::CMP0054)) @@ -134,7 +132,7 @@ bool cmConditionEvaluator::IsTrue( } //========================================================================= -const char* cmConditionEvaluator::GetDefinitionIfUnquoted( +cmProp cmConditionEvaluator::GetDefinitionIfUnquoted( cmExpandedCommandArgument const& argument) const { if ((this->Policy54Status != cmPolicies::WARN && @@ -143,12 +141,11 @@ const char* cmConditionEvaluator::GetDefinitionIfUnquoted( return nullptr; } - const char* def = this->Makefile.GetDefinition(argument.GetValue()); + cmProp def = this->Makefile.GetDefinition(argument.GetValue()); if (def && argument.WasQuoted() && this->Policy54Status == cmPolicies::WARN) { - if (!this->Makefile.HasCMP0054AlreadyBeenReported( - this->ExecutionContext)) { + if (!this->Makefile.HasCMP0054AlreadyBeenReported(this->Backtrace.Top())) { std::ostringstream e; e << (cmPolicies::GetPolicyWarning(cmPolicies::CMP0054)) << "\n"; e << "Quoted variables like \"" << argument.GetValue() @@ -165,13 +162,13 @@ const char* cmConditionEvaluator::GetDefinitionIfUnquoted( } //========================================================================= -const char* cmConditionEvaluator::GetVariableOrString( +cmProp cmConditionEvaluator::GetVariableOrString( const cmExpandedCommandArgument& argument) const { - const char* def = this->GetDefinitionIfUnquoted(argument); + cmProp def = this->GetDefinitionIfUnquoted(argument); if (!def) { - def = argument.c_str(); + def = &argument.GetValue(); } return def; @@ -191,8 +188,7 @@ bool cmConditionEvaluator::IsKeyword(std::string const& keyword, if (isKeyword && argument.WasQuoted() && this->Policy54Status == cmPolicies::WARN) { - if (!this->Makefile.HasCMP0054AlreadyBeenReported( - this->ExecutionContext)) { + if (!this->Makefile.HasCMP0054AlreadyBeenReported(this->Backtrace.Top())) { std::ostringstream e; e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0054) << "\n"; e << "Quoted keywords like \"" << argument.GetValue() @@ -231,7 +227,7 @@ bool cmConditionEvaluator::GetBooleanValue( // Check for numbers. if (!arg.empty()) { char* end; - double d = strtod(arg.c_str(), &end); + double d = 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); @@ -239,7 +235,7 @@ bool cmConditionEvaluator::GetBooleanValue( } // Check definition. - const char* def = this->GetDefinitionIfUnquoted(arg); + cmProp def = this->GetDefinitionIfUnquoted(arg); return !cmIsOff(def); } @@ -256,13 +252,13 @@ bool cmConditionEvaluator::GetBooleanValueOld( if (arg == "1") { return true; } - const char* def = this->GetDefinitionIfUnquoted(arg); + cmProp def = this->GetDefinitionIfUnquoted(arg); return !cmIsOff(def); } // Old GetVariableOrNumber behavior. - const char* def = this->GetDefinitionIfUnquoted(arg); - if (!def && atoi(arg.c_str())) { - def = arg.c_str(); + cmProp def = this->GetDefinitionIfUnquoted(arg); + if (!def && atoi(arg.GetValue().c_str())) { + def = &arg.GetValue(); } return !cmIsOff(def); } @@ -434,36 +430,38 @@ bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&, this->IncrementArguments(newArgs, argP1, argP2); // does a file exist if (this->IsKeyword(keyEXISTS, *arg) && argP1 != newArgs.end()) { - this->HandlePredicate(cmSystemTools::FileExists(argP1->c_str()), + this->HandlePredicate(cmSystemTools::FileExists(argP1->GetValue()), reducible, arg, newArgs, argP1, argP2); } // does a directory with this name exist if (this->IsKeyword(keyIS_DIRECTORY, *arg) && argP1 != newArgs.end()) { - this->HandlePredicate(cmSystemTools::FileIsDirectory(argP1->c_str()), - reducible, arg, newArgs, argP1, argP2); + this->HandlePredicate( + cmSystemTools::FileIsDirectory(argP1->GetValue()), reducible, arg, + newArgs, argP1, argP2); } // does a symlink with this name exist if (this->IsKeyword(keyIS_SYMLINK, *arg) && argP1 != newArgs.end()) { - this->HandlePredicate(cmSystemTools::FileIsSymlink(argP1->c_str()), + this->HandlePredicate(cmSystemTools::FileIsSymlink(argP1->GetValue()), reducible, arg, newArgs, argP1, argP2); } // is the given path an absolute path ? if (this->IsKeyword(keyIS_ABSOLUTE, *arg) && argP1 != newArgs.end()) { - this->HandlePredicate(cmSystemTools::FileIsFullPath(argP1->c_str()), + this->HandlePredicate(cmSystemTools::FileIsFullPath(argP1->GetValue()), reducible, arg, newArgs, argP1, argP2); } // does a command exist if (this->IsKeyword(keyCOMMAND, *arg) && argP1 != newArgs.end()) { cmState::Command command = - this->Makefile.GetState()->GetCommand(argP1->c_str()); + this->Makefile.GetState()->GetCommand(argP1->GetValue()); this->HandlePredicate(command != nullptr, reducible, arg, newArgs, argP1, argP2); } // does a policy exist if (this->IsKeyword(keyPOLICY, *arg) && argP1 != newArgs.end()) { cmPolicies::PolicyID pid; - this->HandlePredicate(cmPolicies::GetPolicyID(argP1->c_str(), pid), - reducible, arg, newArgs, argP1, argP2); + this->HandlePredicate( + cmPolicies::GetPolicyID(argP1->GetValue().c_str(), pid), reducible, + arg, newArgs, argP1, argP2); } // does a target exist if (this->IsKeyword(keyTARGET, *arg) && argP1 != newArgs.end()) { @@ -475,7 +473,7 @@ bool cmConditionEvaluator::HandleLevel1(cmArgumentList& newArgs, std::string&, if (this->Policy64Status != cmPolicies::OLD && this->Policy64Status != cmPolicies::WARN) { if (this->IsKeyword(keyTEST, *arg) && argP1 != newArgs.end()) { - const cmTest* haveTest = this->Makefile.GetTest(argP1->c_str()); + const cmTest* haveTest = this->Makefile.GetTest(argP1->GetValue()); this->HandlePredicate(haveTest != nullptr, reducible, arg, newArgs, argP1, argP2); } @@ -522,8 +520,8 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs, { int reducible; std::string def_buf; - const char* def; - const char* def2; + cmProp def; + cmProp def2; do { reducible = 0; auto arg = newArgs.begin(); @@ -534,15 +532,16 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs, this->IncrementArguments(newArgs, argP1, argP2); if (argP1 != newArgs.end() && argP2 != newArgs.end() && IsKeyword(keyMATCHES, *argP1)) { - def = this->GetVariableOrString(*arg); - if (def != arg->c_str() // yes, we compare the pointer value - && cmHasLiteralPrefix(arg->GetValue(), "CMAKE_MATCH_")) { + def = this->GetDefinitionIfUnquoted(*arg); + 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.c_str(); + def_buf = *def; + def = &def_buf; } - const char* rex = argP2->c_str(); + const std::string& rex = argP2->GetValue(); this->Makefile.ClearMatches(); cmsys::RegularExpression regEntry; if (!regEntry.compile(rex)) { @@ -552,7 +551,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs, status = MessageType::FATAL_ERROR; return false; } - if (regEntry.find(def)) { + if (regEntry.find(*def)) { this->Makefile.StoreMatches(regEntry); *arg = cmExpandedCommandArgument("1", true); } else { @@ -584,7 +583,8 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs, double lhs; double rhs; bool result; - if (sscanf(def, "%lg", &lhs) != 1 || sscanf(def2, "%lg", &rhs) != 1) { + if (sscanf(def->c_str(), "%lg", &lhs) != 1 || + sscanf(def2->c_str(), "%lg", &rhs) != 1) { result = false; } else if (*(argP1) == keyLESS) { result = (lhs < rhs); @@ -608,7 +608,7 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs, this->IsKeyword(keySTREQUAL, *argP1))) { def = this->GetVariableOrString(*arg); def2 = this->GetVariableOrString(*argP2); - int val = strcmp(def, def2); + int val = (*def).compare(*def2); bool result; if (*(argP1) == keySTRLESS) { result = (val < 0); @@ -645,7 +645,8 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs, } else { // version_equal op = cmSystemTools::OP_EQUAL; } - bool result = cmSystemTools::VersionCompare(op, def, def2); + bool result = + cmSystemTools::VersionCompare(op, def->c_str(), def2->c_str()); this->HandleBinaryOp(result, reducible, arg, newArgs, argP1, argP2); } @@ -670,9 +671,8 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs, def2 = this->Makefile.GetDefinition(argP2->GetValue()); if (def2) { - std::vector<std::string> list = cmExpandedList(def2, true); - - result = cm::contains(list, def); + std::vector<std::string> list = cmExpandedList(*def2, true); + result = cm::contains(list, *def); } this->HandleBinaryOp(result, reducible, arg, newArgs, argP1, argP2); |