Index: cfe/trunk/docs/LibASTMatchersReference.html =================================================================== --- cfe/trunk/docs/LibASTMatchersReference.html +++ cfe/trunk/docs/LibASTMatchersReference.html @@ -4342,7 +4342,7 @@
Matches any argument of a call expression or a constructor call -expression. +expression, or an ObjC-message-send expression. Given void x(int, int, int) { int y; x(1, y, 42); } @@ -4350,6 +4350,12 @@ matches x(1, y, 42) with hasAnyArgument(...) matching y + +For ObjectiveC, given + @interface I - (void) f:(int) y; @end + void foo(I *i) { [i f:12] } +objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) + matches [i f:12]
Matches any argument of a call expression or a constructor call -expression. +expression, or an ObjC-message-send expression. Given void x(int, int, int) { int y; x(1, y, 42); } @@ -4697,6 +4703,12 @@ matches x(1, y, 42) with hasAnyArgument(...) matching y + +For ObjectiveC, given + @interface I - (void) f:(int) y; @end + void foo(I *i) { [i f:12] } +objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) + matches [i f:12]
Matches any argument of a call expression or a constructor call +expression, or an ObjC-message-send expression. + +Given + void x(int, int, int) { int y; x(1, y, 42); } +callExpr(hasAnyArgument(declRefExpr())) + matches x(1, y, 42) +with hasAnyArgument(...) + matching y + +For ObjectiveC, given + @interface I - (void) f:(int) y; @end + void foo(I *i) { [i f:12] } +objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) + matches [i f:12] +
Matches the n'th argument of a call expression or a constructor call expression. Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h @@ -3412,7 +3412,7 @@ } /// \brief Matches any argument of a call expression or a constructor call -/// expression. +/// expression, or an ObjC-message-send expression. /// /// Given /// \code @@ -3422,9 +3422,18 @@ /// matches x(1, y, 42) /// with hasAnyArgument(...) /// matching y +/// +/// For ObjectiveC, given +/// \code +/// @interface I - (void) f:(int) y; @end +/// void foo(I *i) { [i f:12]; } +/// \endcode +/// objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) +/// matches [i f:12] AST_POLYMORPHIC_MATCHER_P(hasAnyArgument, AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr, - CXXConstructExpr), + CXXConstructExpr, + ObjCMessageExpr), internal::Matcher, InnerMatcher) { for (const Expr *Arg : Node.arguments()) { BoundNodesTreeBuilder Result(*Builder); Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp =================================================================== --- cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -403,11 +403,18 @@ } TEST(Matcher, AnyArgument) { - StatementMatcher CallArgumentY = callExpr( - hasAnyArgument( - ignoringParenImpCasts(declRefExpr(to(varDecl(hasName("y"))))))); + auto HasArgumentY = hasAnyArgument( + ignoringParenImpCasts(declRefExpr(to(varDecl(hasName("y")))))); + StatementMatcher CallArgumentY = callExpr(HasArgumentY); + StatementMatcher ObjCCallArgumentY = objcMessageExpr(HasArgumentY); EXPECT_TRUE(matches("void x(int, int) { int y; x(1, y); }", CallArgumentY)); EXPECT_TRUE(matches("void x(int, int) { int y; x(y, 42); }", CallArgumentY)); + EXPECT_TRUE(matchesObjC("@interface I -(void)f:(int) y; @end " + "void x(I* i) { int y; [i f:y]; }", + ObjCCallArgumentY)); + EXPECT_FALSE(matchesObjC("@interface I -(void)f:(int) z; @end " + "void x(I* i) { int z; [i f:z]; }", + ObjCCallArgumentY)); EXPECT_TRUE(notMatches("void x(int, int) { x(1, 2); }", CallArgumentY)); StatementMatcher ImplicitCastedArgument = callExpr(