diff --git a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt index 11d93f526f3c99..d911b5df70c509 100644 --- a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt +++ b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt @@ -1,5 +1,4 @@ set(LLVM_LINK_COMPONENTS - FrontendOpenMP Support TestingSupport ) @@ -21,7 +20,6 @@ target_include_directories(ClangIncludeCleanerTests clang_target_link_libraries(ClangIncludeCleanerTests PRIVATE clangAST - clangASTMatchers clangBasic clangFrontend clangLex diff --git a/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp b/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp index f347db927e27d9..7d0fd1b56e096b 100644 --- a/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/LocateSymbolTest.cpp @@ -9,14 +9,12 @@ #include "clang-include-cleaner/Types.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclBase.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" -#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/AST/RecursiveASTVisitor.h" #include "clang/Basic/SourceLocation.h" #include "clang/Lex/Preprocessor.h" #include "clang/Testing/TestAST.h" #include "clang/Tooling/Inclusions/StandardLibrary.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Support/Casting.h" #include "llvm/Testing/Support/Annotations.h" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -53,27 +51,25 @@ struct LocateExample { }()) {} const Decl &findDecl(llvm::StringRef SymbolName) { - const NamedDecl *DeclToLocate; - struct MatchCB : public ast_matchers::MatchFinder::MatchCallback { - MatchCB(const NamedDecl *&Out) : Out(Out) {} - void run(const ast_matchers::MatchFinder::MatchResult &Result) override { - Out = Result.Nodes.getNodeAs("id"); - assert(Out); - Out = llvm::cast(Out->getCanonicalDecl()); + struct Visitor : RecursiveASTVisitor { + llvm::StringRef NameToFind; + const NamedDecl *Out = nullptr; + bool VisitNamedDecl(const NamedDecl *ND) { + if (ND->getName() == NameToFind) { + EXPECT_TRUE(Out == nullptr || Out == ND->getCanonicalDecl()) + << "Found multiple matches for " << NameToFind; + Out = cast(ND->getCanonicalDecl()); + } + return true; } - const NamedDecl *&Out; - } CB(DeclToLocate); - ast_matchers::MatchFinder Finder; - Finder.addMatcher(ast_matchers::namedDecl( - ast_matchers::unless(ast_matchers::isImplicit()), - ast_matchers::hasName(SymbolName)) - .bind("id"), - &CB); - Finder.matchAST(AST.context()); - if (!DeclToLocate) + }; + Visitor V; + V.NameToFind = SymbolName; + V.TraverseDecl(AST.context().getTranslationUnitDecl()); + if (!V.Out) ADD_FAILURE() << "Couldn't find any decls with name: " << SymbolName; - assert(DeclToLocate); - return *DeclToLocate; + assert(V.Out); + return *V.Out; } Macro findMacro(llvm::StringRef Name) {