From 434886f0e6cc7f86bbe15206751708a9c7182949 Mon Sep 17 00:00:00 2001 From: swasti16 Date: Tue, 13 Aug 2024 19:14:13 +0530 Subject: [PATCH] Fix #6690: Add isFunctionPointer to typeDef-info --- lib/tokenize.cpp | 17 ++++++++++++++--- lib/tokenize.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c954ca0eba74..f7cedc415336 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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%")) @@ -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(); @@ -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) { @@ -6194,11 +6200,16 @@ std::string Tokenizer::dumpTypedefInfo() const outs += std::to_string(typedefInfo.used?1:0); outs += "\""; - outs += "/>"; + outs += " isFunctionPointer=\""; + outs += std::to_string(typedefInfo.isFunctionPointer); + outs += "\""; + + outs += "/>"; + outs += '\n'; + } + outs += " "; outs += '\n'; } - outs += " "; - outs += '\n'; return outs; } diff --git a/lib/tokenize.h b/lib/tokenize.h index cb66342797e4..ea4ddffcffa6 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -667,6 +667,7 @@ class CPPCHECKLIB Tokenizer { int lineNumber; int column; bool used; + bool isFunctionPointer; }; std::vector mTypedefInfo;