summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2014-02-24 09:27:46 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2014-02-24 09:27:46 +0000
commit3790613579db81a9f78a7ddad5382dbeec43a07a (patch)
treeb04c9e0764cdcadd3a815daaf1ac81dec6056f54
parent5e8440c0e59675badba925a26191b0d38189d7fb (diff)
downloadclang-3790613579db81a9f78a7ddad5382dbeec43a07a.tar.gz
clang-3790613579db81a9f78a7ddad5382dbeec43a07a.tar.bz2
clang-3790613579db81a9f78a7ddad5382dbeec43a07a.tar.xz
ASTMatchers: added CXXMethodDecl matcher isPure()
The isPure() CXXMethodDecl matcher matches pure method declaration like "A::x" in this example: class A { virtual void x() = 0; } Patch by Konrad Kleine. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202012 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/ASTMatchers/ASTMatchers.h16
-rw-r--r--unittests/ASTMatchers/ASTMatchersTest.cpp7
2 files changed, 22 insertions, 1 deletions
diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h
index e010133ca2..167b0fc790 100644
--- a/include/clang/ASTMatchers/ASTMatchers.h
+++ b/include/clang/ASTMatchers/ASTMatchers.h
@@ -555,7 +555,7 @@ const internal::VariadicDynCastAllOfMatcher<
///
/// Example matches y
/// \code
-/// class X { void y() };
+/// class X { void y(); };
/// \endcode
const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> methodDecl;
@@ -2656,6 +2656,20 @@ AST_MATCHER(CXXMethodDecl, isVirtual) {
return Node.isVirtual();
}
+/// \brief Matches if the given method declaration is pure.
+///
+/// Given
+/// \code
+/// class A {
+/// public:
+/// virtual void x() = 0;
+/// };
+/// \endcode
+/// matches A::x
+AST_MATCHER(CXXMethodDecl, isPure) {
+ return Node.isPure();
+}
+
/// \brief Matches if the given method declaration is const.
///
/// Given
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp
index cf77f2f4dd..aa3c795b57 100644
--- a/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -1588,6 +1588,13 @@ TEST(Matcher, MatchesVirtualMethod) {
methodDecl(isVirtual())));
}
+TEST(Matcher, MatchesPureMethod) {
+ EXPECT_TRUE(matches("class X { virtual int f() = 0; };",
+ methodDecl(isPure(), hasName("::X::f"))));
+ EXPECT_TRUE(notMatches("class X { int f(); };",
+ methodDecl(isPure())));
+}
+
TEST(Matcher, MatchesConstMethod) {
EXPECT_TRUE(matches("struct A { void foo() const; };",
methodDecl(isConst())));