<div dir="ltr">No, this is not templateName patch. The templateName one is in r277155.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 29, 2016 at 4:45 PM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@gmail.com" target="_blank">benny.kra@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Fri, Jul 29, 2016 at 3:57 PM, Haojian Wu via cfe-commits<br>
<<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
> Author: hokein<br>
> Date: Fri Jul 29 08:57:27 2016<br>
> New Revision: 277142<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=277142&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=277142&view=rev</a><br>
> Log:<br>
> [ASTMatcher] Add hasTemplateArgument/hasAnyTemplateArgument support in functionDecl.<br>
><br>
> Reviewers: klimek<br>
><br>
> Subscribers: klimek, cfe-commits<br>
><br>
> Differential Revision: <a href="https://reviews.llvm.org/D22957" rel="noreferrer" target="_blank">https://reviews.llvm.org/D22957</a><br>
><br>
> Modified:<br>
> cfe/trunk/docs/LibASTMatchersReference.html<br>
> cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h<br>
> cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h<br>
> cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp<br>
><br>
> Modified: cfe/trunk/docs/LibASTMatchersReference.html<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=277142&r1=277141&r2=277142&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=277142&r1=277141&r2=277142&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/docs/LibASTMatchersReference.html (original)<br>
> +++ cfe/trunk/docs/LibASTMatchersReference.html Fri Jul 29 08:57:27 2016<br>
> @@ -4240,30 +4240,44 @@ caseStmt(hasCaseConstant(integerLiteral(<br>
><br>
><br>
> <tr><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html</a>">ClassTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('hasAnyTemplateArgument0')"><a name="hasAnyTemplateArgument0Anchor">hasAnyTemplateArgument</a></td><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html</a>">TemplateArgument</a>> InnerMatcher</td></tr><br>
> -<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument0"><pre>Matches classTemplateSpecializations that have at least one<br>
> -TemplateArgument matching the given InnerMatcher.<br>
> +<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument0"><pre>Matches classTemplateSpecializations, templateSpecializationType and<br>
> +functionDecl that have at least one TemplateArgument matching the given<br>
> +InnerMatcher.<br>
><br>
> Given<br>
> template<typename T> class A {};<br>
> template<> class A<double> {};<br>
> A<int> a;<br>
> +<br>
> + template<typenmae T> f() {};<br>
> + void func() { f<int>(); };<br>
> +<br>
> classTemplateSpecializationDecl(hasAnyTemplateArgument(<br>
> refersToType(asString("int"))))<br>
> matches the specialization A<int><br>
> +<br>
> +functionDecl(hasAnyTemplateArgument(refersToType(asString("int"))))<br>
> + matches the specialization f<int><br>
> </pre></td></tr><br>
><br>
><br>
> <tr><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html</a>">ClassTemplateSpecializationDecl</a>></td><td class="name" onclick="toggle('hasTemplateArgument0')"><a name="hasTemplateArgument0Anchor">hasTemplateArgument</a></td><td>unsigned N, Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html</a>">TemplateArgument</a>> InnerMatcher</td></tr><br>
> -<tr><td colspan="4" class="doc" id="hasTemplateArgument0"><pre>Matches classTemplateSpecializations where the n'th TemplateArgument<br>
> -matches the given InnerMatcher.<br>
> +<tr><td colspan="4" class="doc" id="hasTemplateArgument0"><pre>Matches classTemplateSpecializations, templateSpecializationType and<br>
> +functionDecl where the n'th TemplateArgument matches the given InnerMatcher.<br>
><br>
> Given<br>
> template<typename T, typename U> class A {};<br>
> A<bool, int> b;<br>
> A<int, bool> c;<br>
> +<br>
> + template<typenmae T> f() {};<br>
> + void func() { f<int>(); };<br>
> classTemplateSpecializationDecl(hasTemplateArgument(<br>
> 1, refersToType(asString("int"))))<br>
> matches the specialization A<bool, int><br>
> +<br>
> +functionDecl(hasTemplateArgument(0, refersToType(asString("int"))))<br>
> + matches the specialization f<int><br>
> </pre></td></tr><br>
><br>
><br>
> @@ -4679,6 +4693,28 @@ with hasAnyParameter(...)<br>
> </pre></td></tr><br>
><br>
><br>
> +<tr><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html</a>">FunctionDecl</a>></td><td class="name" onclick="toggle('hasAnyTemplateArgument2')"><a name="hasAnyTemplateArgument2Anchor">hasAnyTemplateArgument</a></td><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html</a>">TemplateArgument</a>> InnerMatcher</td></tr><br>
> +<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument2"><pre>Matches classTemplateSpecializations, templateSpecializationType and<br>
> +functionDecl that have at least one TemplateArgument matching the given<br>
> +InnerMatcher.<br>
> +<br>
> +Given<br>
> + template<typename T> class A {};<br>
> + template<> class A<double> {};<br>
> + A<int> a;<br>
> +<br>
> + template<typenmae T> f() {};<br>
> + void func() { f<int>(); };<br>
> +<br>
> +classTemplateSpecializationDecl(hasAnyTemplateArgument(<br>
> + refersToType(asString("int"))))<br>
> + matches the specialization A<int><br>
> +<br>
> +functionDecl(hasAnyTemplateArgument(refersToType(asString("int"))))<br>
> + matches the specialization f<int><br>
> +</pre></td></tr><br>
> +<br>
> +<br>
> <tr><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html</a>">FunctionDecl</a>></td><td class="name" onclick="toggle('hasBody4')"><a name="hasBody4Anchor">hasBody</a></td><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1Stmt.html</a>">Stmt</a>> InnerMatcher</td></tr><br>
> <tr><td colspan="4" class="doc" id="hasBody4"><pre>Matches a 'for', 'while', 'do while' statement or a function<br>
> definition that has a given body.<br>
> @@ -4704,6 +4740,26 @@ with hasParameter(...)<br>
> </pre></td></tr><br>
><br>
><br>
> +<tr><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html</a>">FunctionDecl</a>></td><td class="name" onclick="toggle('hasTemplateArgument2')"><a name="hasTemplateArgument2Anchor">hasTemplateArgument</a></td><td>unsigned N, Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html</a>">TemplateArgument</a>> InnerMatcher</td></tr><br>
> +<tr><td colspan="4" class="doc" id="hasTemplateArgument2"><pre>Matches classTemplateSpecializations, templateSpecializationType and<br>
> +functionDecl where the n'th TemplateArgument matches the given InnerMatcher.<br>
> +<br>
> +Given<br>
> + template<typename T, typename U> class A {};<br>
> + A<bool, int> b;<br>
> + A<int, bool> c;<br>
> +<br>
> + template<typenmae T> f() {};<br>
> + void func() { f<int>(); };<br>
> +classTemplateSpecializationDecl(hasTemplateArgument(<br>
> + 1, refersToType(asString("int"))))<br>
> + matches the specialization A<bool, int><br>
> +<br>
> +functionDecl(hasTemplateArgument(0, refersToType(asString("int"))))<br>
> + matches the specialization f<int><br>
> +</pre></td></tr><br>
> +<br>
> +<br>
> <tr><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html</a>">FunctionDecl</a>></td><td class="name" onclick="toggle('returns0')"><a name="returns0Anchor">returns</a></td><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1QualType.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1QualType.html</a>">QualType</a>> InnerMatcher</td></tr><br>
> <tr><td colspan="4" class="doc" id="returns0"><pre>Matches the return type of a function declaration.<br>
><br>
> @@ -5311,16 +5367,24 @@ classTemplateSpecializationDecl(hasAnyTe<br>
><br>
><br>
> <tr><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html</a>">TemplateSpecializationType</a>></td><td class="name" onclick="toggle('hasAnyTemplateArgument1')"><a name="hasAnyTemplateArgument1Anchor">hasAnyTemplateArgument</a></td><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html</a>">TemplateArgument</a>> InnerMatcher</td></tr><br>
> -<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument1"><pre>Matches classTemplateSpecializations that have at least one<br>
> -TemplateArgument matching the given InnerMatcher.<br>
> +<tr><td colspan="4" class="doc" id="hasAnyTemplateArgument1"><pre>Matches classTemplateSpecializations, templateSpecializationType and<br>
> +functionDecl that have at least one TemplateArgument matching the given<br>
> +InnerMatcher.<br>
><br>
> Given<br>
> template<typename T> class A {};<br>
> template<> class A<double> {};<br>
> A<int> a;<br>
> +<br>
> + template<typenmae T> f() {};<br>
> + void func() { f<int>(); };<br>
> +<br>
> classTemplateSpecializationDecl(hasAnyTemplateArgument(<br>
> refersToType(asString("int"))))<br>
> matches the specialization A<int><br>
> +<br>
> +functionDecl(hasAnyTemplateArgument(refersToType(asString("int"))))<br>
> + matches the specialization f<int><br>
> </pre></td></tr><br>
><br>
><br>
> @@ -5347,16 +5411,22 @@ Usable as: Matcher<<a href="<a href="http://cl" rel="noreferrer" target="_blank">http://cl</a><br>
><br>
><br>
> <tr><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html</a>">TemplateSpecializationType</a>></td><td class="name" onclick="toggle('hasTemplateArgument1')"><a name="hasTemplateArgument1Anchor">hasTemplateArgument</a></td><td>unsigned N, Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html" rel="noreferrer" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1TemplateArgument.html</a>">TemplateArgument</a>> InnerMatcher</td></tr><br>
> -<tr><td colspan="4" class="doc" id="hasTemplateArgument1"><pre>Matches classTemplateSpecializations where the n'th TemplateArgument<br>
> -matches the given InnerMatcher.<br>
> +<tr><td colspan="4" class="doc" id="hasTemplateArgument1"><pre>Matches classTemplateSpecializations, templateSpecializationType and<br>
> +functionDecl where the n'th TemplateArgument matches the given InnerMatcher.<br>
><br>
> Given<br>
> template<typename T, typename U> class A {};<br>
> A<bool, int> b;<br>
> A<int, bool> c;<br>
> +<br>
> + template<typenmae T> f() {};<br>
> + void func() { f<int>(); };<br>
> classTemplateSpecializationDecl(hasTemplateArgument(<br>
> 1, refersToType(asString("int"))))<br>
> matches the specialization A<bool, int><br>
> +<br>
> +functionDecl(hasTemplateArgument(0, refersToType(asString("int"))))<br>
> + matches the specialization f<int><br>
> </pre></td></tr><br>
><br>
><br>
><br>
> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=277142&r1=277141&r2=277142&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=277142&r1=277141&r2=277142&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)<br>
> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Jul 29 08:57:27 2016<br>
> @@ -556,22 +556,32 @@ AST_MATCHER(Decl, isImplicit) {<br>
> return Node.isImplicit();<br>
> }<br>
><br>
> -/// \brief Matches classTemplateSpecializations that have at least one<br>
> -/// TemplateArgument matching the given InnerMatcher.<br>
> +/// \brief Matches classTemplateSpecializations, templateSpecializationType and<br>
> +/// functionDecl that have at least one TemplateArgument matching the given<br>
> +/// InnerMatcher.<br>
> ///<br>
> /// Given<br>
> /// \code<br>
> /// template<typename T> class A {};<br>
> /// template<> class A<double> {};<br>
> /// A<int> a;<br>
> +///<br>
> +/// template<typenmae T> f() {};<br>
<br>
</div></div>typenmae?<br>
<div class="HOEnZb"><div class="h5"><br>
> +/// void func() { f<int>(); };<br>
> +/// \endcode<br>
> +///<br>
> /// \endcode<br>
> /// classTemplateSpecializationDecl(hasAnyTemplateArgument(<br>
> /// refersToType(asString("int"))))<br>
> /// matches the specialization \c A<int><br>
> +///<br>
> +/// functionDecl(hasAnyTemplateArgument(refersToType(asString("int"))))<br>
> +/// matches the specialization \c f<int><br>
> AST_POLYMORPHIC_MATCHER_P(<br>
> hasAnyTemplateArgument,<br>
> AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl,<br>
> - TemplateSpecializationType),<br>
> + TemplateSpecializationType,<br>
> + FunctionDecl),<br>
> internal::Matcher<TemplateArgument>, InnerMatcher) {<br>
> ArrayRef<TemplateArgument> List =<br>
> internal::getTemplateSpecializationArgs(Node);<br>
> @@ -698,22 +708,29 @@ AST_MATCHER_P(QualType, ignoringParens,<br>
> return InnerMatcher.matches(Node.IgnoreParens(), Finder, Builder);<br>
> }<br>
><br>
> -/// \brief Matches classTemplateSpecializations where the n'th TemplateArgument<br>
> -/// matches the given InnerMatcher.<br>
> +/// \brief Matches classTemplateSpecializations, templateSpecializationType and<br>
> +/// functionDecl where the n'th TemplateArgument matches the given InnerMatcher.<br>
> ///<br>
> /// Given<br>
> /// \code<br>
> /// template<typename T, typename U> class A {};<br>
> /// A<bool, int> b;<br>
> /// A<int, bool> c;<br>
> +///<br>
> +/// template<typenmae T> f() {};<br>
> +/// void func() { f<int>(); };<br>
> /// \endcode<br>
> /// classTemplateSpecializationDecl(hasTemplateArgument(<br>
> /// 1, refersToType(asString("int"))))<br>
> /// matches the specialization \c A<bool, int><br>
> +///<br>
> +/// functionDecl(hasTemplateArgument(0, refersToType(asString("int"))))<br>
> +/// matches the specialization \c f<int><br>
> AST_POLYMORPHIC_MATCHER_P2(<br>
> hasTemplateArgument,<br>
> AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl,<br>
> - TemplateSpecializationType),<br>
> + TemplateSpecializationType,<br>
> + FunctionDecl),<br>
> unsigned, N, internal::Matcher<TemplateArgument>, InnerMatcher) {<br>
> ArrayRef<TemplateArgument> List =<br>
> internal::getTemplateSpecializationArgs(Node);<br>
><br>
> Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=277142&r1=277141&r2=277142&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h?rev=277142&r1=277141&r2=277142&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h (original)<br>
> +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchersInternal.h Fri Jul 29 08:57:27 2016<br>
> @@ -1638,6 +1638,13 @@ getTemplateSpecializationArgs(const Temp<br>
> return llvm::makeArrayRef(T.getArgs(), T.getNumArgs());<br>
> }<br>
><br>
> +inline ArrayRef<TemplateArgument><br>
> +getTemplateSpecializationArgs(const FunctionDecl &FD) {<br>
> + if (const auto* TemplateArgs = FD.getTemplateSpecializationArgs())<br>
> + return TemplateArgs->asArray();<br>
> + return ArrayRef<TemplateArgument>();<br>
> +}<br>
> +<br>
> struct NotEqualsBoundNodePredicate {<br>
> bool operator()(const internal::BoundNodesMap &Nodes) const {<br>
> return Nodes.getNode(ID) != Node;<br>
><br>
> Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp?rev=277142&r1=277141&r2=277142&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp?rev=277142&r1=277141&r2=277142&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp (original)<br>
> +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp Fri Jul 29 08:57:27 2016<br>
> @@ -594,6 +594,14 @@ TEST(Matcher, MatchesSpecificArgument) {<br>
> "A<int, bool> a;",<br>
> templateSpecializationType(hasTemplateArgument(<br>
> 1, refersToType(asString("int"))))));<br>
> +<br>
> + EXPECT_TRUE(matches(<br>
> + "template<typename T> void f() {};"<br>
> + "void func() { f<int>(); }",<br>
> + functionDecl(hasTemplateArgument(0, refersToType(asString("int"))))));<br>
> + EXPECT_TRUE(notMatches(<br>
> + "template<typename T> void f() {};",<br>
> + functionDecl(hasTemplateArgument(0, refersToType(asString("int"))))));<br>
> }<br>
><br>
> TEST(TemplateArgument, Matches) {<br>
> @@ -603,6 +611,11 @@ TEST(TemplateArgument, Matches) {<br>
> EXPECT_TRUE(matches(<br>
> "template<typename T> struct C {}; C<int> c;",<br>
> templateSpecializationType(hasAnyTemplateArgument(templateArgument()))));<br>
> +<br>
> + EXPECT_TRUE(matches(<br>
> + "template<typename T> void f() {};"<br>
> + "void func() { f<int>(); }",<br>
> + functionDecl(hasAnyTemplateArgument(templateArgument()))));<br>
> }<br>
><br>
> TEST(RefersToIntegralType, Matches) {<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>