From 7d2fb2ecde84c5cab0355eac0fbe8502a18e5b21 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 5 Mar 2011 20:48:28 -0500 Subject: [PATCH] partial fix for #2624 (better function pointer support needed) --- lib/tokenize.cpp | 10 ++++++---- test/testsimplifytokens.cpp | 28 ++++++---------------------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 76374f498..4dc6a9a9a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5385,7 +5385,7 @@ void Tokenizer:: simplifyFunctionPointers() { for (Token *tok = _tokens; tok; tok = tok->next()) { - if (tok->previous() && !Token::Match(tok->previous(), "[{};]")) + if (tok->previous() && !Token::Match(tok->previous(), "{|}|;|(|public:|protected:|private:")) continue; if (Token::Match(tok, "%type% *| *| ( * %var% ) (")) @@ -5398,8 +5398,8 @@ void Tokenizer:: simplifyFunctionPointers() while (tok->next()->str() == "*") tok = tok->next(); - // check that the declaration ends with ; - if (!Token::simpleMatch(tok->tokAt(5)->link(), ") ;")) + // check that the declaration ends + if (!Token::Match(tok->tokAt(5)->link(), ") ;|,|)|=")) continue; // ok simplify this function pointer to an ordinary pointer @@ -7063,6 +7063,7 @@ bool Tokenizer::simplifyCalculations() // keep parentheses here: int ( * * ( * compilerHookVector ) (void) ) ( ) ; // keep parentheses here: operator new [] (size_t); // keep parentheses here: Functor()(a ... ) + // keep parentheses here: ) ( var ) ; if (Token::Match(tok->next(), "( %var% ) [;),+-*/><]]") && !tok->isName() && tok->str() != ">" && @@ -7071,7 +7072,8 @@ bool Tokenizer::simplifyCalculations() !Token::simpleMatch(tok->previous(), "* )") && !Token::simpleMatch(tok->previous(), ") )") && !Token::Match(tok->tokAt(-2), "* %var% )") && - !Token::Match(tok->tokAt(-2), "%type% ( ) ( %var%") + !Token::Match(tok->tokAt(-2), "%type% ( ) ( %var%") && + !Token::Match(tok, ") ( %var% ) ;") ) { tok->deleteNext(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index e1a17d748..72e508bd2 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -3557,8 +3557,8 @@ private: const char expected[] = "; " - "void addCallback ( bool ( * callback ) ( int i ) ) { } " - "void addCallback1 ( bool ( * callback ) ( int i ) , int j ) { }"; + "void addCallback ( bool * callback ) { } " + "void addCallback1 ( bool * callback , int j ) { }"; ASSERT_EQUALS(expected, tok(code, false)); } @@ -3574,28 +3574,12 @@ private: const char expected[] = "; " - "void g ( int ( * f ) ( ) ) " + "void g ( int * f ) " "{ " - "int ( * f2 ) ( ) = ( int ( * ) ( ) ) f ; " + "int * f2 ; f2 = ( int ( * ) ( ) ) f ; " "}"; ASSERT_EQUALS(expected, tok(code, false)); - - // TODO: the definition and assignment should be split up - const char wanted[] = - "; " - "void g ( fp f ) " - "{ " - "int ( * f2 ) ( ) ; f2 = ( int ( * ) ( ) ) f ; " - "}"; - const char current[] = - "; " - "void g ( int ( * f ) ( ) ) " - "{ " - "int ( * f2 ) ( ) = ( int ( * ) ( ) ) f ; " - "}"; - - TODO_ASSERT_EQUALS(wanted, current, tok(code, false)); } { @@ -3607,9 +3591,9 @@ private: const char expected[] = "; " - "void g ( int ( * f ) ( ) ) " + "void g ( int * f ) " "{ " - "int ( * f2 ) ( ) = static_cast < int ( * ) ( ) > ( f ) ; " + "int * f2 ; f2 = static_cast < int ( * ) ( ) > ( f ) ; " "}"; ASSERT_EQUALS(expected, tok(code, false));