simplify casts
This commit is contained in:
parent
62874b54ef
commit
f8cd34198b
|
@ -1395,11 +1395,12 @@ bool Tokenizer::simplifyCasts()
|
|||
bool ret = false;
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (!tok->isName() && Token::Match(tok->next(), "( %type% * )"))
|
||||
if (Token::Match(tok->next(), "( %type% * )") || Token::Match(tok->next(), "( %type% %type% * )"))
|
||||
{
|
||||
tok->deleteNext();
|
||||
tok->deleteNext();
|
||||
tok->deleteNext();
|
||||
if (tok->isName() && tok->str() != "return")
|
||||
continue;
|
||||
while (tok->next()->str() != ")")
|
||||
tok->deleteNext();
|
||||
tok->deleteNext();
|
||||
ret = true;
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ private:
|
|||
void run()
|
||||
{
|
||||
TEST_CASE(cast0);
|
||||
TEST_CASE(cast1);
|
||||
TEST_CASE(iftruefalse);
|
||||
TEST_CASE(combine_strings);
|
||||
TEST_CASE(double_plus);
|
||||
|
@ -99,6 +100,13 @@ private:
|
|||
ASSERT_EQUALS(tok(code1), tok(code2));
|
||||
}
|
||||
|
||||
void cast1()
|
||||
{
|
||||
const char code[] = "return (unsigned char *)str;";
|
||||
const char expected[] = "return str;";
|
||||
ASSERT_EQUALS(tok(expected), tok(code));
|
||||
}
|
||||
|
||||
void iftruefalse()
|
||||
{
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue