Sfoglia il codice sorgente

cmCommand refactor: cmBreakCommand

Gabor Bencze 6 anni fa
parent
commit
e6a27adf9f
3 ha cambiato i file con 11 aggiunte e 31 eliminazioni
  1. 7 7
      Source/cmBreakCommand.cxx
  2. 3 23
      Source/cmBreakCommand.h
  3. 1 1
      Source/cmCommands.cxx

+ 7 - 7
Source/cmBreakCommand.cxx

@@ -10,14 +10,14 @@
 #include "cmPolicies.h"
 
 // cmBreakCommand
-bool cmBreakCommand::InitialPass(std::vector<std::string> const& args,
-                                 cmExecutionStatus& status)
+bool cmBreakCommand(std::vector<std::string> const& args,
+                    cmExecutionStatus& status)
 {
-  if (!this->Makefile->IsLoopBlock()) {
+  if (!status.GetMakefile().IsLoopBlock()) {
     bool issueMessage = true;
     std::ostringstream e;
     MessageType messageType = MessageType::AUTHOR_WARNING;
-    switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0055)) {
+    switch (status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0055)) {
       case cmPolicies::WARN:
         e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0055) << "\n";
         break;
@@ -34,7 +34,7 @@ bool cmBreakCommand::InitialPass(std::vector<std::string> const& args,
     if (issueMessage) {
       e << "A BREAK command was found outside of a proper "
            "FOREACH or WHILE loop scope.";
-      this->Makefile->IssueMessage(messageType, e.str());
+      status.GetMakefile().IssueMessage(messageType, e.str());
       if (messageType == MessageType::FATAL_ERROR) {
         return false;
       }
@@ -47,7 +47,7 @@ bool cmBreakCommand::InitialPass(std::vector<std::string> const& args,
     bool issueMessage = true;
     std::ostringstream e;
     MessageType messageType = MessageType::AUTHOR_WARNING;
-    switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0055)) {
+    switch (status.GetMakefile().GetPolicyStatus(cmPolicies::CMP0055)) {
       case cmPolicies::WARN:
         e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0055) << "\n";
         break;
@@ -63,7 +63,7 @@ bool cmBreakCommand::InitialPass(std::vector<std::string> const& args,
 
     if (issueMessage) {
       e << "The BREAK command does not accept any arguments.";
-      this->Makefile->IssueMessage(messageType, e.str());
+      status.GetMakefile().IssueMessage(messageType, e.str());
       if (messageType == MessageType::FATAL_ERROR) {
         return false;
       }

+ 3 - 23
Source/cmBreakCommand.h

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

+ 1 - 1
Source/cmCommands.cxx

@@ -116,7 +116,7 @@
 
 void GetScriptingCommands(cmState* state)
 {
-  state->AddBuiltinCommand("break", cm::make_unique<cmBreakCommand>());
+  state->AddBuiltinCommand("break", cmBreakCommand);
   state->AddBuiltinCommand("cmake_minimum_required",
                            cm::make_unique<cmCMakeMinimumRequired>());
   state->AddBuiltinCommand("cmake_policy",