فهرست منبع

cmCommand refactor: cmUnsetCommand

Gabor Bencze 6 سال پیش
والد
کامیت
c33c52bb32
3فایلهای تغییر یافته به همراه12 افزوده شده و 33 حذف شده
  1. 1 1
      Source/cmCommands.cxx
  2. 8 9
      Source/cmUnsetCommand.cxx
  3. 3 23
      Source/cmUnsetCommand.h

+ 1 - 1
Source/cmCommands.cxx

@@ -161,7 +161,7 @@ void GetScriptingCommands(cmState* state)
                            cm::make_unique<cmSetPropertyCommand>());
   state->AddBuiltinCommand("site_name", cmSiteNameCommand);
   state->AddBuiltinCommand("string", cm::make_unique<cmStringCommand>());
-  state->AddBuiltinCommand("unset", cm::make_unique<cmUnsetCommand>());
+  state->AddBuiltinCommand("unset", cmUnsetCommand);
   state->AddBuiltinCommand("while", cmWhileCommand);
 
   state->AddUnexpectedCommand(

+ 8 - 9
Source/cmUnsetCommand.cxx

@@ -2,18 +2,17 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmUnsetCommand.h"
 
+#include "cmExecutionStatus.h"
 #include "cmMakefile.h"
 #include "cmStringAlgorithms.h"
 #include "cmSystemTools.h"
 
-class cmExecutionStatus;
-
 // cmUnsetCommand
-bool cmUnsetCommand::InitialPass(std::vector<std::string> const& args,
-                                 cmExecutionStatus&)
+bool cmUnsetCommand(std::vector<std::string> const& args,
+                    cmExecutionStatus& status)
 {
   if (args.empty() || args.size() > 2) {
-    this->SetError("called with incorrect number of arguments");
+    status.SetError("called with incorrect number of arguments");
     return false;
   }
 
@@ -31,20 +30,20 @@ bool cmUnsetCommand::InitialPass(std::vector<std::string> const& args,
   }
   // unset(VAR)
   if (args.size() == 1) {
-    this->Makefile->RemoveDefinition(variable);
+    status.GetMakefile().RemoveDefinition(variable);
     return true;
   }
   // unset(VAR CACHE)
   if ((args.size() == 2) && (args[1] == "CACHE")) {
-    this->Makefile->RemoveCacheDefinition(variable);
+    status.GetMakefile().RemoveCacheDefinition(variable);
     return true;
   }
   // unset(VAR PARENT_SCOPE)
   if ((args.size() == 2) && (args[1] == "PARENT_SCOPE")) {
-    this->Makefile->RaiseScope(variable, nullptr);
+    status.GetMakefile().RaiseScope(variable, nullptr);
     return true;
   }
   // ERROR: second argument isn't CACHE or PARENT_SCOPE
-  this->SetError("called with an invalid second argument");
+  status.SetError("called with an invalid second argument");
   return false;
 }

+ 3 - 23
Source/cmUnsetCommand.h

@@ -8,34 +8,14 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
-
 class cmExecutionStatus;
 
-/** \class cmUnsetCommand
+/**
  * \brief Unset a CMAKE variable
  *
  * cmUnsetCommand unsets or removes a variable.
  */
-class cmUnsetCommand : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  std::unique_ptr<cmCommand> Clone() override
-  {
-    return cm::make_unique<cmUnsetCommand>();
-  }
-
-  /**
-   * This is called when the command is first encountered in
-   * the CMakeLists.txt file.
-   */
-  bool InitialPass(std::vector<std::string> const& args,
-                   cmExecutionStatus& status) override;
-};
+bool cmUnsetCommand(std::vector<std::string> const& args,
+                    cmExecutionStatus& status);
 
 #endif