tokenizer: Remove redundant parantheses around number. Ticket: #105
This commit is contained in:
parent
265ef0f4a5
commit
56d685c179
|
@ -849,8 +849,9 @@ void Tokenizer::simplifyTokenList()
|
|||
|
||||
|
||||
// Simple calculations..
|
||||
for (bool done = false; !done; done = true)
|
||||
for (bool done = false; !done; )
|
||||
{
|
||||
done = true;
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
if (Token::simpleMatch(tok->next(), "* 1") || Token::simpleMatch(tok->next(), "1 *"))
|
||||
|
@ -896,6 +897,15 @@ void Tokenizer::simplifyTokenList()
|
|||
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Remove parantheses around number..
|
||||
if (!tok->isName() && Token::Match(tok->next(), "( %num% )"))
|
||||
{
|
||||
tok->deleteNext();
|
||||
tok = tok->next();
|
||||
tok->deleteNext();
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ private:
|
|||
TEST_CASE(combine_strings);
|
||||
TEST_CASE(double_plus);
|
||||
TEST_CASE(redundant_plus);
|
||||
TEST_CASE(parantheses1);
|
||||
}
|
||||
|
||||
std::string tok(const char code[])
|
||||
|
@ -281,6 +282,13 @@ private:
|
|||
ASSERT_EQUALS("void foo ( int a , int b ) { a = a - b ; } ", tok(code1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void parantheses1()
|
||||
{
|
||||
const char code1[] = "<= (10+100);";
|
||||
ASSERT_EQUALS("<= 110 ; ", tok(code1));
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestSimplifyTokens)
|
||||
|
|
Loading…
Reference in New Issue