-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang] Add hasAnyNameInVector matcher #139594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Created using spr 1.3.4
@llvm/pr-subscribers-clang Author: Florian Mayer (fmayer) ChangesThis is useful for matching functions whose name is given as a Full diff: https://github.com/llvm/llvm-project/pull/139594.diff 1 Files Affected:
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.
///
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any planned in-tree uses for this matcher? We don't typically add matchers without a need in tree due to the overhead of the matcher interfaces.
If there are in-tree uses planned, then some additional work is needed: regenerate the documentation (there's a script in the docs directory) and test coverage. I don't think Registry.cpp needs to be updated though as this cannot be used via the dynamic matchers, I believe.
I had a downstream use planned. Does this mean I will have to reimplement |
Can you adapt the code to use |
The use is for a runtime list of names, so I don't think the variadic would work? |
This is useful for matching functions whose name is given as a
parameter, e.g.