Browse Source

cmCommand refactor: cmIncludeGuardCommand

Gabor Bencze 6 years ago
parent
commit
ceab7bda44
3 changed files with 10 additions and 31 deletions
  1. 1 2
      Source/cmCommands.cxx
  2. 6 6
      Source/cmIncludeGuardCommand.cxx
  3. 3 23
      Source/cmIncludeGuardCommand.h

+ 1 - 2
Source/cmCommands.cxx

@@ -143,8 +143,7 @@ void GetScriptingCommands(cmState* state)
   state->AddBuiltinCommand("get_property", cmGetPropertyCommand);
   state->AddBuiltinCommand("if", cmIfCommand);
   state->AddBuiltinCommand("include", cmIncludeCommand);
-  state->AddBuiltinCommand("include_guard",
-                           cm::make_unique<cmIncludeGuardCommand>());
+  state->AddBuiltinCommand("include_guard", cmIncludeGuardCommand);
   state->AddBuiltinCommand("list", cm::make_unique<cmListCommand>());
   state->AddBuiltinCommand("macro", cm::make_unique<cmMacroCommand>());
   state->AddBuiltinCommand("make_directory",

+ 6 - 6
Source/cmIncludeGuardCommand.cxx

@@ -50,11 +50,11 @@ bool CheckIncludeGuardIsSet(cmMakefile* mf, std::string const& includeGuardVar)
 } // anonymous namespace
 
 // cmIncludeGuardCommand
-bool cmIncludeGuardCommand::InitialPass(std::vector<std::string> const& args,
-                                        cmExecutionStatus& status)
+bool cmIncludeGuardCommand(std::vector<std::string> const& args,
+                           cmExecutionStatus& status)
 {
   if (args.size() > 1) {
-    this->SetError(
+    status.SetError(
       "given an invalid number of arguments. The command takes at "
       "most 1 argument.");
     return false;
@@ -69,15 +69,15 @@ bool cmIncludeGuardCommand::InitialPass(std::vector<std::string> const& args,
     } else if (arg == "GLOBAL") {
       scope = GLOBAL;
     } else {
-      this->SetError("given an invalid scope: " + arg);
+      status.SetError("given an invalid scope: " + arg);
       return false;
     }
   }
 
   std::string includeGuardVar = GetIncludeGuardVariableName(
-    this->Makefile->GetDefinition("CMAKE_CURRENT_LIST_FILE"));
+    status.GetMakefile().GetDefinition("CMAKE_CURRENT_LIST_FILE"));
 
-  cmMakefile* const mf = this->Makefile;
+  cmMakefile* const mf = &status.GetMakefile();
 
   switch (scope) {
     case VARIABLE:

+ 3 - 23
Source/cmIncludeGuardCommand.h

@@ -8,35 +8,15 @@
 #include <string>
 #include <vector>
 
-#include "cm_memory.hxx"
-
-#include "cmCommand.h"
-
 class cmExecutionStatus;
 
-/** \class cmIncludeGuardCommand
+/**
  * \brief cmIncludeGuardCommand identical to C++ #pragma_once command
  * Can work in 3 modes: GLOBAL (works on global properties),
  * DIRECTORY(use directory property), VARIABLE(unnamed overload without
  * arguments) define an ordinary variable to be used as include guard checker
  */
-class cmIncludeGuardCommand : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  std::unique_ptr<cmCommand> Clone() override
-  {
-    return cm::make_unique<cmIncludeGuardCommand>();
-  }
-
-  /**
-   * 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 cmIncludeGuardCommand(std::vector<std::string> const& args,
+                           cmExecutionStatus& status);
 
 #endif