Memory leaks: fixed try/catch and nested loops simplifications

This commit is contained in:
Daniel Marjamäki 2010-09-11 21:07:35 +02:00
parent 4064712baa
commit d4e045cee5
2 changed files with 10 additions and 6 deletions

View File

@ -1855,10 +1855,9 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false;
}
// Replace "loop callfunc ;" with ";"
if (Token::simpleMatch(tok2, "loop callfunc ;"))
// Replace "loop loop .." with "loop .."
if (Token::simpleMatch(tok2, "loop loop"))
{
tok2->deleteThis();
tok2->deleteThis();
done = false;
}
@ -1945,10 +1944,11 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false;
}
// callfunc callfunc
while (Token::simpleMatch(tok2, "callfunc callfunc"))
// try/catch
if (Token::simpleMatch(tok2, "try ; catch exit ;"))
{
tok2->deleteNext();
Token::eraseTokens(tok2, tok2->tokAt(4));
tok2->deleteThis();
done = false;
}

View File

@ -707,6 +707,7 @@ private:
ASSERT_EQUALS("; loop alloc ;", simplifycode("; loop { alloc ; }"));
ASSERT_EQUALS("; alloc ; alloc ;", simplifycode("; alloc ; do { alloc ; } loop ;"));
ASSERT_EQUALS("; exit ;", simplifycode("; alloc ; do { } loop ; exit ;"));
ASSERT_EQUALS("; loop use ;", simplifycode("; loop { loop loop use ; } ;"));
ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; while(!var) alloc ;"));
@ -740,6 +741,9 @@ private:
TODO_ASSERT_EQUALS(";", simplifycode("; alloc ; if(var) { exit; }"));
TODO_ASSERT_EQUALS(";\n; alloc ;", simplifycode("; alloc ; ifv { exit; }"));
// try-catch
ASSERT_EQUALS("; }", simplifycode("; try ; catch exit ; }"));
// dealloc; dealloc;
ASSERT_EQUALS("; alloc ; if dealloc ; dealloc ;", simplifycode("; alloc ; if { dealloc ; } dealloc ;"));