[PATCH] D54307: [clang] overload ignoringParens for Expr
JonasToth added inline comments. Comment at: include/clang/ASTMatchers/ASTMatchers.h:814 /// would match the declaration for fp. -AST_MATCHER_P(QualType, ignoringParens, - internal::Matcher, InnerMatcher) { +AST_MATCHER_P_OVERLOAD(QualType, ignoringParens, internal::Matcher, + InnerMatcher, 0) { aaron.ballman wrote: > sbenza wrote: > > JonasToth wrote: > > > aaron.ballman wrote: > > > > JonasToth wrote: > > > > > aaron.ballman wrote: > > > > > > Can you do this via `AST_POLYMORPHIC_MATCHER_P` instead, given that > > > > > > the implementation is the same? > > > > > Do you want me to add more types? e.g. `TypeLoc` has > > > > > `IgnoreParens()`, too. > > > > I'd not be opposed, given that we already expose the `typeLoc()` > > > > matcher. I'll leave that to your discretion. > > > as discussed on IRC making it an `AST_POLYMORPHIC_MATCHER_P` does not > > > seem to work, as the polymorphism is only in the return type. We do need > > > the `Node` itself to be polymorphic (same type as returntype). The only > > > working version I got was using the overloads. > > You can't use AST_POLYMORPHIC_MATCHER_P to overload on input types. > > You could try using templates, but that will make registering the matcher > > harder. > > Another one that does input+output polymorphism, `id`, is simply not > > supported dynamically. > Good to know, thank you! thanks for clarifying. Repository: rC Clang https://reviews.llvm.org/D54307 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D54307: [clang] overload ignoringParens for Expr
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM! Comment at: include/clang/ASTMatchers/ASTMatchers.h:814 /// would match the declaration for fp. -AST_MATCHER_P(QualType, ignoringParens, - internal::Matcher, InnerMatcher) { +AST_MATCHER_P_OVERLOAD(QualType, ignoringParens, internal::Matcher, + InnerMatcher, 0) { sbenza wrote: > JonasToth wrote: > > aaron.ballman wrote: > > > JonasToth wrote: > > > > aaron.ballman wrote: > > > > > Can you do this via `AST_POLYMORPHIC_MATCHER_P` instead, given that > > > > > the implementation is the same? > > > > Do you want me to add more types? e.g. `TypeLoc` has `IgnoreParens()`, > > > > too. > > > I'd not be opposed, given that we already expose the `typeLoc()` matcher. > > > I'll leave that to your discretion. > > as discussed on IRC making it an `AST_POLYMORPHIC_MATCHER_P` does not seem > > to work, as the polymorphism is only in the return type. We do need the > > `Node` itself to be polymorphic (same type as returntype). The only working > > version I got was using the overloads. > You can't use AST_POLYMORPHIC_MATCHER_P to overload on input types. > You could try using templates, but that will make registering the matcher > harder. > Another one that does input+output polymorphism, `id`, is simply not > supported dynamically. Good to know, thank you! Repository: rC Clang https://reviews.llvm.org/D54307 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D54307: [clang] overload ignoringParens for Expr
sbenza added inline comments. Comment at: include/clang/ASTMatchers/ASTMatchers.h:814 /// would match the declaration for fp. -AST_MATCHER_P(QualType, ignoringParens, - internal::Matcher, InnerMatcher) { +AST_MATCHER_P_OVERLOAD(QualType, ignoringParens, internal::Matcher, + InnerMatcher, 0) { JonasToth wrote: > aaron.ballman wrote: > > JonasToth wrote: > > > aaron.ballman wrote: > > > > Can you do this via `AST_POLYMORPHIC_MATCHER_P` instead, given that the > > > > implementation is the same? > > > Do you want me to add more types? e.g. `TypeLoc` has `IgnoreParens()`, > > > too. > > I'd not be opposed, given that we already expose the `typeLoc()` matcher. > > I'll leave that to your discretion. > as discussed on IRC making it an `AST_POLYMORPHIC_MATCHER_P` does not seem to > work, as the polymorphism is only in the return type. We do need the `Node` > itself to be polymorphic (same type as returntype). The only working version > I got was using the overloads. You can't use AST_POLYMORPHIC_MATCHER_P to overload on input types. You could try using templates, but that will make registering the matcher harder. Another one that does input+output polymorphism, `id`, is simply not supported dynamically. Repository: rC Clang https://reviews.llvm.org/D54307 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D54307: [clang] overload ignoringParens for Expr
aaron.ballman added reviewers: sbenza, klimek. aaron.ballman added a comment. Adding a few other reviewers in case they have ideas on how to use the polymorphic matcher rather than the overload. If they don't have a better idea, then I think the overload approach is fine. Repository: rC Clang https://reviews.llvm.org/D54307 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D54307: [clang] overload ignoringParens for Expr
JonasToth updated this revision to Diff 173391. JonasToth marked 3 inline comments as done. JonasToth added a comment. - add unit test Repository: rC Clang https://reviews.llvm.org/D54307 Files: docs/LibASTMatchersReference.html include/clang/ASTMatchers/ASTMatchers.h lib/ASTMatchers/Dynamic/Registry.cpp unittests/ASTMatchers/ASTMatchersNodeTest.cpp Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp === --- unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -1147,6 +1147,14 @@ parenExpr())); } +TEST(ParenExpression, IgnoringParens) { + EXPECT_FALSE(matches("const char* str = (\"my-string\");", + implicitCastExpr(hasSourceExpression(stringLiteral(); + EXPECT_TRUE(matches( + "const char* str = (\"my-string\");", + implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral()); +} + TEST(TypeMatching, MatchesTypes) { EXPECT_TRUE(matches("struct S {};", qualType().bind("loc"))); } Index: lib/ASTMatchers/Dynamic/Registry.cpp === --- lib/ASTMatchers/Dynamic/Registry.cpp +++ lib/ASTMatchers/Dynamic/Registry.cpp @@ -106,6 +106,7 @@ REGISTER_OVERLOADED_2(callee); REGISTER_OVERLOADED_2(hasPrefix); REGISTER_OVERLOADED_2(hasType); + REGISTER_OVERLOADED_2(ignoringParens); REGISTER_OVERLOADED_2(isDerivedFrom); REGISTER_OVERLOADED_2(isSameOrDerivedFrom); REGISTER_OVERLOADED_2(loc); @@ -318,7 +319,6 @@ REGISTER_MATCHER(ignoringImplicit); REGISTER_MATCHER(ignoringParenCasts); REGISTER_MATCHER(ignoringParenImpCasts); - REGISTER_MATCHER(ignoringParens); REGISTER_MATCHER(imaginaryLiteral); REGISTER_MATCHER(implicitCastExpr); REGISTER_MATCHER(implicitValueInitExpr); Index: include/clang/ASTMatchers/ASTMatchers.h === --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -811,11 +811,28 @@ /// varDecl(hasType(pointerType(pointee(ignoringParens(functionType()) /// \endcode /// would match the declaration for fp. -AST_MATCHER_P(QualType, ignoringParens, - internal::Matcher, InnerMatcher) { +AST_MATCHER_P_OVERLOAD(QualType, ignoringParens, internal::Matcher, + InnerMatcher, 0) { return InnerMatcher.matches(Node.IgnoreParens(), Finder, Builder); } +/// Overload \c ignoringParens for \c Expr. +/// +/// Given +/// \code +/// const char* str = ("my-string"); +/// \endcode +/// The matcher +/// \code +/// implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral( +/// \endcode +/// would match the implicit cast resulting from the assignment. +AST_MATCHER_P_OVERLOAD(Expr, ignoringParens, internal::Matcher, + InnerMatcher, 1) { + const Expr *E = Node.IgnoreParens(); + return InnerMatcher.matches(*E, Finder, Builder); +} + /// Matches expressions that are instantiation-dependent even if it is /// neither type- nor value-dependent. /// Index: docs/LibASTMatchersReference.html === --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -5552,6 +5552,17 @@ +Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>ExprignoringParensMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr InnerMatcher +Overload ignoringParens for Expr. + +Given + const char* str = ("my-string"); +The matcher + implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral( +would match the implicit cast resulting from the assignment. + + + Matcherhttps://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html;>FieldDeclhasInClassInitializerMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr InnerMatcher Matches non-static data members that have an in-class initializer. Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp === --- unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -1147,6 +1147,14 @@ parenExpr())); } +TEST(ParenExpression, IgnoringParens) { + EXPECT_FALSE(matches("const char* str = (\"my-string\");", + implicitCastExpr(hasSourceExpression(stringLiteral(); + EXPECT_TRUE(matches( + "const char* str = (\"my-string\");", + implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral()); +} + TEST(TypeMatching, MatchesTypes) { EXPECT_TRUE(matches("struct S {};", qualType().bind("loc"))); } Index: lib/ASTMatchers/Dynamic/Registry.cpp === --- lib/ASTMatchers/Dynamic/Registry.cpp +++ lib/ASTMatchers/Dynamic/Registry.cpp @@ -106,6 +106,7 @@
[PATCH] D54307: [clang] overload ignoringParens for Expr
JonasToth added inline comments. Comment at: include/clang/ASTMatchers/ASTMatchers.h:814 /// would match the declaration for fp. -AST_MATCHER_P(QualType, ignoringParens, - internal::Matcher, InnerMatcher) { +AST_MATCHER_P_OVERLOAD(QualType, ignoringParens, internal::Matcher, + InnerMatcher, 0) { aaron.ballman wrote: > JonasToth wrote: > > aaron.ballman wrote: > > > Can you do this via `AST_POLYMORPHIC_MATCHER_P` instead, given that the > > > implementation is the same? > > Do you want me to add more types? e.g. `TypeLoc` has `IgnoreParens()`, too. > I'd not be opposed, given that we already expose the `typeLoc()` matcher. > I'll leave that to your discretion. as discussed on IRC making it an `AST_POLYMORPHIC_MATCHER_P` does not seem to work, as the polymorphism is only in the return type. We do need the `Node` itself to be polymorphic (same type as returntype). The only working version I got was using the overloads. Repository: rC Clang https://reviews.llvm.org/D54307 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D54307: [clang] overload ignoringParens for Expr
aaron.ballman added inline comments. Comment at: include/clang/ASTMatchers/ASTMatchers.h:814 /// would match the declaration for fp. -AST_MATCHER_P(QualType, ignoringParens, - internal::Matcher, InnerMatcher) { +AST_MATCHER_P_OVERLOAD(QualType, ignoringParens, internal::Matcher, + InnerMatcher, 0) { JonasToth wrote: > aaron.ballman wrote: > > Can you do this via `AST_POLYMORPHIC_MATCHER_P` instead, given that the > > implementation is the same? > Do you want me to add more types? e.g. `TypeLoc` has `IgnoreParens()`, too. I'd not be opposed, given that we already expose the `typeLoc()` matcher. I'll leave that to your discretion. Repository: rC Clang https://reviews.llvm.org/D54307 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D54307: [clang] overload ignoringParens for Expr
JonasToth added inline comments. Comment at: include/clang/ASTMatchers/ASTMatchers.h:814 /// would match the declaration for fp. -AST_MATCHER_P(QualType, ignoringParens, - internal::Matcher, InnerMatcher) { +AST_MATCHER_P_OVERLOAD(QualType, ignoringParens, internal::Matcher, + InnerMatcher, 0) { aaron.ballman wrote: > Can you do this via `AST_POLYMORPHIC_MATCHER_P` instead, given that the > implementation is the same? Do you want me to add more types? e.g. `TypeLoc` has `IgnoreParens()`, too. Repository: rC Clang https://reviews.llvm.org/D54307 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D54307: [clang] overload ignoringParens for Expr
aaron.ballman added a comment. Also: the patch is missing unit tests. Repository: rC Clang https://reviews.llvm.org/D54307 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D54307: [clang] overload ignoringParens for Expr
aaron.ballman added inline comments. Comment at: include/clang/ASTMatchers/ASTMatchers.h:814 /// would match the declaration for fp. -AST_MATCHER_P(QualType, ignoringParens, - internal::Matcher, InnerMatcher) { +AST_MATCHER_P_OVERLOAD(QualType, ignoringParens, internal::Matcher, + InnerMatcher, 0) { Can you do this via `AST_POLYMORPHIC_MATCHER_P` instead, given that the implementation is the same? Repository: rC Clang https://reviews.llvm.org/D54307 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D54307: [clang] overload ignoringParens for Expr
JonasToth created this revision. JonasToth added a reviewer: aaron.ballman. Herald added a subscriber: cfe-commits. This patch allows fixing PR39583. Repository: rC Clang https://reviews.llvm.org/D54307 Files: docs/LibASTMatchersReference.html include/clang/ASTMatchers/ASTMatchers.h lib/ASTMatchers/Dynamic/Registry.cpp Index: lib/ASTMatchers/Dynamic/Registry.cpp === --- lib/ASTMatchers/Dynamic/Registry.cpp +++ lib/ASTMatchers/Dynamic/Registry.cpp @@ -106,6 +106,7 @@ REGISTER_OVERLOADED_2(callee); REGISTER_OVERLOADED_2(hasPrefix); REGISTER_OVERLOADED_2(hasType); + REGISTER_OVERLOADED_2(ignoringParens); REGISTER_OVERLOADED_2(isDerivedFrom); REGISTER_OVERLOADED_2(isSameOrDerivedFrom); REGISTER_OVERLOADED_2(loc); @@ -318,7 +319,6 @@ REGISTER_MATCHER(ignoringImplicit); REGISTER_MATCHER(ignoringParenCasts); REGISTER_MATCHER(ignoringParenImpCasts); - REGISTER_MATCHER(ignoringParens); REGISTER_MATCHER(imaginaryLiteral); REGISTER_MATCHER(implicitCastExpr); REGISTER_MATCHER(implicitValueInitExpr); Index: include/clang/ASTMatchers/ASTMatchers.h === --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -811,11 +811,28 @@ /// varDecl(hasType(pointerType(pointee(ignoringParens(functionType()) /// \endcode /// would match the declaration for fp. -AST_MATCHER_P(QualType, ignoringParens, - internal::Matcher, InnerMatcher) { +AST_MATCHER_P_OVERLOAD(QualType, ignoringParens, internal::Matcher, + InnerMatcher, 0) { return InnerMatcher.matches(Node.IgnoreParens(), Finder, Builder); } +/// Overload \c ignoringParens for \c Expr. +/// +/// Given +/// \code +/// const char* str = ("my-string"); +/// \endcode +/// The matcher +/// \code +/// implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral( +/// \endcode +/// would match the implicit cast resulting from the assignment. +AST_MATCHER_P_OVERLOAD(Expr, ignoringParens, internal::Matcher, + InnerMatcher, 1) { + const Expr *E = Node.IgnoreParens(); + return InnerMatcher.matches(*E, Finder, Builder); +} + /// Matches expressions that are instantiation-dependent even if it is /// neither type- nor value-dependent. /// Index: docs/LibASTMatchersReference.html === --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -5552,6 +5552,17 @@ +Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>ExprignoringParensMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr InnerMatcher +Overload ignoringParens for Expr. + +Given + const char* str = ("my-string"); +The matcher + implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral( +would match the implicit cast resulting from the assignment. + + + Matcherhttps://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html;>FieldDeclhasInClassInitializerMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr InnerMatcher Matches non-static data members that have an in-class initializer. Index: lib/ASTMatchers/Dynamic/Registry.cpp === --- lib/ASTMatchers/Dynamic/Registry.cpp +++ lib/ASTMatchers/Dynamic/Registry.cpp @@ -106,6 +106,7 @@ REGISTER_OVERLOADED_2(callee); REGISTER_OVERLOADED_2(hasPrefix); REGISTER_OVERLOADED_2(hasType); + REGISTER_OVERLOADED_2(ignoringParens); REGISTER_OVERLOADED_2(isDerivedFrom); REGISTER_OVERLOADED_2(isSameOrDerivedFrom); REGISTER_OVERLOADED_2(loc); @@ -318,7 +319,6 @@ REGISTER_MATCHER(ignoringImplicit); REGISTER_MATCHER(ignoringParenCasts); REGISTER_MATCHER(ignoringParenImpCasts); - REGISTER_MATCHER(ignoringParens); REGISTER_MATCHER(imaginaryLiteral); REGISTER_MATCHER(implicitCastExpr); REGISTER_MATCHER(implicitValueInitExpr); Index: include/clang/ASTMatchers/ASTMatchers.h === --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -811,11 +811,28 @@ /// varDecl(hasType(pointerType(pointee(ignoringParens(functionType()) /// \endcode /// would match the declaration for fp. -AST_MATCHER_P(QualType, ignoringParens, - internal::Matcher, InnerMatcher) { +AST_MATCHER_P_OVERLOAD(QualType, ignoringParens, internal::Matcher, + InnerMatcher, 0) { return InnerMatcher.matches(Node.IgnoreParens(), Finder, Builder); } +/// Overload \c ignoringParens for \c Expr. +/// +/// Given +/// \code +/// const char* str = ("my-string"); +/// \endcode +/// The matcher +/// \code +/// implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral( +/// \endcode +/// would match the implicit cast resulting from the assignment.