From 025f6b19815916e357a5a11d600cffde25d427e1 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. llvm-svn: 235348 --- clang/include/clang/ASTMatchers/ASTMatchers.h | 9 +++++++++ clang/lib/ASTMatchers/Dynamic/Registry.cpp | 1 + clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index 6a7b530..3280083 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/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/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp index e46e6da..04d3a32 100644 --- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/clang/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/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 4b0580a..46ddb8d 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/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.7.4