]> granicus.if.org Git - clang/commitdiff
Add conversionDecl matcher for node CXXConversionDecl.
authorSamuel Benzaquen <sbenza@google.com>
Mon, 20 Apr 2015 20:58:50 +0000 (20:58 +0000)
committerSamuel Benzaquen <sbenza@google.com>
Mon, 20 Apr 2015 20:58:50 +0000 (20:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235348 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/ASTMatchers/ASTMatchers.h
lib/ASTMatchers/Dynamic/Registry.cpp
unittests/ASTMatchers/ASTMatchersTest.cpp

index 6a7b5303604d465afac2e92e6fff9ee6553b70c9..3280083b2b82367e120b2d9267f86154436bb7d1 100644 (file)
@@ -757,6 +757,15 @@ const internal::VariadicDynCastAllOfMatcher<
 /// \endcode
 const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> methodDecl;
 
+/// \brief Matches conversion operator declarations.
+///
+/// Example matches the operator.
+/// \code
+///   class X { operator int() const; };
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<Decl, CXXConversionDecl>
+    conversionDecl;
+
 /// \brief Matches variable declarations.
 ///
 /// Note: this does not match declarations of member variables, which are
index e46e6dafaddc905911d3db9de77f3d5394ca54e0..04d3a32563139338037a06207b6dba93565cc54a 100644 (file)
@@ -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);
index 4b0580a8147a9b97eb1be2e2c9c473dc3d02cae0..46ddb8d0fb66ffe3c82a20ac4d1e524ed8e5d724 100644 (file)
@@ -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) {