From 56d685c179475bdb96de0a2b8affd27f4f11bc6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 15 Feb 2009 13:28:54 +0000 Subject: [PATCH] tokenizer: Remove redundant parantheses around number. Ticket: #105 --- src/tokenize.cpp | 12 +++++++++++- test/testsimplifytokens.cpp | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 745d41df1..35ab06f94 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -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; + } } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index f0e206ba0..7f45b90c7 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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)