Skip to content

Commit 3678766

Browse files
committed
Add tag line and column in typedef-info in dump file
1 parent a8f83c1 commit 3678766

3 files changed

Lines changed: 36 additions & 14 deletions

File tree

lib/tokenize.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,16 +1106,22 @@ void Tokenizer::simplifyTypedef()
11061106
typedefInfo.column = typedefToken->column();
11071107
typedefInfo.used = t.second.isUsed();
11081108
typedefInfo.isFunctionPointer = isFunctionPointer(t.second.nameToken());
1109-
if (typedefInfo.isFunctionPointer) {
1110-
const Token* tok = typedefToken;
1111-
while (tok != t.second.endToken()) {
1109+
const Token* tok = typedefToken;
1110+
while (tok != t.second.endToken()) {
1111+
if (tok->str() == typedefInfo.name) {
1112+
typedefInfo.tagLineNumber = tok->linenr();
1113+
typedefInfo.tagColumn = tok->column();
1114+
if (!typedefInfo.isFunctionPointer)
1115+
break;
1116+
}
1117+
if (typedefInfo.isFunctionPointer) {
11121118
TypedefToken ttok;
11131119
ttok.name = tok->str();
11141120
ttok.lineNumber = tok->linenr();
11151121
ttok.column = tok->column();
11161122
typedefInfo.typedefInfoTokens.emplace_back(ttok);
1117-
tok = tok->next();
11181123
}
1124+
tok = tok->next();
11191125
}
11201126
mTypedefInfo.push_back(std::move(typedefInfo));
11211127

@@ -1638,20 +1644,26 @@ void Tokenizer::simplifyTypedefCpp()
16381644
TypedefInfo typedefInfo;
16391645
typedefInfo.name = typeName->str();
16401646
typedefInfo.filename = list.file(typeName);
1641-
typedefInfo.lineNumber = typeName->linenr();
1642-
typedefInfo.column = typeName->column();
1647+
typedefInfo.lineNumber = typeDef->linenr();
1648+
typedefInfo.column = typeDef->column();
16431649
typedefInfo.used = false;
16441650
typedefInfo.isFunctionPointer = isFunctionPointer(typeName);
1645-
if (typedefInfo.isFunctionPointer) {
1646-
const Token* t = typeDef;
1647-
while (t != tok) {
1651+
const Token* t = typeDef;
1652+
while (t != tok) {
1653+
if (t->str() == typedefInfo.name) {
1654+
typedefInfo.tagLineNumber = t->linenr();
1655+
typedefInfo.tagColumn = t->column();
1656+
if (!typedefInfo.isFunctionPointer)
1657+
break;
1658+
}
1659+
if (typedefInfo.isFunctionPointer) {
16481660
TypedefToken ttok;
16491661
ttok.name = t->str();
16501662
ttok.lineNumber = t->linenr();
16511663
ttok.column = t->column();
16521664
typedefInfo.typedefInfoTokens.emplace_back(ttok);
1653-
t = t->next();
16541665
}
1666+
t = t->next();
16551667
}
16561668
mTypedefInfo.push_back(std::move(typedefInfo));
16571669

@@ -6327,6 +6339,14 @@ std::string Tokenizer::dumpTypedefInfo() const
63276339
outs += std::to_string(typedefInfo.column);
63286340
outs += "\"";
63296341

6342+
outs += " tagline=\"";
6343+
outs += std::to_string(typedefInfo.tagLineNumber);
6344+
outs += "\"";
6345+
6346+
outs += " tagcolumn=\"";
6347+
outs += std::to_string(typedefInfo.tagColumn);
6348+
outs += "\"";
6349+
63306350
outs += " used=\"";
63316351
outs += std::to_string(typedefInfo.used?1:0);
63326352
outs += "\"";

lib/tokenize.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,8 @@ class CPPCHECKLIB Tokenizer {
696696
std::string filename;
697697
int lineNumber;
698698
int column;
699+
int tagLineNumber;
700+
int tagColumn;
699701
bool used;
700702
bool isFunctionPointer;
701703
std::vector<TypedefToken> typedefInfoTokens;

test/testsimplifytypedef.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4584,7 +4584,7 @@ class TestSimplifyTypedef : public TestFixture {
45844584
void typedefInfo1() {
45854585
const std::string xml = dumpTypedefInfo("typedef int A;\nA x;");
45864586
ASSERT_EQUALS(" <typedef-info>\n"
4587-
" <info name=\"A\" file=\"file.c\" line=\"1\" column=\"1\" used=\"1\" isFunctionPointer=\"0\"/>\n"
4587+
" <info name=\"A\" file=\"file.c\" line=\"1\" column=\"1\" tagline=\"1\" tagcolumn=\"13\" used=\"1\" isFunctionPointer=\"0\"/>\n"
45884588
" </typedef-info>\n",
45894589
xml);
45904590
}
@@ -4596,7 +4596,7 @@ class TestSimplifyTypedef : public TestFixture {
45964596
" typedef fp16 ( *pfp16 ) ( void );\n"
45974597
"}\n");
45984598
ASSERT_EQUALS(" <typedef-info>\n"
4599-
" <info name=\"fp16\" file=\"file.c\" line=\"2\" column=\"1\" used=\"1\" isFunctionPointer=\"1\">\n"
4599+
" <info name=\"fp16\" file=\"file.c\" line=\"2\" column=\"1\" tagline=\"2\" tagcolumn=\"17\" used=\"1\" isFunctionPointer=\"1\">\n"
46004600
" <token line=\"2\" column=\"1\" str=\"typedef\"/>\n"
46014601
" <token line=\"2\" column=\"9\" str=\"void\"/>\n"
46024602
" <token line=\"2\" column=\"14\" str=\"(\"/>\n"
@@ -4608,8 +4608,8 @@ class TestSimplifyTypedef : public TestFixture {
46084608
" <token line=\"2\" column=\"33\" str=\"n\"/>\n"
46094609
" <token line=\"2\" column=\"35\" str=\")\"/>\n"
46104610
" </info>\n"
4611-
" <info name=\"int16_t\" file=\"file.c\" line=\"1\" column=\"1\" used=\"1\" isFunctionPointer=\"0\"/>\n"
4612-
" <info name=\"pfp16\" file=\"file.c\" line=\"4\" column=\"20\" used=\"0\" isFunctionPointer=\"1\">\n"
4611+
" <info name=\"int16_t\" file=\"file.c\" line=\"1\" column=\"1\" tagline=\"1\" tagcolumn=\"22\" used=\"1\" isFunctionPointer=\"0\"/>\n"
4612+
" <info name=\"pfp16\" file=\"file.c\" line=\"4\" column=\"4\" tagline=\"4\" tagcolumn=\"20\" used=\"0\" isFunctionPointer=\"1\">\n"
46134613
" <token line=\"4\" column=\"4\" str=\"typedef\"/>\n"
46144614
" <token line=\"4\" column=\"12\" str=\"void\"/>\n"
46154615
" <token line=\"4\" column=\"12\" str=\"(\"/>\n"

0 commit comments

Comments
 (0)