r369380 - Removed the 'id' AST matcher, which is superseded by '.bind()'

Dmitri Gribenko via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 20 06:02:28 PDT 2019


Author: gribozavr
Date: Tue Aug 20 06:02:28 2019
New Revision: 369380

URL: http://llvm.org/viewvc/llvm-project?rev=369380&view=rev
Log:
Removed the 'id' AST matcher, which is superseded by '.bind()'

Summary:
The 'id' matcher is not even included in the AST Matchers Reference
document, so I don't expect there to be a significant number of users.

There's no reason to provide two ways to do the exact same thing that
only have a minor syntactic difference.

Subscribers: cfe-commits

Tags: #clang

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

Modified:
    cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
    cfe/trunk/unittests/Tooling/RefactoringCallbacksTest.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=369380&r1=369379&r2=369380&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Tue Aug 20 06:02:28 2019
@@ -19,15 +19,15 @@
 //
 //  For more complicated match expressions we're often interested in accessing
 //  multiple parts of the matched AST nodes once a match is found. In that case,
-//  use the id(...) matcher around the match expressions that match the nodes
-//  you want to access.
+//  call `.bind("name")` on match expressions that match the nodes you want to
+//  access.
 //
 //  For example, when we're interested in child classes of a certain class, we
 //  would write:
-//    cxxRecordDecl(hasName("MyClass"), has(id("child", recordDecl())))
+//    cxxRecordDecl(hasName("MyClass"), has(recordDecl().bind("child")))
 //  When the match is found via the MatchFinder, a user provided callback will
 //  be called with a BoundNodes instance that contains a mapping from the
-//  strings that we provided for the id(...) calls to the nodes that were
+//  strings that we provided for the `.bind()` calls to the nodes that were
 //  matched.
 //  In the given example, each time our matcher finds a match we get a callback
 //  where "child" is bound to the RecordDecl node of the matching child
@@ -131,15 +131,6 @@ private:
   internal::BoundNodesMap MyBoundNodes;
 };
 
-/// If the provided matcher matches a node, binds the node to \c ID.
-///
-/// FIXME: Do we want to support this now that we have bind()?
-template <typename T>
-internal::Matcher<T> id(StringRef ID,
-                        const internal::BindableMatcher<T> &InnerMatcher) {
-  return InnerMatcher.bind(ID);
-}
-
 /// Types of matchers for the top-level classes in the AST class
 /// hierarchy.
 /// @{

