Browse Source

Combine all unexpected commands to a single class

Daniel Pfeifer 9 years ago
parent
commit
67303794f0

+ 2 - 14
Source/CMakeLists.txt

@@ -440,24 +440,10 @@ set(SRCS
   cmCreateTestSourceList.h
   cmDefinePropertyCommand.cxx
   cmDefinePropertyCommand.h
-  cmElseCommand.cxx
-  cmElseCommand.h
-  cmElseIfCommand.cxx
-  cmElseIfCommand.h
   cmEnableLanguageCommand.cxx
   cmEnableLanguageCommand.h
   cmEnableTestingCommand.cxx
   cmEnableTestingCommand.h
-  cmEndForEachCommand.cxx
-  cmEndForEachCommand.h
-  cmEndFunctionCommand.cxx
-  cmEndFunctionCommand.h
-  cmEndIfCommand.cxx
-  cmEndIfCommand.h
-  cmEndMacroCommand.cxx
-  cmEndMacroCommand.h
-  cmEndWhileCommand.cxx
-  cmEndWhileCommand.h
   cmExecProgramCommand.cxx
   cmExecProgramCommand.h
   cmExecuteProcessCommand.cxx
@@ -612,6 +598,8 @@ set(SRCS
   cmTryCompileCommand.h
   cmTryRunCommand.cxx
   cmTryRunCommand.h
+  cmUnexpectedCommand.cxx
+  cmUnexpectedCommand.h
   cmUnsetCommand.cxx
   cmUnsetCommand.h
   cmUseMangledMesaCommand.cxx

+ 29 - 14
Source/cmCommands.cxx

@@ -18,14 +18,8 @@
 #include "cmContinueCommand.h"
 #include "cmCreateTestSourceList.h"
 #include "cmDefinePropertyCommand.h"
-#include "cmElseCommand.h"
 #include "cmEnableLanguageCommand.h"
 #include "cmEnableTestingCommand.h"
-#include "cmEndForEachCommand.h"
-#include "cmEndFunctionCommand.h"
-#include "cmEndIfCommand.h"
-#include "cmEndMacroCommand.h"
-#include "cmEndWhileCommand.h"
 #include "cmExecProgramCommand.h"
 #include "cmExecuteProcessCommand.h"
 #include "cmFileCommand.h"
@@ -74,6 +68,7 @@
 #include "cmTargetLinkLibrariesCommand.h"
 #include "cmTryCompileCommand.h"
 #include "cmTryRunCommand.h"
+#include "cmUnexpectedCommand.h"
 #include "cmUnsetCommand.h"
 #include "cmWhileCommand.h"
 
@@ -82,7 +77,6 @@
 #include "cmAuxSourceDirectoryCommand.h"
 #include "cmBuildNameCommand.h"
 #include "cmCMakeHostSystemInformationCommand.h"
-#include "cmElseIfCommand.h"
 #include "cmExportCommand.h"
 #include "cmExportLibraryDependenciesCommand.h"
 #include "cmFLTKWrapUICommand.h"
@@ -130,14 +124,8 @@ std::vector<cmCommand*> GetPredefinedCommands()
   commands.push_back(new cmContinueCommand);
   commands.push_back(new cmCreateTestSourceList);
   commands.push_back(new cmDefinePropertyCommand);
-  commands.push_back(new cmElseCommand);
   commands.push_back(new cmEnableLanguageCommand);
   commands.push_back(new cmEnableTestingCommand);
-  commands.push_back(new cmEndForEachCommand);
-  commands.push_back(new cmEndFunctionCommand);
-  commands.push_back(new cmEndIfCommand);
-  commands.push_back(new cmEndMacroCommand);
-  commands.push_back(new cmEndWhileCommand);
   commands.push_back(new cmExecProgramCommand);
   commands.push_back(new cmExecuteProcessCommand);
   commands.push_back(new cmFileCommand);
@@ -189,12 +177,39 @@ std::vector<cmCommand*> GetPredefinedCommands()
   commands.push_back(new cmUnsetCommand);
   commands.push_back(new cmWhileCommand);
 
+  commands.push_back(new cmUnexpectedCommand(
+    "else", "An ELSE command was found outside of a proper "
+            "IF ENDIF structure. Or its arguments did not match "
+            "the opening IF command."));
+  commands.push_back(new cmUnexpectedCommand(
+    "elseif", "An ELSEIF command was found outside of a proper "
+              "IF ENDIF structure."));
+  commands.push_back(new cmUnexpectedCommand(
+    "endforeach", "An ENDFOREACH command was found outside of a proper "
+                  "FOREACH ENDFOREACH structure. Or its arguments did "
+                  "not match the opening FOREACH command."));
+  commands.push_back(new cmUnexpectedCommand(
+    "endfunction", "An ENDFUNCTION command was found outside of a proper "
+                   "FUNCTION ENDFUNCTION structure. Or its arguments did not "
+                   "match the opening FUNCTION command."));
+  commands.push_back(new cmUnexpectedCommand(
+    "endif", "An ENDIF command was found outside of a proper "
+             "IF ENDIF structure. Or its arguments did not match "
+             "the opening IF command."));
+  commands.push_back(new cmUnexpectedCommand(
+    "endmacro", "An ENDMACRO command was found outside of a proper "
+                "MACRO ENDMACRO structure. Or its arguments did not "
+                "match the opening MACRO command."));
+  commands.push_back(new cmUnexpectedCommand(
+    "endwhile", "An ENDWHILE command was found outside of a proper "
+                "WHILE ENDWHILE structure. Or its arguments did not "
+                "match the opening WHILE command."));
+
 #if defined(CMAKE_BUILD_WITH_CMAKE)
   commands.push_back(new cmAddCompileOptionsCommand);
   commands.push_back(new cmAuxSourceDirectoryCommand);
   commands.push_back(new cmBuildNameCommand);
   commands.push_back(new cmCMakeHostSystemInformationCommand);
-  commands.push_back(new cmElseIfCommand);
   commands.push_back(new cmExportCommand);
   commands.push_back(new cmExportLibraryDependenciesCommand);
   commands.push_back(new cmFLTKWrapUICommand);

+ 0 - 14
Source/cmElseCommand.cxx

@@ -1,14 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#include "cmElseCommand.h"
-
-class cmExecutionStatus;
-
-bool cmElseCommand::InitialPass(std::vector<std::string> const&,
-                                cmExecutionStatus&)
-{
-  this->SetError("An ELSE command was found outside of a proper "
-                 "IF ENDIF structure. Or its arguments did not match "
-                 "the opening IF command.");
-  return false;
-}

+ 0 - 45
Source/cmElseCommand.h

@@ -1,45 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#ifndef cmElseCommand_h
-#define cmElseCommand_h
-
-#include <cmConfigure.h>
-#include <string>
-#include <vector>
-
-#include "cmCommand.h"
-
-class cmExecutionStatus;
-
-/** \class cmElseCommand
- * \brief ends an if block
- *
- * cmElseCommand ends an if block
- */
-class cmElseCommand : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  cmCommand* Clone() CM_OVERRIDE { return new cmElseCommand; }
-
-  /**
-   * This is called when the command is first encountered in
-   * the CMakeLists.txt file.
-   */
-  bool InitialPass(std::vector<std::string> const& args,
-                   cmExecutionStatus& status) CM_OVERRIDE;
-
-  /**
-   * This determines if the command is invoked when in script mode.
-   */
-  bool IsScriptable() const CM_OVERRIDE { return true; }
-
-  /**
-   * The name of the command as specified in CMakeList.txt.
-   */
-  std::string GetName() const CM_OVERRIDE { return "else"; }
-};
-
-#endif

+ 0 - 13
Source/cmElseIfCommand.cxx

@@ -1,13 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#include "cmElseIfCommand.h"
-
-class cmExecutionStatus;
-
-bool cmElseIfCommand::InitialPass(std::vector<std::string> const&,
-                                  cmExecutionStatus&)
-{
-  this->SetError("An ELSEIF command was found outside of a proper "
-                 "IF ENDIF structure.");
-  return false;
-}

+ 0 - 45
Source/cmElseIfCommand.h

@@ -1,45 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#ifndef cmElseIfCommand_h
-#define cmElseIfCommand_h
-
-#include <cmConfigure.h>
-#include <string>
-#include <vector>
-
-#include "cmCommand.h"
-
-class cmExecutionStatus;
-
-/** \class cmElseIfCommand
- * \brief ends an if block
- *
- * cmElseIfCommand ends an if block
- */
-class cmElseIfCommand : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  cmCommand* Clone() CM_OVERRIDE { return new cmElseIfCommand; }
-
-  /**
-   * This is called when the command is first encountered in
-   * the CMakeLists.txt file.
-   */
-  bool InitialPass(std::vector<std::string> const& args,
-                   cmExecutionStatus& status) CM_OVERRIDE;
-
-  /**
-   * This determines if the command is invoked when in script mode.
-   */
-  bool IsScriptable() const CM_OVERRIDE { return true; }
-
-  /**
-   * The name of the command as specified in CMakeList.txt.
-   */
-  std::string GetName() const CM_OVERRIDE { return "elseif"; }
-};
-
-#endif

