[clang] db1f40d - Modernize DeclTest

Dmitri Gribenko via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 13 02:46:52 PDT 2020


Author: Marcel Hlopko
Date: 2020-03-13T10:37:48+01:00
New Revision: db1f40d1a16f868a86501e30feadbfb285c2e922

URL: https://github.com/llvm/llvm-project/commit/db1f40d1a16f868a86501e30feadbfb285c2e922
DIFF: https://github.com/llvm/llvm-project/commit/db1f40d1a16f868a86501e30feadbfb285c2e922.diff

LOG: Modernize DeclTest

Summary:
This patch removes a call to the old ASTUnit::findFileRegionDecls and
replaces it with ast matchers.

Reviewers: gribozavr, gribozavr2

Reviewed By: gribozavr2

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D76121

Added: 
    

Modified: 
    clang/unittests/AST/DeclTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/unittests/AST/DeclTest.cpp b/clang/unittests/AST/DeclTest.cpp
index f6aa7de08147..bd16df8a4fd2 100644
--- a/clang/unittests/AST/DeclTest.cpp
+++ b/clang/unittests/AST/DeclTest.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Mangle.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Tooling/Tooling.h"
@@ -77,14 +78,9 @@ TEST(Decl, AsmLabelAttr) {
   assert(Ctx.getTargetInfo().getDataLayout().getGlobalPrefix() &&
          "Expected target to have a global prefix");
   DiagnosticsEngine &Diags = AST->getDiagnostics();
-  SourceManager &SM = AST->getSourceManager();
-  FileID MainFileID = SM.getMainFileID();
 
-  // Find the method decls within the AST.
-  SmallVector<Decl *, 1> Decls;
-  AST->findFileRegionDecls(MainFileID, Code.find('{'), 0, Decls);
-  ASSERT_TRUE(Decls.size() == 1);
-  CXXRecordDecl *DeclS = cast<CXXRecordDecl>(Decls[0]);
+  auto *DeclS =
+      selectFirst<CXXRecordDecl>("d", match(cxxRecordDecl().bind("d"), Ctx));
   NamedDecl *DeclF = *DeclS->method_begin();
   NamedDecl *DeclG = *(++DeclS->method_begin());
 


        


More information about the cfe-commits mailing list