ENH: Refactor function blocker deletion

When a function blocker decides to remove itself we previously removed
it at every return point from the C++ scope in which its removal is
needed.  This teaches function blockers to transfer ownership of
themselves from cmMakefile to an automatic variable for deletion on
return.  Since this removes blockers before they replay their commands,
we no longer need to avoid running blockers on their own commands.
This commit is contained in:
Brad King
2009-01-20 14:36:18 -05:00
parent a541cac325
commit 2c81e5fb5c
8 changed files with 27 additions and 47 deletions
+4 -11
View File
@@ -20,13 +20,6 @@ bool cmForEachFunctionBlocker::
IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
cmExecutionStatus &inStatus)
{
// Prevent recusion and don't let this blocker block its own
// commands.
if (this->Executing)
{
return false;
}
if (!cmSystemTools::Strucmp(lff.Name.c_str(),"foreach"))
{
// record the number of nested foreach commands
@@ -37,6 +30,10 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
// if this is the endofreach for this statement
if (!this->Depth)
{
// Remove the function blocker for this scope or bail.
cmsys::auto_ptr<cmFunctionBlocker> fb(mf.RemoveFunctionBlocker(lff));
if(!fb.get()) { return false; }
// at end of for each execute recorded commands
// store the old value
std::string oldDef;
@@ -44,7 +41,6 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
{
oldDef = mf.GetDefinition(this->Args[0].c_str());
}
this->Executing = true;
std::vector<std::string>::const_iterator j = this->Args.begin();
++j;
@@ -65,21 +61,18 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
inStatus.SetReturnInvoked(true);
// restore the variable to its prior value
mf.AddDefinition(this->Args[0].c_str(),oldDef.c_str());
mf.RemoveFunctionBlocker(lff);
return true;
}
if (status.GetBreakInvoked())
{
// restore the variable to its prior value
mf.AddDefinition(this->Args[0].c_str(),oldDef.c_str());
mf.RemoveFunctionBlocker(lff);
return true;
}
}
}
// restore the variable to its prior value
mf.AddDefinition(this->Args[0].c_str(),oldDef.c_str());
mf.RemoveFunctionBlocker(lff);
return true;
}
else