summaryrefslogtreecommitdiffstats
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
commit51c1b55bc2ff3dafde49f40306262aee4e662375 (patch)
tree44a4001d3c696ca27fe5157c4e63d6cfe809f04c
parentcf5d8e4f29227f6124e4b7aa5c24f16667cf5c78 (diff)
downloadbcm5719-llvm-51c1b55bc2ff3dafde49f40306262aee4e662375.tar.gz
bcm5719-llvm-51c1b55bc2ff3dafde49f40306262aee4e662375.zip
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. llvm-svn: 202012
-rw-r--r--clang/include/clang/ASTMatchers/ASTMatchers.h16
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersTest.cpp7
2 files changed, 22 insertions, 1 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index e010133ca23..167b0fc7906 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/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/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
index cf77f2f4dd5..aa3c795b57d 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/clang/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())));
OpenPOWER on IntegriCloud