Răsfoiți Sursa

cmState: introduce method for adding scripted commands

Daniel Pfeifer 8 ani în urmă
părinte
comite
a44dab461f

+ 1 - 5
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;

+ 1 - 1
Source/cmLoadCommandCommand.cxx

@@ -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. "

+ 1 - 4
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;

+ 6 - 0
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;

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