made the Tokenizer::simplifyCasts more generic
This commit is contained in:
parent
c7c13ce3c1
commit
eac29d151c
|
@ -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();
|
||||
|
|
|
@ -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)"));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue