Skip to content

Commit 4ab71fc

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

3 files changed

Lines changed: 40 additions & 14 deletions

File tree

lib/tokenize.cpp

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,18 +1104,26 @@ void Tokenizer::simplifyTypedef()
11041104
typedefInfo.filename = list.file(typedefToken);
11051105
typedefInfo.lineNumber = typedefToken->linenr();
11061106
typedefInfo.column = typedefToken->column();
1107+
typedefInfo.tagLineNumber = typedefInfo.lineNumber;
1108+
typedefInfo.tagColumn = typedefInfo.column;
11071109
typedefInfo.used = t.second.isUsed();
11081110
typedefInfo.isFunctionPointer = isFunctionPointer(t.second.nameToken());
1109-
if (typedefInfo.isFunctionPointer) {
1110-
const Token* tok = typedefToken;
1111-
while (tok != t.second.endToken()) {
1111+
const Token* tok = typedefToken;
1112+
while (tok != t.second.endToken()) {
1113+
if (tok->str() == typedefInfo.name) {
1114+
typedefInfo.tagLineNumber = tok->linenr();
1115+
typedefInfo.tagColumn = tok->column();
1116+
if (!typedefInfo.isFunctionPointer)
1117+
break;
1118+
}
1119+
if (typedefInfo.isFunctionPointer) {
11121120
TypedefToken ttok;
11131121
ttok.name = tok->str();
11141122
ttok.lineNumber = tok->linenr();
11151123
ttok.column = tok->column();
11161124
typedefInfo.typedefInfoTokens.emplace_back(ttok);
1117-
tok = tok->next();
11181125
}
1126+
tok = tok->next();
11191127
}
11201128
mTypedefInfo.push_back(std::move(typedefInfo));
11211129

@@ -1638,20 +1646,28 @@ void Tokenizer::simplifyTypedefCpp()
16381646
TypedefInfo typedefInfo;
16391647
typedefInfo.name = typeName->str();
16401648
typedefInfo.filename = list.file(typeName);
1641-
typedefInfo.lineNumber = typeName->linenr();
1642-
typedefInfo.column = typeName->column();
1649+
typedefInfo.lineNumber = typeDef->linenr();
1650+
typedefInfo.column = typeDef->column();
1651+
typedefInfo.tagLineNumber = typedefInfo.lineNumber;
1652+
typedefInfo.tagColumn = typedefInfo.column;
16431653
typedefInfo.used = false;
16441654
typedefInfo.isFunctionPointer = isFunctionPointer(typeName);
1645-
if (typedefInfo.isFunctionPointer) {
1646-
const Token* t = typeDef;
1647-
while (t != tok) {
1655+
const Token* t = typeDef;
1656+
while (t != tok) {
1657+
if (t->str() == typedefInfo.name) {
1658+
typedefInfo.tagLineNumber = t->linenr();
1659+
typedefInfo.tagColumn = t->column();
1660+
if (!typedefInfo.isFunctionPointer)
1661+
break;
1662+
}
1663+
if (typedefInfo.isFunctionPointer) {
16481664
TypedefToken ttok;
16491665
ttok.name = t->str();
16501666
ttok.lineNumber = t->linenr();
16511667
ttok.column = t->column();
16521668
typedefInfo.typedefInfoTokens.emplace_back(ttok);
1653-
t = t->next();
16541669
}
1670+
t = t->next();
16551671
}
16561672
mTypedefInfo.push_back(std::move(typedefInfo));
16571673

@@ -6327,6 +6343,14 @@ std::string Tokenizer::dumpTypedefInfo() const
63276343
outs += std::to_string(typedefInfo.column);
63286344
outs += "\"";
63296345

6346+
outs += " tagline=\"";
6347+
outs += std::to_string(typedefInfo.tagLineNumber);
6348+
outs += "\"";
6349+
6350+
outs += " tagcolumn=\"";
6351+
outs += std::to_string(typedefInfo.tagColumn);
6352+
outs += "\"";
6353+
63306354
outs += " used=\"";
63316355
outs += std::to_string(typedefInfo.used?1:0);
63326356
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)