[clang] [clang] Add hasAnyNameInVector matcher (PR #139594)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 12 10:50:47 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Florian Mayer (fmayer)
<details>
<summary>Changes</summary>
This is useful for matching functions whose name is given as a
parameter, e.g.
---
Full diff: https://github.com/llvm/llvm-project/pull/139594.diff
1 Files Affected:
- (modified) clang/include/clang/ASTMatchers/ASTMatchers.h (+18)
``````````diff
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index e6b684b24b080..255f7d3487f9d 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3144,6 +3144,24 @@ extern const internal::VariadicFunction<internal::Matcher<NamedDecl>, StringRef,
internal::hasAnyNameFunc>
hasAnyName;
+/// Matches NamedDecl nodes that have any of the names in vector.
+///
+/// This is useful for matching a list of names that are only known at runtime,
+/// e.g. through a command line argument.
+///
+/// \code
+/// hasAnyName({a, b, c})
+/// \endcode
+/// is equivalent to
+/// \code
+/// anyOf(hasName(a), hasName(b), hasName(c))
+/// \endcode
+inline internal::Matcher<NamedDecl>
+hasAnyNameInVector(std::vector<std::string> Names) {
+ return internal::Matcher<NamedDecl>(
+ new internal::HasNameMatcher(std::move(Names)));
+}
+
/// Matches NamedDecl nodes whose fully qualified names contain
/// a substring matched by the given RegExp.
///
``````````
</details>
https://github.com/llvm/llvm-project/pull/139594
More information about the cfe-commits
mailing list