summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRegina Pfeifer <regina@mailbox.org>2019-04-07 19:46:46 (GMT)
committerRegina Pfeifer <regina@mailbox.org>2019-07-21 07:25:32 (GMT)
commit28f2d12a055e025aa0ddeb9842f204f29181eaff (patch)
treec72caeac0330934a280f3a014688b43c55a11eea
parentde77d355ac1808164b7247290f45b8133ce1246b (diff)
downloadCMake-28f2d12a055e025aa0ddeb9842f204f29181eaff.zip
CMake-28f2d12a055e025aa0ddeb9842f204f29181eaff.tar.gz
CMake-28f2d12a055e025aa0ddeb9842f204f29181eaff.tar.bz2
cmCommand: De-virtualize function InvokeInitialPass
-rw-r--r--Source/cmCommand.h4
-rw-r--r--Source/cmCommands.cxx4
-rw-r--r--Source/cmIfCommand.cxx17
-rw-r--r--Source/cmIfCommand.h39
-rw-r--r--Source/cmWhileCommand.cxx12
-rw-r--r--Source/cmWhileCommand.h34
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<cmListFileArgument>& args,
- cmExecutionStatus& status);
+ bool InvokeInitialPass(const std::vector<cmListFileArgument>& 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<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",
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 <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;
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 <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
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 <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;
}
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 <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