[clang] 06fdbf3 - Unnest struct in Matcher implementation
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 31 09:05:04 PST 2019
Author: Stephen Kelly
Date: 2019-12-31T17:04:39Z
New Revision: 06fdbf3dafb76e54ea76e0eb5f690bc3d6773023
URL: https://github.com/llvm/llvm-project/commit/06fdbf3dafb76e54ea76e0eb5f690bc3d6773023
DIFF: https://github.com/llvm/llvm-project/commit/06fdbf3dafb76e54ea76e0eb5f690bc3d6773023.diff
LOG: Unnest struct in Matcher implementation
This allows implementation of the traverse() matcher to surround
matchers like unless().
Added:
Modified:
clang/include/clang/ASTMatchers/ASTMatchersInternal.h
Removed:
################################################################################
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 47fb5a79ffe6..dacb7a2da535 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1129,6 +1129,23 @@ using HasDeclarationSupportedTypes =
TemplateSpecializationType, TemplateTypeParmType, TypedefType,
UnresolvedUsingType, ObjCIvarRefExpr>;
+template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
+ typename T, typename ToTypes>
+class ArgumentAdaptingMatcherFuncAdaptor {
+public:
+ explicit ArgumentAdaptingMatcherFuncAdaptor(const Matcher<T> &InnerMatcher)
+ : InnerMatcher(InnerMatcher) {}
+
+ using ReturnTypes = ToTypes;
+
+ template <typename To> operator Matcher<To>() const {
+ return Matcher<To>(new ArgumentAdapterT<To, T>(InnerMatcher));
+ }
+
+private:
+ const Matcher<T> InnerMatcher;
+};
+
/// Converts a \c Matcher<T> to a matcher of desired type \c To by
/// "adapting" a \c To into a \c T.
///
@@ -1146,28 +1163,16 @@ template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
typename FromTypes = AdaptativeDefaultFromTypes,
typename ToTypes = AdaptativeDefaultToTypes>
struct ArgumentAdaptingMatcherFunc {
- template <typename T> class Adaptor {
- public:
- explicit Adaptor(const Matcher<T> &InnerMatcher)
- : InnerMatcher(InnerMatcher) {}
-
- using ReturnTypes = ToTypes;
-
- template <typename To> operator Matcher<To>() const {
- return Matcher<To>(new ArgumentAdapterT<To, T>(InnerMatcher));
- }
-
- private:
- const Matcher<T> InnerMatcher;
- };
-
template <typename T>
- static Adaptor<T> create(const Matcher<T> &InnerMatcher) {
- return Adaptor<T>(InnerMatcher);
+ static ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT, T, ToTypes>
+ create(const Matcher<T> &InnerMatcher) {
+ return ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT, T, ToTypes>(
+ InnerMatcher);
}
template <typename T>
- Adaptor<T> operator()(const Matcher<T> &InnerMatcher) const {
+ ArgumentAdaptingMatcherFuncAdaptor<ArgumentAdapterT, T, ToTypes>
+ operator()(const Matcher<T> &InnerMatcher) const {
return create(InnerMatcher);
}
};
More information about the cfe-commits
mailing list