r188560 - Refactor ArgumentAdaptativeMatcher matchers to remove the template from their declaration.
Samuel Benzaquen
sbenza at google.com
Fri Aug 16 09:19:43 PDT 2013
Author: sbenza
Date: Fri Aug 16 11:19:42 2013
New Revision: 188560
URL: http://llvm.org/viewvc/llvm-project?rev=188560&view=rev
Log:
Refactor ArgumentAdaptativeMatcher matchers to remove the template from their declaration.
Summary:
Refactor ArgumentAdaptativeMatcher matchers to remove the template from their declaration.
This facilitates dynamic registration. Change the registry code to use the regular overload resolution mechanism for adaptative matchers.
Reviewers: klimek
CC: cfe-commits, revane
Differential Revision: http://llvm-reviews.chandlerc.com/D1402
Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/docs/tools/dump_ast_matchers.py
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=188560&r1=188559&r2=188560&view=diff
==============================================================================
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Fri Aug 16 11:19:42 2013
@@ -631,6 +631,15 @@ Example matches x()
</pre></td></tr>
+<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('floatLiteral0')"><a name="floatLiteral0Anchor">floatLiteral</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FloatingLiteral.html">FloatingLiteral</a>>...</td></tr>
+<tr><td colspan="4" class="doc" id="floatLiteral0"><pre>Matches float literals of all sizes encodings, e.g.
+1.0, 1.0f, 1.0L and 1e10.
+
+Does not match implicit conversions such as
+ float a = 10;
+</pre></td></tr>
+
+
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('forRangeStmt0')"><a name="forRangeStmt0Anchor">forRangeStmt</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXForRangeStmt.html">CXXForRangeStmt</a>>...</td></tr>
<tr><td colspan="4" class="doc" id="forRangeStmt0"><pre>Matches range-based for statements.
@@ -699,11 +708,10 @@ initList()
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>></td><td class="name" onclick="toggle('integerLiteral0')"><a name="integerLiteral0Anchor">integerLiteral</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1IntegerLiteral.html">IntegerLiteral</a>>...</td></tr>
-<tr><td colspan="4" class="doc" id="integerLiteral0"><pre>Matches integer literals of all sizes encodings.
-
-Not matching character-encoded integers such as L'a'.
+<tr><td colspan="4" class="doc" id="integerLiteral0"><pre>Matches integer literals of all sizes encodings, e.g.
+1, 1L, 0x1 and 1U.
-Example matches 1, 1L, 0x1, 1U
+Does not match character-encoded integers such as L'a'.
</pre></td></tr>
@@ -2025,7 +2033,7 @@ Usable as: Any Matcher
</pre></td></tr>
-<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEach0')"><a name="forEach0Anchor">forEach</a></td><td>Matcher<ChildT> ChildMatcher</td></tr>
+<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEach0')"><a name="forEach0Anchor">forEach</a></td><td>Matcher<*></td></tr>
<tr><td colspan="4" class="doc" id="forEach0"><pre>Matches AST nodes that have child AST nodes that match the
provided matcher.
@@ -2043,7 +2051,7 @@ Usable as: Any Matcher
</pre></td></tr>
-<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEachDescendant0')"><a name="forEachDescendant0Anchor">forEachDescendant</a></td><td>Matcher<DescendantT> DescendantMatcher</td></tr>
+<tr><td>Matcher<*></td><td class="name" onclick="toggle('forEachDescendant0')"><a name="forEachDescendant0Anchor">forEachDescendant</a></td><td>Matcher<*></td></tr>
<tr><td colspan="4" class="doc" id="forEachDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the
provided matcher.
@@ -2067,7 +2075,7 @@ Usable as: Any Matcher
</pre></td></tr>
-<tr><td>Matcher<*></td><td class="name" onclick="toggle('has0')"><a name="has0Anchor">has</a></td><td>Matcher<ChildT> ChildMatcher</td></tr>
+<tr><td>Matcher<*></td><td class="name" onclick="toggle('has0')"><a name="has0Anchor">has</a></td><td>Matcher<*></td></tr>
<tr><td colspan="4" class="doc" id="has0"><pre>Matches AST nodes that have child AST nodes that match the
provided matcher.
@@ -2082,7 +2090,7 @@ Usable as: Any Matcher
</pre></td></tr>
-<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasAncestor0')"><a name="hasAncestor0Anchor">hasAncestor</a></td><td>Matcher<AncestorT> AncestorMatcher</td></tr>
+<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasAncestor0')"><a name="hasAncestor0Anchor">hasAncestor</a></td><td>Matcher<*></td></tr>
<tr><td colspan="4" class="doc" id="hasAncestor0"><pre>Matches AST nodes that have an ancestor that matches the provided
matcher.
@@ -2095,7 +2103,7 @@ Usable as: Any Matcher
</pre></td></tr>
-<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasDescendant0')"><a name="hasDescendant0Anchor">hasDescendant</a></td><td>Matcher<DescendantT> DescendantMatcher</td></tr>
+<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasDescendant0')"><a name="hasDescendant0Anchor">hasDescendant</a></td><td>Matcher<*></td></tr>
<tr><td colspan="4" class="doc" id="hasDescendant0"><pre>Matches AST nodes that have descendant AST nodes that match the
provided matcher.
@@ -2111,7 +2119,7 @@ Usable as: Any Matcher
</pre></td></tr>
-<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasParent0')"><a name="hasParent0Anchor">hasParent</a></td><td>Matcher<ParentT> ParentMatcher</td></tr>
+<tr><td>Matcher<*></td><td class="name" onclick="toggle('hasParent0')"><a name="hasParent0Anchor">hasParent</a></td><td>Matcher<*></td></tr>
<tr><td colspan="4" class="doc" id="hasParent0"><pre>Matches AST nodes that have a parent that matches the provided
matcher.
Modified: cfe/trunk/docs/tools/dump_ast_matchers.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/tools/dump_ast_matchers.py?rev=188560&r1=188559&r2=188560&view=diff
==============================================================================
--- cfe/trunk/docs/tools/dump_ast_matchers.py (original)
+++ cfe/trunk/docs/tools/dump_ast_matchers.py Fri Aug 16 11:19:42 2013
@@ -230,6 +230,16 @@ def act_on_decl(declaration, comment, al
add_matcher(result_type, name, args, comment)
return
+ # Parse ArgumentAdapting matchers.
+ m = re.match(
+ r"""^.*ArgumentAdaptingMatcherFunc<.*>\s*([a-zA-Z]*)\s*=\s*{};$""",
+ declaration, flags=re.X)
+ if m:
+ name = m.groups()[0]
+ add_matcher('*', name, 'Matcher<*>', comment)
+ return
+
+
# Parse free standing matcher functions, like:
# Matcher<ResultType> Name(Matcher<ArgumentType> InnerMatcher) {
m = re.match(r"""^\s*(.*)\s+
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=188560&r1=188559&r2=188560&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Aug 16 11:19:42 2013
@@ -1597,12 +1597,7 @@ AST_MATCHER_P(CXXRecordDecl, hasMethod,
/// ChildT must be an AST base type.
///
/// Usable as: Any Matcher
-template <typename ChildT>
-internal::ArgumentAdaptingMatcher<internal::HasMatcher, ChildT> has(
- const internal::Matcher<ChildT> &ChildMatcher) {
- return internal::ArgumentAdaptingMatcher<internal::HasMatcher,
- ChildT>(ChildMatcher);
-}
+const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher> has = {};
/// \brief Matches AST nodes that have descendant AST nodes that match the
/// provided matcher.
@@ -1618,13 +1613,8 @@ internal::ArgumentAdaptingMatcher<intern
/// DescendantT must be an AST base type.
///
/// Usable as: Any Matcher
-template <typename DescendantT>
-internal::ArgumentAdaptingMatcher<internal::HasDescendantMatcher, DescendantT>
-hasDescendant(const internal::Matcher<DescendantT> &DescendantMatcher) {
- return internal::ArgumentAdaptingMatcher<
- internal::HasDescendantMatcher,
- DescendantT>(DescendantMatcher);
-}
+const internal::ArgumentAdaptingMatcherFunc<internal::HasDescendantMatcher>
+hasDescendant = {};
/// \brief Matches AST nodes that have child AST nodes that match the
/// provided matcher.
@@ -1642,13 +1632,8 @@ hasDescendant(const internal::Matcher<De
/// matches instead of only on the first one.
///
/// Usable as: Any Matcher
-template <typename ChildT>
-internal::ArgumentAdaptingMatcher<internal::ForEachMatcher, ChildT> forEach(
- const internal::Matcher<ChildT> &ChildMatcher) {
- return internal::ArgumentAdaptingMatcher<
- internal::ForEachMatcher,
- ChildT>(ChildMatcher);
-}
+const internal::ArgumentAdaptingMatcherFunc<internal::ForEachMatcher> forEach =
+ {};
/// \brief Matches AST nodes that have descendant AST nodes that match the
/// provided matcher.
@@ -1674,15 +1659,8 @@ internal::ArgumentAdaptingMatcher<intern
/// \endcode
///
/// Usable as: Any Matcher
-template <typename DescendantT>
-internal::ArgumentAdaptingMatcher<internal::ForEachDescendantMatcher,
- DescendantT>
-forEachDescendant(
- const internal::Matcher<DescendantT> &DescendantMatcher) {
- return internal::ArgumentAdaptingMatcher<
- internal::ForEachDescendantMatcher,
- DescendantT>(DescendantMatcher);
-}
+const internal::ArgumentAdaptingMatcherFunc<internal::ForEachDescendantMatcher>
+forEachDescendant = {};
/// \brief Matches if the node or any descendant matches.
///
@@ -1702,7 +1680,8 @@ forEachDescendant(
template <typename T>
internal::PolymorphicMatcherWithParam2<
internal::EachOfMatcher, internal::Matcher<T>,
- internal::ArgumentAdaptingMatcher<internal::ForEachDescendantMatcher, T> >
+ internal::ArgumentAdaptingMatcherFunc<
+ internal::ForEachDescendantMatcher>::Adaptor<T> >
findAll(const internal::Matcher<T> &Matcher) {
return eachOf(Matcher, forEachDescendant(Matcher));
}
@@ -1717,15 +1696,9 @@ findAll(const internal::Matcher<T> &Matc
/// \c compoundStmt(hasParent(ifStmt())) matches "{ int x = 43; }".
///
/// Usable as: Any Matcher
-template <typename ParentT>
-internal::ArgumentAdaptingMatcher<internal::HasParentMatcher, ParentT,
- internal::TypeList<Decl, Stmt>,
- internal::TypeList<Decl, Stmt> >
-hasParent(const internal::Matcher<ParentT> &ParentMatcher) {
- return internal::ArgumentAdaptingMatcher<
- internal::HasParentMatcher, ParentT, internal::TypeList<Decl, Stmt>,
- internal::TypeList<Decl, Stmt> >(ParentMatcher);
-}
+const internal::ArgumentAdaptingMatcherFunc<
+ internal::HasParentMatcher, internal::TypeList<Decl, Stmt>,
+ internal::TypeList<Decl, Stmt> > hasParent = {};
/// \brief Matches AST nodes that have an ancestor that matches the provided
/// matcher.
@@ -1738,15 +1711,9 @@ hasParent(const internal::Matcher<Parent
/// \c expr(integerLiteral(hasAncestor(ifStmt()))) matches \c 42, but not 43.
///
/// Usable as: Any Matcher
-template <typename AncestorT>
-internal::ArgumentAdaptingMatcher<internal::HasAncestorMatcher, AncestorT,
- internal::TypeList<Decl, Stmt>,
- internal::TypeList<Decl, Stmt> >
-hasAncestor(const internal::Matcher<AncestorT> &AncestorMatcher) {
- return internal::ArgumentAdaptingMatcher<
- internal::HasAncestorMatcher, AncestorT, internal::TypeList<Decl, Stmt>,
- internal::TypeList<Decl, Stmt> >(AncestorMatcher);
-}
+const internal::ArgumentAdaptingMatcherFunc<
+ internal::HasAncestorMatcher, internal::TypeList<Decl, Stmt>,
+ internal::TypeList<Decl, Stmt> > hasAncestor = {};
/// \brief Matches if the provided matcher does not match.
///
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=188560&r1=188559&r2=188560&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Aug 16 11:19:42 2013
@@ -803,22 +803,33 @@ typedef TypeList<Decl, Stmt, NestedNameS
/// If a matcher does not need knowledge about the inner type, prefer to use
/// PolymorphicMatcherWithParam1.
template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
- typename T, typename FromTypes = AdaptativeDefaultFromTypes,
+ typename FromTypes = AdaptativeDefaultFromTypes,
typename ToTypes = AdaptativeDefaultToTypes>
-class ArgumentAdaptingMatcher {
-public:
- explicit ArgumentAdaptingMatcher(const Matcher<T> &InnerMatcher)
- : InnerMatcher(InnerMatcher) {}
-
- typedef ToTypes ReturnTypes;
-
- template <typename To>
- operator Matcher<To>() const {
- return Matcher<To>(new ArgumentAdapterT<To, T>(InnerMatcher));
+struct ArgumentAdaptingMatcherFunc {
+ template <typename T> class Adaptor {
+ public:
+ explicit Adaptor(const Matcher<T> &InnerMatcher)
+ : InnerMatcher(InnerMatcher) {}
+
+ typedef ToTypes ReturnTypes;
+
+ 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);
}
-private:
- const Matcher<T> InnerMatcher;
+ template <typename T>
+ Adaptor<T> operator()(const Matcher<T> &InnerMatcher) const {
+ return create(InnerMatcher);
+ }
};
/// \brief A PolymorphicMatcherWithParamN<MatcherT, P1, ..., PN> object can be
Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h?rev=188560&r1=188559&r2=188560&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h Fri Aug 16 11:19:42 2013
@@ -280,6 +280,74 @@ variadicMatcherCreateCallback(StringRef
return Out;
}
+/// \brief Helper class used to collect all the possible overloads of an
+/// argument adaptative matcher function.
+template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
+ typename FromTypes, typename ToTypes>
+class AdaptativeOverloadCollector {
+public:
+ AdaptativeOverloadCollector(StringRef Name,
+ std::vector<MatcherCreateCallback *> &Out)
+ : Name(Name), Out(Out) {
+ collect(FromTypes());
+ }
+
+private:
+ typedef ast_matchers::internal::ArgumentAdaptingMatcherFunc<
+ ArgumentAdapterT, FromTypes, ToTypes> AdaptativeFunc;
+
+ /// \brief End case for the recursion
+ static void collect(ast_matchers::internal::EmptyTypeList) {}
+
+ /// \brief Recursive case. Get the overload for the head of the list, and
+ /// recurse to the tail.
+ template <typename FromTypeList> inline void collect(FromTypeList);
+
+ const StringRef Name;
+ std::vector<MatcherCreateCallback *> &Out;
+};
+
+/// \brief MatcherCreateCallback that wraps multiple "overloads" of the same
+/// matcher.
+///
+/// It will try every overload and generate appropriate errors for when none or
+/// more than one overloads match the arguments.
+class OverloadedMatcherCreateCallback : public MatcherCreateCallback {
+public:
+ OverloadedMatcherCreateCallback(ArrayRef<MatcherCreateCallback *> Callbacks)
+ : Overloads(Callbacks) {}
+
+ virtual ~OverloadedMatcherCreateCallback() {
+ llvm::DeleteContainerPointers(Overloads);
+ }
+
+ virtual VariantMatcher run(const SourceRange &NameRange,
+ ArrayRef<ParserValue> Args,
+ Diagnostics *Error) const {
+ std::vector<VariantMatcher> Constructed;
+ Diagnostics::OverloadContext Ctx(Error);
+ for (size_t i = 0, e = Overloads.size(); i != e; ++i) {
+ VariantMatcher SubMatcher = Overloads[i]->run(NameRange, Args, Error);
+ if (!SubMatcher.isNull()) {
+ Constructed.push_back(SubMatcher);
+ }
+ }
+
+ if (Constructed.empty()) return VariantMatcher(); // No overload matched.
+ // We ignore the errors if any matcher succeeded.
+ Ctx.revertErrors();
+ if (Constructed.size() > 1) {
+ // More than one constructed. It is ambiguous.
+ Error->addError(NameRange, Error->ET_RegistryAmbiguousOverload);
+ return VariantMatcher();
+ }
+ return Constructed[0];
+ }
+
+private:
+ std::vector<MatcherCreateCallback *> Overloads;
+};
+
/// Helper functions to select the appropriate marshaller functions.
/// They detect the number of arguments, arguments types and return type.
@@ -318,6 +386,30 @@ makeMatcherAutoMarshall(llvm::VariadicFu
&variadicMatcherCreateCallback<ResultT, ArgT, Func>, MatcherName);
}
+/// \brief Argument adaptative overload.
+template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
+ typename FromTypes, typename ToTypes>
+MatcherCreateCallback *
+makeMatcherAutoMarshall(ast_matchers::internal::ArgumentAdaptingMatcherFunc<
+ ArgumentAdapterT, FromTypes, ToTypes>,
+ StringRef MatcherName) {
+ std::vector<MatcherCreateCallback *> Overloads;
+ AdaptativeOverloadCollector<ArgumentAdapterT, FromTypes, ToTypes>(MatcherName,
+ Overloads);
+ return new OverloadedMatcherCreateCallback(Overloads);
+}
+
+template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
+ typename FromTypes, typename ToTypes>
+template <typename FromTypeList>
+inline void
+AdaptativeOverloadCollector<ArgumentAdapterT, FromTypes, ToTypes>::collect(
+ FromTypeList) {
+ Out.push_back(makeMatcherAutoMarshall(
+ &AdaptativeFunc::template create<typename FromTypeList::head>, Name));
+ collect(typename FromTypeList::tail());
+}
+
} // namespace internal
} // namespace dynamic
} // namespace ast_matchers
Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=188560&r1=188559&r2=188560&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Fri Aug 16 11:19:42 2013
@@ -48,48 +48,6 @@ void RegistryMaps::registerMatcher(Strin
Constructors[MatcherName] = Callback;
}
-/// \brief MatcherCreateCallback that wraps multiple "overloads" of the same
-/// matcher.
-///
-/// It will try every overload and generate appropriate errors for when none or
-/// more than one overloads match the arguments.
-class OverloadedMatcherCreateCallback : public MatcherCreateCallback {
- public:
- OverloadedMatcherCreateCallback(ArrayRef<MatcherCreateCallback *> Callbacks)
- : Overloads(Callbacks) {}
-
- virtual ~OverloadedMatcherCreateCallback() {
- for (size_t i = 0, e = Overloads.size(); i != e; ++i)
- delete Overloads[i];
- }
-
- virtual VariantMatcher run(const SourceRange &NameRange,
- ArrayRef<ParserValue> Args,
- Diagnostics *Error) const {
- std::vector<VariantMatcher> Constructed;
- Diagnostics::OverloadContext Ctx(Error);
- for (size_t i = 0, e = Overloads.size(); i != e; ++i) {
- VariantMatcher SubMatcher = Overloads[i]->run(NameRange, Args, Error);
- if (!SubMatcher.isNull()) {
- Constructed.push_back(SubMatcher);
- }
- }
-
- if (Constructed.empty()) return VariantMatcher(); // No overload matched.
- // We ignore the errors if any matcher succeeded.
- Ctx.revertErrors();
- if (Constructed.size() > 1) {
- // More than one constructed. It is ambiguous.
- Error->addError(NameRange, Error->ET_RegistryAmbiguousOverload);
- return VariantMatcher();
- }
- return Constructed[0];
- }
-
- private:
- std::vector<MatcherCreateCallback*> Overloads;
-};
-
#define REGISTER_MATCHER(name) \
registerMatcher(#name, internal::makeMatcherAutoMarshall( \
::clang::ast_matchers::name, #name));
@@ -106,65 +64,8 @@ class OverloadedMatcherCreateCallback :
internal::makeMatcherAutoMarshall(SPECIFIC_MATCHER_OVERLOAD(name, 1), \
#name) \
}; \
- registerMatcher(#name, new OverloadedMatcherCreateCallback(Callbacks)); \
- } while (0)
-
-/// \brief Class that allows us to bind to the constructor of an
-/// \c ArgumentAdaptingMatcher.
-/// This class, together with \c collectAdaptativeMatcherOverloads below, help
-/// us detect the Adapter class and create overload functions for the
-/// appropriate To/From types.
-/// We instantiate the \c createAdatingMatcher function for every type in
-/// \c FromTypes. \c ToTypes is handled on the marshaller side by using the
-/// \c ReturnTypes typedef in \c ArgumentAdaptingMatcher.
-template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
- typename FromTypes, typename ToTypes>
-struct AdaptativeMatcherWrapper {
- template <typename FromArg>
- static ast_matchers::internal::ArgumentAdaptingMatcher<
- ArgumentAdapterT, FromArg, FromTypes, ToTypes>
- createAdatingMatcher(
- const ast_matchers::internal::Matcher<FromArg> &InnerMatcher) {
- return ast_matchers::internal::ArgumentAdaptingMatcher<
- ArgumentAdapterT, FromArg, FromTypes, ToTypes>(InnerMatcher);
- }
-
- static void collectOverloads(StringRef Name,
- std::vector<MatcherCreateCallback *> &Out,
- ast_matchers::internal::EmptyTypeList) {}
-
- template <typename FromTypeList>
- static void collectOverloads(StringRef Name,
- std::vector<MatcherCreateCallback *> &Out,
- FromTypeList TypeList) {
- Out.push_back(internal::makeMatcherAutoMarshall(
- &createAdatingMatcher<typename FromTypeList::head>, Name));
- collectOverloads(Name, Out, typename FromTypeList::tail());
- }
-
- static void collectOverloads(StringRef Name,
- std::vector<MatcherCreateCallback *> &Out) {
- collectOverloads(Name, Out, FromTypes());
- }
-};
-
-template <template <typename ToArg, typename FromArg> class ArgumentAdapterT,
- typename DummyArg, typename FromTypes, typename ToTypes>
-void collectAdaptativeMatcherOverloads(
- StringRef Name,
- ast_matchers::internal::ArgumentAdaptingMatcher<ArgumentAdapterT, DummyArg,
- FromTypes, ToTypes>(
- *func)(const ast_matchers::internal::Matcher<DummyArg> &),
- std::vector<MatcherCreateCallback *> &Out) {
- AdaptativeMatcherWrapper<ArgumentAdapterT, FromTypes,
- ToTypes>::collectOverloads(Name, Out);
-}
-
-#define REGISTER_ADAPTATIVE(name) \
- do { \
- std::vector<MatcherCreateCallback *> Overloads; \
- collectAdaptativeMatcherOverloads(#name, &name<Decl>, Overloads); \
- registerMatcher(#name, new OverloadedMatcherCreateCallback(Overloads)); \
+ registerMatcher(#name, \
+ new internal::OverloadedMatcherCreateCallback(Callbacks)); \
} while (0)
/// \brief Generate a registry map with all the known matchers.
@@ -196,13 +97,6 @@ RegistryMaps::RegistryMaps() {
REGISTER_OVERLOADED_2(references);
REGISTER_OVERLOADED_2(thisPointerType);
- REGISTER_ADAPTATIVE(forEach);
- REGISTER_ADAPTATIVE(forEachDescendant);
- REGISTER_ADAPTATIVE(has);
- REGISTER_ADAPTATIVE(hasAncestor);
- REGISTER_ADAPTATIVE(hasDescendant);
- REGISTER_ADAPTATIVE(hasParent);
-
REGISTER_MATCHER(accessSpecDecl);
REGISTER_MATCHER(alignOfExpr);
REGISTER_MATCHER(anything);
@@ -254,6 +148,8 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(expr);
REGISTER_MATCHER(fieldDecl);
REGISTER_MATCHER(floatLiteral);
+ REGISTER_MATCHER(forEach);
+ REGISTER_MATCHER(forEachDescendant);
REGISTER_MATCHER(forField);
REGISTER_MATCHER(forRangeStmt);
REGISTER_MATCHER(forStmt);
@@ -262,6 +158,8 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(functionType);
REGISTER_MATCHER(functionalCastExpr);
REGISTER_MATCHER(gotoStmt);
+ REGISTER_MATCHER(has);
+ REGISTER_MATCHER(hasAncestor);
REGISTER_MATCHER(hasAnyArgument);
REGISTER_MATCHER(hasAnyConstructorInitializer);
REGISTER_MATCHER(hasAnyParameter);
@@ -277,6 +175,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(hasConditionVariableStatement);
REGISTER_MATCHER(hasDeclContext);
REGISTER_MATCHER(hasDeducedType);
+ REGISTER_MATCHER(hasDescendant);
REGISTER_MATCHER(hasDestinationType);
REGISTER_MATCHER(hasEitherOperand);
REGISTER_MATCHER(hasElementType);
@@ -294,6 +193,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(hasOperatorName);
REGISTER_MATCHER(hasOverloadedOperatorName);
REGISTER_MATCHER(hasParameter);
+ REGISTER_MATCHER(hasParent);
REGISTER_MATCHER(hasQualifier);
REGISTER_MATCHER(hasRHS);
REGISTER_MATCHER(hasSingleDecl);
More information about the cfe-commits
mailing list