+ 0 - 14
Source/cmEndForEachCommand.cxx

@@ -1,14 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#include "cmEndForEachCommand.h"
-
-class cmExecutionStatus;
-
-bool cmEndForEachCommand::InitialPass(std::vector<std::string> const&,
-                                      cmExecutionStatus&)
-{
-  this->SetError("An ENDFOREACH command was found outside of a proper "
-                 "FOREACH ENDFOREACH structure. Or its arguments did "
-                 "not match the opening FOREACH command.");
-  return false;
-}

+ 0 - 45
Source/cmEndForEachCommand.h

@@ -1,45 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#ifndef cmEndForEachCommand_h
-#define cmEndForEachCommand_h
-
-#include <cmConfigure.h>
-#include <string>
-#include <vector>
-
-#include "cmCommand.h"
-
-class cmExecutionStatus;
-
-/** \class cmEndForEachCommand
- * \brief ends an if block
- *
- * cmEndForEachCommand ends an if block
- */
-class cmEndForEachCommand : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  cmCommand* Clone() CM_OVERRIDE { return new cmEndForEachCommand; }
-
-  /**
-   * This is called when the command is first encountered in
-   * the CMakeLists.txt file.
-   */
-  bool InitialPass(std::vector<std::string> const&,
-                   cmExecutionStatus&) CM_OVERRIDE;
-
-  /**
-   * This determines if the command is invoked when in script mode.
-   */
-  bool IsScriptable() const CM_OVERRIDE { return true; }
-
-  /**
-   * The name of the command as specified in CMakeList.txt.
-   */
-  std::string GetName() const CM_OVERRIDE { return "endforeach"; }
-};
-
-#endif

