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"
27 using namespace clang;
34 std::string Signature;
36 if (!isa<CXXConstructorDecl>(Target) && !isa<CXXDestructorDecl>(Target) &&
37 !isa<CXXConversionDecl>(Target))
41 for (
int i = 0, paramsCount = Target->
getNumParams(); i < paramsCount; ++i) {
43 Signature.append(
", ");
48 Signature.append(
", ...");
49 Signature.append(
")");
54 if (!TargetT || !isa<CXXMethodDecl>(Target))
57 if (TargetT->isConst())
58 Signature.append(
" const");
59 if (TargetT->isVolatile())
60 Signature.append(
" volatile");
61 if (TargetT->isRestrict())
62 Signature.append(
" restrict");
64 if (
const auto *TargetPT =
66 switch (TargetPT->getRefQualifier()) {
68 Signature.append(
" &");
71 Signature.append(
" &&");
85 if (
const auto *ND = dyn_cast<NamedDecl>(D)) {
88 switch (ND->getKind()) {
93 DeclName = ND->getQualifiedNameAsString();
95 case Decl::CXXConstructor:
96 case Decl::CXXDestructor:
97 case Decl::CXXConversion:
100 DeclName =
GetSignature(dyn_cast_or_null<FunctionDecl>(ND));
102 case Decl::ObjCMethod:
105 DeclName = ND->getQualifiedNameAsString();
121 llvm::line_iterator LI(*Buffer,
false);
122 for (; !LI.is_at_eof() && LI.line_number() !=
Line; ++LI)
134 StringRef::size_type col = Str.find_first_not_of(Whitespaces);
135 if (col == StringRef::npos)
141 llvm::MemoryBuffer *
Buffer =
150 Buffer->getBufferStart(), BufferPos, Buffer->getBufferEnd());
152 size_t NextStart = 0;
153 std::ostringstream LineBuff;
161 return LineBuff.str();
166 llvm::MD5::MD5Result MD5Res;
169 Hash.update(Content);
171 llvm::MD5::stringifyResult(MD5Res, Res);
178 StringRef CheckerName, StringRef BugType,
181 static StringRef Delimiter =
"$";
183 return (llvm::Twine(CheckerName) + Delimiter +
192 StringRef CheckerName, StringRef BugType,
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
Defines the clang::ASTContext interface.
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
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...
Defines the SourceManager interface.
Decl - This represents one declaration (or definition), e.g.
const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const
Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer...
llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
std::string getAsString() const
std::unique_ptr< llvm::MemoryBuffer > Buffer
llvm::SmallString< 32 > GetIssueHash(const SourceManager &SM, FullSourceLoc &IssueLoc, llvm::StringRef CheckerName, llvm::StringRef BugType, const Decl *D, const LangOptions &LangOpts)
Get an MD5 hash to help identify bugs.
static std::string GetEnclosingDeclContextSignature(const Decl *D)
unsigned getExpansionLineNumber(bool *Invalid=nullptr) const
QualType getReturnType() const
Token - This structure provides full information about a lexed token.
static StringRef GetNthLineOfFile(llvm::MemoryBuffer *Buffer, int Line)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
unsigned getExpansionColumnNumber(bool *Invalid=nullptr) const
An lvalue ref-qualifier was provided (&).
bool isVariadic() const
Whether this function is variadic.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
SourceLocation translateLineCol(FileID FID, unsigned Line, unsigned Col) const
Get the source location in FID for the given line:col.
const ParmVarDecl * getParamDecl(unsigned i) const
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
static std::string GetSignature(const FunctionDecl *Target)
Encodes a location in the source.
unsigned getNumParams() const
getNumParams - Return the number of parameters this function must have based on its FunctionType...
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
An rvalue ref-qualifier was provided (&&).
static std::string NormalizeLine(const SourceManager &SM, FullSourceLoc &L, const LangOptions &LangOpts)
Defines various enumerations that describe declaration and type specifiers.
std::string getQualifiedNameAsString() const
std::string GetIssueString(const SourceManager &SM, FullSourceLoc &IssueLoc, llvm::StringRef CheckerName, llvm::StringRef BugType, const Decl *D, const LangOptions &LangOpts)
Get the string representation of issue hash.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
A SourceLocation and its associated SourceManager.
unsigned getLength() const
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
static llvm::SmallString< 32 > GetHashOfContent(StringRef Content)
This class handles loading and caching of source files into memory.