mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-01 19:30:13 -06:00
cmCommand: De-virtualize function InvokeInitialPass
This commit is contained in:
@@ -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<cmListFileArgument>& args,
|
||||
cmExecutionStatus& status);
|
||||
bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
|
||||
cmExecutionStatus& status);
|
||||
|
||||
/**
|
||||
* This is called when the command is first encountered in
|
||||
|
||||
@@ -147,7 +147,7 @@ void GetScriptingCommands(cmState* state)
|
||||
cm::make_unique<cmGetFilenameComponentCommand>());
|
||||
state->AddBuiltinCommand("get_property",
|
||||
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_guard",
|
||||
cm::make_unique<cmIncludeGuardCommand>());
|
||||
@@ -173,7 +173,7 @@ void GetScriptingCommands(cmState* state)
|
||||
state->AddBuiltinCommand("site_name", cm::make_unique<cmSiteNameCommand>());
|
||||
state->AddBuiltinCommand("string", cm::make_unique<cmStringCommand>());
|
||||
state->AddBuiltinCommand("unset", cm::make_unique<cmUnsetCommand>());
|
||||
state->AddBuiltinCommand("while", cm::make_unique<cmWhileCommand>());
|
||||
state->AddBuiltinCommand("while", cmWhileCommand);
|
||||
|
||||
state->AddUnexpectedCommand(
|
||||
"else",
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmake.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
static std::string cmIfCommandError(
|
||||
@@ -176,19 +177,19 @@ bool cmIfFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
bool cmIfCommand::InvokeInitialPass(
|
||||
const std::vector<cmListFileArgument>& args, cmExecutionStatus&)
|
||||
bool cmIfCommand(std::vector<cmListFileArgument> const& args,
|
||||
cmExecutionStatus& inStatus)
|
||||
{
|
||||
cmMakefile& makefile = inStatus.GetMakefile();
|
||||
std::string errorString;
|
||||
|
||||
std::vector<cmExpandedCommandArgument> 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;
|
||||
|
||||
@@ -5,17 +5,12 @@
|
||||
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<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);
|
||||
};
|
||||
bool cmIfCommand(std::vector<cmListFileArgument> const& args,
|
||||
cmExecutionStatus& status);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "cmMessageType.h"
|
||||
#include "cmSystemTools.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
cmWhileFunctionBlocker::cmWhileFunctionBlocker(cmMakefile* mf)
|
||||
@@ -129,19 +130,20 @@ bool cmWhileFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cmWhileCommand::InvokeInitialPass(
|
||||
const std::vector<cmListFileArgument>& args, cmExecutionStatus&)
|
||||
bool cmWhileCommand(std::vector<cmListFileArgument> 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<cmWhileFunctionBlocker>(this->Makefile);
|
||||
cmMakefile& makefile = status.GetMakefile();
|
||||
auto fb = cm::make_unique<cmWhileFunctionBlocker>(&makefile);
|
||||
fb->Args = args;
|
||||
this->Makefile->AddFunctionBlocker(std::move(fb));
|
||||
makefile.AddFunctionBlocker(std::move(fb));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,12 +5,8 @@
|
||||
|
||||
#include "cmConfigure.h" // IWYU pragma: keep
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<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;
|
||||
}
|
||||
};
|
||||
bool cmWhileCommand(std::vector<cmListFileArgument> const& args,
|
||||
cmExecutionStatus& status);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user