[PATCH] D39948: Make isDefinition matcher support ObjCMethodDecl
This revision was automatically updated to reflect the committed changes. Closed by commit rL318152: Make isDefinition matcher support ObjCMethodDecl (authored by kastiglione). Repository: rL LLVM https://reviews.llvm.org/D39948 Files: cfe/trunk/docs/LibASTMatchersReference.html cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp === --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -1315,6 +1315,14 @@ cxxMethodDecl(hasName("a"), isDefinition()); EXPECT_TRUE(matches("class A { void a() {} };", DefinitionOfMethodA)); EXPECT_TRUE(notMatches("class A { void a(); };", DefinitionOfMethodA)); + + DeclarationMatcher DefinitionOfObjCMethodA = +objcMethodDecl(hasName("a"), isDefinition()); + EXPECT_TRUE(matchesObjC("@interface A @end " + "@implementation A; -(void)a {} @end", + DefinitionOfObjCMethodA)); + EXPECT_TRUE(notMatchesObjC("@interface A; - (void)a; @end", + DefinitionOfObjCMethodA)); } TEST(Matcher, HandlesNullQualTypes) { Index: cfe/trunk/docs/LibASTMatchersReference.html === --- cfe/trunk/docs/LibASTMatchersReference.html +++ cfe/trunk/docs/LibASTMatchersReference.html @@ -2746,18 +2746,25 @@ -Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisDefinition -Matches if a declaration has a body attached. +Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisDefinition +Matches if a declaration has a body attached. Example matches A, va, fa class A {}; class B; Doesn't match, as it has no body. int va; extern int vb; Doesn't match, as it doesn't define the variable. void fa() {} void fb(); Doesn't match, as it has no body. + @interface X + - (void)ma; Doesn't match, interface is declaration. + @end + @implementation X + - (void)ma {} + @end -Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagDecl.html;>TagDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl +Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagDecl.html;>TagDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl, + Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html;>ObjCMethodDecl @@ -3154,6 +3161,28 @@ +Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html;>ObjCMethodDeclisDefinition +Matches if a declaration has a body attached. + +Example matches A, va, fa + class A {}; + class B; Doesn't match, as it has no body. + int va; + extern int vb; Doesn't match, as it doesn't define the variable. + void fa() {} + void fb(); Doesn't match, as it has no body. + @interface X + - (void)ma; Doesn't match, interface is declaration. + @end + @implementation X + - (void)ma {} + @end + +Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagDecl.html;>TagDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl, + Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html;>ObjCMethodDecl + + + Matcherhttp://clang.llvm.org/doxygen/classclang_1_1QualType.html;>QualTypeasStringstd::string Name Matches if the matched type is represented by the given string. @@ -3433,8 +3462,15 @@ extern int vb; Doesn't match, as it doesn't define the variable. void fa() {} void fb(); Doesn't match, as it has no body. + @interface X + - (void)ma; Doesn't match, interface is declaration. + @end + @implementation X + - (void)ma {} + @end -Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagDecl.html;>TagDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl +Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagDecl.html;>TagDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl, + Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html;>ObjCMethodDecl @@ -3696,8 +3732,15 @@ extern int vb; Doesn't match, as it doesn't define the variable. void fa() {} void fb(); Doesn't match, as it has no body. + @interface X + - (void)ma; Doesn't match, interface is declaration. + @end + @implementation X + - (void)ma {} +
[PATCH] D39948: Make isDefinition matcher support ObjCMethodDecl
kastiglione updated this revision to Diff 122831. kastiglione added a comment. Regenerate AST Matcher docs https://reviews.llvm.org/D39948 Files: docs/LibASTMatchersReference.html include/clang/ASTMatchers/ASTMatchers.h unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp === --- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -1315,6 +1315,14 @@ cxxMethodDecl(hasName("a"), isDefinition()); EXPECT_TRUE(matches("class A { void a() {} };", DefinitionOfMethodA)); EXPECT_TRUE(notMatches("class A { void a(); };", DefinitionOfMethodA)); + + DeclarationMatcher DefinitionOfObjCMethodA = +objcMethodDecl(hasName("a"), isDefinition()); + EXPECT_TRUE(matchesObjC("@interface A @end " + "@implementation A; -(void)a {} @end", + DefinitionOfObjCMethodA)); + EXPECT_TRUE(notMatchesObjC("@interface A; - (void)a; @end", + DefinitionOfObjCMethodA)); } TEST(Matcher, HandlesNullQualTypes) { Index: include/clang/ASTMatchers/ASTMatchers.h === --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -4201,11 +4201,19 @@ /// extern int vb; // Doesn't match, as it doesn't define the variable. /// void fa() {} /// void fb(); // Doesn't match, as it has no body. +/// @interface X +/// - (void)ma; // Doesn't match, interface is declaration. +/// @end +/// @implementation X +/// - (void)ma {} +/// @end /// \endcode /// -/// Usable as: Matcher, Matcher, Matcher +/// Usable as: Matcher, Matcher, Matcher, +/// Matcher AST_POLYMORPHIC_MATCHER(isDefinition, AST_POLYMORPHIC_SUPPORTED_TYPES(TagDecl, VarDecl, +ObjCMethodDecl, FunctionDecl)) { return Node.isThisDeclarationADefinition(); } Index: docs/LibASTMatchersReference.html === --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -2746,18 +2746,25 @@ -Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisDefinition -Matches if a declaration has a body attached. +Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisDefinition +Matches if a declaration has a body attached. Example matches A, va, fa class A {}; class B; Doesn't match, as it has no body. int va; extern int vb; Doesn't match, as it doesn't define the variable. void fa() {} void fb(); Doesn't match, as it has no body. + @interface X + - (void)ma; Doesn't match, interface is declaration. + @end + @implementation X + - (void)ma {} + @end -Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagDecl.html;>TagDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl +Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagDecl.html;>TagDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl, + Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html;>ObjCMethodDecl @@ -3154,6 +3161,28 @@ +Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html;>ObjCMethodDeclisDefinition +Matches if a declaration has a body attached. + +Example matches A, va, fa + class A {}; + class B; Doesn't match, as it has no body. + int va; + extern int vb; Doesn't match, as it doesn't define the variable. + void fa() {} + void fb(); Doesn't match, as it has no body. + @interface X + - (void)ma; Doesn't match, interface is declaration. + @end + @implementation X + - (void)ma {} + @end + +Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagDecl.html;>TagDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl, + Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html;>ObjCMethodDecl + + + Matcherhttp://clang.llvm.org/doxygen/classclang_1_1QualType.html;>QualTypeasStringstd::string Name Matches if the matched type is represented by the given string. @@ -3433,8 +3462,15 @@ extern int vb; Doesn't match, as it doesn't define the variable. void fa() {} void fb(); Doesn't match, as it has no body. + @interface X + - (void)ma; Doesn't match, interface is declaration. + @end + @implementation X + - (void)ma {} + @end -Usable as:
[PATCH] D39948: Make isDefinition matcher support ObjCMethodDecl
kastiglione updated this revision to Diff 122830. kastiglione added a comment. Update isDefinition comment docs to reflect addition of ObjCMethodDecl https://reviews.llvm.org/D39948 Files: docs/LibASTMatchersReference.html include/clang/ASTMatchers/ASTMatchers.h unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp === --- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -1315,6 +1315,14 @@ cxxMethodDecl(hasName("a"), isDefinition()); EXPECT_TRUE(matches("class A { void a() {} };", DefinitionOfMethodA)); EXPECT_TRUE(notMatches("class A { void a(); };", DefinitionOfMethodA)); + + DeclarationMatcher DefinitionOfObjCMethodA = +objcMethodDecl(hasName("a"), isDefinition()); + EXPECT_TRUE(matchesObjC("@interface A @end " + "@implementation A; -(void)a {} @end", + DefinitionOfObjCMethodA)); + EXPECT_TRUE(notMatchesObjC("@interface A; - (void)a; @end", + DefinitionOfObjCMethodA)); } TEST(Matcher, HandlesNullQualTypes) { Index: include/clang/ASTMatchers/ASTMatchers.h === --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -4201,11 +4201,19 @@ /// extern int vb; // Doesn't match, as it doesn't define the variable. /// void fa() {} /// void fb(); // Doesn't match, as it has no body. +/// @interface X +/// - (void)ma; // Doesn't match, interface is declaration. +/// @end +/// @implementation X +/// - (void)ma {} +/// @end /// \endcode /// -/// Usable as: Matcher, Matcher, Matcher +/// Usable as: Matcher, Matcher, Matcher, +/// Matcher AST_POLYMORPHIC_MATCHER(isDefinition, AST_POLYMORPHIC_SUPPORTED_TYPES(TagDecl, VarDecl, +ObjCMethodDecl, FunctionDecl)) { return Node.isThisDeclarationADefinition(); } Index: docs/LibASTMatchersReference.html === --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -2746,16 +2746,22 @@ -Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisDefinition -Matches if a declaration has a body attached. +Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisDefinition +Matches if a declaration has a body attached. Example matches A, va, fa class A {}; class B; Doesn't match, as it has no body. int va; extern int vb; Doesn't match, as it doesn't define the variable. void fa() {} void fb(); Doesn't match, as it has no body. + @interface X + - (void)ma; Doesn't match, interface is declaration. + @end + @implementation X + - (void)ma {} + @end Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagDecl.html;>TagDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl @@ -3154,6 +3160,27 @@ +Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html;>ObjCMethodDeclisDefinition +Matches if a declaration has a body attached. + +Example matches A, va, fa + class A {}; + class B; Doesn't match, as it has no body. + int va; + extern int vb; Doesn't match, as it doesn't define the variable. + void fa() {} + void fb(); Doesn't match, as it has no body. + @interface X + - (void)ma; Doesn't match, interface is declaration. + @end + @implementation X + - (void)ma {} + @end + +Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagDecl.html;>TagDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl + + + Matcherhttp://clang.llvm.org/doxygen/classclang_1_1QualType.html;>QualTypeasStringstd::string Name Matches if the matched type is represented by the given string. @@ -3433,6 +3460,12 @@ extern int vb; Doesn't match, as it doesn't define the variable. void fa() {} void fb(); Doesn't match, as it has no body. + @interface X + - (void)ma; Doesn't match, interface is declaration. + @end + @implementation X + - (void)ma {} + @end Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagDecl.html;>TagDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl @@ -3696,6 +3729,12 @@ extern int vb; Doesn't match, as it doesn't define the variable. void fa() {} void fb(); Doesn't match, as it has no body. + @interface X + - (void)ma; Doesn't match, interface is
[PATCH] D39948: Make isDefinition matcher support ObjCMethodDecl
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM! https://reviews.llvm.org/D39948 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D39948: Make isDefinition matcher support ObjCMethodDecl
kastiglione created this revision. Herald added a subscriber: klimek. Allow the `isDefinition()` matcher to apply to `ObjCMethodDecl` nodes, in addition to those it already supports. For whatever reason, `ObjCMethodDecl` does not inherit from `FunctionDecl` and so this is specialization is necessary. https://reviews.llvm.org/D39948 Files: docs/LibASTMatchersReference.html include/clang/ASTMatchers/ASTMatchers.h unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp === --- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -1315,6 +1315,14 @@ cxxMethodDecl(hasName("a"), isDefinition()); EXPECT_TRUE(matches("class A { void a() {} };", DefinitionOfMethodA)); EXPECT_TRUE(notMatches("class A { void a(); };", DefinitionOfMethodA)); + + DeclarationMatcher DefinitionOfObjCMethodA = +objcMethodDecl(hasName("a"), isDefinition()); + EXPECT_TRUE(matchesObjC("@interface A @end " + "@implementation A; -(void)a {} @end", + DefinitionOfObjCMethodA)); + EXPECT_TRUE(notMatchesObjC("@interface A; - (void)a; @end", + DefinitionOfObjCMethodA)); } TEST(Matcher, HandlesNullQualTypes) { Index: include/clang/ASTMatchers/ASTMatchers.h === --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -4201,11 +4201,18 @@ /// extern int vb; // Doesn't match, as it doesn't define the variable. /// void fa() {} /// void fb(); // Doesn't match, as it has no body. +/// @interface X +/// - (void)ma; // Doesn't match, interface is declaration. +/// @end +/// @implementation X +/// - (void)ma {} +/// @end /// \endcode /// /// Usable as: Matcher, Matcher, Matcher AST_POLYMORPHIC_MATCHER(isDefinition, AST_POLYMORPHIC_SUPPORTED_TYPES(TagDecl, VarDecl, +ObjCMethodDecl, FunctionDecl)) { return Node.isThisDeclarationADefinition(); } Index: docs/LibASTMatchersReference.html === --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -2746,16 +2746,22 @@ -Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisDefinition -Matches if a declaration has a body attached. +Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisDefinition +Matches if a declaration has a body attached. Example matches A, va, fa class A {}; class B; Doesn't match, as it has no body. int va; extern int vb; Doesn't match, as it doesn't define the variable. void fa() {} void fb(); Doesn't match, as it has no body. + @interface X + - (void)ma; Doesn't match, interface is declaration. + @end + @implementation X + - (void)ma {} + @end Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagDecl.html;>TagDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl @@ -3154,6 +3160,27 @@ +Matcherhttp://clang.llvm.org/doxygen/classclang_1_1ObjCMethodDecl.html;>ObjCMethodDeclisDefinition +Matches if a declaration has a body attached. + +Example matches A, va, fa + class A {}; + class B; Doesn't match, as it has no body. + int va; + extern int vb; Doesn't match, as it doesn't define the variable. + void fa() {} + void fb(); Doesn't match, as it has no body. + @interface X + - (void)ma; Doesn't match, interface is declaration. + @end + @implementation X + - (void)ma {} + @end + +Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagDecl.html;>TagDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl + + + Matcherhttp://clang.llvm.org/doxygen/classclang_1_1QualType.html;>QualTypeasStringstd::string Name Matches if the matched type is represented by the given string. @@ -3433,6 +3460,12 @@ extern int vb; Doesn't match, as it doesn't define the variable. void fa() {} void fb(); Doesn't match, as it has no body. + @interface X + - (void)ma; Doesn't match, interface is declaration. + @end + @implementation X + - (void)ma {} + @end Usable as: Matcherhttp://clang.llvm.org/doxygen/classclang_1_1TagDecl.html;>TagDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1VarDecl.html;>VarDecl, Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDecl @@ -3696,6 +3729,12 @@ extern int vb; Doesn't match, as it doesn't define the variable. void fa() {} void fb(); Doesn't