+ 0 - 14
Source/cmEndFunctionCommand.cxx

@@ -1,14 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#include "cmEndFunctionCommand.h"
-
-class cmExecutionStatus;
-
-bool cmEndFunctionCommand::InitialPass(std::vector<std::string> const&,
-                                       cmExecutionStatus&)
-{
-  this->SetError("An ENDFUNCTION command was found outside of a proper "
-                 "FUNCTION ENDFUNCTION structure. Or its arguments did not "
-                 "match the opening FUNCTION command.");
-  return false;
-}

+ 0 - 45
Source/cmEndFunctionCommand.h

@@ -1,45 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#ifndef cmEndFunctionCommand_h
-#define cmEndFunctionCommand_h
-
-#include <cmConfigure.h>
-#include <string>
-#include <vector>
-
-#include "cmCommand.h"
-
-class cmExecutionStatus;
-
-/** \class cmEndFunctionCommand
- * \brief ends an if block
- *
- * cmEndFunctionCommand ends an if block
- */
-class cmEndFunctionCommand : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  cmCommand* Clone() CM_OVERRIDE { return new cmEndFunctionCommand; }
-
-  /**
-   * This is called when the command is first encountered in
-   * the CMakeLists.txt file.
-   */
-  bool InitialPass(std::vector<std::string> const&,
-                   cmExecutionStatus&) CM_OVERRIDE;
-
-  /**
-   * This determines if the command is invoked when in script mode.
-   */
-  bool IsScriptable() const CM_OVERRIDE { return true; }
-
-  /**
-   * The name of the command as specified in CMakeList.txt.
-   */
-  std::string GetName() const CM_OVERRIDE { return "endfunction"; }
-};
-
-#endif

+ 0 - 24
Source/cmEndIfCommand.cxx

@@ -1,24 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#include "cmEndIfCommand.h"
-
-#include <stdlib.h> // required for atof
-
-#include "cmMakefile.h"
-
-class cmExecutionStatus;
-
-bool cmEndIfCommand::InitialPass(std::vector<std::string> const&,
-                                 cmExecutionStatus&)
-{
-  const char* versionValue =
-    this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
-  if (!versionValue || (atof(versionValue) <= 1.4)) {
-    return true;
-  }
-
-  this->SetError("An ENDIF command was found outside of a proper "
-                 "IF ENDIF structure. Or its arguments did not match "
-                 "the opening IF command.");
-  return false;
-}

+ 0 - 45
Source/cmEndIfCommand.h

@@ -1,45 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#ifndef cmEndIfCommand_h
-#define cmEndIfCommand_h
-
-#include <cmConfigure.h>
-#include <string>
-#include <vector>
-
-#include "cmCommand.h"
-
-class cmExecutionStatus;
-
-/** \class cmEndIfCommand
- * \brief ends an if block
- *
- * cmEndIfCommand ends an if block
- */
-class cmEndIfCommand : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  cmCommand* Clone() CM_OVERRIDE { return new cmEndIfCommand; }
-
-  /**
-   * This is called when the command is first encountered in
-   * the CMakeLists.txt file.
-   */
-  bool InitialPass(std::vector<std::string> const& args,
-                   cmExecutionStatus& status) CM_OVERRIDE;
-
-  /**
-   * This determines if the command is invoked when in script mode.
-   */
-  bool IsScriptable() const CM_OVERRIDE { return true; }
-
-  /**
-   * The name of the command as specified in CMakeList.txt.
-   */
-  std::string GetName() const CM_OVERRIDE { return "endif"; }
-};
-
-#endif

+ 0 - 14
Source/cmEndMacroCommand.cxx

@@ -1,14 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#include "cmEndMacroCommand.h"
-
-class cmExecutionStatus;
-
-bool cmEndMacroCommand::InitialPass(std::vector<std::string> const&,
-                                    cmExecutionStatus&)
-{
-  this->SetError("An ENDMACRO command was found outside of a proper "
-                 "MACRO ENDMACRO structure. Or its arguments did not "
-                 "match the opening MACRO command.");
-  return false;
-}

+ 0 - 45
Source/cmEndMacroCommand.h

@@ -1,45 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#ifndef cmEndMacroCommand_h
-#define cmEndMacroCommand_h
-
-#include <cmConfigure.h>
-#include <string>
-#include <vector>
-
-#include "cmCommand.h"
-
-class cmExecutionStatus;
-
-/** \class cmEndMacroCommand
- * \brief ends an if block
- *
- * cmEndMacroCommand ends an if block
- */
-class cmEndMacroCommand : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  cmCommand* Clone() CM_OVERRIDE { return new cmEndMacroCommand; }
-
-  /**
-   * This is called when the command is first encountered in
-   * the CMakeLists.txt file.
-   */
-  bool InitialPass(std::vector<std::string> const&,
-                   cmExecutionStatus&) CM_OVERRIDE;
-
-  /**
-   * This determines if the command is invoked when in script mode.
-   */
-  bool IsScriptable() const CM_OVERRIDE { return true; }
-
-  /**
-   * The name of the command as specified in CMakeList.txt.
-   */
-  std::string GetName() const CM_OVERRIDE { return "endmacro"; }
-};
-
-#endif

+ 0 - 14
Source/cmEndWhileCommand.cxx

@@ -1,14 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#include "cmEndWhileCommand.h"
-
-class cmExecutionStatus;
-
-bool cmEndWhileCommand::InitialPass(std::vector<std::string> const&,
-                                    cmExecutionStatus&)
-{
-  this->SetError("An ENDWHILE command was found outside of a proper "
-                 "WHILE ENDWHILE structure. Or its arguments did not "
-                 "match the opening WHILE command.");
-  return false;
-}

+ 0 - 45
Source/cmEndWhileCommand.h

@@ -1,45 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#ifndef cmEndWhileCommand_h
-#define cmEndWhileCommand_h
-
-#include <cmConfigure.h>
-#include <string>
-#include <vector>
-
-#include "cmCommand.h"
-
-class cmExecutionStatus;
-
-/** \class cmEndWhileCommand
- * \brief ends a while loop
- *
- * cmEndWhileCommand ends a while loop
- */
-class cmEndWhileCommand : public cmCommand
-{
-public:
-  /**
-   * This is a virtual constructor for the command.
-   */
-  cmCommand* Clone() CM_OVERRIDE { return new cmEndWhileCommand; }
-
-  /**
-   * This is called when the command is first encountered in
-   * the CMakeLists.txt file.
-   */
-  bool InitialPass(std::vector<std::string> const&,
-                   cmExecutionStatus&) CM_OVERRIDE;
-
-  /**
-   * This determines if the command is invoked when in script mode.
-   */
-  bool IsScriptable() const CM_OVERRIDE { return true; }
-
-  /**
-   * The name of the command as specified in CMakeList.txt.
-   */
-  std::string GetName() const CM_OVERRIDE { return "endwhile"; }
-};
-
-#endif

+ 22 - 0
Source/cmUnexpectedCommand.cxx

@@ -0,0 +1,22 @@
+/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+   file Copyright.txt or https://cmake.org/licensing for details.  */
+#include "cmUnexpectedCommand.h"
+
+#include <stdlib.h>
+
+#include "cmMakefile.h"
+
+class cmExecutionStatus;
+
+bool cmUnexpectedCommand::InitialPass(std::vector<std::string> const&,
+                                      cmExecutionStatus&)
+{
+  const char* versionValue =
+    this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
+  if (this->Name == "endif" && (!versionValue || atof(versionValue) <= 1.4)) {
+    return true;
+  }
+
+  this->SetError(this->Error);
+  return false;
+}

+ 40 - 0
Source/cmUnexpectedCommand.h

@@ -0,0 +1,40 @@
+/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+   file Copyright.txt or https://cmake.org/licensing for details.  */
+#ifndef cmUnexpectedCommand_h
+#define cmUnexpectedCommand_h
+
+#include <cmConfigure.h>
+#include <string>
+#include <vector>
+
+#include "cmCommand.h"
+
+class cmExecutionStatus;
+
+class cmUnexpectedCommand : public cmCommand
+{
+public:
+  cmUnexpectedCommand(std::string const& name, const char* error)
+    : Name(name)
+    , Error(error)
+  {
+  }
+
+  cmCommand* Clone() CM_OVERRIDE
+  {
+    return new cmUnexpectedCommand(this->Name, this->Error);
+  }
+
+  bool InitialPass(std::vector<std::string> const& args,
+                   cmExecutionStatus& status) CM_OVERRIDE;
+
+  bool IsScriptable() const CM_OVERRIDE { return true; }
+
+  std::string GetName() const CM_OVERRIDE { return this->Name; }
+
+private:
+  std::string Name;
+  const char* Error;
+};
+
+#endif

+ 1 - 6
bootstrap

@@ -277,14 +277,8 @@ CMAKE_CXX_SOURCES="\
   cmDepends \
   cmDependsC \
   cmDocumentationFormatter \
-  cmElseCommand \
   cmEnableLanguageCommand \
   cmEnableTestingCommand \
-  cmEndForEachCommand \
-  cmEndFunctionCommand \
-  cmEndIfCommand \
-  cmEndMacroCommand \
-  cmEndWhileCommand \
   cmExecProgramCommand \
   cmExecuteProcessCommand \
   cmExpandedCommandArgument \
@@ -406,6 +400,7 @@ CMAKE_CXX_SOURCES="\
   cmTimestamp \
   cmTryCompileCommand \
   cmTryRunCommand \
+  cmUnexpectedCommand \
   cmUnsetCommand \
   cmVersion \
   cmWhileCommand \