cmCommand: De-virtualize function InvokeInitialPass

This commit is contained in:
Regina Pfeifer
2019-04-07 21:46:46 +02:00
parent de77d355ac
commit 28f2d12a05
6 changed files with 24 additions and 86 deletions
+2 -2
View File
@@ -52,8 +52,8 @@ public:
* encountered in the CMakeLists.txt file. It expands the command's * encountered in the CMakeLists.txt file. It expands the command's
* arguments and then invokes the InitialPass. * arguments and then invokes the InitialPass.
*/ */
virtual bool InvokeInitialPass(const std::vector<cmListFileArgument>& args, bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
cmExecutionStatus& status); cmExecutionStatus& status);
/** /**
* This is called when the command is first encountered in * This is called when the command is first encountered in
+2 -2
View File
@@ -147,7 +147,7 @@ void GetScriptingCommands(cmState* state)
cm::make_unique<cmGetFilenameComponentCommand>()); cm::make_unique<cmGetFilenameComponentCommand>());
state->AddBuiltinCommand("get_property", state->AddBuiltinCommand("get_property",
cm::make_unique<cmGetPropertyCommand>()); cm::make_unique<cmGetPropertyCommand>());
state->AddBuiltinCommand("if", cm::make_unique<cmIfCommand>()); state->AddBuiltinCommand("if", cmIfCommand);
state->AddBuiltinCommand("include", cm::make_unique<cmIncludeCommand>()); state->AddBuiltinCommand("include", cm::make_unique<cmIncludeCommand>());
state->AddBuiltinCommand("include_guard", state->AddBuiltinCommand("include_guard",
cm::make_unique<cmIncludeGuardCommand>()); cm::make_unique<cmIncludeGuardCommand>());
@@ -173,7 +173,7 @@ void GetScriptingCommands(cmState* state)
state->AddBuiltinCommand("site_name", cm::make_unique<cmSiteNameCommand>()); state->AddBuiltinCommand("site_name", cm::make_unique<cmSiteNameCommand>());
state->AddBuiltinCommand("string", cm::make_unique<cmStringCommand>()); state->AddBuiltinCommand("string", cm::make_unique<cmStringCommand>());
state->AddBuiltinCommand("unset", cm::make_unique<cmUnsetCommand>()); state->AddBuiltinCommand("unset", cm::make_unique<cmUnsetCommand>());
state->AddBuiltinCommand("while", cm::make_unique<cmWhileCommand>()); state->AddBuiltinCommand("while", cmWhileCommand);
state->AddUnexpectedCommand( state->AddUnexpectedCommand(
"else", "else",
+9 -8
View File
@@ -13,6 +13,7 @@
#include "cmSystemTools.h" #include "cmSystemTools.h"
#include "cmake.h" #include "cmake.h"
#include <string>
#include <utility> #include <utility>
static std::string cmIfCommandError( static std::string cmIfCommandError(
@@ -176,19 +177,19 @@ bool cmIfFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
} }
//========================================================================= //=========================================================================
bool cmIfCommand::InvokeInitialPass( bool cmIfCommand(std::vector<cmListFileArgument> const& args,
const std::vector<cmListFileArgument>& args, cmExecutionStatus&) cmExecutionStatus& inStatus)
{ {
cmMakefile& makefile = inStatus.GetMakefile();
std::string errorString; std::string errorString;
std::vector<cmExpandedCommandArgument> expandedArguments; std::vector<cmExpandedCommandArgument> expandedArguments;
this->Makefile->ExpandArguments(args, expandedArguments); makefile.ExpandArguments(args, expandedArguments);
MessageType status; MessageType status;
cmConditionEvaluator conditionEvaluator( cmConditionEvaluator conditionEvaluator(
*(this->Makefile), this->Makefile->GetExecutionContext(), makefile, makefile.GetExecutionContext(), makefile.GetBacktrace());
this->Makefile->GetBacktrace());
bool isTrue = bool isTrue =
conditionEvaluator.IsTrue(expandedArguments, errorString, status); conditionEvaluator.IsTrue(expandedArguments, errorString, status);
@@ -197,11 +198,11 @@ bool cmIfCommand::InvokeInitialPass(
std::string err = "if " + cmIfCommandError(expandedArguments); std::string err = "if " + cmIfCommandError(expandedArguments);
err += errorString; err += errorString;
if (status == MessageType::FATAL_ERROR) { if (status == MessageType::FATAL_ERROR) {
this->Makefile->IssueMessage(MessageType::FATAL_ERROR, err); makefile.IssueMessage(MessageType::FATAL_ERROR, err);
cmSystemTools::SetFatalErrorOccured(); cmSystemTools::SetFatalErrorOccured();
return true; return true;
} }
this->Makefile->IssueMessage(status, err); makefile.IssueMessage(status, err);
} }
{ {
@@ -213,7 +214,7 @@ bool cmIfCommand::InvokeInitialPass(
fb->HasRun = true; fb->HasRun = true;
} }
fb->Args = args; fb->Args = args;
this->Makefile->AddFunctionBlocker(std::move(fb)); makefile.AddFunctionBlocker(std::move(fb));
} }
return true; return true;
+2 -37
View File
@@ -5,17 +5,12 @@
#include "cmConfigure.h" // IWYU pragma: keep #include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector> #include <vector>
#include "cm_memory.hxx"
#include "cmCommand.h"
#include "cmFunctionBlocker.h" #include "cmFunctionBlocker.h"
#include "cmListFileCache.h" #include "cmListFileCache.h"
class cmExecutionStatus; class cmExecutionStatus;
class cmExpandedCommandArgument;
class cmMakefile; class cmMakefile;
class cmIfFunctionBlocker : public cmFunctionBlocker class cmIfFunctionBlocker : public cmFunctionBlocker
@@ -34,37 +29,7 @@ public:
}; };
/// Starts an if block /// Starts an if block
class cmIfCommand : public cmCommand bool cmIfCommand(std::vector<cmListFileArgument> const& args,
{ cmExecutionStatus& status);
public:
/**
* This is a virtual constructor for the command.
*/
std::unique_ptr<cmCommand> Clone() override
{
return cm::make_unique<cmIfCommand>();
}
/**
* This overrides the default InvokeInitialPass implementation.
* It records the arguments before expansion.
*/
bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
cmExecutionStatus&) override;
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const&,
cmExecutionStatus&) override
{
return false;
}
// Filter the given variable definition based on policy CMP0054.
static const char* GetDefinitionIfUnquoted(
const cmMakefile* mf, cmExpandedCommandArgument const& argument);
};
#endif #endif
+7 -5
View File
@@ -11,6 +11,7 @@
#include "cmMessageType.h" #include "cmMessageType.h"
#include "cmSystemTools.h" #include "cmSystemTools.h"
#include <string>
#include <utility> #include <utility>
cmWhileFunctionBlocker::cmWhileFunctionBlocker(cmMakefile* mf) cmWhileFunctionBlocker::cmWhileFunctionBlocker(cmMakefile* mf)
@@ -129,19 +130,20 @@ bool cmWhileFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
return false; return false;
} }
bool cmWhileCommand::InvokeInitialPass( bool cmWhileCommand(std::vector<cmListFileArgument> const& args,
const std::vector<cmListFileArgument>& args, cmExecutionStatus&) cmExecutionStatus& status)
{ {
if (args.empty()) { if (args.empty()) {
this->SetError("called with incorrect number of arguments"); status.SetError("called with incorrect number of arguments");
return false; return false;
} }
// create a function blocker // create a function blocker
{ {
auto fb = cm::make_unique<cmWhileFunctionBlocker>(this->Makefile); cmMakefile& makefile = status.GetMakefile();
auto fb = cm::make_unique<cmWhileFunctionBlocker>(&makefile);
fb->Args = args; fb->Args = args;
this->Makefile->AddFunctionBlocker(std::move(fb)); makefile.AddFunctionBlocker(std::move(fb));
} }
return true; return true;
} }
+2 -32
View File
@@ -5,12 +5,8 @@
#include "cmConfigure.h" // IWYU pragma: keep #include "cmConfigure.h" // IWYU pragma: keep
#include <string>
#include <vector> #include <vector>
#include "cm_memory.hxx"
#include "cmCommand.h"
#include "cmFunctionBlocker.h" #include "cmFunctionBlocker.h"
#include "cmListFileCache.h" #include "cmListFileCache.h"
@@ -35,33 +31,7 @@ private:
}; };
/// \brief Starts a while loop /// \brief Starts a while loop
class cmWhileCommand : public cmCommand bool cmWhileCommand(std::vector<cmListFileArgument> const& args,
{ cmExecutionStatus& status);
public:
/**
* This is a virtual constructor for the command.
*/
std::unique_ptr<cmCommand> Clone() override
{
return cm::make_unique<cmWhileCommand>();
}
/**
* This overrides the default InvokeInitialPass implementation.
* It records the arguments before expansion.
*/
bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
cmExecutionStatus&) override;
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
bool InitialPass(std::vector<std::string> const&,
cmExecutionStatus&) override
{
return false;
}
};
#endif #endif