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;
41 Target = InstantiatedFrom;
43 if (!isa<CXXConstructorDecl>(Target) && !isa<CXXDestructorDecl>(Target) &&
44 !isa<CXXConversionDecl>(Target))
48 for (
int i = 0, paramsCount = Target->
getNumParams(); i < paramsCount; ++i) {
50 Signature.append(
", ");
55 Signature.append(
", ...");
56 Signature.append(
")");
61 if (!TargetT || !isa<CXXMethodDecl>(Target))
64 if (TargetT->isConst())
65 Signature.append(
" const");
66 if (TargetT->isVolatile())
67 Signature.append(
" volatile");
68 if (TargetT->isRestrict())
69 Signature.append(
" restrict");
71 if (
const auto *TargetPT =
73 switch (TargetPT->getRefQualifier()) {
75 Signature.append(
" &");
78 Signature.append(
" &&");
92 if (
const auto *ND = dyn_cast<NamedDecl>(D)) {
95 switch (ND->getKind()) {
100 DeclName = ND->getQualifiedNameAsString();
102 case Decl::CXXConstructor:
103 case Decl::CXXDestructor:
104 case Decl::CXXConversion:
105 case Decl::CXXMethod:
107 DeclName =
GetSignature(dyn_cast_or_null<FunctionDecl>(ND));
109 case Decl::ObjCMethod:
112 DeclName = ND->getQualifiedNameAsString();
128 llvm::line_iterator LI(*Buffer,
false);
129 for (; !LI.is_at_eof() && LI.line_number() !=
Line; ++LI)
137 static StringRef Whitespaces =
" \t\n";
141 StringRef::size_type col = Str.find_first_not_of(Whitespaces);
142 if (col == StringRef::npos)
148 llvm::MemoryBuffer *Buffer =
157 Buffer->getBufferStart(), BufferPos, Buffer->getBufferEnd());
159 size_t NextStart = 0;
160 std::ostringstream LineBuff;
168 return LineBuff.str();
173 llvm::MD5::MD5Result MD5Res;
176 Hash.update(Content);
178 llvm::MD5::stringifyResult(MD5Res, Res);
185 StringRef CheckerName, StringRef BugType,
188 static StringRef Delimiter =
"$";
190 return (llvm::Twine(CheckerName) + Delimiter +
199 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.
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::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.
QualType getReturnType() const
static std::string GetEnclosingDeclContextSignature(const Decl *D)
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...
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)
llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
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.
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.