16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/Twine.h"
20 #include "llvm/Support/LineIterator.h"
21 #include "llvm/Support/MD5.h"
22 #include "llvm/Support/Path.h"
28 using namespace clang;
35 std::string Signature;
37 if (!isa<CXXConstructorDecl>(Target) && !isa<CXXDestructorDecl>(Target) &&
38 !isa<CXXConversionDecl>(Target))
42 for (
int i = 0, paramsCount = Target->
getNumParams(); i < paramsCount; ++i) {
44 Signature.append(
", ");
49 Signature.append(
", ...");
50 Signature.append(
")");
55 if (!TargetT || !isa<CXXMethodDecl>(Target))
58 if (TargetT->isConst())
59 Signature.append(
" const");
60 if (TargetT->isVolatile())
61 Signature.append(
" volatile");
62 if (TargetT->isRestrict())
63 Signature.append(
" restrict");
65 if (
const auto *TargetPT =
67 switch (TargetPT->getRefQualifier()) {
69 Signature.append(
" &");
72 Signature.append(
" &&");
86 if (
const auto *ND = dyn_cast<NamedDecl>(D)) {
89 switch (ND->getKind()) {
94 DeclName = ND->getQualifiedNameAsString();
96 case Decl::CXXConstructor:
97 case Decl::CXXDestructor:
98 case Decl::CXXConversion:
101 DeclName =
GetSignature(dyn_cast_or_null<FunctionDecl>(ND));
103 case Decl::ObjCMethod:
106 DeclName = ND->getQualifiedNameAsString();
122 llvm::line_iterator LI(*Buffer,
false);
123 for (; !LI.is_at_eof() && LI.line_number() !=
Line; ++LI)
135 StringRef::size_type col = Str.find_first_not_of(Whitespaces);
136 if (col == StringRef::npos)
142 llvm::MemoryBuffer *
Buffer =
151 Buffer->getBufferStart(), BufferPos, Buffer->getBufferEnd());
153 size_t NextStart = 0;
154 std::ostringstream LineBuff;
162 return LineBuff.str();
167 llvm::MD5::MD5Result MD5Res;
170 Hash.update(Content);
172 llvm::MD5::stringifyResult(MD5Res, Res);
179 StringRef CheckerName, StringRef BugType,
182 static StringRef Delimiter =
"$";
184 return (llvm::Twine(CheckerName) + Delimiter +
193 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.
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.