made the Tokenizer::simplifyCasts more generic

This commit is contained in:
Daniel Marjamäki 2009-03-10 21:26:08 +01:00
parent c7c13ce3c1
commit eac29d151c
2 changed files with 11 additions and 2 deletions

View File

@ -1395,10 +1395,19 @@ bool Tokenizer::simplifyCasts()
bool ret = false;
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok->next(), "( %type% * )") || Token::Match(tok->next(), "( %type% %type% * )"))
if (Token::Match(tok->next(), "( %type% *| )") || Token::Match(tok->next(), "( %type% %type% *| )"))
{
if (tok->isName() && tok->str() != "return")
continue;
// Is it a cast of some variable?
const Token *tok2 = tok->tokAt(3);
while (tok2 && tok2->str() != ")")
tok2 = tok2->next();
if (!Token::Match(tok2, ") %var%"))
continue;
// Remove cast..
while (tok->next()->str() != ")")
tok->deleteNext();
tok->deleteNext();

View File

@ -327,7 +327,7 @@ private:
ASSERT_EQUALS("if ( a < p ) { ", tok("if(a<(p))"));
// keep parantheses..
ASSERT_EQUALS("= ( char ) a ; ", tok("= (char)a;"));
ASSERT_EQUALS("= a ; ", tok("= (char)a;"));
ASSERT_EQUALS("cast < char * > ( p ) ", tok("cast<char *>(p)"));
}