Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #13013: Add isFunctionPointer to typeDef-info #6690

Merged
merged 1 commit into from
Aug 16, 2024
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
10 changes: 10 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,10 @@ namespace {
return mEndToken;
}

Token* nameToken() const {
return mNameToken;
}

private:
static bool isCast(const Token* tok) {
if (Token::Match(tok, "( %name% ) (|%name%|%num%"))
Expand Down Expand Up @@ -1145,6 +1149,7 @@ void Tokenizer::simplifyTypedef()
typedefInfo.lineNumber = typedefToken->linenr();
typedefInfo.column = typedefToken->column();
typedefInfo.used = t.second.isUsed();
typedefInfo.isFunctionPointer = Token::Match(t.second.nameToken(), "%name% ) (");
mTypedefInfo.push_back(std::move(typedefInfo));

t.second.removeDeclaration();
Expand Down Expand Up @@ -1645,6 +1650,7 @@ void Tokenizer::simplifyTypedefCpp()
typedefInfo.lineNumber = typeName->linenr();
typedefInfo.column = typeName->column();
typedefInfo.used = false;
typedefInfo.isFunctionPointer = Token::Match(typeName, "%name% ) (");
mTypedefInfo.push_back(std::move(typedefInfo));

while (!done) {
Expand Down Expand Up @@ -6194,6 +6200,10 @@ std::string Tokenizer::dumpTypedefInfo() const
outs += std::to_string(typedefInfo.used?1:0);
outs += "\"";

outs += " isFunctionPointer=\"";
outs += std::to_string(typedefInfo.isFunctionPointer);
outs += "\"";

outs += "/>";
outs += '\n';
}
Expand Down
1 change: 1 addition & 0 deletions lib/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ class CPPCHECKLIB Tokenizer {
int lineNumber;
int column;
bool used;
bool isFunctionPointer;
};
std::vector<TypedefInfo> mTypedefInfo;

Expand Down
17 changes: 16 additions & 1 deletion test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ class TestSimplifyTypedef : public TestFixture {
TEST_CASE(simplifyTypedefOriginalName);

TEST_CASE(typedefInfo1);

TEST_CASE(typedefInfo2);
}

#define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__)
Expand Down Expand Up @@ -4402,10 +4404,23 @@ 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\"/>\n"
" <info name=\"A\" file=\"file.c\" line=\"1\" column=\"1\" used=\"1\" isFunctionPointer=\"0\"/>\n"
" </typedef-info>\n",
xml);
}

void typedefInfo2() {
const std::string xml = dumpTypedefInfo("typedef signed short int16_t;\n"
"typedef void ( *fp16 )( int16_t n );\n"
"void R_11_1 ( void ){\n"
" 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=\"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"
" </typedef-info>\n",xml);
}
};

REGISTER_TEST(TestSimplifyTypedef)
Loading