Index: cfe/trunk/docs/LibASTMatchersReference.html =================================================================== --- cfe/trunk/docs/LibASTMatchersReference.html +++ cfe/trunk/docs/LibASTMatchersReference.html @@ -124,6 +124,18 @@ +Matcher<Decl>blockDeclMatcher<BlockDecl>... +
Matches block declarations.
+
+Example matches the declaration of the nameless block printing an input
+integer.
+
+  myFunc(^(int p) {
+    printf("%d", p);
+  })
+
+ + Matcher<Decl>classTemplateDeclMatcher<ClassTemplateDecl>...
Matches C++ class template declarations.
 
@@ -4352,6 +4364,55 @@
 
+Matcher<BlockDecl>hasAnyParameterMatcher<ParmVarDecl> InnerMatcher +
Matches any parameter of a function or an ObjC method declaration or a
+block.
+
+Does not match the 'this' parameter of a method.
+
+Given
+  class X { void f(int x, int y, int z) {} };
+cxxMethodDecl(hasAnyParameter(hasName("y")))
+  matches f(int x, int y, int z) {}
+with hasAnyParameter(...)
+  matching int y
+
+For ObjectiveC, given
+  @interface I - (void) f:(int) y; @end
+
+the matcher objcMethodDecl(hasAnyParameter(hasName("y")))
+matches the declaration of method f with hasParameter
+matching y.
+
+For blocks, given
+  b = ^(int y) { printf("%d", y) };
+
+the matcher blockDecl(hasAnyParameter(hasName("y")))
+matches the declaration of the block b with hasParameter
+matching y.
+
+ + +Matcher<BlockDecl>hasParameterunsigned N, Matcher<ParmVarDecl> InnerMatcher +
Matches the n'th parameter of a function or an ObjC method
+declaration or a block.
+
+Given
+  class X { void f(int x) {} };
+cxxMethodDecl(hasParameter(0, hasType(varDecl())))
+  matches f(int x) {}
+with hasParameter(...)
+  matching int x
+
+For ObjectiveC, given
+  @interface I - (void) f:(int) y; @end
+
+the matcher objcMethodDecl(hasParameter(0, hasName("y")))
+matches the declaration of method f with hasParameter
+matching y.
+
+ + Matcher<BlockPointerTypeLoc>pointeeLocMatcher<TypeLoc>
Narrows PointerType (and similar) matchers to those where the
 pointee matches a given matcher.
@@ -5336,7 +5397,8 @@
 
 
 Matcher<FunctionDecl>hasAnyParameterMatcher<ParmVarDecl> InnerMatcher
-
Matches any parameter of a function or ObjC method declaration.
+
Matches any parameter of a function or an ObjC method declaration or a
+block.
 
 Does not match the 'this' parameter of a method.
 
@@ -5353,6 +5415,13 @@
 the matcher objcMethodDecl(hasAnyParameter(hasName("y")))
 matches the declaration of method f with hasParameter
 matching y.
+
+For blocks, given
+  b = ^(int y) { printf("%d", y) };
+
+the matcher blockDecl(hasAnyParameter(hasName("y")))
+matches the declaration of the block b with hasParameter
+matching y.
 
@@ -5393,7 +5462,7 @@ Matcher<FunctionDecl>hasParameterunsigned N, Matcher<ParmVarDecl> InnerMatcher
Matches the n'th parameter of a function or an ObjC method
-declaration.
+declaration or a block.
 
 Given
   class X { void f(int x) {} };
@@ -5767,7 +5836,8 @@
 
 
 Matcher<ObjCMethodDecl>hasAnyParameterMatcher<ParmVarDecl> InnerMatcher
-
Matches any parameter of a function or ObjC method declaration.
+
Matches any parameter of a function or an ObjC method declaration or a
+block.
 
 Does not match the 'this' parameter of a method.
 
@@ -5784,12 +5854,19 @@
 the matcher objcMethodDecl(hasAnyParameter(hasName("y")))
 matches the declaration of method f with hasParameter
 matching y.
+
+For blocks, given
+  b = ^(int y) { printf("%d", y) };
+
+the matcher blockDecl(hasAnyParameter(hasName("y")))
+matches the declaration of the block b with hasParameter
+matching y.
 
Matcher<ObjCMethodDecl>hasParameterunsigned N, Matcher<ParmVarDecl> InnerMatcher
Matches the n'th parameter of a function or an ObjC method
-declaration.
+declaration or a block.
 
 Given
   class X { void f(int x) {} };
Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
@@ -1227,6 +1227,19 @@
 extern const internal::VariadicDynCastAllOfMatcher
     objcMethodDecl;
 
