simplifyTypedef: Better handling of 'typedef int RexxFunctionHandler();'. Ticket: #2348

This commit is contained in:
Robert Reif 2010-12-29 20:25:47 +01:00 committed by Daniel Marjamäki
parent 3f1f50e970
commit 3900ac731e
2 changed files with 24 additions and 7 deletions

View File

@ -1440,6 +1440,9 @@ void Tokenizer::simplifyTypedef()
tok2 = tok2->tokAt(5)->link(); tok2 = tok2->tokAt(5)->link();
else if (Token::Match(tok2->next(), "* ( * %type% ) (")) else if (Token::Match(tok2->next(), "* ( * %type% ) ("))
tok2 = tok2->tokAt(6)->link(); tok2 = tok2->tokAt(6)->link();
else if (Token::Match(tok2->next(), "* ( %type% [") &&
Token::Match(tok2->tokAt(4)->link(), "] ) ;|="))
tok2 = tok2->tokAt(4)->link()->next();
else else
{ {
if (tok2->next()->str() == "(") if (tok2->next()->str() == "(")

View File

@ -228,6 +228,7 @@ private:
TEST_CASE(simplifyTypedef68); // ticket #2355 TEST_CASE(simplifyTypedef68); // ticket #2355
TEST_CASE(simplifyTypedef69); // ticket #2348 TEST_CASE(simplifyTypedef69); // ticket #2348
TEST_CASE(simplifyTypedef70); // ticket #2348 TEST_CASE(simplifyTypedef70); // ticket #2348
TEST_CASE(simplifyTypedef71); // ticket #2348
TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685 TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -4654,13 +4655,11 @@ private:
"{\n" "{\n"
" CompilerHook *(*compilerHookVector)(void);\n" " CompilerHook *(*compilerHookVector)(void);\n"
"}VirtualMachine;\n"; "}VirtualMachine;\n";
const std::string expected = "; " const std::string expected = "; "
"struct VirtualMachine " "struct VirtualMachine "
"{ " "{ "
"int ( * * ( * compilerHookVector ) ( void ) ) ( ) ; " "int ( * * ( * compilerHookVector ) ( void ) ) ( ) ; "
"} ;"; "} ;";
ASSERT_EQUALS(expected, sizeof_(code)); ASSERT_EQUALS(expected, sizeof_(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
@ -4669,17 +4668,32 @@ private:
{ {
const char code[] = "typedef int pread_f ( int ) ;\n" const char code[] = "typedef int pread_f ( int ) ;\n"
"pread_f *(*test_func)(char *filename);\n"; "pread_f *(*test_func)(char *filename);\n";
const std::string expected = "; " const std::string expected = "; "
"int ( * ( * test_func ) ( char * filename ) ) ( int ) ;"; "int ( * ( * test_func ) ( char * filename ) ) ( int ) ;";
ASSERT_EQUALS(expected, sizeof_(code)); ASSERT_EQUALS(expected, sizeof_(code));
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void simplifyTypedef71() // ticket #2348
{
{
const char code[] = "typedef int RexxFunctionHandler();\n"
"RexxFunctionHandler *(efuncs[1]);\n";
const std::string expected = "; "
"int ( * ( efuncs [ 1 ] ) ) ( ) ;";
ASSERT_EQUALS(expected, sizeof_(code));
ASSERT_EQUALS("", errout.str());
}
{
const char code[] = "typedef int RexxFunctionHandler();\n"
"RexxFunctionHandler *(efuncs[]) = { NULL, NULL };\n";
const std::string expected = "; "
"int ( * ( efuncs [ ] ) ) ( ) = { 0 , 0 } ;";
ASSERT_EQUALS(expected, sizeof_(code));
ASSERT_EQUALS("", errout.str());
}
}
void simplifyTypedefFunction1() void simplifyTypedefFunction1()
{ {
{ {