1 //===--- USRFinder.h - Clang refactoring library --------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Methods for determining the USR of a symbol at a location in source
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDER_H
17 #define LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDER_H
19 #include "clang/AST/AST.h"
20 #include "clang/AST/ASTContext.h"
21 #include "clang/ASTMatchers/ASTMatchFinder.h"
26 using namespace clang::ast_matchers;
37 // Given an AST context and a point, returns a NamedDecl identifying the symbol
38 // at the point. Returns null if nothing is found at the point.
39 const NamedDecl *getNamedDeclAt(const ASTContext &Context,
40 const SourceLocation Point);
42 // Given an AST context and a fully qualified name, returns a NamedDecl
43 // identifying the symbol with a matching name. Returns null if nothing is
44 // found for the name.
45 const NamedDecl *getNamedDeclFor(const ASTContext &Context,
46 const std::string &Name);
48 // Converts a Decl into a USR.
49 std::string getUSRForDecl(const Decl *Decl);
51 // FIXME: Implement RecursiveASTVisitor<T>::VisitNestedNameSpecifier instead.
52 class NestedNameSpecifierLocFinder : public MatchFinder::MatchCallback {
54 explicit NestedNameSpecifierLocFinder(ASTContext &Context)
57 std::vector<NestedNameSpecifierLoc> getNestedNameSpecifierLocations() {
59 Finder.matchAST(Context);
65 const auto NestedNameSpecifierLocMatcher =
66 nestedNameSpecifierLoc().bind("nestedNameSpecifierLoc");
67 Finder.addMatcher(NestedNameSpecifierLocMatcher, this);
70 void run(const MatchFinder::MatchResult &Result) override {
71 const auto *NNS = Result.Nodes.getNodeAs<NestedNameSpecifierLoc>(
72 "nestedNameSpecifierLoc");
73 Locations.push_back(*NNS);
77 std::vector<NestedNameSpecifierLoc> Locations;
81 } // end namespace tooling
82 } // end namespace clang
84 #endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_USR_FINDER_H