simplify casts

This commit is contained in:
Daniel Marjamäki 2009-03-09 19:47:21 +01:00
parent 62874b54ef
commit f8cd34198b
2 changed files with 13 additions and 4 deletions

View File

@ -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;
}

View File

@ -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()
{
{