[cmake-developers] Please review patch for 'continue' keyword
Gregor Jasny
gjasny at googlemail.com
Fri Oct 31 16:00:11 EDT 2014
Hello,
I use CMake extensively for cross platform and sometimes I write really
complex functions. Sometimes I wish we had a 'continue' keyword to keep
loops readable. There is a wishlist report about that and Doug Barbieri
even added a patch:
http://www.cmake.org/Bug/view.php?id=14013
I re-applied the patch to master, fixed some bit-rot and formatted it
via git format-patch (also attached). Could you please take a look? It
would be great if the 'continue' keyword support would be part of CMake
3.2.
Thanks,
Gregor
PS: I'm unable to see Doug Barbieri email address in Mantis, so I cannot
properly attribute him as original patch author.
-------------- next part --------------
From 55dd89a8105e5576b1f6a3c0fde7ed7ffc8418ed Mon Sep 17 00:00:00 2001
From: Gregor Jasny <gjasny at googlemail.com>
Date: Thu, 23 Oct 2014 09:28:55 +0200
Subject: [PATCH] Add continue keyword (#14013)
Original patch by Doug Barbieri.
Signed-off-by: Gregor Jasny <gjasny at googlemail.com>
---
Help/command/continue.rst | 7 ++++++
Source/cmBootstrapCommands1.cxx | 2 ++
Source/cmContinueCommand.cxx | 21 ++++++++++++++++
Source/cmContinueCommand.h | 55 +++++++++++++++++++++++++++++++++++++++++
Source/cmExecutionStatus.h | 7 ++++++
Source/cmForEachCommand.cxx | 4 +++
Source/cmIfCommand.cxx | 5 ++++
Source/cmWhileCommand.cxx | 4 +++
8 files changed, 105 insertions(+)
create mode 100644 Help/command/continue.rst
create mode 100644 Source/cmContinueCommand.cxx
create mode 100644 Source/cmContinueCommand.h
diff --git a/Help/command/continue.rst b/Help/command/continue.rst
new file mode 100644
index 0000000..d377542
--- /dev/null
+++ b/Help/command/continue.rst
@@ -0,0 +1,7 @@
+continue
+--------
+
+Continue to the top of enclosing foreach or while loop.
+
+Continue allows the cmake script to abort the rest of a block in a foreach
+or while loop, and start at the top of the next iteration. See also break().
diff --git a/Source/cmBootstrapCommands1.cxx b/Source/cmBootstrapCommands1.cxx
index 9093579..d129aef 100644
--- a/Source/cmBootstrapCommands1.cxx
+++ b/Source/cmBootstrapCommands1.cxx
@@ -28,6 +28,7 @@
#include "cmCMakePolicyCommand.cxx"
#include "cmCommandArgumentsHelper.cxx"
#include "cmConfigureFileCommand.cxx"
+#include "cmContinueCommand.cxx"
#include "cmCoreTryCompile.cxx"
#include "cmCreateTestSourceList.cxx"
#include "cmDefinePropertyCommand.cxx"
@@ -68,6 +69,7 @@ void GetBootstrapCommands1(std::list<cmCommand*>& commands)
commands.push_back(new cmCMakeMinimumRequired);
commands.push_back(new cmCMakePolicyCommand);
commands.push_back(new cmConfigureFileCommand);
+ commands.push_back(new cmContinueCommand);
commands.push_back(new cmCreateTestSourceList);
commands.push_back(new cmDefinePropertyCommand);
commands.push_back(new cmElseCommand);
diff --git a/Source/cmContinueCommand.cxx b/Source/cmContinueCommand.cxx
new file mode 100644
index 0000000..ecb894b
--- /dev/null
+++ b/Source/cmContinueCommand.cxx
@@ -0,0 +1,21 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+#include "cmContinueCommand.h"
+
+// cmContinueCommand
+bool cmContinueCommand::InitialPass(std::vector<std::string> const&,
+ cmExecutionStatus &status)
+{
+ status.SetContinueInvoked(true);
+ return true;
+}
+
diff --git a/Source/cmContinueCommand.h b/Source/cmContinueCommand.h
new file mode 100644
index 0000000..2107637
--- /dev/null
+++ b/Source/cmContinueCommand.h
@@ -0,0 +1,55 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+#ifndef cmContinueCommand_h
+#define cmContinueCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmContinueCommand
+ * \brief Continue from an enclosing foreach or while loop
+ *
+ * cmContinueCommand returns from an enclosing foreach or while loop
+ */
+class cmContinueCommand : public cmCommand
+{
+public:
+ /**
+ * This is a virtual constructor for the command.
+ */
+ virtual cmCommand* Clone()
+ {
+ return new cmContinueCommand;
+ }
+
+ /**
+ * This is called when the command is first encountered in
+ * the CMakeLists.txt file.
+ */
+ virtual bool InitialPass(std::vector<std::string> const& args,
+ cmExecutionStatus &status);
+
+ /**
+ * This determines if the command is invoked when in script mode.
+ */
+ virtual bool IsScriptable() const { return true; }
+
+ /**
+ * The name of the command as specified in CMakeList.txt.
+ */
+ virtual std::string GetName() const { return "continue"; }
+
+ cmTypeMacro(cmContinueCommand, cmCommand);
+};
+
+
+
+#endif
diff --git a/Source/cmExecutionStatus.h b/Source/cmExecutionStatus.h
index 5c94a97..d4da5a4 100644
--- a/Source/cmExecutionStatus.h
+++ b/Source/cmExecutionStatus.h
@@ -36,10 +36,16 @@ public:
virtual bool GetBreakInvoked()
{ return this->BreakInvoked; }
+ virtual void SetContinueInvoked(bool val)
+ { this->ContinueInvoked = val; }
+ virtual bool GetContinueInvoked()
+ { return this->ContinueInvoked; }
+
virtual void Clear()
{
this->ReturnInvoked = false;
this->BreakInvoked = false;
+ this->ContinueInvoked = false;
this->NestedError = false;
}
virtual void SetNestedError(bool val) { this->NestedError = val; }
@@ -49,6 +55,7 @@ public:
protected:
bool ReturnInvoked;
bool BreakInvoked;
+ bool ContinueInvoked;
bool NestedError;
};
diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx
index e3f66c1..dfb9ae7 100644
--- a/Source/cmForEachCommand.cxx
+++ b/Source/cmForEachCommand.cxx
@@ -67,6 +67,10 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
mf.AddDefinition(this->Args[0],oldDef.c_str());
return true;
}
+ if (status.GetContinueInvoked())
+ {
+ break;
+ }
if(cmSystemTools::GetFatalErrorOccured() )
{
return true;
diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx
index f728c15..b8e30b7 100644
--- a/Source/cmIfCommand.cxx
+++ b/Source/cmIfCommand.cxx
@@ -151,6 +151,11 @@ IsFunctionBlocked(const cmListFileFunction& lff,
inStatus.SetBreakInvoked(true);
return true;
}
+ if (status.GetContinueInvoked())
+ {
+ inStatus.SetContinueInvoked(true);
+ return true;
+ }
}
}
return true;
diff --git a/Source/cmWhileCommand.cxx b/Source/cmWhileCommand.cxx
index 851c4cb..d648a0c 100644
--- a/Source/cmWhileCommand.cxx
+++ b/Source/cmWhileCommand.cxx
@@ -81,6 +81,10 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
{
return true;
}
+ if (status.GetContinueInvoked())
+ {
+ break;
+ }
if(cmSystemTools::GetFatalErrorOccured() )
{
return true;
--
1.9.3 (Apple Git-50)
More information about the cmake-developers
mailing list