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