From 7ccb6217bf72631faf12bb18b0f29240ef120f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 4 Feb 2009 19:40:48 +0000 Subject: [PATCH] remove casts: Added test case to ensure that function declarations are not reduced --- src/tokenize.cpp | 2 +- test/testtokenize.cpp | 49 +++++++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 490cb55e3..98355fa95 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -1308,7 +1308,7 @@ bool Tokenizer::simplifyCasts() bool ret = false; for (Token *tok = _tokens; tok; tok = tok->next()) { - if (Token::Match(tok->next(), "( %type% * )")) + if (!tok->isName() && Token::Match(tok->next(), "( %type% * )")) { tok->deleteNext(); tok->deleteNext(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 9341c554b..eee2a5b24 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -40,6 +40,8 @@ private: { TEST_CASE(longtok); + TEST_CASE(removeCast1); + TEST_CASE(inlineasm); TEST_CASE(dupfuncname); @@ -76,8 +78,7 @@ private: TEST_CASE(simplify_function_parameters); - TEST_CASE(reduce_redundant_paranthesis1); // Ticket #61 - TEST_CASE(reduce_redundant_paranthesis2); // Ticket #61 + TEST_CASE(reduce_redundant_paranthesis); // Ticket #61 TEST_CASE(sizeof1); TEST_CASE(sizeof2); @@ -144,6 +145,26 @@ private: } + + // Dont remove "(int *)".. + void removeCast1() + { + const char code[] = "int *f(int *);"; + + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + tokenizer.simplifyCasts(); + + std::ostringstream ostr; + for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) + ostr << " " << tok->str(); + ASSERT_EQUALS(std::string(" int * f ( int * ) ;"), ostr.str()); + } + + void inlineasm() { const char filedata[] = "void foo()\n" @@ -810,7 +831,7 @@ private: // Simplify "((..))" into "(..)" - void reduce_redundant_paranthesis1() + void reduce_redundant_paranthesis() { const char code[] = "void foo()\n" "{\n" @@ -830,28 +851,6 @@ private: ASSERT_EQUALS(std::string(" void foo ( ) { free ( p ) ; }"), ostr.str()); } - // Simplify "((..))" into "(..)" - void reduce_redundant_paranthesis2() - { - const char code[] = "class A\n" - "{\n" - "public:\n" - " A();\n" - " int *p(int *);\n" - "}"; - - // tokenize.. - Tokenizer tokenizer; - std::istringstream istr(code); - tokenizer.tokenize(istr, "test.cpp"); - - tokenizer.simplifyTokenList(); - - std::ostringstream ostr; - for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) - ostr << " " << tok->str(); - ASSERT_EQUALS(std::string(" class A { public: A ( ) ; int * p ( int * ) ; }"), ostr.str()); - }