CheckMemoryLeak: Simplified and updated the code reducers

This commit is contained in:
Daniel Marjamäki 2008-08-16 19:19:56 +00:00
parent 68f409aca5
commit 76fdae51d9
1 changed files with 42 additions and 26 deletions

View File

@ -664,42 +664,58 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
done = false; done = false;
} }
// Delete "else { }", "else if { }", "else ;" and "else if ;" // Delete empty block
if ( Match(tok2->next, "else") ) if ( Match(tok2->next, "{ }") )
{ {
const TOKEN *_tok2 = gettok(tok2,2); erase(tok2, gettok(tok2,3));
done = false;
}
// Delete optional "if" // Delete braces around a single instruction..
if ( Match( _tok2, "if" ) ) if ( Match(tok2->next, "{ %var% ; }") )
_tok2 = _tok2->next; {
erase( tok2, gettok(tok2,2) );
erase( tok2->next->next, gettok(tok2,4) );
done = false;
}
// Delete "{ }" or ";" // Delete empty if
if (Match(_tok2, "{ }")) if ( Match(tok2,"[;{}] if ;") ||
Match(tok2,"[;{}] if(var) ;") ||
Match(tok2,"[;{}] if(!var) ;") )
{
if ( ! Match(gettok(tok2,3), "else") )
{ {
erase(tok2, _tok2->next->next); erase(tok2, gettok(tok2, 3));
done = false;
}
else if ( Match(_tok2, ";") )
{
erase(tok2, _tok2->next);
done = false; done = false;
continue;
} }
} }
// Delete "loop ;" and "loop { }" // Delete "else ;" and "else if ;"
if ( Match(tok2->next, "loop") ) if ( Match(tok2->next, "else if ;") )
{ {
if ( Match(gettok(tok2,2), ";") ) erase(tok2, gettok(tok2,4));
{ done = false;
erase(tok2, gettok(tok2,3)); }
done = false; if ( Match(tok2->next, "else ;") )
} {
erase(tok2, gettok(tok2,3));
done = false;
}
else if ( Match(gettok(tok2,2), "{ }") ) // Delete "loop ;"
{ if ( Match(tok2->next, "loop ;") )
erase(tok2, gettok(tok2,4)); {
done = false; erase(tok2, gettok(tok2,3));
} done = false;
}
// Delete "alloc ; if(!var) return ;"
if ( Match(tok2->next, "alloc ; if(!var) return ;") )
{
erase(tok2, gettok(tok2,6));
done = false;
} }
} }
} }