Skip to content

Commit 74d0e0e

Browse files
committed
Add tokens to function pointer typedef
1 parent 107d10e commit 74d0e0e

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

lib/tokenize.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,17 @@ void Tokenizer::simplifyTypedef()
10891089
typedefInfo.column = typedefToken->column();
10901090
typedefInfo.used = t.second.isUsed();
10911091
typedefInfo.isFunctionPointer = Token::Match(t.second.nameToken(), "%name% ) (");
1092+
if (typedefInfo.isFunctionPointer) {
1093+
const Token* tok = typedefToken;
1094+
while (tok != t.second.endToken()) {
1095+
TypedefToken ttok;
1096+
ttok.name = tok->str();
1097+
ttok.lineNumber = tok->linenr();
1098+
ttok.column = tok->column();
1099+
typedefInfo.typedefInfoTokens.emplace_back(ttok);
1100+
tok = tok->next();
1101+
}
1102+
}
10921103
mTypedefInfo.push_back(std::move(typedefInfo));
10931104

10941105
t.second.removeDeclaration();
@@ -1612,6 +1623,17 @@ void Tokenizer::simplifyTypedefCpp()
16121623
typedefInfo.column = typeName->column();
16131624
typedefInfo.used = false;
16141625
typedefInfo.isFunctionPointer = Token::Match(typeName, "%name% ) (");
1626+
if (typedefInfo.isFunctionPointer) {
1627+
const Token* t = typeDef;
1628+
while (t != tok) {
1629+
TypedefToken ttok;
1630+
ttok.name = t->str();
1631+
ttok.lineNumber = t->linenr();
1632+
ttok.column = t->column();
1633+
typedefInfo.typedefInfoTokens.emplace_back(ttok);
1634+
t = t->next();
1635+
}
1636+
}
16151637
mTypedefInfo.push_back(std::move(typedefInfo));
16161638

16171639
while (!done) {
@@ -6291,6 +6313,16 @@ std::string Tokenizer::dumpTypedefInfo() const
62916313

62926314
outs += "/>";
62936315
outs += '\n';
6316+
for (const auto& t : typedefInfo.typedefInfoTokens) {
6317+
outs += " <token ";
6318+
outs += "column=\"";
6319+
outs += std::to_string(t.column);
6320+
outs += "\" ";
6321+
outs += "str=\"";
6322+
outs += ErrorLogger::toxml(t.name);
6323+
outs += "\"/>";
6324+
outs += '\n';
6325+
}
62946326
}
62956327
outs += " </typedef-info>";
62966328
outs += '\n';

lib/tokenize.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,13 +655,19 @@ class CPPCHECKLIB Tokenizer {
655655
/** sizeof information for known types */
656656
std::map<std::string, int> mTypeSize;
657657

658+
struct TypedefToken {
659+
std::string name;
660+
int lineNumber;
661+
int column;
662+
};
658663
struct TypedefInfo {
659664
std::string name;
660665
std::string filename;
661666
int lineNumber;
662667
int column;
663668
bool used;
664669
bool isFunctionPointer;
670+
std::vector<TypedefToken> typedefInfoTokens;
665671
};
666672
std::vector<TypedefInfo> mTypedefInfo;
667673

0 commit comments

Comments
 (0)