[clang] Refactor traverse function with clearer function names (PR #71441)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 6 12:24:00 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: None (796e43a5a8cdb73b92b)

<details>
<summary>Changes</summary>

The `traverse` function has been updated for better readability and maintainability. The function now has clearer function names.

---
Full diff: https://github.com/llvm/llvm-project/pull/71441.diff


1 Files Affected:

- (modified) clang/lib/ASTMatchers/ASTMatchFinder.cpp (+9-8) 


``````````diff
diff --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index 0bac2ed63a927ef..56bddce7d02ddfc 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -395,14 +395,15 @@ class MatchChildASTVisitor
 
   // Traverses the subtree rooted at 'Node'; returns true if the
   // traversal should continue after this function returns.
-  template <typename T>
-  bool traverse(const T &Node) {
-    static_assert(IsBaseType<T>::value,
-                  "traverse can only be instantiated with base type");
-    if (!match(Node))
-      return false;
-    return baseTraverse(Node);
-  }
+template <typename NodeType>
+bool traverse(const NodeType &node) {
+    static_assert(IsBaseType<NodeType>::value,
+        "traverse can only be instantiated with base type");
+    if (!shouldContinue(node))
+        return false;
+    return continueTraversal(node);
+}
+
 
   const DynTypedMatcher *const Matcher;
   ASTMatchFinder *const Finder;

``````````

</details>


https://github.com/llvm/llvm-project/pull/71441


More information about the cfe-commits mailing list