diff options
Diffstat (limited to 'clang-tools-extra/clang-rename/USRFinder.h')
-rw-r--r-- | clang-tools-extra/clang-rename/USRFinder.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-rename/USRFinder.h b/clang-tools-extra/clang-rename/USRFinder.h index 78985b6fc12..727a81514fb 100644 --- a/clang-tools-extra/clang-rename/USRFinder.h +++ b/clang-tools-extra/clang-rename/USRFinder.h @@ -15,8 +15,14 @@ #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDER_H #define LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_FINDER_H +#include "clang/AST/AST.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" #include <string> +using namespace llvm; +using namespace clang::ast_matchers; + namespace clang { class ASTContext; class Decl; @@ -39,6 +45,36 @@ const NamedDecl *getNamedDeclFor(const ASTContext &Context, // Converts a Decl into a USR. std::string getUSRForDecl(const Decl *Decl); +// FIXME: Implement RecursiveASTVisitor<T>::VisitNestedNameSpecifier instead. +class NestedNameSpecifierLocFinder : public MatchFinder::MatchCallback { +public: + explicit NestedNameSpecifierLocFinder(ASTContext &Context) + : Context(Context) {} + + std::vector<NestedNameSpecifierLoc> getNestedNameSpecifierLocations() { + addMatchers(); + Finder.matchAST(Context); + return Locations; + } + +private: + void addMatchers() { + const auto NestedNameSpecifierLocMatcher = + nestedNameSpecifierLoc().bind("nestedNameSpecifierLoc"); + Finder.addMatcher(NestedNameSpecifierLocMatcher, this); + } + + virtual void run(const MatchFinder::MatchResult &Result) { + const auto *NNS = + Result.Nodes.getNodeAs<NestedNameSpecifierLoc>("nestedNameSpecifierLoc"); + Locations.push_back(*NNS); + } + + ASTContext &Context; + std::vector<NestedNameSpecifierLoc> Locations; + MatchFinder Finder; +}; + } } |