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
This commit is contained in:
Dmitri Gribenko 2014-02-24 09:27:46 +00:00
parent cf5d8e4f29
commit 51c1b55bc2
2 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -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())));