From 28c6e11471bad6b548e331973199167a3a695b7b Mon Sep 17 00:00:00 2001 From: swasti16 Date: Tue, 13 Aug 2024 19:14:13 +0530 Subject: [PATCH] Add isFunctionPointer to typeDef-info --- lib/tokenize.cpp | 11 +++++++++++ lib/tokenize.h | 1 + 2 files changed, 12 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f4bcf9574770..640e0e3cf3fe 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1134,6 +1134,12 @@ void Tokenizer::simplifyTypedef() if (!typedefs.empty()) { // remove typedefs + auto isFunctionPointer = [](const Token* start, const Token* end) { + for (const Token* t = start; t != end; t = t->next()) { + if (Token::Match(t, "* %name% ) (")) + return true; + } + }; for (auto &t: typedefs) { if (t.second.replaceFailed()) { syntaxError(t.second.getTypedefToken()); @@ -1145,6 +1151,7 @@ void Tokenizer::simplifyTypedef() typedefInfo.lineNumber = typedefToken->linenr(); typedefInfo.column = typedefToken->column(); typedefInfo.used = t.second.isUsed(); + typedefInfo.isFunctionPointer = isFunctionPointer(typedefToken->next(), t.second.endToken()); mTypedefInfo.push_back(std::move(typedefInfo)); t.second.removeDeclaration(); @@ -6184,6 +6191,10 @@ void Tokenizer::dump(std::ostream &out) const outs += std::to_string(typedefInfo.used?1:0); outs += "\""; + outs += " isFunctionPointer=\""; + outs += std::to_string(typedefInfo.isFunctionPointer); + outs += "\""; + outs += "/>"; outs += '\n'; } diff --git a/lib/tokenize.h b/lib/tokenize.h index 5043c67d73bb..c3cd47cf31f2 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -666,6 +666,7 @@ class CPPCHECKLIB Tokenizer { int lineNumber; int column; bool used; + bool isFunctionPointer; }; std::vector mTypedefInfo;