summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
authorGregor Jasny <gjasny@googlemail.com>2014-11-18 15:34:30 (GMT)
committerBrad King <brad.king@kitware.com>2014-11-25 19:14:15 (GMT)
commitbae604d9a80d5d97c676c85848e37783a153ff19 (patch)
treef2b423072548cf614d9a4248381ad15f8800960a /Source/cmMakefile.cxx
parent66ba7ea831ca8d44b137e59e8271de3c7756cfe3 (diff)
downloadCMake-bae604d9a80d5d97c676c85848e37783a153ff19.zip
CMake-bae604d9a80d5d97c676c85848e37783a153ff19.tar.gz
CMake-bae604d9a80d5d97c676c85848e37783a153ff19.tar.bz2
Track nested loop levels in CMake language with a stack of counters
It gets incremented while entering a loop block (e.g. foreach or while) and gets decremented when leaving the block. Because scope borders for example at function borders must be taken into account the counter is put into a stack. With every new scope an empty counter is pushed on the stack, when leaving the scope the original value is restored. This will allow easy querying if the break command is properly nested within a loop scope. Signed-off-by: Gregor Jasny <gjasny@googlemail.com>
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx39
1 files changed, 39 insertions, 0 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 61807b2..6eca0f0 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -171,6 +171,9 @@ void cmMakefile::Initialize()
// Protect the directory-level policies.
this->PushPolicyBarrier();
+ // push empty loop block
+ this->PushLoopBlockBarrier();
+
// By default the check is not done. It is enabled by
// cmListFileCache in the top level if necessary.
this->CheckCMP0000 = false;
@@ -3354,6 +3357,38 @@ void cmMakefile::PopFunctionBlockerBarrier(bool reportError)
}
//----------------------------------------------------------------------------
+void cmMakefile::PushLoopBlock()
+{
+ assert(!this->LoopBlockCounter.empty());
+ this->LoopBlockCounter.top()++;
+}
+
+void cmMakefile::PopLoopBlock()
+{
+ assert(!this->LoopBlockCounter.empty());
+ assert(this->LoopBlockCounter.top() > 0);
+ this->LoopBlockCounter.top()--;
+}
+
+void cmMakefile::PushLoopBlockBarrier()
+{
+ this->LoopBlockCounter.push(0);
+}
+
+void cmMakefile::PopLoopBlockBarrier()
+{
+ assert(!this->LoopBlockCounter.empty());
+ assert(this->LoopBlockCounter.top() == 0);
+ this->LoopBlockCounter.pop();
+}
+
+bool cmMakefile::IsLoopBlock() const
+{
+ assert(!this->LoopBlockCounter.empty());
+ return !this->LoopBlockCounter.empty() && this->LoopBlockCounter.top() > 0;
+}
+
+//----------------------------------------------------------------------------
bool cmMakefile::ExpandArguments(
std::vector<cmListFileArgument> const& inArgs,
std::vector<std::string>& outArgs) const
@@ -4487,10 +4522,14 @@ void cmMakefile::PushScope()
this->Internal->VarStack.push(cmDefinitions(parent));
this->Internal->VarInitStack.push(init);
this->Internal->VarUsageStack.push(usage);
+
+ this->PushLoopBlockBarrier();
}
void cmMakefile::PopScope()
{
+ this->PopLoopBlockBarrier();
+
cmDefinitions* current = &this->Internal->VarStack.top();
std::set<std::string> init = this->Internal->VarInitStack.top();
std::set<std::string> usage = this->Internal->VarUsageStack.top();