diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d64fc0ab1..8fcb6afd7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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(); + } + } } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index a3591707a..7d77bc5b2 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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]"));