Memory leaks: reduce 'loop { if continue ;' to 'loop {'

This commit is contained in:
Daniel Marjamäki 2010-09-12 21:15:19 +02:00
parent 0a30aba2e6
commit 5a95303405
2 changed files with 9 additions and 1 deletions

View File

@ -1860,13 +1860,20 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false;
}
// Reduce "loop if break ; => ";"
// Reduce "loop if break|continue ; !!else" => ";"
if (Token::Match(tok2->next(), "loop if break|continue ; !!else"))
{
Token::eraseTokens(tok2, tok2->tokAt(4));
done = false;
}
// Reduce "loop { if break|continue ; !!else" => "loop {"
if (Token::Match(tok2, "loop { if break|continue ; !!else"))
{
Token::eraseTokens(tok2->next(), tok2->tokAt(5));
done = false;
}
// Replace "do ; loop ;" with ";"
if (Token::simpleMatch(tok2, "; loop ;"))
{

View File

@ -710,6 +710,7 @@ private:
ASSERT_EQUALS("; exit ;", simplifycode("; alloc ; do { } loop ; exit ;"));
ASSERT_EQUALS("; loop use ;", simplifycode("; loop { loop loop use ; } ;"));
ASSERT_EQUALS("; }", simplifycode("; loop { if break ; break ; } ; }"));
ASSERT_EQUALS("; }", simplifycode("; loop { if continue ; if continue ; } ; }"));
ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; while(!var) alloc ;"));