Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -662,6 +662,18 @@ +
Matches an Objective-C autorelease pool statement. + +Given + @autoreleasepool { + int x = 0; + } +autoreleasePoolStmt(stmt()) matches the declaration of "x" +inside the autorelease pool. +
Matches binary conditional operator expressions (GNU extension). @@ -5222,8 +5234,8 @@
Overloaded to match the declaration of the expression's or value ++ Matcher<Expr> hasType Matcher<Decl> InnerMatcher @@ -5248,9 +5262,11 @@ Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) and U (matcher = typedefDecl(hasType(asString("int"))) + and friend class X (matcher = friendDecl(hasType("X")) class X {}; void y(X &x) { x; X z; } typedef int U; + class Y { friend class X; }; Overloaded to match the declaration of the expression's or value declaration's type. In case of a value declaration (for example a variable declaration), @@ -5234,8 +5246,10 @@ Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) + and friend class X (matcher = friendDecl(hasType("X")) class X {}; void y(X &x) { x; X z; } + class Y { friend class X; }; Usable as: Matcher<Expr>, Matcher<ValueDecl>
Overloaded to match the declaration of the expression's or value +declaration's type. + +In case of a value declaration (for example a variable declaration), +this resolves one layer of indirection. For example, in the value +declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of +X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the +declaration of x. + +Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) + and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) + and friend class X (matcher = friendDecl(hasType("X")) + class X {}; + void y(X &x) { x; X z; } + class Y { friend class X; }; + +Usable as: Matcher<Expr>, Matcher<ValueDecl> +
Matches if the expression's or declaration's type matches a type +matcher. + +Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) + and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) + and U (matcher = typedefDecl(hasType(asString("int"))) + and friend class X (matcher = friendDecl(hasType("X")) + class X {}; + void y(X &x) { x; X z; } + typedef int U; + class Y { friend class X; }; +
Matches any parameter of a function or an ObjC method declaration or a block. @@ -6432,16 +6484,18 @@
Matches if the expression's or declaration's type matches a type ++ Matcher<TypedefNameDecl> hasType Matcher<QualType> InnerMatcher @@ -6564,8 +6618,8 @@ matches using X::b but not using X::a Matches if the expression's or declaration's type matches a type matcher. Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) and U (matcher = typedefDecl(hasType(asString("int"))) + and friend class X (matcher = friendDecl(hasType("X")) class X {}; void y(X &x) { x; X z; } typedef int U; + class Y { friend class X; };
Overloaded to match the declaration of the expression's or value ++ Matcher<ValueDecl> hasType Matcher<Decl> InnerMatcher - Overloaded to match the declaration of the expression's or value declaration's type. In case of a value declaration (for example a variable declaration), @@ -6576,23 +6630,27 @@ Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) + and friend class X (matcher = friendDecl(hasType("X")) class X {}; void y(X &x) { x; X z; } + class Y { friend class X; }; Usable as: Matcher<Expr>, Matcher<ValueDecl>- Matcher<ValueDecl> hasType Matcher<QualType> InnerMatcher Matches if the expression's or declaration's type matches a type ++ Matcher<ValueDecl> hasType Matcher<QualType> InnerMatcher Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -966,6 +966,19 @@ return Node.getAsIntegral().toString(10) == Value; } +/// Matches an Objective-C autorelease pool statement. +/// +/// Given +/// \code +/// @autoreleasepool { +/// int x = 0; +/// } +/// \endcode +/// autoreleasePoolStmt(stmt()) matches the declaration of "x" +/// inside the autorelease pool. +extern const internal::VariadicDynCastAllOfMatcher Matches if the expression's or declaration's type matches a type matcher. Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) and U (matcher = typedefDecl(hasType(asString("int"))) + and friend class X (matcher = friendDecl(hasType("X")) class X {}; void y(X &x) { x; X z; } typedef int U; + class Y { friend class X; };autoreleasePoolStmt; + /// Matches any value declaration. /// /// Example matches A, B, C and F Index: lib/ASTMatchers/ASTMatchersInternal.cpp =================================================================== --- lib/ASTMatchers/ASTMatchersInternal.cpp +++ lib/ASTMatchers/ASTMatchersInternal.cpp @@ -548,6 +548,8 @@ } // end namespace internal +const internal::VariadicDynCastAllOfMatcher + autoreleasePoolStmt; const internal::VariadicDynCastAllOfMatcher translationUnitDecl; const internal::VariadicDynCastAllOfMatcher typedefDecl; Index: lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- lib/ASTMatchers/Dynamic/Registry.cpp +++ lib/ASTMatchers/Dynamic/Registry.cpp @@ -134,6 +134,7 @@ REGISTER_MATCHER(atomicExpr); REGISTER_MATCHER(atomicType); REGISTER_MATCHER(autoType); + REGISTER_MATCHER(autoreleasePoolStmt) REGISTER_MATCHER(binaryOperator); REGISTER_MATCHER(binaryConditionalOperator); REGISTER_MATCHER(blockDecl); Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -1687,5 +1687,17 @@ objcFinallyStmt())); } +TEST(ObjCAutoreleaseMatcher, AutoreleasePool) { + std::string ObjCString = + "void f() {" + "@autoreleasepool {" + " int x = 1;" + "}" + "}"; + EXPECT_TRUE(matchesObjC(ObjCString, autoreleasePoolStmt())); + std::string ObjCStringNoPool = "void f() { int x = 1; }"; + EXPECT_FALSE(matchesObjC(ObjCStringNoPool, autoreleasePoolStmt())); +} + } // namespace ast_matchers } // namespace clang