16#include "llvm/ADT/StringExtras.h"
17#include "llvm/ADT/StringRef.h"
18#include "llvm/ADT/Twine.h"
19#include "llvm/Support/LineIterator.h"
20#include "llvm/Support/MD5.h"
21#include "llvm/Support/Path.h"
35 std::string Signature;
41 Target->getTemplateInstantiationPattern())
44 if (!isa<CXXConstructorDecl>(
Target) && !isa<CXXDestructorDecl>(
Target) &&
45 !isa<CXXConversionDecl>(
Target))
46 Signature.append(
Target->getReturnType().getAsString()).append(
" ");
47 Signature.append(
Target->getQualifiedNameAsString()).append(
"(");
49 for (
int i = 0, paramsCount =
Target->getNumParams(); i < paramsCount; ++i) {
51 Signature.append(
", ");
52 Signature.append(
Target->getParamDecl(i)->getType().getAsString());
56 Signature.append(
", ...");
57 Signature.append(
")");
60 llvm::dyn_cast_or_null<FunctionType>(
Target->getType().getTypePtr());
62 if (!TargetT || !isa<CXXMethodDecl>(
Target))
65 if (TargetT->isConst())
66 Signature.append(
" const");
67 if (TargetT->isVolatile())
68 Signature.append(
" volatile");
69 if (TargetT->isRestrict())
70 Signature.append(
" restrict");
72 if (
const auto *TargetPT =
73 dyn_cast_or_null<FunctionProtoType>(
Target->getType().getTypePtr())) {
74 switch (TargetPT->getRefQualifier()) {
76 Signature.append(
" &");
79 Signature.append(
" &&");
93 if (
const auto *ND = dyn_cast<NamedDecl>(D)) {
96 switch (ND->getKind()) {
101 DeclName = ND->getQualifiedNameAsString();
103 case Decl::CXXConstructor:
104 case Decl::CXXDestructor:
105 case Decl::CXXConversion:
106 case Decl::CXXMethod:
108 DeclName =
GetSignature(dyn_cast_or_null<FunctionDecl>(ND));
110 case Decl::ObjCMethod:
113 DeclName = ND->getQualifiedNameAsString();
130 llvm::line_iterator LI(*Buffer,
false);
131 for (; !LI.is_at_eof() && LI.line_number() != Line; ++LI)
139 static StringRef Whitespaces =
" \t\n";
143 StringRef::size_type col = Str.find_first_not_of(Whitespaces);
144 if (col == StringRef::npos)
150 std::optional<llvm::MemoryBufferRef> Buffer =
151 SM.getBufferOrNone(
SM.getFileID(StartOfLine), StartOfLine);
155 const char *BufferPos =
SM.getCharacterData(StartOfLine);
158 Lexer Lexer(
SM.getLocForStartOfFile(
SM.getFileID(StartOfLine)), LangOpts,
159 Buffer->getBufferStart(), BufferPos, Buffer->getBufferEnd());
161 size_t NextStart = 0;
162 std::ostringstream LineBuff;
170 return LineBuff.str();
175 llvm::MD5::MD5Result MD5Res;
178 Hash.update(Content);
180 llvm::MD5::stringifyResult(MD5Res, Res);
186 StringRef CheckerName,
187 StringRef WarningMessage,
188 const Decl *IssueDecl,
190 static StringRef Delimiter =
"$";
192 return (llvm::Twine(CheckerName) + Delimiter +
196 Delimiter + WarningMessage)
201 StringRef CheckerName,
202 StringRef WarningMessage,
203 const Decl *IssueDecl,
207 IssueLoc, CheckerName, WarningMessage, IssueDecl, LangOpts));
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
static std::string NormalizeLine(const SourceManager &SM, const FullSourceLoc &L, const LangOptions &LangOpts)
static llvm::SmallString< 32 > GetMD5HashOfContent(StringRef Content)
static std::string GetSignature(const FunctionDecl *Target)
static StringRef GetNthLineOfFile(std::optional< llvm::MemoryBufferRef > Buffer, int Line)
static std::string GetEnclosingDeclContextSignature(const Decl *D)
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
Decl - This represents one declaration (or definition), e.g.
A SourceLocation and its associated SourceManager.
unsigned getExpansionColumnNumber(bool *Invalid=nullptr) const
const SourceManager & getManager() const
unsigned getExpansionLineNumber(bool *Invalid=nullptr) const
Represents a function declaration or definition.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens.
bool LexFromRawLexer(Token &Result)
LexFromRawLexer - Lex a token from a designated raw lexer (one with no associated preprocessor object...
Encodes a location in the source.
This class handles loading and caching of source files into memory.
Token - This structure provides full information about a lexed token.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
unsigned getLength() const
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
llvm::SmallString< 32 > getIssueHash(const FullSourceLoc &IssueLoc, llvm::StringRef CheckerName, llvm::StringRef WarningMessage, const Decl *IssueDecl, const LangOptions &LangOpts)
Returns an opaque identifier for a diagnostic.
std::string getIssueString(const FullSourceLoc &IssueLoc, llvm::StringRef CheckerName, llvm::StringRef WarningMessage, const Decl *IssueDecl, const LangOptions &LangOpts)
Get the unhashed string representation of the V1 issue hash.