Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/cppcheckdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ def iterconfigurations(self):
# Parse tokens
elif node.tag == 'tokenlist' and event == 'start':
continue
elif node.tag == 'token' and event == 'start' and not iter_directive:
elif node.tag == 'token' and event == 'start' and not iter_directive and not iter_typedef_info:
cfg.tokenlist.append(Token(node))

# Parse scopes
Expand Down
32 changes: 32 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,17 @@ void Tokenizer::simplifyTypedef()
typedefInfo.column = typedefToken->column();
typedefInfo.used = t.second.isUsed();
typedefInfo.isFunctionPointer = Token::Match(t.second.nameToken(), "%name% ) (");
if (typedefInfo.isFunctionPointer) {
const Token* tok = typedefToken;
while (tok != t.second.endToken()) {
TypedefToken ttok;
ttok.name = tok->str();
ttok.lineNumber = tok->linenr();
ttok.column = tok->column();
typedefInfo.typedefInfoTokens.emplace_back(ttok);
tok = tok->next();
}
}
mTypedefInfo.push_back(std::move(typedefInfo));

t.second.removeDeclaration();
Expand Down Expand Up @@ -1612,6 +1623,17 @@ void Tokenizer::simplifyTypedefCpp()
typedefInfo.column = typeName->column();
typedefInfo.used = false;
typedefInfo.isFunctionPointer = Token::Match(typeName, "%name% ) (");
if (typedefInfo.isFunctionPointer) {
const Token* t = typeDef;
while (t != tok) {
TypedefToken ttok;
ttok.name = t->str();
ttok.lineNumber = t->linenr();
ttok.column = t->column();
typedefInfo.typedefInfoTokens.emplace_back(ttok);
t = t->next();
}
}
mTypedefInfo.push_back(std::move(typedefInfo));

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

outs += "/>";
outs += '\n';
for (const auto& t : typedefInfo.typedefInfoTokens) {
outs += " <token ";
outs += "column=\"";
outs += std::to_string(t.column);
outs += "\" ";
outs += "str=\"";
outs += ErrorLogger::toxml(t.name);
outs += "\"/>";
outs += '\n';
}
}
outs += " </typedef-info>";
outs += '\n';
Expand Down
6 changes: 6 additions & 0 deletions lib/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -655,13 +655,19 @@ class CPPCHECKLIB Tokenizer {
/** sizeof information for known types */
std::map<std::string, int> mTypeSize;

struct TypedefToken {
std::string name;
int lineNumber;
int column;
};
struct TypedefInfo {
std::string name;
std::string filename;
int lineNumber;
int column;
bool used;
bool isFunctionPointer;
std::vector<TypedefToken> typedefInfoTokens;
};
std::vector<TypedefInfo> mTypedefInfo;

Expand Down
27 changes: 27 additions & 0 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4557,8 +4557,35 @@ class TestSimplifyTypedef : public TestFixture {
"}\n");
ASSERT_EQUALS(" <typedef-info>\n"
" <info name=\"fp16\" file=\"file.c\" line=\"2\" column=\"1\" used=\"1\" isFunctionPointer=\"1\"/>\n"
" <token column=\"1\" str=\"typedef\"/>\n"
" <token column=\"9\" str=\"void\"/>\n"
" <token column=\"14\" str=\"(\"/>\n"
" <token column=\"16\" str=\"*\"/>\n"
" <token column=\"17\" str=\"fp16\"/>\n"
" <token column=\"22\" str=\")\"/>\n"
" <token column=\"23\" str=\"(\"/>\n"
" <token column=\"25\" str=\"int16_t\"/>\n"
" <token column=\"33\" str=\"n\"/>\n"
" <token column=\"35\" str=\")\"/>\n"
" <info name=\"int16_t\" file=\"file.c\" line=\"1\" column=\"1\" used=\"1\" isFunctionPointer=\"0\"/>\n"
" <info name=\"pfp16\" file=\"file.c\" line=\"4\" column=\"20\" used=\"0\" isFunctionPointer=\"1\"/>\n"
" <token column=\"4\" str=\"typedef\"/>\n"
" <token column=\"12\" str=\"void\"/>\n"
" <token column=\"12\" str=\"(\"/>\n"
" <token column=\"12\" str=\"*\"/>\n"
" <token column=\"17\" str=\"(\"/>\n"
" <token column=\"19\" str=\"*\"/>\n"
" <token column=\"20\" str=\"pfp16\"/>\n"
" <token column=\"26\" str=\")\"/>\n"
" <token column=\"28\" str=\"(\"/>\n"
" <token column=\"30\" str=\"void\"/>\n"
" <token column=\"35\" str=\")\"/>\n"
" <token column=\"35\" str=\")\"/>\n"
" <token column=\"35\" str=\"(\"/>\n"
" <token column=\"35\" str=\"signed\"/>\n"
" <token column=\"35\" str=\"short\"/>\n"
" <token column=\"35\" str=\"n\"/>\n"
" <token column=\"35\" str=\")\"/>\n"
" </typedef-info>\n",xml);
}

Expand Down