mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
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>
This commit is contained in:
@@ -27,6 +27,8 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
|
||||
// if this is the endofreach for this statement
|
||||
if (!this->Depth)
|
||||
{
|
||||
cmMakefile::LoopBlockPop loopBlockPop(&mf);
|
||||
|
||||
// Remove the function blocker for this scope or bail.
|
||||
cmsys::auto_ptr<cmFunctionBlocker>
|
||||
fb(mf.RemoveFunctionBlocker(this, lff));
|
||||
@@ -73,6 +75,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// restore the variable to its prior value
|
||||
mf.AddDefinition(this->Args[0],oldDef.c_str());
|
||||
return true;
|
||||
@@ -199,6 +202,8 @@ bool cmForEachCommand
|
||||
}
|
||||
this->Makefile->AddFunctionBlocker(f);
|
||||
|
||||
this->Makefile->PushLoopBlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -242,5 +247,8 @@ bool cmForEachCommand::HandleInMode(std::vector<std::string> const& args)
|
||||
}
|
||||
|
||||
this->Makefile->AddFunctionBlocker(f.release()); // TODO: pass auto_ptr
|
||||
|
||||
this->Makefile->PushLoopBlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user