Index: docs/LibASTMatchersReference.html
===================================================================
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -2746,8 +2746,8 @@
-
Matcher<FunctionDecl> | isDefinition | |
-Matches if a declaration has a body attached.
+Matcher<FunctionDecl> | isDefinition | |
+Matches if a declaration has a body attached.
Example matches A, va, fa
class A {};
@@ -2756,6 +2756,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: Matcher<TagDecl>, Matcher<VarDecl>, Matcher<FunctionDecl>
|
@@ -3154,6 +3160,27 @@
|
+Matcher<ObjCMethodDecl> | isDefinition | |
+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: Matcher<TagDecl>, Matcher<VarDecl>, Matcher<FunctionDecl>
+ |
+
+
Matcher<QualType> | asString | std::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: Matcher<TagDecl>, Matcher<VarDecl>, Matcher<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 declaration.
+ @end
+ @implementation X
+ - (void)ma {}
+ @end
Usable as: Matcher<TagDecl>, Matcher<VarDecl>, Matcher<FunctionDecl>
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: 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) {