Memory leaks: improved simplification for 'callfunc'
This commit is contained in:
parent
73122c3e8a
commit
4064712baa
|
@ -1492,21 +1492,6 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
tok2->str("return");
|
tok2->str("return");
|
||||||
}
|
}
|
||||||
|
|
||||||
// reduce "if callfunc {" => "if {"
|
|
||||||
for (Token *tok2 = tok; tok2; tok2 = tok2->next())
|
|
||||||
{
|
|
||||||
if (Token::Match(tok2, "if|ifv callfunc {"))
|
|
||||||
tok2->deleteNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
// reduce "; callfunc ; %var%"
|
|
||||||
for (Token *tok2 = tok; tok2; tok2 = tok2->next())
|
|
||||||
{
|
|
||||||
if (Token::Match(tok2, ";|{|} callfunc ; %type%") ||
|
|
||||||
Token::Match(tok2, ";|{|} callfunc ; ;"))
|
|
||||||
tok2->deleteNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove redundant braces..
|
// remove redundant braces..
|
||||||
for (Token *start = tok; start; start = start->next())
|
for (Token *start = tok; start; start = start->next())
|
||||||
{
|
{
|
||||||
|
@ -1542,6 +1527,16 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
//tok->printOut("simplifycode loop..");
|
//tok->printOut("simplifycode loop..");
|
||||||
done = true;
|
done = true;
|
||||||
|
|
||||||
|
// reduce callfunc
|
||||||
|
for (Token *tok2 = tok; tok2; tok2 = tok2->next())
|
||||||
|
{
|
||||||
|
if (tok2->str() == "callfunc")
|
||||||
|
{
|
||||||
|
if (!Token::Match(tok2->previous(), "[;{}] callfunc ; }"))
|
||||||
|
tok2->deleteThis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// simplify "while1" contents..
|
// simplify "while1" contents..
|
||||||
for (Token *tok2 = tok; tok2; tok2 = tok2->next())
|
for (Token *tok2 = tok; tok2; tok2 = tok2->next())
|
||||||
{
|
{
|
||||||
|
@ -1950,6 +1945,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// callfunc callfunc
|
||||||
|
while (Token::simpleMatch(tok2, "callfunc callfunc"))
|
||||||
|
{
|
||||||
|
tok2->deleteNext();
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Delete second case in "case ; case ;"
|
// Delete second case in "case ; case ;"
|
||||||
while (Token::simpleMatch(tok2, "case ; case ;"))
|
while (Token::simpleMatch(tok2, "case ; case ;"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -725,10 +725,11 @@ private:
|
||||||
TODO_ASSERT_EQUALS("; assign ; if alloc ; }", simplifycode("; assign ; { dealloc ; if alloc ; } }"));
|
TODO_ASSERT_EQUALS("; assign ; if alloc ; }", simplifycode("; assign ; { dealloc ; if alloc ; } }"));
|
||||||
|
|
||||||
// callfunc..
|
// callfunc..
|
||||||
ASSERT_EQUALS("; callfunc ;", simplifycode(";callfunc;"));
|
ASSERT_EQUALS("; callfunc ; }", simplifycode(";callfunc;}"));
|
||||||
ASSERT_EQUALS(";", simplifycode(";callfunc;;"));
|
ASSERT_EQUALS(";", simplifycode(";callfunc;;"));
|
||||||
|
ASSERT_EQUALS("; callfunc ; }", simplifycode(";callfunc callfunc ; }"));
|
||||||
ASSERT_EQUALS("dealloc ; alloc ; return ; }", simplifycode("while1 { dealloc ; alloc ; } callfunc ; return ; }"));
|
ASSERT_EQUALS("dealloc ; alloc ; return ; }", simplifycode("while1 { dealloc ; alloc ; } callfunc ; return ; }"));
|
||||||
ASSERT_EQUALS(";", simplifycode("loop callfunc ;"));
|
ASSERT_EQUALS("; }", simplifycode("loop callfunc ; }"));
|
||||||
|
|
||||||
// exit..
|
// exit..
|
||||||
ASSERT_EQUALS("; exit ;", simplifycode("; alloc; exit;"));
|
ASSERT_EQUALS("; exit ;", simplifycode("; alloc; exit;"));
|
||||||
|
|
Loading…
Reference in New Issue