From b6eb867cf5fe6cd57535c5395ad89b03f3e44087 Mon Sep 17 00:00:00 2001 From: Samuel Benzaquen Date: Mon, 20 Apr 2015 20:58:50 +0000 Subject: [PATCH] Add conversionDecl matcher for node CXXConversionDecl. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235348 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/ASTMatchers/ASTMatchers.h | 9 +++++++++ lib/ASTMatchers/Dynamic/Registry.cpp | 1 + unittests/ASTMatchers/ASTMatchersTest.cpp | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 6a7b530360..3280083b2b 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -757,6 +757,15 @@ const internal::VariadicDynCastAllOfMatcher< /// \endcode const internal::VariadicDynCastAllOfMatcher methodDecl; +/// \brief Matches conversion operator declarations. +/// +/// Example matches the operator. +/// \code +/// class X { operator int() const; }; +/// \endcode +const internal::VariadicDynCastAllOfMatcher + conversionDecl; + /// \brief Matches variable declarations. /// /// Note: this does not match declarations of member variables, which are diff --git a/lib/ASTMatchers/Dynamic/Registry.cpp b/lib/ASTMatchers/Dynamic/Registry.cpp index e46e6dafad..04d3a32563 100644 --- a/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/lib/ASTMatchers/Dynamic/Registry.cpp @@ -128,6 +128,7 @@ RegistryMaps::RegistryMaps() { REGISTER_MATCHER(constructorDecl); REGISTER_MATCHER(containsDeclaration); REGISTER_MATCHER(continueStmt); + REGISTER_MATCHER(conversionDecl); REGISTER_MATCHER(cStyleCastExpr); REGISTER_MATCHER(ctorInitializer); REGISTER_MATCHER(CUDAKernelCallExpr); diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 4b0580a814..46ddb8d0fb 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1398,6 +1398,12 @@ TEST(Callee, MatchesDeclarations) { EXPECT_TRUE(matches("class Y { void x() { x(); } };", CallMethodX)); EXPECT_TRUE(notMatches("class Y { void x() {} };", CallMethodX)); + + CallMethodX = callExpr(callee(conversionDecl())); + EXPECT_TRUE( + matches("struct Y { operator int() const; }; int i = Y();", CallMethodX)); + EXPECT_TRUE(notMatches("struct Y { operator int() const; }; Y y = Y();", + CallMethodX)); } TEST(Callee, MatchesMemberExpressions) { -- 2.40.0