Fixed #1307 (Internal error with typedef in parameter list)

This commit is contained in:
Robert Reif 2010-01-24 22:40:35 +01:00 committed by Daniel Marjamäki
parent 724c55b32a
commit 989e8393e4
2 changed files with 43 additions and 4 deletions

View File

@ -685,11 +685,21 @@ void Tokenizer::simplifyTypedef()
{
if (tok2->next()->str() != ")" && tok2->next()->str() != ",")
{
tok2 = tok2->next();
if (Token::Match(tok2->next(), "( * %type% ) ("))
tok2 = tok2->tokAt(5)->link();
else
{
tok2 = tok2->next();
// skip over typedef parameter
if (tok2->next()->str() == "(")
tok2 = tok2->next()->link();
// skip over typedef parameter
if (tok2->next()->str() == "(")
{
tok2 = tok2->next()->link();
if (tok2->next()->str() == "(")
tok2 = tok2->next()->link();
}
}
}
}

View File

@ -162,6 +162,7 @@ private:
TEST_CASE(simplifyTypedef23);
TEST_CASE(simplifyTypedef24);
TEST_CASE(simplifyTypedef25);
TEST_CASE(simplifyTypedef26);
TEST_CASE(reverseArraySyntax)
TEST_CASE(simplify_numeric_condition)
@ -2890,6 +2891,34 @@ private:
}
}
void simplifyTypedef26()
{
{
const char code[] = "typedef void (*Callback) ();\n"
"void addCallback(Callback (*callback)());";
const char expected[] =
"; "
"void addCallback ( void ( * ( * callback ) ( ) ) ( ) ) ;";
ASSERT_EQUALS(expected, tok(code, false));
}
{
// ticket # 1307
const char code[] = "typedef void (*pc_video_update_proc)(bitmap_t *bitmap,\n"
"struct mscrtc6845 *crtc);\n"
"\n"
"struct mscrtc6845 *pc_video_start(pc_video_update_proc (*choosevideomode)(running_machine *machine, int *width, int *height, struct mscrtc6845 *crtc));";
const char expected[] =
"; "
"struct mscrtc6845 * pc_video_start ( void ( * ( * choosevideomode ) ( running_machine * machine , int * width , int * height , struct mscrtc6845 * crtc ) ) ( bitmap_t * bitmap , struct mscrtc6845 * crtc ) ) ;";
ASSERT_EQUALS(expected, tok(code, false));
}
}
void reverseArraySyntax()
{
ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));