15 #include "llvm/ADT/StringExtras.h" 16 #include "llvm/ADT/StringRef.h" 17 #include "llvm/ADT/Twine.h" 18 #include "llvm/Support/LineIterator.h" 19 #include "llvm/Support/MD5.h" 20 #include "llvm/Support/Path.h" 26 using namespace clang;
33 std::string Signature;
40 Target = InstantiatedFrom;
42 if (!isa<CXXConstructorDecl>(Target) && !isa<CXXDestructorDecl>(Target) &&
43 !isa<CXXConversionDecl>(Target))
47 for (
int i = 0, paramsCount = Target->
getNumParams(); i < paramsCount; ++i) {
49 Signature.append(
", ");
54 Signature.append(
", ...");
55 Signature.append(
")");
60 if (!TargetT || !isa<CXXMethodDecl>(Target))
63 if (TargetT->isConst())
64 Signature.append(
" const");
65 if (TargetT->isVolatile())
66 Signature.append(
" volatile");
67 if (TargetT->isRestrict())
68 Signature.append(
" restrict");
70 if (
const auto *TargetPT =
72 switch (TargetPT->getRefQualifier()) {
74 Signature.append(
" &");
77 Signature.append(
" &&");
91 if (
const auto *ND = dyn_cast<NamedDecl>(D)) {
94 switch (ND->getKind()) {
99 DeclName = ND->getQualifiedNameAsString();
101 case Decl::CXXConstructor:
102 case Decl::CXXDestructor:
103 case Decl::CXXConversion:
104 case Decl::CXXMethod:
106 DeclName =
GetSignature(dyn_cast_or_null<FunctionDecl>(ND));
108 case Decl::ObjCMethod:
111 DeclName = ND->getQualifiedNameAsString();
127 llvm::line_iterator LI(*Buffer,
false);
128 for (; !LI.is_at_eof() && LI.line_number() !=
Line; ++LI)
136 static StringRef Whitespaces =
" \t\n";
140 StringRef::size_type col = Str.find_first_not_of(Whitespaces);
141 if (col == StringRef::npos)
147 const llvm::MemoryBuffer *Buffer =
156 Buffer->getBufferStart(), BufferPos, Buffer->getBufferEnd());
158 size_t NextStart = 0;
159 std::ostringstream LineBuff;
167 return LineBuff.str();
172 llvm::MD5::MD5Result MD5Res;
175 Hash.update(Content);
177 llvm::MD5::stringifyResult(MD5Res, Res);
184 StringRef CheckerName, StringRef BugType,
187 static StringRef Delimiter =
"$";
189 return (llvm::Twine(CheckerName) + Delimiter +
198 StringRef CheckerName, StringRef BugType,
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file. ...
Defines the clang::ASTContext interface.
Represents 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::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.
constexpr XRayInstrMask Function
static StringRef GetNthLineOfFile(const llvm::MemoryBuffer *Buffer, int Line)
QualType getReturnType() const
static std::string GetEnclosingDeclContextSignature(const Decl *D)
Token - This structure provides full information about a lexed token.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
An lvalue ref-qualifier was provided (&).
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
unsigned getExpansionColumnNumber(bool *Invalid=nullptr) const
bool isVariadic() const
Whether this function is variadic.
const AnnotatedLine * Line
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.
const ParmVarDecl * getParamDecl(unsigned i) const
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
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.
const llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
Dataflow Directional Tag Classes.
FunctionDecl * getTemplateInstantiationPattern() const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
SourceLocation translateLineCol(FileID FID, unsigned Line, unsigned Col) const
Get the source location in FID for the given line:col.
unsigned getLength() const
unsigned getExpansionLineNumber(bool *Invalid=nullptr) const
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
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.
std::string getQualifiedNameAsString() const
static llvm::SmallString< 32 > GetHashOfContent(StringRef Content)
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
This class handles loading and caching of source files into memory.