+/// Matches block declarations.
+/// 
+/// Example matches the declaration of the nameless block printing an input
+/// integer.
+///
+/// \code
+///   myFunc(^(int p) {
+///     printf("%d", p);
+///   })
+/// \endcode
+extern const internal::VariadicDynCastAllOfMatcher
+    blockDecl;
+
 /// Matches Objective-C instance variable declarations.
 ///
 /// Example matches _enabled
@@ -3479,7 +3492,7 @@
 }
 
 /// Matches the n'th parameter of a function or an ObjC method
-/// declaration.
+/// declaration or a block.
 ///
 /// Given
 /// \code
@@ -3500,7 +3513,8 @@
 /// matching y.
 AST_POLYMORPHIC_MATCHER_P2(hasParameter,
                            AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
-                                                           ObjCMethodDecl),
+                                                           ObjCMethodDecl,
+                                                           BlockDecl),
                            unsigned, N, internal::Matcher,
                            InnerMatcher) {
   return (N < Node.parameters().size()
@@ -3561,7 +3575,8 @@
   return Matched;
 }
 
-/// Matches any parameter of a function or ObjC method declaration.
+/// Matches any parameter of a function or an ObjC method declaration or a
+/// block.
 ///
 /// Does not match the 'this' parameter of a method.
 ///
@@ -3582,9 +3597,19 @@
 /// the matcher objcMethodDecl(hasAnyParameter(hasName("y")))
 /// matches the declaration of method f with hasParameter
 /// matching y.
+///
+/// For blocks, given
+/// \code
+///   b = ^(int y) { printf("%d", y) };
+/// \endcode
+/// 
+/// the matcher blockDecl(hasAnyParameter(hasName("y")))
+/// matches the declaration of the block b with hasParameter
+/// matching y.
 AST_POLYMORPHIC_MATCHER_P(hasAnyParameter,
                           AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
-                                                          ObjCMethodDecl),
+                                                          ObjCMethodDecl,
+                                                          BlockDecl),
                           internal::Matcher,
                           InnerMatcher) {
   return matchesFirstInPointerRange(InnerMatcher, Node.param_begin(),
Index: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
===================================================================
--- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -626,6 +626,8 @@
     objcCategoryImplDecl;
 const internal::VariadicDynCastAllOfMatcher
     objcMethodDecl;
+const internal::VariadicDynCastAllOfMatcher
+    blockDecl;
 const internal::VariadicDynCastAllOfMatcher objcIvarDecl;
 const internal::VariadicDynCastAllOfMatcher
     objcPropertyDecl;
Index: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
===================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -136,6 +136,7 @@
   REGISTER_MATCHER(autoType);
   REGISTER_MATCHER(binaryOperator);
   REGISTER_MATCHER(binaryConditionalOperator);
+  REGISTER_MATCHER(blockDecl);
   REGISTER_MATCHER(blockPointerType);
   REGISTER_MATCHER(booleanType);
   REGISTER_MATCHER(breakStmt);
Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
===================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
@@ -132,7 +132,7 @@
                                      bool ExpectMatch = true) {
   return matchesConditionally(Code, AMatcher, ExpectMatch,
                               {"-fobjc-nonfragile-abi", "-Wno-objc-root-class",
-                               "-Wno-incomplete-implementation"},
+                               "-fblocks", "-Wno-incomplete-implementation"},
                               FileContentMappings(), "input.m");
 }
 
Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -541,6 +541,8 @@
                          cxxMethodDecl(hasParameter(0, hasName("x")))));
   EXPECT_TRUE(matchesObjC("@interface I -(void)f:(int) x; @end",
                           objcMethodDecl(hasParameter(0, hasName("x")))));
+  EXPECT_TRUE(matchesObjC("int main() { void (^b)(int) = ^(int p) {}; }",
+                          blockDecl(hasParameter(0, hasName("p")))));
 }
 
 TEST(HasParameter, DoesNotMatchIfIndexOutOfBounds) {
@@ -572,6 +574,8 @@
     cxxMethodDecl(hasAnyParameter(hasType(recordDecl(hasName("X")))))));
   EXPECT_TRUE(matchesObjC("@interface I -(void)f:(int) x; @end",
                           objcMethodDecl(hasAnyParameter(hasName("x")))));
+  EXPECT_TRUE(matchesObjC("int main() { void (^b)(int) = ^(int p) {}; }",
+                          blockDecl(hasAnyParameter(hasName("p")))));
 }
 
 TEST(Returns, MatchesReturnTypes) {