partial fix for #2624 (better function pointer support needed)

This commit is contained in:
Robert Reif 2011-03-05 20:48:28 -05:00
parent b9df7735c5
commit 7d2fb2ecde
2 changed files with 12 additions and 26 deletions

View File

@ -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();

View File

@ -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));