Modified: cfe/trunk/unittests/Tooling/RefactoringCallbacksTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RefactoringCallbacksTest.cpp?rev=369380&r1=369379&r2=369380&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/RefactoringCallbacksTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/RefactoringCallbacksTest.cpp Tue Aug 20 06:02:28 2019
@@ -38,28 +38,28 @@ TEST(RefactoringCallbacksTest, ReplacesS
   std::string Code = "void f() { int i = 1; }";
   std::string Expected = "void f() { ; }";
   ReplaceStmtWithText Callback("id", ";");
-  expectRewritten(Code, Expected, id("id", declStmt()), Callback);
+  expectRewritten(Code, Expected, declStmt().bind("id"), Callback);
 }
 
 TEST(RefactoringCallbacksTest, ReplacesStmtsInCalledMacros) {
   std::string Code = "#define A void f() { int i = 1; }\nA";
   std::string Expected = "#define A void f() { ; }\nA";
   ReplaceStmtWithText Callback("id", ";");
-  expectRewritten(Code, Expected, id("id", declStmt()), Callback);
+  expectRewritten(Code, Expected, declStmt().bind("id"), Callback);
 }
 
 TEST(RefactoringCallbacksTest, IgnoresStmtsInUncalledMacros) {
   std::string Code = "#define A void f() { int i = 1; }";
   std::string Expected = "#define A void f() { int i = 1; }";
   ReplaceStmtWithText Callback("id", ";");
-  expectRewritten(Code, Expected, id("id", declStmt()), Callback);
+  expectRewritten(Code, Expected, declStmt().bind("id"), Callback);
 }
 
 TEST(RefactoringCallbacksTest, ReplacesInteger) {
   std::string Code = "void f() { int i = 1; }";
   std::string Expected = "void f() { int i = 2; }";
   ReplaceStmtWithText Callback("id", "2");
-  expectRewritten(Code, Expected, id("id", expr(integerLiteral())), Callback);
+  expectRewritten(Code, Expected, expr(integerLiteral()).bind("id"), Callback);
 }
 
 TEST(RefactoringCallbacksTest, ReplacesStmtWithStmt) {
@@ -68,9 +68,9 @@ TEST(RefactoringCallbacksTest, ReplacesS
   ReplaceStmtWithStmt Callback("always-false", "should-be");
   expectRewritten(
       Code, Expected,
-      id("always-false",
-         conditionalOperator(hasCondition(cxxBoolLiteral(equals(false))),
-                             hasFalseExpression(id("should-be", expr())))),
+      conditionalOperator(hasCondition(cxxBoolLiteral(equals(false))),
+                          hasFalseExpression(expr().bind("should-be")))
+          .bind("always-false"),
       Callback);
 }
 
@@ -78,20 +78,20 @@ TEST(RefactoringCallbacksTest, ReplacesI
   std::string Code = "bool a; void f() { if (a) f(); else a = true; }";
   std::string Expected = "bool a; void f() { f(); }";
   ReplaceIfStmtWithItsBody Callback("id", true);
-  expectRewritten(
-      Code, Expected,
-      id("id", ifStmt(hasCondition(implicitCastExpr(hasSourceExpression(
-                   declRefExpr(to(varDecl(hasName("a"))))))))),
-      Callback);
+  expectRewritten(Code, Expected,
+                  ifStmt(hasCondition(implicitCastExpr(hasSourceExpression(
+                             declRefExpr(to(varDecl(hasName("a"))))))))
+                      .bind("id"),
+                  Callback);
 }
 
 TEST(RefactoringCallbacksTest, RemovesEntireIfOnEmptyElse) {
   std::string Code = "void f() { if (false) int i = 0; }";
   std::string Expected = "void f() {  }";
   ReplaceIfStmtWithItsBody Callback("id", false);
-  expectRewritten(Code, Expected,
-                  id("id", ifStmt(hasCondition(cxxBoolLiteral(equals(false))))),
-                  Callback);
+  expectRewritten(
+      Code, Expected,
+      ifStmt(hasCondition(cxxBoolLiteral(equals(false)))).bind("id"), Callback);
 }
 
 TEST(RefactoringCallbacksTest, TemplateJustText) {
@@ -99,7 +99,7 @@ TEST(RefactoringCallbacksTest, TemplateJ
   std::string Expected = "void f() { FOO }";
   auto Callback = ReplaceNodeWithTemplate::create("id", "FOO");
   EXPECT_FALSE(Callback.takeError());
-  expectRewritten(Code, Expected, id("id", declStmt()), **Callback);
+  expectRewritten(Code, Expected, declStmt().bind("id"), **Callback);
 }
 
 TEST(RefactoringCallbacksTest, TemplateSimpleSubst) {
@@ -108,7 +108,7 @@ TEST(RefactoringCallbacksTest, TemplateS
   auto Callback = ReplaceNodeWithTemplate::create("decl", "long x = ${init}");
   EXPECT_FALSE(Callback.takeError());
   expectRewritten(Code, Expected,
-                  id("decl", varDecl(hasInitializer(id("init", expr())))),
+                  varDecl(hasInitializer(expr().bind("init"))).bind("decl"),
                   **Callback);
 }
 
@@ -119,7 +119,7 @@ TEST(RefactoringCallbacksTest, TemplateL
                                                   "string x = \"$$-${init}\"");
   EXPECT_FALSE(Callback.takeError());
   expectRewritten(Code, Expected,
-                  id("decl", varDecl(hasInitializer(id("init", expr())))),
+                  varDecl(hasInitializer(expr().bind("init"))).bind("decl"),
                   **Callback);
 }
 




More information about the cfe-commits mailing list