Tokenizer: Better handling of array of function pointers
This commit is contained in:
parent
326d6df9f5
commit
987392f254
|
@ -5734,9 +5734,9 @@ void Tokenizer:: simplifyFunctionPointers()
|
|||
else if (tok->previous() && !Token::Match(tok->previous(), "{|}|;|(|public:|protected:|private:"))
|
||||
continue;
|
||||
|
||||
if (Token::Match(tok, "%type% *| *| ( * %var% ) ("))
|
||||
if (Token::Match(tok, "%type% *| *| ( * %var% [| ]| ) ("))
|
||||
;
|
||||
else if (Token::Match(tok, "%type% %type% *| *| ( * %var% ) ("))
|
||||
else if (Token::Match(tok, "%type% %type% *| *| ( * %var% [| ]| ) ("))
|
||||
tok = tok->next();
|
||||
else
|
||||
continue;
|
||||
|
@ -5745,13 +5745,14 @@ void Tokenizer:: simplifyFunctionPointers()
|
|||
tok = tok->next();
|
||||
|
||||
// check that the declaration ends
|
||||
if (!Token::Match(tok->linkAt(5), ") ;|,|)|=|["))
|
||||
const Token *endTok = tok->next()->link()->next()->link();
|
||||
if (!Token::Match(endTok, ") ;|,|)|=|["))
|
||||
continue;
|
||||
|
||||
// ok simplify this function pointer to an ordinary pointer
|
||||
Token::eraseTokens(tok->next()->link(), endTok->next());
|
||||
tok->next()->link()->deleteThis();
|
||||
tok->deleteNext();
|
||||
tok->tokAt(2)->deleteNext();
|
||||
Token::eraseTokens(tok->tokAt(2), tok->linkAt(3)->next());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -315,6 +315,7 @@ private:
|
|||
TEST_CASE(functionpointer2);
|
||||
TEST_CASE(functionpointer3);
|
||||
TEST_CASE(functionpointer4);
|
||||
TEST_CASE(functionpointer5);
|
||||
|
||||
TEST_CASE(removeRedundantAssignment);
|
||||
|
||||
|
@ -5078,6 +5079,13 @@ private:
|
|||
ASSERT_EQUALS(expected, tokenizeDebugListing(code, false));
|
||||
}
|
||||
|
||||
void functionpointer5() {
|
||||
const char code[] = ";void (*fp[])(int a) = {0,0,0};";
|
||||
const char expected[] = "\n\n##file 0\n"
|
||||
"1: ; void * fp@1 [ ] = { 0 , 0 , 0 } ;\n";
|
||||
ASSERT_EQUALS(expected, tokenizeDebugListing(code, false));
|
||||
}
|
||||
|
||||
void removeRedundantAssignment() {
|
||||
ASSERT_EQUALS("void f ( ) { int * q ; }", tokenizeAndStringify("void f() { int *p, *q; p = q; }", true));
|
||||
ASSERT_EQUALS("void f ( ) { int * q ; }", tokenizeAndStringify("void f() { int *p = 0, *q; p = q; }", true));
|
||||
|
|
Loading…
Reference in New Issue