Memory leaks: Improved the simplifycode for 'use ; if| use ;'

This commit is contained in:
Daniel Marjamäki 2010-09-11 20:18:16 +02:00
parent e48592c644
commit 73122c3e8a
2 changed files with 14 additions and 0 deletions

View File

@ -1925,6 +1925,17 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false;
}
// use; if| use; => use;
while (Token::Match(tok2, "[;{}] use ; if| use ;"))
{
Token *t = tok2->tokAt(2);
t->deleteNext();
t->deleteNext();
if (t->strAt(1) == ";")
t->deleteNext();
done = false;
}
// use; if return; dealloc; => if return; dealloc;
if (Token::Match(tok2, "[;{}] use ; if return ; dealloc ;"))
{

View File

@ -658,6 +658,9 @@ private:
ASSERT_EQUALS("alloc ;", simplifycode("alloc ; if ; if(var) ; ifv ; if(!var) ;"));
ASSERT_EQUALS("alloc ;", simplifycode("alloc ; if ; else ;"));
// use..
ASSERT_EQUALS("; alloc ; dealloc ; }", simplifycode("; alloc ; use ; use ; if use ; dealloc ; }"));
// if, else..
ASSERT_EQUALS("; alloc ; if break ; dealloc ;", simplifycode("; alloc ; if { break; } dealloc ;"));
ASSERT_EQUALS("; alloc ; if continue ; dealloc ;", simplifycode("; alloc ; if { continue; } dealloc ;"));