fix #1280 (Pointer to function support)

This commit is contained in:
Robert Reif 2011-03-19 16:21:26 -04:00
parent 92316e5745
commit fc13854095
2 changed files with 17 additions and 3 deletions

View File

@ -5563,7 +5563,7 @@ void Tokenizer:: simplifyFunctionPointers()
tok = tok->next();
// check that the declaration ends
if (!Token::Match(tok->tokAt(5)->link(), ") ;|,|)|="))
if (!Token::Match(tok->tokAt(5)->link(), ") ;|,|)|=|["))
continue;
// ok simplify this function pointer to an ordinary pointer

View File

@ -267,7 +267,8 @@ private:
TEST_CASE(simplifyConst);
TEST_CASE(switchCase);
TEST_CASE(functionpointer);
TEST_CASE(functionpointer1);
TEST_CASE(functionpointer2);
TEST_CASE(removeRedundantAssignment);
@ -4738,7 +4739,7 @@ private:
return ostr.str();
}
void functionpointer()
void functionpointer1()
{
ASSERT_EQUALS(" void* f;", simplifyFunctionPointers("void (*f)();"));
ASSERT_EQUALS(" void** f;", simplifyFunctionPointers("void *(*f)();"));
@ -4746,6 +4747,19 @@ private:
ASSERT_EQUALS(" unsigned int** f;", simplifyFunctionPointers("unsigned int * (*f)();"));
}
void functionpointer2()
{
const char code[] = "typedef void (* PF)();"
"void f1 ( ) { }"
"PF pf = &f1;"
"PF pfs[] = { &f1, &f1 };";
const char expected[] = "; "
"void f1(){} "
"void* pf; pf=& f1; "
"void* pfs[]={& f1,& f1};";
ASSERT_EQUALS(expected, simplifyFunctionPointers(code));
}
void removeRedundantAssignment()
{
ASSERT_EQUALS("void f ( ) { ; int * q ; }", tokenizeAndStringify("void f() { int *p, *q; p = q; }", true));