Skip to content
Open
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
22 changes: 16 additions & 6 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1113,14 +1113,18 @@ void Tokenizer::simplifyTypedef()
syntaxError(t.second.getTypedefToken());
} else {
const Token* const typedefToken = t.second.getTypedefToken();
const Token* const nameToken = t.second.nameToken();
TypedefInfo typedefInfo;
typedefInfo.name = t.second.name();
typedefInfo.filename = list.file(typedefToken);
typedefInfo.lineNumber = typedefToken->linenr();
typedefInfo.column = typedefToken->column();
if (Token::Match(typedefToken->next(), "struct|enum|class|union %name% {") && typedefToken->strAt(2) == typedefInfo.name) {
typedefInfo.tagLine = typedefToken->tokAt(2)->linenr();
typedefInfo.tagColumn = typedefToken->tokAt(2)->column();
typedefInfo.filename = list.file(nameToken);
typedefInfo.lineNumber = nameToken->linenr();
typedefInfo.column = nameToken->column();
if (Token::Match(typedefToken->next(), "struct|enum|class|union %name% {")) {
typedefInfo.originalName = typedefToken->strAt(2);
if (typedefToken->strAt(2) == typedefInfo.name) {
typedefInfo.tagLine = typedefToken->tokAt(2)->linenr();
typedefInfo.tagColumn = typedefToken->tokAt(2)->column();
}
}
typedefInfo.used = t.second.isUsed();
typedefInfo.isFunctionPointer = isFunctionPointer(t.second.nameToken());
Expand Down Expand Up @@ -6371,6 +6375,12 @@ std::string Tokenizer::dumpTypedefInfo() const
outs += typedefInfo.name;
outs += "\"";

if (!typedefInfo.originalName.empty()) {
outs += " originalName=\"";
outs += typedefInfo.originalName;
outs += "\"";
}

outs += " file=\"";
outs += ErrorLogger::toxml(typedefInfo.filename);
outs += "\"";
Expand Down
1 change: 1 addition & 0 deletions lib/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ class CPPCHECKLIB Tokenizer {
};
struct TypedefInfo {
std::string name;
std::string originalName;
std::string filename;
int lineNumber;
int column;
Expand Down
4 changes: 2 additions & 2 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def test_addon_misra(tmpdir):
assert lines == [
'Checking {} ...'.format(test_file)
]
assert stderr == '{}:2:1: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-2.3]\ntypedef int MISRA_5_6_VIOLATION;\n^\n'.format(test_file)
assert stderr == '{}:2:13: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-2.3]\ntypedef int MISRA_5_6_VIOLATION;\n ^\n'.format(test_file)


def test_addon_y2038(tmpdir):
Expand Down Expand Up @@ -2674,7 +2674,7 @@ def __test_addon_suppr(tmp_path, extra_args):
assert exitcode == 0, stdout
assert stdout == ''
assert stderr.splitlines() == [
'{}:4:1: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-2.3]'.format(test_file),
'{}:4:13: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-2.3]'.format(test_file),
]


Expand Down
8 changes: 4 additions & 4 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4608,7 +4608,7 @@ class TestSimplifyTypedef : public TestFixture {
void typedefInfo1() {
const std::string xml = dumpTypedefInfo("typedef int A;\nA x;");
ASSERT_EQUALS(" <typedef-info>\n"
" <info name=\"A\" file=\"file.c\" line=\"1\" column=\"1\" used=\"1\" isFunctionPointer=\"0\"/>\n"
" <info name=\"A\" file=\"file.c\" line=\"1\" column=\"13\" used=\"1\" isFunctionPointer=\"0\"/>\n"
" </typedef-info>\n",
xml);
}
Expand All @@ -4620,7 +4620,7 @@ class TestSimplifyTypedef : public TestFixture {
" typedef fp16 ( *pfp16 ) ( void );\n"
"}\n");
ASSERT_EQUALS(" <typedef-info>\n"
" <info name=\"fp16\" file=\"file.c\" line=\"2\" column=\"1\" used=\"1\" isFunctionPointer=\"1\">\n"
" <info name=\"fp16\" file=\"file.c\" line=\"2\" column=\"17\" used=\"1\" isFunctionPointer=\"1\">\n"
" <token line=\"2\" column=\"1\" str=\"typedef\"/>\n"
" <token line=\"2\" column=\"9\" str=\"void\"/>\n"
" <token line=\"2\" column=\"14\" str=\"(\"/>\n"
Expand All @@ -4632,7 +4632,7 @@ class TestSimplifyTypedef : public TestFixture {
" <token line=\"2\" column=\"33\" str=\"n\"/>\n"
" <token line=\"2\" column=\"35\" str=\")\"/>\n"
" </info>\n"
" <info name=\"int16_t\" file=\"file.c\" line=\"1\" column=\"1\" used=\"1\" isFunctionPointer=\"0\"/>\n"
" <info name=\"int16_t\" file=\"file.c\" line=\"1\" column=\"22\" used=\"1\" isFunctionPointer=\"0\"/>\n"
" <info name=\"pfp16\" file=\"file.c\" line=\"4\" column=\"4\" used=\"0\" isFunctionPointer=\"1\">\n"
" <token line=\"4\" column=\"4\" str=\"typedef\"/>\n"
" <token line=\"4\" column=\"12\" str=\"void\"/>\n"
Expand Down Expand Up @@ -4670,7 +4670,7 @@ class TestSimplifyTypedef : public TestFixture {
"} coord;\n"
"coord c;");
ASSERT_EQUALS(" <typedef-info>\n"
" <info name=\"coord\" file=\"file.c\" line=\"1\" column=\"1\" tagline=\"1\" tagcolumn=\"16\" used=\"1\" isFunctionPointer=\"0\"/>\n"
" <info name=\"coord\" originalName=\"coord\" file=\"file.c\" line=\"4\" column=\"3\" tagline=\"1\" tagcolumn=\"16\" used=\"1\" isFunctionPointer=\"0\"/>\n"
" </typedef-info>\n", xml);
}
};
Expand Down
Loading