Skip to content

Commit 4278ee6

Browse files
Update tokenize.cpp
1 parent c56d4db commit 4278ee6

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/tokenize.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ namespace {
674674
return;
675675

676676
mUsed = true;
677-
const bool isFunctionPointer = Token::Match(mNameToken, "%name% )");
677+
const bool isFunctionPointer = Tokenizer::isFunctionPointer(mNameToken);
678678

679679
// Special handling for T(...) when T is a pointer
680680
if (Token::Match(tok, "%name% [({]") && !isFunctionPointer && !Token::simpleMatch(tok->linkAt(1), ") (")) {
@@ -1019,6 +1019,11 @@ namespace {
10191019
};
10201020
}
10211021

1022+
bool Tokenizer::isFunctionPointer(const Token* tok) {
1023+
return Token::Match(tok, "%name% ) (");
1024+
}
1025+
1026+
10221027
void Tokenizer::simplifyTypedef()
10231028
{
10241029
// Simplify global typedefs that are not redefined with the fast 1-pass simplification.
@@ -1088,7 +1093,7 @@ void Tokenizer::simplifyTypedef()
10881093
typedefInfo.lineNumber = typedefToken->linenr();
10891094
typedefInfo.column = typedefToken->column();
10901095
typedefInfo.used = t.second.isUsed();
1091-
typedefInfo.isFunctionPointer = Token::Match(t.second.nameToken(), "%name% ) (");
1096+
typedefInfo.isFunctionPointer = isFunctionPointer(t.second.nameToken());
10921097
if (typedefInfo.isFunctionPointer) {
10931098
const Token* tok = typedefToken;
10941099
while (tok != t.second.endToken()) {
@@ -1395,7 +1400,7 @@ void Tokenizer::simplifyTypedefCpp()
13951400
}
13961401

13971402
// function pointer
1398-
if (Token::Match(tokOffset2, "* %name% ) (")) {
1403+
if (isFunctionPointer(tokOffset2)) {
13991404
// name token wasn't a name, it was part of the type
14001405
typeEnd = typeEnd->next();
14011406
functionPtr = true;
@@ -1622,7 +1627,7 @@ void Tokenizer::simplifyTypedefCpp()
16221627
typedefInfo.lineNumber = typeName->linenr();
16231628
typedefInfo.column = typeName->column();
16241629
typedefInfo.used = false;
1625-
typedefInfo.isFunctionPointer = Token::Match(typeName, "%name% ) (");
1630+
typedefInfo.isFunctionPointer = isFunctionPointer(typeName);
16261631
if (typedefInfo.isFunctionPointer) {
16271632
const Token* t = typeDef;
16281633
while (t != tok) {
@@ -7155,7 +7160,7 @@ void Tokenizer::simplifyFunctionPointers()
71557160
while (Token::Match(tok2, "%type%|:: %type%|::"))
71567161
tok2 = tok2->next();
71577162

7158-
if (!Token::Match(tok2, "%name% ) (") &&
7163+
if (!isFunctionPointer(tok2) &&
71597164
!Token::Match(tok2, "%name% [ ] ) (") &&
71607165
!(Token::Match(tok2, "%name% (") && Token::simpleMatch(tok2->linkAt(1), ") ) (")))
71617166
continue;
@@ -7448,7 +7453,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
74487453
}
74497454
// Function pointer
74507455
if (Token::simpleMatch(varName, "( *") &&
7451-
Token::Match(varName->link()->previous(), "%name% ) (") &&
7456+
isFunctionPointer(varName->link()->previous()) &&
74527457
Token::simpleMatch(varName->link()->linkAt(1), ") =")) {
74537458
Token *endDecl = varName->link()->linkAt(1);
74547459
varName = varName->link()->previous();
@@ -9376,7 +9381,7 @@ Token* Tokenizer::getAttributeFuncTok(Token* tok, bool gccattr) const {
93769381
if (Token::simpleMatch(prev, ")")) {
93779382
if (Token::Match(prev->link()->previous(), "%name% ("))
93789383
return prev->link()->previous();
9379-
if (Token::Match(prev->link()->tokAt(-2), "%name% ) ("))
9384+
if (isFunctionPointer(prev->link()->tokAt(-2)))
93809385
return prev->link()->tokAt(-2);
93819386
}
93829387
if (Token::simpleMatch(prev, ")") && Token::Match(prev->link()->tokAt(-2), "operator %op% (") && isCPP())

0 commit comments

Comments
 (0)