From a44dab461ffe269618f008f16e249d9101c5bd88 Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer Date: Wed, 10 May 2017 21:33:06 +0200 Subject: cmState: introduce method for adding scripted commands --- Source/cmFunctionCommand.cxx | 6 +----- Source/cmLoadCommandCommand.cxx | 2 +- Source/cmMacroCommand.cxx | 5 +---- Source/cmState.cxx | 6 ++++++ Source/cmState.h | 1 + 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx index dccc29f..642b029 100644 --- a/Source/cmFunctionCommand.cxx +++ b/Source/cmFunctionCommand.cxx @@ -149,11 +149,7 @@ bool cmFunctionFunctionBlocker::IsFunctionBlocked( f->Functions = this->Functions; f->FilePath = this->GetStartingContext().FilePath; mf.RecordPolicies(f->Policies); - - std::string newName = "_" + this->Args[0]; - mf.GetState()->RenameCommand(this->Args[0], newName); - mf.GetState()->AddCommand(f); - + mf.GetState()->AddScriptedCommand(this->Args[0], f); // remove the function blocker now that the function is defined mf.RemoveFunctionBlocker(this, lff); return true; diff --git a/Source/cmLoadCommandCommand.cxx b/Source/cmLoadCommandCommand.cxx index 5cf1853..8bd212c 100644 --- a/Source/cmLoadCommandCommand.cxx +++ b/Source/cmLoadCommandCommand.cxx @@ -246,7 +246,7 @@ bool cmLoadCommandCommand::InitialPass(std::vector const& args, // create a function blocker and set it up cmLoadedCommand* f = new cmLoadedCommand(); (*initFunction)(&f->info); - this->Makefile->GetState()->AddCommand(f); + this->Makefile->GetState()->AddScriptedCommand(args[0], f); return true; } this->SetError("Attempt to load command failed. " diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 507b579..f386a22 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -184,10 +184,7 @@ bool cmMacroFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, f->Functions = this->Functions; f->FilePath = this->GetStartingContext().FilePath; mf.RecordPolicies(f->Policies); - std::string newName = "_" + this->Args[0]; - mf.GetState()->RenameCommand(this->Args[0], newName); - mf.GetState()->AddCommand(f); - + mf.GetState()->AddScriptedCommand(this->Args[0], f); // remove the function blocker now that the macro is defined mf.RemoveFunctionBlocker(this, lff); return true; diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 510501b..6de4c9f 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -433,6 +433,12 @@ void cmState::AddUnexpectedCommand(std::string const& name, const char* error) this->AddBuiltinCommand(name, new cmUnexpectedCommand(name, error)); } +void cmState::AddScriptedCommand(std::string const& name, cmCommand* command) +{ + this->RenameCommand(name, "_" + name); + this->AddCommand(command); +} + cmCommand* cmState::GetCommand(std::string const& name) const { cmCommand* command = CM_NULLPTR; diff --git a/Source/cmState.h b/Source/cmState.h index 603fe5d..895561e 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -126,6 +126,7 @@ public: void AddDisallowedCommand(std::string const& name, cmCommand* command, cmPolicies::PolicyID policy, const char* message); void AddUnexpectedCommand(std::string const& name, const char* error); + void AddScriptedCommand(std::string const& name, cmCommand* command); void RenameCommand(std::string const& oldName, std::string const& newName); void RemoveUserDefinedCommands(); std::vector GetCommandNames() const; -- cgit v0.12