Re: [PATCH] D21241: Add an ASTMatcher for ignoring ExprWithCleanups.

2016-06-21 Thread Tim Shen via cfe-commits
timshen abandoned this revision.
timshen added a comment.

> I was wondering why we didn't created that Matcher: IgnoreImplicit


Actually you are right. There already exists a IgnoreImplict in clang-tidy and 
I just switched to that.

Abandoning this patch.

Thanks!


http://reviews.llvm.org/D21241



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21241: Add an ASTMatcher for ignoring ExprWithCleanups.

2016-06-15 Thread Etienne Bergeron via cfe-commits
etienneb added a subscriber: etienneb.
etienneb added a comment.

I was wondering why we didn't created that Matcher: IgnoreImplicit

I believe it's more commonly used than 'ignoringExprWithCleanups'.

It can be implemented by calling 'Stmt.IgnoreImplicit'.

  /// Skip past any implicit AST nodes which might surround this
  /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
  Stmt *IgnoreImplicit();



Comment at: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:2018
@@ +2017,3 @@
+ ignoringParenImpCasts(unless(anything(;
+  EXPECT_TRUE(notMatches("float y = (float(0));",
+ varDecl(hasInitializer(ignoringExprWithCleanups(

nit: you can lift that expression to a local variable:

varDecl(hasInitializer(ignoringExprWithCleanups(
 ignoringParenImpCasts(integerLiteral()))

It's used 3 times.


http://reviews.llvm.org/D21241



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21241: Add an ASTMatcher for ignoring ExprWithCleanups.

2016-06-14 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.


Comment at: include/clang/ASTMatchers/ASTMatchers.h:629
@@ +628,3 @@
+/// \brief Matches expressions that match InnerMatcher after ExprWithCleanups
+/// are stripped off.
+AST_MATCHER_P(Expr, ignoringExprWithCleanups, internal::Matcher,

This documentation is used to generate the public docs, so it should include 
examples with matchers (of what does and does not match). It's especially 
important because this AST matcher may not be obvious to everyone as to why 
you'd use it or what it applies to.


Comment at: include/clang/ASTMatchers/ASTMatchers.h:633
@@ +632,3 @@
+  auto E = 
+  if (auto Cleanups = dyn_cast(E))
+E = Cleanups->getSubExpr();

Should be `auto *` (possibly const-qualified if you can get away with it).


http://reviews.llvm.org/D21241



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21241: Add an ASTMatcher for ignoring ExprWithCleanups.

2016-06-14 Thread Tim Shen via cfe-commits
timshen updated this revision to Diff 60704.
timshen added a comment.

Done.


http://reviews.llvm.org/D21241

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1997,5 +1997,34 @@
   EXPECT_TRUE(notMatches(CppString2, returnStmt(forFunction(hasName("F");
 }
 
+TEST(IgnoringExprWithCleanups, MatchesExprWithCleanups) {
+  EXPECT_TRUE(
+  matches("struct A { ~A(); }; A Foo(); A x = Foo();",
+  varDecl(hasInitializer(ignoringExprWithCleanups(
+  cxxConstructExpr(has(materializeTemporaryExpr(;
+}
+
+TEST(IgnoringExprWithCleanups, MatchesWithoutExprWithCleanups) {
+  EXPECT_TRUE(matches(
+  "int x = 0; const int y = x;",
+  varDecl(hasInitializer(ignoringExprWithCleanups(
+  ignoringParenImpCasts(declRefExpr(to(varDecl(hasName("x"));
+}
+
+TEST(IgnoringExprWithCleanups, DoesNotMatchIncorrectly) {
+  EXPECT_TRUE(notMatches("char c = ((3));",
+ varDecl(hasInitializer(ignoringExprWithCleanups(
+ ignoringParenImpCasts(unless(anything(;
+  EXPECT_TRUE(notMatches("float y = (float(0));",
+ varDecl(hasInitializer(ignoringExprWithCleanups(
+ ignoringParenImpCasts(integerLiteral()));
+  EXPECT_TRUE(notMatches("float y = (float)0;",
+ varDecl(hasInitializer(ignoringExprWithCleanups(
+ ignoringParenImpCasts(integerLiteral()));
+  EXPECT_TRUE(notMatches("char* p = static_cast(0);",
+ varDecl(hasInitializer(ignoringExprWithCleanups(
+ ignoringParenImpCasts(integerLiteral()));
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -265,6 +265,7 @@
   REGISTER_MATCHER(hasUnarySelector);
   REGISTER_MATCHER(hasValueType);
   REGISTER_MATCHER(ifStmt);
+  REGISTER_MATCHER(ignoringExprWithCleanups);
   REGISTER_MATCHER(ignoringImpCasts);
   REGISTER_MATCHER(ignoringParenCasts);
   REGISTER_MATCHER(ignoringParenImpCasts);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -625,6 +625,16 @@
   return InnerMatcher.matches(*Node.IgnoreParenImpCasts(), Finder, Builder);
 }
 
+/// \brief Matches expressions that match InnerMatcher after ExprWithCleanups
+/// are stripped off.
+AST_MATCHER_P(Expr, ignoringExprWithCleanups, internal::Matcher,
+  InnerMatcher) {
+  auto E = 
+  if (auto Cleanups = dyn_cast(E))
+E = Cleanups->getSubExpr();
+  return InnerMatcher.matches(*E, Finder, Builder);
+}
+
 /// \brief Matches types that match InnerMatcher after any parens are stripped.
 ///
 /// Given
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -2347,7 +2347,7 @@
   private:   int c;
   };
 fieldDecl(isPrivate())
-  matches 'int c;' 
+  matches 'int c;'
 
 
 
@@ -2361,7 +2361,7 @@
   private:   int c;
   };
 fieldDecl(isProtected())
-  matches 'int b;' 
+  matches 'int b;'
 
 
 
@@ -2375,7 +2375,7 @@
   private:   int c;
   };
 fieldDecl(isPublic())
-  matches 'int a;' 
+  matches 'int a;'
 
 
 
@@ -4432,6 +4432,12 @@
 
 
 
+Matcherhttp://clang.llvm.org/doxygen/classclang_1_1Expr.html;>ExprignoringExprWithCleanupsMatcherhttp://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr InnerMatcher
+Matches expressions that match InnerMatcher after ExprWithCleanups
+are stripped off.
+
+
+
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1Expr.html;>ExprignoringImpCastsMatcherhttp://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr InnerMatcher
 Matches expressions that match InnerMatcher after any implicit casts
 are stripped off.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21241: Add an ASTMatcher for ignoring ExprWithCleanups.

2016-06-12 Thread Aaron Ballman via cfe-commits
aaron.ballman added a subscriber: aaron.ballman.
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added a comment.

Also, please add documentation to the matcher definition and regenerate the 
documentation.


http://reviews.llvm.org/D21241



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D21241: Add an ASTMatcher for ignoring ExprWithCleanups.

2016-06-12 Thread Manuel Klimek via cfe-commits
klimek added a comment.

Please add a test.


http://reviews.llvm.org/D21241



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D21241: Add an ASTMatcher for ignoring ExprWithCleanups.

2016-06-10 Thread Tim Shen via cfe-commits
timshen created this revision.
timshen added a reviewer: rsmith.
timshen added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

This is part of the fix of clang-tidy patterns to adapt to newly added 
ExprWithCleanups node.

http://reviews.llvm.org/D21241

Files:
  include/clang/ASTMatchers/ASTMatchers.h

Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -625,6 +625,16 @@
   return InnerMatcher.matches(*Node.IgnoreParenImpCasts(), Finder, Builder);
 }
 
+/// \brief Matches expressions that match InnerMatcher after ExprWithCleanups
+/// are stripped off.
+AST_MATCHER_P(Expr, ignoringExprWithCleanups, internal::Matcher,
+  InnerMatcher) {
+  auto E = 
+  if (auto Cleanups = dyn_cast(E))
+E = Cleanups->getSubExpr();
+  return InnerMatcher.matches(*E, Finder, Builder);
+}
+
 /// \brief Matches types that match InnerMatcher after any parens are stripped.
 ///
 /// Given


Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -625,6 +625,16 @@
   return InnerMatcher.matches(*Node.IgnoreParenImpCasts(), Finder, Builder);
 }
 
+/// \brief Matches expressions that match InnerMatcher after ExprWithCleanups
+/// are stripped off.
+AST_MATCHER_P(Expr, ignoringExprWithCleanups, internal::Matcher,
+  InnerMatcher) {
+  auto E = 
+  if (auto Cleanups = dyn_cast(E))
+E = Cleanups->getSubExpr();
+  return InnerMatcher.matches(*E, Finder, Builder);
+}
+
 /// \brief Matches types that match InnerMatcher after any parens are stripped.
 ///
 /// Given
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits