cmState: introduce method for adding scripted commands

This commit is contained in:
Daniel Pfeifer 2017-05-10 21:33:06 +02:00
parent c734c8501b
commit a44dab461f
5 changed files with 10 additions and 10 deletions

View File

@ -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;

View File

@ -246,7 +246,7 @@ bool cmLoadCommandCommand::InitialPass(std::vector<std::string> 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. "

View File

@ -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;

View File

@ -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;

View File

@ -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<std::string> GetCommandNames() const;