<div dir="ltr">Here is a patch to SVN with the requested changes (documentation, renamed and added to registry): <div><br></div><div><div>Index: docs/LibASTMatchersReference.html</div><div>===================================================================</div><div>--- docs/LibASTMatchersReference.html<span class="Apple-tab-span" style="white-space:pre"> </span>(revision 262512)</div><div>+++ docs/LibASTMatchersReference.html<span class="Apple-tab-span" style="white-space:pre"> </span>(working copy)</div><div>@@ -2412,7 +2412,7 @@</div><div> </pre></td></tr></div><div> </div><div> </div><div>-<tr><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html</a>">NamedDecl</a>></td><td class="name" onclick="toggle('hasName0')"><a name="hasName0Anchor">hasName</a></td><td>std::string Name</td></tr></div><div>+<tr><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html">http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html</a>">NamedDecl</a>></td><td class="name" onclick="toggle('hasName0')"><a name="hasName0Anchor">hasName</a></td><td>std::string Name</td></tr></div><div> <tr><td colspan="4" class="doc" id="hasName0"><pre>Matches NamedDecl nodes that have the specified name.</div><div> </div><div> Supports specifying enclosing namespaces or classes by prefixing the name</div><div>@@ -3107,7 +3107,7 @@</div><div> </div><div> This matcher is only provided as a performance optimization of hasName.</div><div> hasAnyName(a, b, c)</div><div>- is equivalent but faster than</div><div>+ is equivalent to, but faster than</div><div> anyOf(hasName(a), hasName(b), hasName(c))</div><div> </pre></td></tr></div><div> </div><div>@@ -4180,6 +4180,16 @@</div><div> </pre></td></tr></div><div> </div><div> </div><div>+<tr><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html</a>">FieldDecl</a>></td><td class="name" onclick="toggle('hasDefaultMemberInitializer0')"><a name="hasDefaultMemberInitializer0Anchor">hasDefaultMemberInitializer</a></td><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html">http://clang.llvm.org/doxygen/classclang_1_1Expr.html</a>">Expr</a>> InnerMatcher</td></tr></div><div>+<tr><td colspan="4" class="doc" id="hasDefaultMemberInitializer0"><pre>Matches a C++ default member initializer matching the given matcher</div><div>+</div><div>+Given:</div><div>+ class A { int x = 1; };</div><div>+</div><div>+hasDefaultMemberInitializer(integerLiteral()) matches int x = 1</div><div>+</pre></td></tr></div><div>+</div><div>+</div><div> <tr><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html">http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html</a>">ForStmt</a>></td><td class="name" onclick="toggle('hasBody1')"><a name="hasBody1Anchor">hasBody</a></td><td>Matcher<<a href="<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">http://clang.llvm.org/doxygen/classclang_1_1Stmt.html</a>">Stmt</a>> InnerMatcher</td></tr></div><div> <tr><td colspan="4" class="doc" id="hasBody1"><pre>Matches a 'for', 'while', 'do while' statement or a function</div><div> definition that has a given body.</div><div>Index: include/clang/ASTMatchers/ASTMatchers.h</div><div>===================================================================</div><div>--- include/clang/ASTMatchers/ASTMatchers.h<span class="Apple-tab-span" style="white-space:pre"> </span>(revision 262512)</div><div>+++ include/clang/ASTMatchers/ASTMatchers.h<span class="Apple-tab-span" style="white-space:pre"> </span>(working copy)</div><div>@@ -2848,6 +2848,20 @@</div><div> return Node.isMemberInitializer();</div><div> }</div><div> </div><div>+/// \brief Matches a C++ default member initializer matching the given matcher</div><div>+///</div><div>+/// Given:</div><div>+/// \code</div><div>+/// class A { int x = 1; };</div><div>+/// \endcode</div><div>+///</div><div>+/// \c hasDefaultMemberInitializer(integerLiteral()) matches int x = 1</div><div>+AST_MATCHER_P(FieldDecl, hasDefaultMemberInitializer,</div><div>+ internal::Matcher<Expr>, InnerMatcher) {</div><div>+ return Node.hasInClassInitializer()</div><div>+ && InnerMatcher.matches(*Node.getInClassInitializer(), Finder, Builder);</div><div>+}</div><div>+</div><div> /// \brief Matches any argument of a call expression or a constructor call</div><div> /// expression.</div><div> ///</div><div>Index: lib/ASTMatchers/Dynamic/Registry.cpp</div><div>===================================================================</div><div>--- lib/ASTMatchers/Dynamic/Registry.cpp<span class="Apple-tab-span" style="white-space:pre"> </span>(revision 262512)</div><div>+++ lib/ASTMatchers/Dynamic/Registry.cpp<span class="Apple-tab-span" style="white-space:pre"> </span>(working copy)</div><div>@@ -210,6 +210,7 @@</div><div> REGISTER_MATCHER(hasDeclaration);</div><div> REGISTER_MATCHER(hasDeclContext);</div><div> REGISTER_MATCHER(hasDeducedType);</div><div>+ REGISTER_MATCHER(hasDefaultMemberInitializer);</div><div> REGISTER_MATCHER(hasDescendant);</div><div> REGISTER_MATCHER(hasDestinationType);</div><div> REGISTER_MATCHER(hasEitherOperand);</div><div>Index: unittests/ASTMatchers/ASTMatchersTest.cpp</div><div>===================================================================</div><div>--- unittests/ASTMatchers/ASTMatchersTest.cpp<span class="Apple-tab-span" style="white-space:pre"> </span>(revision 262512)</div><div>+++ unittests/ASTMatchers/ASTMatchersTest.cpp<span class="Apple-tab-span" style="white-space:pre"> </span>(working copy)</div><div>@@ -2402,6 +2402,13 @@</div><div> hasName("E")))));</div><div> }</div><div> </div><div>+TEST(Matcher, inDefaultMemberInitializer) {</div><div>+ EXPECT_TRUE(matches("class A{ int x = 1; };",</div><div>+ fieldDecl(hasDefaultMemberInitializer(integerLiteral()))));</div><div>+ EXPECT_TRUE(notMatches("class A{ int x; void b() { x = 1; } };",</div><div>+ fieldDecl(hasDefaultMemberInitializer(integerLiteral()))));</div><div>+}</div><div>+</div><div> TEST(Matcher, NewExpression) {</div><div> StatementMatcher New = cxxNewExpr();</div><div> </div></div><div><br></div><div><br><div class="gmail_quote"><div dir="ltr">On Wed, Mar 2, 2016 at 12:23 PM Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, Mar 2, 2016 at 12:06 PM, Aaron Ballman via cfe-commits<br>
<<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br>
> On Wed, Mar 2, 2016 at 2:01 PM, Julian Bangert via cfe-commits<br>
> <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br>
>> This adds a matcher for C++ in Class initializers.<br>
>><br>
>> ---<br>
>> include/clang/ASTMatchers/ASTMatchers.h | 14 ++++++++++++++<br>
>> unittests/ASTMatchers/ASTMatchersTest.cpp | 7 +++++++<br>
>> 2 files changed, 21 insertions(+)<br>
>><br>
>> diff --git a/include/clang/ASTMatchers/ASTMatchers.h<br>
>> b/include/clang/ASTMatchers/ASTMatchers.h<br>
><br>
> Please also generate the AST matcher documentation by running<br>
> dump-ast-matchers.py and register the function in Registry.cpp. Also,<br>
> if you can provide an svn patch instead of a git patch, it would be<br>
> appreciated (especially if you need someone to commit on your behalf).<br>
<br>
Please also name this "hasDefaultMemberInitializer" to match the C++<br>
standard's (fairly new) name for this feature. We'll rename Clang's<br>
internals to match at some point soon.<br>
<br>
>> index 21a4969..6b0a5d6 100644<br>
>> --- a/include/clang/ASTMatchers/ASTMatchers.h<br>
>> +++ b/include/clang/ASTMatchers/ASTMatchers.h<br>
>> @@ -2848,6 +2848,20 @@ AST_MATCHER(CXXCtorInitializer, isMemberInitializer)<br>
>> {<br>
>> return Node.isMemberInitializer();<br>
>> }<br>
>><br>
>> +/// \brief Matches a C++ inClassInitializer matching the given matcher<br>
>> +///<br>
>> +/// Given:<br>
>> +/// \code<br>
>> +/// class A { int x = 1; };<br>
>> +/// \endcode<br>
>> +///<br>
>> +/// \c hasInClassInitializer(integerLiteral()) matches int x = 1<br>
>> +AST_MATCHER_P(FieldDecl, hasInClassInitializer,<br>
>> + internal::Matcher<Expr>, InnerMatcher) {<br>
>> + return Node.hasInClassInitializer()<br>
>> + && InnerMatcher.matches(*Node.getInClassInitializer(), Finder,<br>
>> Builder);<br>
>> +}<br>
>> +<br>
>> /// \brief Matches any argument of a call expression or a constructor call<br>
>> /// expression.<br>
>> ///<br>
>> diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp<br>
>> b/unittests/ASTMatchers/ASTMatchersTest.cpp<br>
>> index 133dc70..15776d7 100644<br>
>> --- a/unittests/ASTMatchers/ASTMatchersTest.cpp<br>
>> +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp<br>
>> @@ -2402,6 +2402,13 @@ TEST(HasAnyConstructorInitializer, IsBaseInitializer)<br>
>> {<br>
>> hasName("E")))));<br>
>> }<br>
>><br>
>> +TEST(Matcher, inClassInitializer) {<br>
>> + EXPECT_TRUE(matches("class A{ int x = 1; };",<br>
>> + fieldDecl(hasInClassInitializer(integerLiteral()))));<br>
>> + EXPECT_FALSE(matches("class A{ int x; void b() { x = 1; } };",<br>
><br>
> This should use EXPECT_TRUE and notMatches.<br>
><br>
> ~Aaron<br>
><br>
>> +<br>
>> fieldDecl(hasInClassInitializer(integerLiteral()))));<br>
>> +}<br>
>> +<br>
>> TEST(Matcher, NewExpression) {<br>
>> StatementMatcher New = cxxNewExpr();<br>
>><br>
>><br>
>> _______________________________________________<br>
>> cfe-commits mailing list<br>
>> <a href="mailto:cfe-commits@lists.llvm.org" target="_blank">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>
>><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org" target="_blank">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>
</blockquote></div></div></div>