From 28f2d12a055e025aa0ddeb9842f204f29181eaff Mon Sep 17 00:00:00 2001 From: Regina Pfeifer Date: Sun, 7 Apr 2019 21:46:46 +0200 Subject: cmCommand: De-virtualize function InvokeInitialPass --- Source/cmCommand.h | 4 ++-- Source/cmCommands.cxx | 4 ++-- Source/cmIfCommand.cxx | 17 +++++++++-------- Source/cmIfCommand.h | 39 ++------------------------------------- Source/cmWhileCommand.cxx | 12 +++++++----- Source/cmWhileCommand.h | 34 ++-------------------------------- 6 files changed, 24 insertions(+), 86 deletions(-) diff --git a/Source/cmCommand.h b/Source/cmCommand.h index 9e978b3..bcb178d 100644 --- a/Source/cmCommand.h +++ b/Source/cmCommand.h @@ -52,8 +52,8 @@ public: * encountered in the CMakeLists.txt file. It expands the command's * arguments and then invokes the InitialPass. */ - virtual bool InvokeInitialPass(const std::vector& args, - cmExecutionStatus& status); + bool InvokeInitialPass(const std::vector& args, + cmExecutionStatus& status); /** * This is called when the command is first encountered in diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 96c7105..9ae2f71 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -147,7 +147,7 @@ void GetScriptingCommands(cmState* state) cm::make_unique()); state->AddBuiltinCommand("get_property", cm::make_unique()); - state->AddBuiltinCommand("if", cm::make_unique()); + state->AddBuiltinCommand("if", cmIfCommand); state->AddBuiltinCommand("include", cm::make_unique()); state->AddBuiltinCommand("include_guard", cm::make_unique()); @@ -173,7 +173,7 @@ void GetScriptingCommands(cmState* state) state->AddBuiltinCommand("site_name", cm::make_unique()); state->AddBuiltinCommand("string", cm::make_unique()); state->AddBuiltinCommand("unset", cm::make_unique()); - state->AddBuiltinCommand("while", cm::make_unique()); + state->AddBuiltinCommand("while", cmWhileCommand); state->AddUnexpectedCommand( "else", diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index 4edea17..385022c 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -13,6 +13,7 @@ #include "cmSystemTools.h" #include "cmake.h" +#include #include static std::string cmIfCommandError( @@ -176,19 +177,19 @@ bool cmIfFunctionBlocker::ShouldRemove(const cmListFileFunction& lff, } //========================================================================= -bool cmIfCommand::InvokeInitialPass( - const std::vector& args, cmExecutionStatus&) +bool cmIfCommand(std::vector const& args, + cmExecutionStatus& inStatus) { + cmMakefile& makefile = inStatus.GetMakefile(); std::string errorString; std::vector expandedArguments; - this->Makefile->ExpandArguments(args, expandedArguments); + makefile.ExpandArguments(args, expandedArguments); MessageType status; cmConditionEvaluator conditionEvaluator( - *(this->Makefile), this->Makefile->GetExecutionContext(), - this->Makefile->GetBacktrace()); + makefile, makefile.GetExecutionContext(), makefile.GetBacktrace()); bool isTrue = conditionEvaluator.IsTrue(expandedArguments, errorString, status); @@ -197,11 +198,11 @@ bool cmIfCommand::InvokeInitialPass( std::string err = "if " + cmIfCommandError(expandedArguments); err += errorString; if (status == MessageType::FATAL_ERROR) { - this->Makefile->IssueMessage(MessageType::FATAL_ERROR, err); + makefile.IssueMessage(MessageType::FATAL_ERROR, err); cmSystemTools::SetFatalErrorOccured(); return true; } - this->Makefile->IssueMessage(status, err); + makefile.IssueMessage(status, err); } { @@ -213,7 +214,7 @@ bool cmIfCommand::InvokeInitialPass( fb->HasRun = true; } fb->Args = args; - this->Makefile->AddFunctionBlocker(std::move(fb)); + makefile.AddFunctionBlocker(std::move(fb)); } return true; diff --git a/Source/cmIfCommand.h b/Source/cmIfCommand.h index 4a67760..775e609 100644 --- a/Source/cmIfCommand.h +++ b/Source/cmIfCommand.h @@ -5,17 +5,12 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include #include -#include "cm_memory.hxx" - -#include "cmCommand.h" #include "cmFunctionBlocker.h" #include "cmListFileCache.h" class cmExecutionStatus; -class cmExpandedCommandArgument; class cmMakefile; class cmIfFunctionBlocker : public cmFunctionBlocker @@ -34,37 +29,7 @@ public: }; /// Starts an if block -class cmIfCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr Clone() override - { - return cm::make_unique(); - } - - /** - * This overrides the default InvokeInitialPass implementation. - * It records the arguments before expansion. - */ - bool InvokeInitialPass(const std::vector& args, - cmExecutionStatus&) override; - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector const&, - cmExecutionStatus&) override - { - return false; - } - - // Filter the given variable definition based on policy CMP0054. - static const char* GetDefinitionIfUnquoted( - const cmMakefile* mf, cmExpandedCommandArgument const& argument); -}; +bool cmIfCommand(std::vector const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmWhileCommand.cxx b/Source/cmWhileCommand.cxx index 434c298..37d1c74 100644 --- a/Source/cmWhileCommand.cxx +++ b/Source/cmWhileCommand.cxx @@ -11,6 +11,7 @@ #include "cmMessageType.h" #include "cmSystemTools.h" +#include #include cmWhileFunctionBlocker::cmWhileFunctionBlocker(cmMakefile* mf) @@ -129,19 +130,20 @@ bool cmWhileFunctionBlocker::ShouldRemove(const cmListFileFunction& lff, return false; } -bool cmWhileCommand::InvokeInitialPass( - const std::vector& args, cmExecutionStatus&) +bool cmWhileCommand(std::vector const& args, + cmExecutionStatus& status) { if (args.empty()) { - this->SetError("called with incorrect number of arguments"); + status.SetError("called with incorrect number of arguments"); return false; } // create a function blocker { - auto fb = cm::make_unique(this->Makefile); + cmMakefile& makefile = status.GetMakefile(); + auto fb = cm::make_unique(&makefile); fb->Args = args; - this->Makefile->AddFunctionBlocker(std::move(fb)); + makefile.AddFunctionBlocker(std::move(fb)); } return true; } diff --git a/Source/cmWhileCommand.h b/Source/cmWhileCommand.h index 857d1c8..2257799 100644 --- a/Source/cmWhileCommand.h +++ b/Source/cmWhileCommand.h @@ -5,12 +5,8 @@ #include "cmConfigure.h" // IWYU pragma: keep -#include #include -#include "cm_memory.hxx" - -#include "cmCommand.h" #include "cmFunctionBlocker.h" #include "cmListFileCache.h" @@ -35,33 +31,7 @@ private: }; /// \brief Starts a while loop -class cmWhileCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr Clone() override - { - return cm::make_unique(); - } - - /** - * This overrides the default InvokeInitialPass implementation. - * It records the arguments before expansion. - */ - bool InvokeInitialPass(const std::vector& args, - cmExecutionStatus&) override; - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector const&, - cmExecutionStatus&) override - { - return false; - } -}; +bool cmWhileCommand(std::vector const& args, + cmExecutionStatus& status); #endif -- cgit v0.12