Re: Add hasInClassInitializer matcher

2016-03-02 Thread Aaron Ballman via cfe-commits
On Wed, Mar 2, 2016 at 4:14 PM, Julian Bangert  wrote:
> Here is a patch to SVN with the requested changes (documentation, renamed
> and added to registry):

LGTM!

~Aaron

>
> Index: docs/LibASTMatchersReference.html
> ===
> --- docs/LibASTMatchersReference.html (revision 262512)
> +++ docs/LibASTMatchersReference.html (working copy)
> @@ -2412,7 +2412,7 @@
>  
>
>
> -Matcher href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html;>NamedDecl class="name" onclick="toggle('hasName0')"> name="hasName0Anchor">hasNamestd::string Name
> +Matcher href="http://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html;>NamedDecl class="name" onclick="toggle('hasName0')"> name="hasName0Anchor">hasNamestd::string  Name
>  Matches NamedDecl nodes
> that have the specified name.
>
>  Supports specifying enclosing namespaces or classes by prefixing the name
> @@ -3107,7 +3107,7 @@
>
>  This matcher is only provided as a performance optimization of hasName.
>  hasAnyName(a, b, c)
> - is equivalent but faster than
> + is equivalent to, but faster than
>  anyOf(hasName(a), hasName(b), hasName(c))
>  
>
> @@ -4180,6 +4180,16 @@
>  
>
>
> +Matcher href="http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html;>FieldDecl class="name" onclick="toggle('hasDefaultMemberInitializer0')"> name="hasDefaultMemberInitializer0Anchor">hasDefaultMemberInitializerMatcher href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr
> InnerMatcher
> + id="hasDefaultMemberInitializer0">Matches a C++ default member
> initializer matching the given matcher
> +
> +Given:
> +  class A { int x = 1; };
> +
> +hasDefaultMemberInitializer(integerLiteral()) matches int x = 1
> +
> +
> +
>  Matcher href="http://clang.llvm.org/doxygen/classclang_1_1ForStmt.html;>ForStmt class="name" onclick="toggle('hasBody1')"> name="hasBody1Anchor">hasBodyMatcher href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>Stmt
> InnerMatcher
>  Matches a 'for',
> 'while', 'do while' statement or a function
>  definition that has a given body.
> Index: include/clang/ASTMatchers/ASTMatchers.h
> ===
> --- include/clang/ASTMatchers/ASTMatchers.h (revision 262512)
> +++ include/clang/ASTMatchers/ASTMatchers.h (working copy)
> @@ -2848,6 +2848,20 @@
>return Node.isMemberInitializer();
>  }
>
> +/// \brief Matches a C++ default member initializer matching the given
> matcher
> +///
> +/// Given:
> +/// \code
> +///   class A { int x = 1; };
> +/// \endcode
> +///
> +/// \c hasDefaultMemberInitializer(integerLiteral()) matches int x = 1
> +AST_MATCHER_P(FieldDecl, hasDefaultMemberInitializer,
> +  internal::Matcher, InnerMatcher) {
> +  return Node.hasInClassInitializer()
> +  && InnerMatcher.matches(*Node.getInClassInitializer(), Finder,
> Builder);
> +}
> +
>  /// \brief Matches any argument of a call expression or a constructor call
>  /// expression.
>  ///
> Index: lib/ASTMatchers/Dynamic/Registry.cpp
> ===
> --- lib/ASTMatchers/Dynamic/Registry.cpp (revision 262512)
> +++ lib/ASTMatchers/Dynamic/Registry.cpp (working copy)
> @@ -210,6 +210,7 @@
>REGISTER_MATCHER(hasDeclaration);
>REGISTER_MATCHER(hasDeclContext);
>REGISTER_MATCHER(hasDeducedType);
> +  REGISTER_MATCHER(hasDefaultMemberInitializer);
>REGISTER_MATCHER(hasDescendant);
>REGISTER_MATCHER(hasDestinationType);
>REGISTER_MATCHER(hasEitherOperand);
> Index: unittests/ASTMatchers/ASTMatchersTest.cpp
> ===
> --- unittests/ASTMatchers/ASTMatchersTest.cpp (revision 262512)
> +++ unittests/ASTMatchers/ASTMatchersTest.cpp (working copy)
> @@ -2402,6 +2402,13 @@
>  hasName("E");
>  }
>
> +TEST(Matcher, inDefaultMemberInitializer) {
> +  EXPECT_TRUE(matches("class A{ int x = 1; };",
> +
> fieldDecl(hasDefaultMemberInitializer(integerLiteral();
> +  EXPECT_TRUE(notMatches("class A{ int x; void b() { x = 1; } };",
> +
> fieldDecl(hasDefaultMemberInitializer(integerLiteral();
> +}
> +
>  TEST(Matcher, NewExpression) {
>StatementMatcher New = cxxNewExpr();
>
>
>
> On Wed, Mar 2, 2016 at 12:23 PM Richard Smith  wrote:
>>
>> On Wed, Mar 2, 2016 at 12:06 PM, Aaron Ballman via cfe-commits
>>  wrote:
>> > On Wed, Mar 2, 2016 at 2:01 PM, Julian Bangert via cfe-commits
>> >  wrote:
>> >> This adds a matcher for C++ in Class initializers.
>> >>
>> >> ---
>> >>  include/clang/ASTMatchers/ASTMatchers.h   | 14 ++
>> >>  unittests/ASTMatchers/ASTMatchersTest.cpp |  7 +++
>> >>  2 files changed, 21 insertions(+)
>> >>
>> >> diff --git a/include/clang/ASTMatchers/ASTMatchers.h
>> >> b/include/clang/ASTMatchers/ASTMatchers.h
>> >
>> > Please also generate the AST matcher documentation by 

Re: Add hasInClassInitializer matcher

2016-03-02 Thread Julian Bangert via cfe-commits
Here is a patch to SVN with the requested changes (documentation, renamed
and added to registry):

Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html (revision 262512)
+++ docs/LibASTMatchersReference.html (working copy)
@@ -2412,7 +2412,7 @@
 


-Matcherhttp://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html;>NamedDeclhasNamestd::string Name
+Matcherhttp://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html;>NamedDeclhasNamestd::string  Name
 Matches NamedDecl nodes
that have the specified name.

 Supports specifying enclosing namespaces or classes by prefixing the name
@@ -3107,7 +3107,7 @@

 This matcher is only provided as a performance optimization of hasName.
 hasAnyName(a, b, c)
- is equivalent but faster than
+ is equivalent to, but faster than
 anyOf(hasName(a), hasName(b), hasName(c))
 

@@ -4180,6 +4180,16 @@
 


+Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html;>FieldDeclhasDefaultMemberInitializerMatcherhttp://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr
InnerMatcher
+Matches a C++ default member
initializer matching the given matcher
+
+Given:
+  class A { int x = 1; };
+
+hasDefaultMemberInitializer(integerLiteral()) matches int x = 1
+
+
+
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ForStmt.html;>ForStmthasBodyMatcherhttp://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>Stmt
InnerMatcher
 Matches a 'for',
'while', 'do while' statement or a function
 definition that has a given body.
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h (revision 262512)
+++ include/clang/ASTMatchers/ASTMatchers.h (working copy)
@@ -2848,6 +2848,20 @@
   return Node.isMemberInitializer();
 }

+/// \brief Matches a C++ default member initializer matching the given
matcher
+///
+/// Given:
+/// \code
+///   class A { int x = 1; };
+/// \endcode
+///
+/// \c hasDefaultMemberInitializer(integerLiteral()) matches int x = 1
+AST_MATCHER_P(FieldDecl, hasDefaultMemberInitializer,
+  internal::Matcher, InnerMatcher) {
+  return Node.hasInClassInitializer()
+  && InnerMatcher.matches(*Node.getInClassInitializer(), Finder,
Builder);
+}
+
 /// \brief Matches any argument of a call expression or a constructor call
 /// expression.
 ///
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp (revision 262512)
+++ lib/ASTMatchers/Dynamic/Registry.cpp (working copy)
@@ -210,6 +210,7 @@
   REGISTER_MATCHER(hasDeclaration);
   REGISTER_MATCHER(hasDeclContext);
   REGISTER_MATCHER(hasDeducedType);
+  REGISTER_MATCHER(hasDefaultMemberInitializer);
   REGISTER_MATCHER(hasDescendant);
   REGISTER_MATCHER(hasDestinationType);
   REGISTER_MATCHER(hasEitherOperand);
Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTest.cpp (revision 262512)
+++ unittests/ASTMatchers/ASTMatchersTest.cpp (working copy)
@@ -2402,6 +2402,13 @@
 hasName("E");
 }

+TEST(Matcher, inDefaultMemberInitializer) {
+  EXPECT_TRUE(matches("class A{ int x = 1; };",
+
 fieldDecl(hasDefaultMemberInitializer(integerLiteral();
+  EXPECT_TRUE(notMatches("class A{ int x; void b() { x = 1; } };",
+
fieldDecl(hasDefaultMemberInitializer(integerLiteral();
+}
+
 TEST(Matcher, NewExpression) {
   StatementMatcher New = cxxNewExpr();



On Wed, Mar 2, 2016 at 12:23 PM Richard Smith  wrote:

> On Wed, Mar 2, 2016 at 12:06 PM, Aaron Ballman via cfe-commits
>  wrote:
> > On Wed, Mar 2, 2016 at 2:01 PM, Julian Bangert via cfe-commits
> >  wrote:
> >> This adds a matcher for C++ in Class initializers.
> >>
> >> ---
> >>  include/clang/ASTMatchers/ASTMatchers.h   | 14 ++
> >>  unittests/ASTMatchers/ASTMatchersTest.cpp |  7 +++
> >>  2 files changed, 21 insertions(+)
> >>
> >> diff --git a/include/clang/ASTMatchers/ASTMatchers.h
> >> b/include/clang/ASTMatchers/ASTMatchers.h
> >
> > Please also generate the AST matcher documentation by running
> > dump-ast-matchers.py and register the function in Registry.cpp. Also,
> > if you can provide an svn patch instead of a git patch, it would be
> > appreciated (especially if you need someone to commit on your behalf).
>
> Please also name this "hasDefaultMemberInitializer" to match the C++
> standard's (fairly new) name for this feature. We'll rename Clang's
> internals to match at some point soon.
>
> >> index 21a4969..6b0a5d6 100644
> >> --- a/include/clang/ASTMatchers/ASTMatchers.h
> >> +++ b/include/clang/ASTMatchers/ASTMatchers.h
> >> @@ -2848,6 +2848,20 @@ AST_MATCHER(CXXCtorInitializer,
> isMemberInitializer)
> >> {
> >>return Node.isMemberInitializer();
> >>  }
> 

Re: Add hasInClassInitializer matcher

2016-03-02 Thread Julian Bangert via cfe-commits
In case my MUA messed up the formatting, see the attached

On Wed, Mar 2, 2016 at 1:14 PM Julian Bangert  wrote:

> Here is a patch to SVN with the requested changes (documentation, renamed
> and added to registry):
>
> Index: docs/LibASTMatchersReference.html
> ===
> --- docs/LibASTMatchersReference.html (revision 262512)
> +++ docs/LibASTMatchersReference.html (working copy)
> @@ -2412,7 +2412,7 @@
>  
>
>
> -Matcherhttp://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html;>NamedDecl class="name" onclick="toggle('hasName0')"> name="hasName0Anchor">hasNamestd::string Name
> +Matcherhttp://clang.llvm.org/doxygen/classclang_1_1NamedDecl.html;>NamedDecl class="name" onclick="toggle('hasName0')"> name="hasName0Anchor">hasNamestd::string  Name
>  Matches NamedDecl
> nodes that have the specified name.
>
>  Supports specifying enclosing namespaces or classes by prefixing the name
> @@ -3107,7 +3107,7 @@
>
>  This matcher is only provided as a performance optimization of hasName.
>  hasAnyName(a, b, c)
> - is equivalent but faster than
> + is equivalent to, but faster than
>  anyOf(hasName(a), hasName(b), hasName(c))
>  
>
> @@ -4180,6 +4180,16 @@
>  
>
>
> +Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html;>FieldDecl class="name" onclick="toggle('hasDefaultMemberInitializer0')"> name="hasDefaultMemberInitializer0Anchor">hasDefaultMemberInitializerMatcher href="http://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr
> InnerMatcher
> + id="hasDefaultMemberInitializer0">Matches a C++ default member
> initializer matching the given matcher
> +
> +Given:
> +  class A { int x = 1; };
> +
> +hasDefaultMemberInitializer(integerLiteral()) matches int x = 1
> +
> +
> +
>  Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ForStmt.html;>ForStmt class="name" onclick="toggle('hasBody1')"> name="hasBody1Anchor">hasBodyMatcherhttp://clang.llvm.org/doxygen/classclang_1_1Stmt.html;>Stmt
> InnerMatcher
>  Matches a 'for',
> 'while', 'do while' statement or a function
>  definition that has a given body.
> Index: include/clang/ASTMatchers/ASTMatchers.h
> ===
> --- include/clang/ASTMatchers/ASTMatchers.h (revision 262512)
> +++ include/clang/ASTMatchers/ASTMatchers.h (working copy)
> @@ -2848,6 +2848,20 @@
>return Node.isMemberInitializer();
>  }
>
> +/// \brief Matches a C++ default member initializer matching the given
> matcher
> +///
> +/// Given:
> +/// \code
> +///   class A { int x = 1; };
> +/// \endcode
> +///
> +/// \c hasDefaultMemberInitializer(integerLiteral()) matches int x = 1
> +AST_MATCHER_P(FieldDecl, hasDefaultMemberInitializer,
> +  internal::Matcher, InnerMatcher) {
> +  return Node.hasInClassInitializer()
> +  && InnerMatcher.matches(*Node.getInClassInitializer(), Finder,
> Builder);
> +}
> +
>  /// \brief Matches any argument of a call expression or a constructor call
>  /// expression.
>  ///
> Index: lib/ASTMatchers/Dynamic/Registry.cpp
> ===
> --- lib/ASTMatchers/Dynamic/Registry.cpp (revision 262512)
> +++ lib/ASTMatchers/Dynamic/Registry.cpp (working copy)
> @@ -210,6 +210,7 @@
>REGISTER_MATCHER(hasDeclaration);
>REGISTER_MATCHER(hasDeclContext);
>REGISTER_MATCHER(hasDeducedType);
> +  REGISTER_MATCHER(hasDefaultMemberInitializer);
>REGISTER_MATCHER(hasDescendant);
>REGISTER_MATCHER(hasDestinationType);
>REGISTER_MATCHER(hasEitherOperand);
> Index: unittests/ASTMatchers/ASTMatchersTest.cpp
> ===
> --- unittests/ASTMatchers/ASTMatchersTest.cpp (revision 262512)
> +++ unittests/ASTMatchers/ASTMatchersTest.cpp (working copy)
> @@ -2402,6 +2402,13 @@
>  hasName("E");
>  }
>
> +TEST(Matcher, inDefaultMemberInitializer) {
> +  EXPECT_TRUE(matches("class A{ int x = 1; };",
> +
>  fieldDecl(hasDefaultMemberInitializer(integerLiteral();
> +  EXPECT_TRUE(notMatches("class A{ int x; void b() { x = 1; } };",
> +
> fieldDecl(hasDefaultMemberInitializer(integerLiteral();
> +}
> +
>  TEST(Matcher, NewExpression) {
>StatementMatcher New = cxxNewExpr();
>
>
>
> On Wed, Mar 2, 2016 at 12:23 PM Richard Smith 
> wrote:
>
>> On Wed, Mar 2, 2016 at 12:06 PM, Aaron Ballman via cfe-commits
>>  wrote:
>> > On Wed, Mar 2, 2016 at 2:01 PM, Julian Bangert via cfe-commits
>> >  wrote:
>> >> This adds a matcher for C++ in Class initializers.
>> >>
>> >> ---
>> >>  include/clang/ASTMatchers/ASTMatchers.h   | 14 ++
>> >>  unittests/ASTMatchers/ASTMatchersTest.cpp |  7 +++
>> >>  2 files changed, 21 insertions(+)
>> >>
>> >> diff --git a/include/clang/ASTMatchers/ASTMatchers.h
>> >> b/include/clang/ASTMatchers/ASTMatchers.h
>> >
>> > Please also generate the AST matcher 

Re: Add hasInClassInitializer matcher

2016-03-02 Thread Aaron Ballman via cfe-commits
On Wed, Mar 2, 2016 at 2:01 PM, Julian Bangert via cfe-commits
 wrote:
> This adds a matcher for C++ in Class initializers.
>
> ---
>  include/clang/ASTMatchers/ASTMatchers.h   | 14 ++
>  unittests/ASTMatchers/ASTMatchersTest.cpp |  7 +++
>  2 files changed, 21 insertions(+)
>
> diff --git a/include/clang/ASTMatchers/ASTMatchers.h
> b/include/clang/ASTMatchers/ASTMatchers.h

Please also generate the AST matcher documentation by running
dump-ast-matchers.py and register the function in Registry.cpp. Also,
if you can provide an svn patch instead of a git patch, it would be
appreciated (especially if you need someone to commit on your behalf).

> index 21a4969..6b0a5d6 100644
> --- a/include/clang/ASTMatchers/ASTMatchers.h
> +++ b/include/clang/ASTMatchers/ASTMatchers.h
> @@ -2848,6 +2848,20 @@ AST_MATCHER(CXXCtorInitializer, isMemberInitializer)
> {
>return Node.isMemberInitializer();
>  }
>
> +/// \brief Matches a C++ inClassInitializer matching the given matcher
> +///
> +/// Given:
> +/// \code
> +///   class A { int x = 1; };
> +/// \endcode
> +///
> +/// \c hasInClassInitializer(integerLiteral()) matches int x = 1
> +AST_MATCHER_P(FieldDecl, hasInClassInitializer,
> +  internal::Matcher, InnerMatcher) {
> +  return Node.hasInClassInitializer()
> +  && InnerMatcher.matches(*Node.getInClassInitializer(), Finder,
> Builder);
> +}
> +
>  /// \brief Matches any argument of a call expression or a constructor call
>  /// expression.
>  ///
> diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp
> b/unittests/ASTMatchers/ASTMatchersTest.cpp
> index 133dc70..15776d7 100644
> --- a/unittests/ASTMatchers/ASTMatchersTest.cpp
> +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp
> @@ -2402,6 +2402,13 @@ TEST(HasAnyConstructorInitializer, IsBaseInitializer)
> {
>  hasName("E");
>  }
>
> +TEST(Matcher, inClassInitializer) {
> +  EXPECT_TRUE(matches("class A{ int x = 1; };",
> +  fieldDecl(hasInClassInitializer(integerLiteral();
> +  EXPECT_FALSE(matches("class A{ int x; void b() { x = 1; } };",

This should use EXPECT_TRUE and notMatches.

~Aaron

> +
> fieldDecl(hasInClassInitializer(integerLiteral();
> +}
> +
>  TEST(Matcher, NewExpression) {
>StatementMatcher New = cxxNewExpr();
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits