From 0101ace1319b5c97472649ec809b67299e2a46ce Mon Sep 17 00:00:00 2001 From: Regina Pfeifer Date: Sun, 7 Apr 2019 20:40:59 +0200 Subject: cmUnexpectedCommand: Replace with lambda expression --- Source/CMakeLists.txt | 2 -- Source/cmState.cxx | 26 +++++++++++++++++++++----- Source/cmState.h | 1 + Source/cmUnexpectedCommand.cxx | 22 ---------------------- Source/cmUnexpectedCommand.h | 40 ---------------------------------------- bootstrap | 1 - 6 files changed, 22 insertions(+), 70 deletions(-) delete mode 100644 Source/cmUnexpectedCommand.cxx delete mode 100644 Source/cmUnexpectedCommand.h diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 0316532..8117916 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -662,8 +662,6 @@ set(SRCS cmTryCompileCommand.h cmTryRunCommand.cxx cmTryRunCommand.h - cmUnexpectedCommand.cxx - cmUnexpectedCommand.h cmUnsetCommand.cxx cmUnsetCommand.h cmUseMangledMesaCommand.cxx diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 57ae324..82b0a52 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -5,6 +5,7 @@ #include "cmsys/RegularExpression.hxx" #include #include +#include #include #include @@ -15,12 +16,13 @@ #include "cmCommand.h" #include "cmDefinitions.h" #include "cmDisallowedCommand.h" +#include "cmExecutionStatus.h" #include "cmGlobVerificationManager.h" #include "cmListFileCache.h" +#include "cmMakefile.h" #include "cmStatePrivate.h" #include "cmStateSnapshot.h" #include "cmSystemTools.h" -#include "cmUnexpectedCommand.h" #include "cmake.h" cmState::cmState() @@ -420,10 +422,14 @@ void cmState::SetIsGeneratorMultiConfig(bool b) void cmState::AddBuiltinCommand(std::string const& name, std::unique_ptr command) { + this->AddBuiltinCommand(name, cmLegacyCommandWrapper(std::move(command))); +} + +void cmState::AddBuiltinCommand(std::string const& name, Command command) +{ assert(name == cmSystemTools::LowerCase(name)); assert(this->BuiltinCommands.find(name) == this->BuiltinCommands.end()); - this->BuiltinCommands.emplace(name, - cmLegacyCommandWrapper(std::move(command))); + this->BuiltinCommands.emplace(name, std::move(command)); } void cmState::AddDisallowedCommand(std::string const& name, @@ -438,8 +444,18 @@ void cmState::AddDisallowedCommand(std::string const& name, void cmState::AddUnexpectedCommand(std::string const& name, const char* error) { - this->AddBuiltinCommand(name, - cm::make_unique(name, error)); + this->AddBuiltinCommand( + name, + [name, error](std::vector const&, + cmExecutionStatus& status) -> bool { + const char* versionValue = + status.GetMakefile().GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION"); + if (name == "endif" && (!versionValue || atof(versionValue) <= 1.4)) { + return true; + } + status.SetError(error); + return false; + }); } void cmState::AddScriptedCommand(std::string const& name, diff --git a/Source/cmState.h b/Source/cmState.h index ed70bd6..a6e9386 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -153,6 +153,7 @@ public: void AddBuiltinCommand(std::string const& name, std::unique_ptr command); + void AddBuiltinCommand(std::string const& name, Command command); void AddDisallowedCommand(std::string const& name, std::unique_ptr command, cmPolicies::PolicyID policy, const char* message); diff --git a/Source/cmUnexpectedCommand.cxx b/Source/cmUnexpectedCommand.cxx deleted file mode 100644 index a8de9e6..0000000 --- a/Source/cmUnexpectedCommand.cxx +++ /dev/null @@ -1,22 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#include "cmUnexpectedCommand.h" - -#include - -#include "cmMakefile.h" - -class cmExecutionStatus; - -bool cmUnexpectedCommand::InitialPass(std::vector const&, - cmExecutionStatus&) -{ - const char* versionValue = - this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION"); - if (this->Name == "endif" && (!versionValue || atof(versionValue) <= 1.4)) { - return true; - } - - this->SetError(this->Error); - return false; -} diff --git a/Source/cmUnexpectedCommand.h b/Source/cmUnexpectedCommand.h deleted file mode 100644 index 6e4cee5..0000000 --- a/Source/cmUnexpectedCommand.h +++ /dev/null @@ -1,40 +0,0 @@ -/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying - file Copyright.txt or https://cmake.org/licensing for details. */ -#ifndef cmUnexpectedCommand_h -#define cmUnexpectedCommand_h - -#include "cmConfigure.h" // IWYU pragma: keep - -#include -#include -#include - -#include "cm_memory.hxx" - -#include "cmCommand.h" - -class cmExecutionStatus; - -class cmUnexpectedCommand : public cmCommand -{ -public: - cmUnexpectedCommand(std::string name, const char* error) - : Name(std::move(name)) - , Error(error) - { - } - - std::unique_ptr Clone() override - { - return cm::make_unique(this->Name, this->Error); - } - - bool InitialPass(std::vector const& args, - cmExecutionStatus& status) override; - -private: - std::string Name; - const char* Error; -}; - -#endif diff --git a/bootstrap b/bootstrap index c2194fe..bb5229b 100755 --- a/bootstrap +++ b/bootstrap @@ -440,7 +440,6 @@ CMAKE_CXX_SOURCES="\ cmTimestamp \ cmTryCompileCommand \ cmTryRunCommand \ - cmUnexpectedCommand \ cmUnsetCommand \ cmUVHandlePtr \ cmUVProcessChain \ -- cgit v0.12