Code coverage: Removed unused code

This commit is contained in:
Daniel Marjamäki 2010-06-05 11:25:47 +02:00
parent 07e00d57d9
commit 1de6e94947
1 changed files with 1 additions and 104 deletions

View File

@ -1544,21 +1544,6 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false; done = false;
} }
// Two "if alloc ;" after one another.. perhaps only one of them can be executed each time
else if (!_settings->inconclusive && Token::Match(tok2, "[;{}] if alloc ; if alloc ;"))
{
Token::eraseTokens(tok2, tok2->tokAt(4));
done = false;
}
else if (Token::Match(tok2, "; if ; else assign|use ; assign|use") ||
Token::Match(tok2, "; if assign|use ; else ; assign|use"))
{
Token::eraseTokens(tok2, tok2->tokAt(4));
done = false;
}
// Reduce "if return ; alloc ;" => "alloc ;" // Reduce "if return ; alloc ;" => "alloc ;"
else if (Token::Match(tok2, "[;{}] if return ; alloc|return ;")) else if (Token::Match(tok2, "[;{}] if return ; alloc|return ;"))
{ {
@ -1618,16 +1603,6 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false; done = false;
} }
// Reducing if..
else if (_settings->inconclusive)
{
if (Token::Match(tok2, "[;{}] if { assign|dealloc|use ; return ; } !!else"))
{
Token::eraseTokens(tok2, tok2->tokAt(8));
done = false;
}
}
continue; continue;
} }
@ -1673,13 +1648,6 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false; done = false;
} }
// Remove "catch ;"
if (Token::simpleMatch(tok2->next(), "catch ;"))
{
Token::eraseTokens(tok2, tok2->tokAt(3));
done = false;
}
// Reduce "if* ;".. // Reduce "if* ;"..
if (Token::Match(tok2->next(), "if(var)|if(!var)|ifv ;")) if (Token::Match(tok2->next(), "if(var)|if(!var)|ifv ;"))
{ {
@ -1739,14 +1707,6 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false; done = false;
} }
// Reduce "if loop ; exit ;" => "; exit ;"
if (Token::Match(tok2, "if loop ; exit ;"))
{
tok2->deleteThis();
tok2->deleteThis();
done = false;
}
// Reduce "alloc|dealloc|use ; if(var) exit ;" // Reduce "alloc|dealloc|use ; if(var) exit ;"
if (Token::Match(tok2, "alloc|dealloc|use ; if(var) exit ;")) if (Token::Match(tok2, "alloc|dealloc|use ; if(var) exit ;"))
{ {
@ -1807,47 +1767,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false; done = false;
} }
// Reduce "loop { assign|dealloc|use ; alloc ; if break ; }" to "assign|dealloc|use ; alloc ;"
if (Token::Match(tok2->next(), "loop { assign|dealloc|use ; alloc ; if break|continue ; }"))
{
// erase "loop {"
Token::eraseTokens(tok2, tok2->tokAt(3));
// erase "if break|continue ; }"
tok2 = tok2->tokAt(4);
Token::eraseTokens(tok2, tok2->tokAt(5));
done = false;
}
// Replace "loop { X ; break ; }" with "X ;"
if (Token::Match(tok2->next(), "loop { %var% ; break ; }"))
{
Token::eraseTokens(tok2, tok2->tokAt(3));
Token::eraseTokens(tok2->tokAt(2), tok2->tokAt(6));
done = false;
}
// Replace "do ; loop ;" with ";" // Replace "do ; loop ;" with ";"
if (Token::Match(tok2->next(), "%any% ; loop ;")) if (Token::simpleMatch(tok2, "; loop ;"))
{ {
if (tok2->next()->str() == "do")
tok2->deleteNext();
else
tok2 = tok2->next();
Token::eraseTokens(tok2, tok2->tokAt(3)); Token::eraseTokens(tok2, tok2->tokAt(3));
done = false; done = false;
} }
// Replace "do ; loop !var ;" with ";"
if (Token::Match(tok2->next(), "%any% ; loop !var ;"))
{
if (tok2->next()->str() == "do")
tok2->deleteNext();
else
tok2 = tok2->next();
Token::eraseTokens(tok2, tok2->tokAt(4));
done = false;
}
// Replace "loop if return ;" with "if return ;" // Replace "loop if return ;" with "if return ;"
if (Token::simpleMatch(tok2->next(), "loop if return")) if (Token::simpleMatch(tok2->next(), "loop if return"))
{ {
@ -1862,13 +1788,6 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false; done = false;
} }
// Delete if block: "alloc; if return use ;"
if (Token::Match(tok2, "alloc ; if return use ; !!else"))
{
Token::eraseTokens(tok2, tok2->tokAt(5));
done = false;
}
// Reduce "[;{}] return use ; %var%" => "[;{}] return use ;" // Reduce "[;{}] return use ; %var%" => "[;{}] return use ;"
if (Token::Match(tok2, "[;{}] return use ; %var%")) if (Token::Match(tok2, "[;{}] return use ; %var%"))
{ {
@ -1883,13 +1802,6 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false; done = false;
} }
// Reduce "if(var) assign|dealloc|use ;" => "assign|dealloc|use ;"
if (Token::Match(tok2->next(), "if(var) assign|dealloc|use ; !!else"))
{
Token::eraseTokens(tok2, tok2->tokAt(2));
done = false;
}
// malloc - realloc => alloc ; dealloc ; alloc ; // malloc - realloc => alloc ; dealloc ; alloc ;
// Reduce "[;{}] alloc ; dealloc ; alloc ;" => "[;{}] alloc ;" // Reduce "[;{}] alloc ; dealloc ; alloc ;" => "[;{}] alloc ;"
if (Token::Match(tok2, "[;{}] alloc ; dealloc ; alloc ;")) if (Token::Match(tok2, "[;{}] alloc ; dealloc ; alloc ;"))
@ -1898,13 +1810,6 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false; done = false;
} }
// Delete second use in "use ; use ;"
while (Token::Match(tok2, "[;{}] use ; use ;"))
{
Token::eraseTokens(tok2, tok2->tokAt(3));
done = false;
}
// Delete first part in "use ; dealloc ;" // Delete first part in "use ; dealloc ;"
if (Token::Match(tok2, "[;{}] use ; dealloc ;")) if (Token::Match(tok2, "[;{}] use ; dealloc ;"))
{ {
@ -1919,14 +1824,6 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false; done = false;
} }
// Delete "callfunc ;" that is followed by "use|if|callfunc"
// If the function doesn't throw exception or exit the application, then the "callfunc" is not needed
if (Token::Match(tok2, "callfunc ; use|if|callfunc"))
{
tok2->deleteThis();
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 ;"))
{ {