30class NamedDeclOccurrenceFindingVisitor
31 :
public RecursiveSymbolVisitor<NamedDeclOccurrenceFindingVisitor> {
35 explicit NamedDeclOccurrenceFindingVisitor(
const SourceLocation Point,
36 const ASTContext &Context)
37 : RecursiveSymbolVisitor(Context.getSourceManager(),
38 Context.getLangOpts()),
39 Point(Point), Context(Context) {}
41 bool visitSymbolOccurrence(
const NamedDecl *ND,
45 for (
const auto &Range : NameRanges) {
46 SourceLocation Start =
Range.getBegin();
47 SourceLocation End =
Range.getEnd();
48 if (!Start.isValid() || !Start.isFileID() || !End.isValid() ||
49 !End.isFileID() || !isPointWithin(Start, End))
56 const NamedDecl *getNamedDecl()
const {
return Result; }
60 bool isPointWithin(
const SourceLocation Start,
const SourceLocation End) {
62 return Point == Start || Point == End ||
63 (Context.getSourceManager().isBeforeInTranslationUnit(Start,
65 Context.getSourceManager().isBeforeInTranslationUnit(Point, End));
68 const NamedDecl *Result =
nullptr;
69 const SourceLocation Point;
70 const ASTContext &Context;
78 NamedDeclOccurrenceFindingVisitor Visitor(Point, Context);
83 for (
auto *CurrDecl : Context.getTranslationUnitDecl()->decls()) {
87 SM.isBeforeInTranslationUnit(StartLoc, Point) !=
88 SM.isBeforeInTranslationUnit(EndLoc, Point))
89 Visitor.TraverseDecl(CurrDecl);
92 return Visitor.getNamedDecl();
99class NamedDeclFindingVisitor
102 explicit NamedDeclFindingVisitor(StringRef Name) : Name(Name) {}
106 bool VisitNamedDecl(
const NamedDecl *ND) {
110 if (Name != ND->getQualifiedNameAsString() &&
111 Name !=
"::" + ND->getQualifiedNameAsString())
117 const NamedDecl *getNamedDecl()
const {
return Result; }
120 const NamedDecl *Result =
nullptr;
127 const std::string &Name) {
128 NamedDeclFindingVisitor Visitor(Name);
129 Visitor.TraverseDecl(Context.getTranslationUnitDecl());
130 return Visitor.getNamedDecl();
140 return std::string(Buff);
Defines the clang::ASTContext interface.
A wrapper class around RecursiveASTVisitor that visits each occurrences of a named symbol.
Defines the SourceManager interface.
Methods for determining the USR of a symbol at a location in source code.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Decl - This represents one declaration (or definition), e.g.
This represents a decl that may have a name.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
bool generateUSRForDecl(const Decl *D, SmallVectorImpl< char > &Buf)
Generate a USR for a Decl, including the USR prefix.
The JSON file list parser is used to communicate input to InstallAPI.
Diagnostic wrappers for TextAPI types for error reporting.