tokenizer: Remove redundant parantheses around number. Ticket: #105

This commit is contained in:
Daniel Marjamäki 2009-02-15 13:28:54 +00:00
parent 265ef0f4a5
commit 56d685c179
2 changed files with 19 additions and 1 deletions

View File

@ -849,8 +849,9 @@ void Tokenizer::simplifyTokenList()
// Simple calculations.. // Simple calculations..
for (bool done = false; !done; done = true) for (bool done = false; !done; )
{ {
done = true;
for (Token *tok = _tokens; tok; tok = tok->next()) for (Token *tok = _tokens; tok; tok = tok->next())
{ {
if (Token::simpleMatch(tok->next(), "* 1") || Token::simpleMatch(tok->next(), "1 *")) if (Token::simpleMatch(tok->next(), "* 1") || Token::simpleMatch(tok->next(), "1 *"))
@ -896,6 +897,15 @@ void Tokenizer::simplifyTokenList()
done = false; done = false;
} }
// Remove parantheses around number..
if (!tok->isName() && Token::Match(tok->next(), "( %num% )"))
{
tok->deleteNext();
tok = tok->next();
tok->deleteNext();
done = false;
}
} }
} }

View File

@ -42,6 +42,7 @@ private:
TEST_CASE(combine_strings); TEST_CASE(combine_strings);
TEST_CASE(double_plus); TEST_CASE(double_plus);
TEST_CASE(redundant_plus); TEST_CASE(redundant_plus);
TEST_CASE(parantheses1);
} }
std::string tok(const char code[]) std::string tok(const char code[])
@ -281,6 +282,13 @@ private:
ASSERT_EQUALS("void foo ( int a , int b ) { a = a - b ; } ", tok(code1)); 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) REGISTER_TEST(TestSimplifyTokens)