steveire created this revision.
steveire added a reviewer: sammccall.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80623

Files:
  clang/include/clang/ASTMatchers/ASTMatchFinder.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp


Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===================================================================
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -798,6 +798,7 @@
         Callback(Callback) {}
 
     void visitMatch(const BoundNodes& BoundNodesView) override {
+      TraversalKindScope RAII(*Context, Callback->getCheckTraversalKind());
       Callback->run(MatchFinder::MatchResult(BoundNodesView, Context));
     }
 
@@ -1058,7 +1059,13 @@
 
 void MatchFinder::addMatcher(const DeclarationMatcher &NodeMatch,
                              MatchCallback *Action) {
-  Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+  if (auto TK = Action->getCheckTraversalKind()) {
+    llvm::errs() << "Overriding getCheckTraversalKind is deprecated. Port to "
+                    "traverse() matcher instead.";
+    Matchers.DeclOrStmt.emplace_back(traverse(*TK, NodeMatch), Action);
+  } else {
+    Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+  }
   Matchers.AllCallbacks.insert(Action);
 }
 
@@ -1070,7 +1077,13 @@
 
 void MatchFinder::addMatcher(const StatementMatcher &NodeMatch,
                              MatchCallback *Action) {
-  Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+  if (auto TK = Action->getCheckTraversalKind()) {
+    llvm::errs() << "Overriding getCheckTraversalKind is deprecated. Port to "
+                    "traverse() matcher instead.";
+    Matchers.DeclOrStmt.emplace_back(traverse(*TK, NodeMatch), Action);
+  } else {
+    Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+  }
   Matchers.AllCallbacks.insert(Action);
 }
 
@@ -1150,5 +1163,10 @@
 
 StringRef MatchFinder::MatchCallback::getID() const { return "<unknown>"; }
 
+llvm::Optional<ast_type_traits::TraversalKind>
+MatchFinder::MatchCallback::getCheckTraversalKind() const {
+  return llvm::None;
+}
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===================================================================
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -110,6 +110,13 @@
     /// This id is used, for example, for the profiling output.
     /// It defaults to "<unknown>".
     virtual StringRef getID() const;
+
+    /// TraversalKind to use while matching and processing
+    /// the result nodes. This API is temporary to facilitate
+    /// third parties porting existing code to the default
+    /// behavior of clang-tidy.
+    virtual llvm::Optional<ast_type_traits::TraversalKind>
+    getCheckTraversalKind() const;
   };
 
   /// Called when parsing is finished. Intended for testing only.


Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===================================================================
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -798,6 +798,7 @@
         Callback(Callback) {}
 
     void visitMatch(const BoundNodes& BoundNodesView) override {
+      TraversalKindScope RAII(*Context, Callback->getCheckTraversalKind());
       Callback->run(MatchFinder::MatchResult(BoundNodesView, Context));
     }
 
@@ -1058,7 +1059,13 @@
 
 void MatchFinder::addMatcher(const DeclarationMatcher &NodeMatch,
                              MatchCallback *Action) {
-  Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+  if (auto TK = Action->getCheckTraversalKind()) {
+    llvm::errs() << "Overriding getCheckTraversalKind is deprecated. Port to "
+                    "traverse() matcher instead.";
+    Matchers.DeclOrStmt.emplace_back(traverse(*TK, NodeMatch), Action);
+  } else {
+    Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+  }
   Matchers.AllCallbacks.insert(Action);
 }
 
@@ -1070,7 +1077,13 @@
 
 void MatchFinder::addMatcher(const StatementMatcher &NodeMatch,
                              MatchCallback *Action) {
-  Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+  if (auto TK = Action->getCheckTraversalKind()) {
+    llvm::errs() << "Overriding getCheckTraversalKind is deprecated. Port to "
+                    "traverse() matcher instead.";
+    Matchers.DeclOrStmt.emplace_back(traverse(*TK, NodeMatch), Action);
+  } else {
+    Matchers.DeclOrStmt.emplace_back(NodeMatch, Action);
+  }
   Matchers.AllCallbacks.insert(Action);
 }
 
@@ -1150,5 +1163,10 @@
 
 StringRef MatchFinder::MatchCallback::getID() const { return "<unknown>"; }
 
+llvm::Optional<ast_type_traits::TraversalKind>
+MatchFinder::MatchCallback::getCheckTraversalKind() const {
+  return llvm::None;
+}
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/include/clang/ASTMatchers/ASTMatchFinder.h
===================================================================
--- clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -110,6 +110,13 @@
     /// This id is used, for example, for the profiling output.
     /// It defaults to "<unknown>".
     virtual StringRef getID() const;
+
+    /// TraversalKind to use while matching and processing
+    /// the result nodes. This API is temporary to facilitate
+    /// third parties porting existing code to the default
+    /// behavior of clang-tidy.
+    virtual llvm::Optional<ast_type_traits::TraversalKind>
+    getCheckTraversalKind() const;
   };
 
   /// Called when parsing is finished. Intended for testing only.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D80623: WIP: Add an ... Stephen Kelly via Phabricator via cfe-commits

Reply via email to