Browse Source

cmCommand refactor: cmMarkAsAdvancedCommand

Gabor Bencze 6 years ago
parent
commit
2b58ae7577
3 changed files with 10 additions and 32 deletions
  1. 1 2
      Source/cmCommands.cxx
  2. 6 7
      Source/cmMarkAsAdvancedCommand.cxx
  3. 3 23
      Source/cmMarkAsAdvancedCommand.h

+ 1 - 2
Source/cmCommands.cxx

@@ -147,8 +147,7 @@ void GetScriptingCommands(cmState* state)
   state->AddBuiltinCommand("list", cmListCommand);
   state->AddBuiltinCommand("macro", cmMacroCommand);
   state->AddBuiltinCommand("make_directory", cmMakeDirectoryCommand);
-  state->AddBuiltinCommand("mark_as_advanced",
-                           cm::make_unique<cmMarkAsAdvancedCommand>());
+  state->AddBuiltinCommand("mark_as_advanced", cmMarkAsAdvancedCommand);
   state->AddBuiltinCommand("math", cm::make_unique<cmMathCommand>());
   state->AddBuiltinCommand("message", cm::make_unique<cmMessageCommand>());
   state->AddBuiltinCommand("option", cm::make_unique<cmOptionCommand>());

+ 6 - 7
Source/cmMarkAsAdvancedCommand.cxx

@@ -2,20 +2,19 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmMarkAsAdvancedCommand.h"
 
+#include "cmExecutionStatus.h"
 #include "cmMakefile.h"
 #include "cmState.h"
 #include "cmStateTypes.h"
 #include "cmSystemTools.h"
 #include "cmake.h"
 
-class cmExecutionStatus;
-
 // cmMarkAsAdvancedCommand
-bool cmMarkAsAdvancedCommand::InitialPass(std::vector<std::string> const& args,
-                                          cmExecutionStatus&)
+bool cmMarkAsAdvancedCommand(std::vector<std::string> 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;
   }
 
@@ -31,9 +30,9 @@ bool cmMarkAsAdvancedCommand::InitialPass(std::vector<std::string> const& args,
   }
   for (; i < args.size(); ++i) {
     std::string const& variable = args[i];
-    cmState* state = this->Makefile->GetState();
+    cmState* state = status.GetMakefile().GetState();
     if (!state->GetCacheEntryValue(variable)) {
-      this->Makefile->GetCMakeInstance()->AddCacheEntry(
+      status.GetMakefile().GetCMakeInstance()->AddCacheEntry(
         variable, nullptr, nullptr, cmStateEnums::UNINITIALIZED);
       overwrite = true;
     }

+ 3 - 23
Source/cmMarkAsAdvancedCommand.h

@@ -8,34 +8,14 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
-
 class cmExecutionStatus;
 
-/** \class cmMarkAsAdvancedCommand
+/**
  * \brief mark_as_advanced command
  *
  * cmMarkAsAdvancedCommand implements the mark_as_advanced CMake command
  */
-class cmMarkAsAdvancedCommand : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  std::unique_ptr<cmCommand> Clone() override
-  {
-    return cm::make_unique<cmMarkAsAdvancedCommand>();
-  }
-
-  /**
-   * 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 cmMarkAsAdvancedCommand(std::vector<std::string> const& args,
+                             cmExecutionStatus& status);
 
 #endif