Fixed #5667 (Tokenizer: simplify 'void (X::*f)()' to 'void *f')

This commit is contained in:
Daniel Marjamäki 2014-04-27 19:49:21 +02:00
parent ed541ba3b4
commit 9c74d914d7
3 changed files with 33 additions and 19 deletions

View File

@ -5135,7 +5135,11 @@ void Tokenizer:: simplifyFunctionPointers()
Token *tok2 = (tok && tok->isName()) ? tok->next() : nullptr;
while (Token::Match(tok2, "*|&"))
tok2 = tok2->next();
if (!Token::Match(tok2, "( * %var%"))
if (!tok2 || tok2->str() != "(")
continue;
while (Token::Match(tok2, "(|:: %type%"))
tok2 = tok2->tokAt(2);
if (!Token::Match(tok2, "(|:: * %var%"))
continue;
tok2 = tok2->tokAt(2);
while (Token::Match(tok2, "%type%|:: %type%|::"))
@ -5157,6 +5161,8 @@ void Tokenizer:: simplifyFunctionPointers()
// ok simplify this function pointer to an ordinary pointer
Token::eraseTokens(tok->link(), endTok->next());
tok->link()->deleteThis();
while (Token::Match(tok, "( %type% ::"))
tok->deleteNext(2);
tok->deleteThis();
}
}

View File

@ -4751,7 +4751,7 @@ private:
"F f;";
// The expected result..
const std::string expected("void ( X :: * f ) ( ) ;");
const std::string expected("void * f ;");
ASSERT_EQUALS(expected, tok(code));
}
}
@ -5995,9 +5995,9 @@ private:
const std::string expected("C f1 ( ) ; "
"C * f2 ; " // this gets simplified to a regular pointer
"C ( & f3 ) ( ) ; "
"C ( C :: * f4 ) ( ) ; "
"C * f4 ; "
"C ( C :: * f5 ) ( ) const ; "
"C ( C :: * f6 ) ( ) ; " // volatile is removed
"C * f6 ; " // volatile is removed
"C ( C :: * f7 ) ( ) const ;"); // volatile is removed
ASSERT_EQUALS(expected, tok(code));
@ -6026,9 +6026,9 @@ private:
const std::string expected("const C f1 ( ) ; "
"const C * f2 ; " // this gets simplified to a regular pointer
"const C ( & f3 ) ( ) ; "
"const C ( C :: * f4 ) ( ) ; "
"const C * f4 ; "
"const C ( C :: * f5 ) ( ) const ; "
"const C ( C :: * f6 ) ( ) ; " // volatile is removed
"const C * f6 ; " // volatile is removed
"const C ( C :: * f7 ) ( ) const ;"); // volatile is removed
ASSERT_EQUALS(expected, tok(code));
@ -6056,9 +6056,9 @@ private:
const std::string expected("const C f1 ( ) ; "
"const C * f2 ; " // this gets simplified to a regular pointer
"const C ( & f3 ) ( ) ; "
"const C ( C :: * f4 ) ( ) ; "
"const C * f4 ; "
"const C ( C :: * f5 ) ( ) const ; "
"const C ( C :: * f6 ) ( ) ; " // volatile is removed
"const C * f6 ; " // volatile is removed
"const C ( C :: * f7 ) ( ) const ;"); // volatile is removed
ASSERT_EQUALS(expected, tok(code));
@ -6086,9 +6086,9 @@ private:
const std::string expected("C * f1 ( ) ; "
"C * * f2 ; " // this gets simplified to a regular pointer
"C * ( & f3 ) ( ) ; "
"C * ( C :: * f4 ) ( ) ; "
"C * * f4 ; "
"C * ( C :: * f5 ) ( ) const ; "
"C * ( C :: * f6 ) ( ) ; " // volatile is removed
"C * * f6 ; " // volatile is removed
"C * ( C :: * f7 ) ( ) const ;"); // volatile is removed
ASSERT_EQUALS(expected, tok(code));
@ -6116,9 +6116,9 @@ private:
const std::string expected("const C * f1 ( ) ; "
"const C * * f2 ; " // this gets simplified to a regular pointer
"const C * ( & f3 ) ( ) ; "
"const C * ( C :: * f4 ) ( ) ; "
"const C * * f4 ; "
"const C * ( C :: * f5 ) ( ) const ; "
"const C * ( C :: * f6 ) ( ) ; " // volatile is removed
"const C * * f6 ; " // volatile is removed
"const C * ( C :: * f7 ) ( ) const ;"); // volatile is removed
ASSERT_EQUALS(expected, tok(code));
@ -6147,9 +6147,9 @@ private:
const std::string expected("const C * f1 ( ) ; "
"const C * * f2 ; " // this gets simplified to a regular pointer
"const C * ( & f3 ) ( ) ; "
"const C * ( C :: * f4 ) ( ) ; "
"const C * * f4 ; "
"const C * ( C :: * f5 ) ( ) const ; "
"const C * ( C :: * f6 ) ( ) ; " // volatile is removed
"const C * * f6 ; " // volatile is removed
"const C * ( C :: * f7 ) ( ) const ;"); // volatile is removed
ASSERT_EQUALS(expected, tok(code));
@ -6207,10 +6207,10 @@ private:
"int * const t2 ; "
"int * t3 ; " // volatile removed, gets simplified to regular pointer
"int * const t4 ; " // volatile removed
"int ( C :: * t5 ) ( float ) ; "
"int ( C :: * const t6 ) ( float ) ; "
"int ( C :: * t7 ) ( float ) ; " // volatile removed
"int ( C :: * const t8 ) ( float ) ; " // volatile removed
"int * t5 ; "
"int * const t6 ; "
"int * t7 ; " // volatile removed
"int * const t8 ; " // volatile removed
"int ( :: C :: * t9 ) ( float ) ; "
"int ( :: C :: * const t10 ) ( float ) ; "
"int ( :: C :: * t11 ) ( float ) ; " // volatile removed

View File

@ -440,6 +440,7 @@ private:
TEST_CASE(functionpointer4);
TEST_CASE(functionpointer5);
TEST_CASE(functionpointer6);
TEST_CASE(functionpointer7);
TEST_CASE(removeRedundantAssignment);
@ -5189,7 +5190,7 @@ private:
"1: struct A ;\n"
"2:\n"
"3: struct A {\n"
"4: bool ( A :: * pFun@1 ) ( ) ;\n"
"4: bool * pFun@1 ;\n"
"5: void setPFun ( int mode@2 ) ;\n"
"6: bool funcNorm ( ) ;\n"
"7: } ;\n"
@ -7074,6 +7075,13 @@ private:
ASSERT_EQUALS(expected2, tokenizeDebugListing(code2, false));
}
void functionpointer7() {
const char code1[] = "void (X::*y)();";
const char expected1[] = "\n\n##file 0\n"
"1: void * y@1 ;\n";
ASSERT_EQUALS(expected1, tokenizeDebugListing(code1, false));
}
void removeRedundantAssignment() {
ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() { int *p, *q; p = q; }", true));
ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() { int *p = 0, *q; p = q; }", true));