ENH: Better handling of mismatched blocks

If a logical block terminates with mismatching arguments we previously
failed to remove the function blocker but replayed the commands anyway,
which led to cases in which we failed to report the mismatch (return
shortly after the ending command).  The recent refactoring of function
blocker deletion changed this behavior to produce an error on the ending
line by not blocking the command.  Furthermore, the function blocker
would stay in place and complain at the end of every equal-level block
of the same type.

This teaches CMake to treat the begin/end commands (if/endif, etc.) as
correct and just warns when the arguments mismatch.  The change allows
cases in which CMake 2.6.2 silently ignored a mismatch to run as before
but with a warning.
This commit is contained in:
Brad King 2009-01-21 09:49:00 -05:00
parent bca1026250
commit 1dcc5b4558
7 changed files with 24 additions and 8 deletions

View File

@ -31,7 +31,8 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
if (!this->Depth) if (!this->Depth)
{ {
// Remove the function blocker for this scope or bail. // Remove the function blocker for this scope or bail.
cmsys::auto_ptr<cmFunctionBlocker> fb(mf.RemoveFunctionBlocker(lff)); cmsys::auto_ptr<cmFunctionBlocker>
fb(mf.RemoveFunctionBlocker(this, lff));
if(!fb.get()) { return false; } if(!fb.get()) { return false; }
// at end of for each execute recorded commands // at end of for each execute recorded commands

View File

@ -222,7 +222,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
mf.AddCommand(f); mf.AddCommand(f);
// remove the function blocker now that the function is defined // remove the function blocker now that the function is defined
mf.RemoveFunctionBlocker(lff); mf.RemoveFunctionBlocker(this, lff);
return true; return true;
} }
else else

View File

@ -39,7 +39,8 @@ IsFunctionBlocked(const cmListFileFunction& lff,
if (!this->ScopeDepth) if (!this->ScopeDepth)
{ {
// Remove the function blocker for this scope or bail. // Remove the function blocker for this scope or bail.
cmsys::auto_ptr<cmFunctionBlocker> fb(mf.RemoveFunctionBlocker(lff)); cmsys::auto_ptr<cmFunctionBlocker>
fb(mf.RemoveFunctionBlocker(this, lff));
if(!fb.get()) { return false; } if(!fb.get()) { return false; }
// execute the functions for the true parts of the if statement // execute the functions for the true parts of the if statement

View File

@ -266,7 +266,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
mf.AddCommand(f); mf.AddCommand(f);
// remove the function blocker now that the macro is defined // remove the function blocker now that the macro is defined
mf.RemoveFunctionBlocker(lff); mf.RemoveFunctionBlocker(this, lff);
return true; return true;
} }
else else

View File

@ -2422,7 +2422,8 @@ void cmMakefile::AddFunctionBlocker(cmFunctionBlocker* fb)
} }
cmsys::auto_ptr<cmFunctionBlocker> cmsys::auto_ptr<cmFunctionBlocker>
cmMakefile::RemoveFunctionBlocker(const cmListFileFunction& lff) cmMakefile::RemoveFunctionBlocker(cmFunctionBlocker* fb,
const cmListFileFunction& lff)
{ {
// Find the function blocker stack barrier for the current scope. // Find the function blocker stack barrier for the current scope.
// We only remove a blocker whose index is not less than the barrier. // We only remove a blocker whose index is not less than the barrier.
@ -2438,8 +2439,20 @@ cmMakefile::RemoveFunctionBlocker(const cmListFileFunction& lff)
{ {
std::vector<cmFunctionBlocker*>::iterator pos = std::vector<cmFunctionBlocker*>::iterator pos =
this->FunctionBlockers.begin() + (i - 1); this->FunctionBlockers.begin() + (i - 1);
if ((*pos)->ShouldRemove(lff, *this)) if (*pos == fb)
{ {
// Warn if the arguments do not match, but always remove.
if(!(*pos)->ShouldRemove(lff, *this))
{
cmListFileContext const& lfc = fb->GetStartingContext();
cmOStringStream e;
e << "A logical block opening on the line\n"
<< " " << lfc << "\n"
<< "closes on the line\n"
<< " " << lff << "\n"
<< "with mis-matching arguments.";
this->IssueMessage(cmake::AUTHOR_WARNING, e.str());
}
cmFunctionBlocker* b = *pos; cmFunctionBlocker* b = *pos;
this->FunctionBlockers.erase(pos); this->FunctionBlockers.erase(pos);
return cmsys::auto_ptr<cmFunctionBlocker>(b); return cmsys::auto_ptr<cmFunctionBlocker>(b);

View File

@ -95,7 +95,7 @@ public:
* This returns ownership of the function blocker object. * This returns ownership of the function blocker object.
*/ */
cmsys::auto_ptr<cmFunctionBlocker> cmsys::auto_ptr<cmFunctionBlocker>
RemoveFunctionBlocker(const cmListFileFunction& lff); RemoveFunctionBlocker(cmFunctionBlocker* fb, const cmListFileFunction& lff);
/** Push/pop a lexical (function blocker) barrier automatically. */ /** Push/pop a lexical (function blocker) barrier automatically. */
class LexicalPushPop class LexicalPushPop

View File

@ -33,7 +33,8 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
if (!this->Depth) if (!this->Depth)
{ {
// Remove the function blocker for this scope or bail. // Remove the function blocker for this scope or bail.
cmsys::auto_ptr<cmFunctionBlocker> fb(mf.RemoveFunctionBlocker(lff)); cmsys::auto_ptr<cmFunctionBlocker>
fb(mf.RemoveFunctionBlocker(this, lff));
if(!fb.get()) { return false; } if(!fb.get()) { return false; }
std::string errorString; std::string errorString;