summaryrefslogtreecommitdiffstats
path: root/Source/cmForEachCommand.cxx
diff options
context:
space:
mode:
authorRegina Pfeifer <regina@mailbox.org>2019-07-23 21:50:33 (GMT)
committerRegina Pfeifer <regina@mailbox.org>2019-07-30 22:03:17 (GMT)
commitef38ff22f71ad0ffe83db42d903d26d4a41f4114 (patch)
tree91700b2676898bbb638b19c574e4ad77425f7c3b /Source/cmForEachCommand.cxx
parentb51fba6298012c3b697c461486ce06c9e5c97c16 (diff)
downloadCMake-ef38ff22f71ad0ffe83db42d903d26d4a41f4114.zip
CMake-ef38ff22f71ad0ffe83db42d903d26d4a41f4114.tar.gz
CMake-ef38ff22f71ad0ffe83db42d903d26d4a41f4114.tar.bz2
cm*FunctionBlocker: Extract function Replay
Diffstat (limited to 'Source/cmForEachCommand.cxx')
-rw-r--r--Source/cmForEachCommand.cxx86
1 files changed, 48 insertions, 38 deletions
diff --git a/Source/cmForEachCommand.cxx b/Source/cmForEachCommand.cxx
index b04f14c..af32040 100644
--- a/Source/cmForEachCommand.cxx
+++ b/Source/cmForEachCommand.cxx
@@ -25,6 +25,8 @@ public:
bool IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile& mf,
cmExecutionStatus&) override;
bool ShouldRemove(const cmListFileFunction& lff, cmMakefile& mf) override;
+ bool Replay(std::vector<cmListFileFunction> const& functions,
+ cmExecutionStatus& inStatus);
std::vector<std::string> Args;
std::vector<cmListFileFunction> Functions;
@@ -63,44 +65,7 @@ bool cmForEachFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff,
return false;
}
- // at end of for each execute recorded commands
- // store the old value
- std::string oldDef;
- if (mf.GetDefinition(this->Args[0])) {
- oldDef = mf.GetDefinition(this->Args[0]);
- }
-
- for (std::string const& arg : cmMakeRange(this->Args).advance(1)) {
- // set the variable to the loop value
- mf.AddDefinition(this->Args[0], arg);
- // Invoke all the functions that were collected in the block.
- cmExecutionStatus status(mf);
- for (cmListFileFunction const& func : this->Functions) {
- status.Clear();
- mf.ExecuteCommand(func, status);
- if (status.GetReturnInvoked()) {
- inStatus.SetReturnInvoked();
- // restore the variable to its prior value
- mf.AddDefinition(this->Args[0], oldDef);
- return true;
- }
- if (status.GetBreakInvoked()) {
- // restore the variable to its prior value
- mf.AddDefinition(this->Args[0], oldDef);
- return true;
- }
- if (status.GetContinueInvoked()) {
- break;
- }
- if (cmSystemTools::GetFatalErrorOccured()) {
- return true;
- }
- }
- }
-
- // restore the variable to its prior value
- mf.AddDefinition(this->Args[0], oldDef);
- return true;
+ return this->Replay(this->Functions, inStatus);
}
// close out a nested foreach
this->Depth--;
@@ -129,6 +94,51 @@ bool cmForEachFunctionBlocker::ShouldRemove(const cmListFileFunction& lff,
return false;
}
+bool cmForEachFunctionBlocker::Replay(
+ std::vector<cmListFileFunction> const& functions,
+ cmExecutionStatus& inStatus)
+{
+ cmMakefile& mf = inStatus.GetMakefile();
+ // at end of for each execute recorded commands
+ // store the old value
+ std::string oldDef;
+ if (mf.GetDefinition(this->Args[0])) {
+ oldDef = mf.GetDefinition(this->Args[0]);
+ }
+
+ for (std::string const& arg : cmMakeRange(this->Args).advance(1)) {
+ // set the variable to the loop value
+ mf.AddDefinition(this->Args[0], arg);
+ // Invoke all the functions that were collected in the block.
+ cmExecutionStatus status(mf);
+ for (cmListFileFunction const& func : functions) {
+ status.Clear();
+ mf.ExecuteCommand(func, status);
+ if (status.GetReturnInvoked()) {
+ inStatus.SetReturnInvoked();
+ // restore the variable to its prior value
+ mf.AddDefinition(this->Args[0], oldDef);
+ return true;
+ }
+ if (status.GetBreakInvoked()) {
+ // restore the variable to its prior value
+ mf.AddDefinition(this->Args[0], oldDef);
+ return true;
+ }
+ if (status.GetContinueInvoked()) {
+ break;
+ }
+ if (cmSystemTools::GetFatalErrorOccured()) {
+ return true;
+ }
+ }
+ }
+
+ // restore the variable to its prior value
+ mf.AddDefinition(this->Args[0], oldDef);
+ return true;
+}
+
bool cmForEachCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{