From 7fca93b428b73bfa3e0e2e64b94d10b1fac6402f Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Tue, 23 Oct 2012 10:40:50 +0000 Subject: [PATCH] Implements the thisExpr matcher. Patch by Gabor Horvath. llvm-svn: 166477 --- clang/include/clang/ASTMatchers/ASTMatchers.h | 12 ++++++++++++ clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index 712b324..b26bc62 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -546,6 +546,18 @@ const internal::VariadicDynCastAllOfMatcher< Stmt, CXXConstructExpr> constructExpr; +/// \brief Matches implicit and explicit this expressions. +/// +/// Example matches the implicit this expression in "return i". +/// (matcher = thisExpr()) +/// \code +/// struct foo { +/// int i; +/// int f() { return i; } +/// }; +/// \endcode +const internal::VariadicDynCastAllOfMatcher thisExpr; + /// \brief Matches nodes where temporaries are created. /// /// Example matches FunctionTakesString(GetStringByValue()) diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 5c97f3a..a97e90d 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1333,6 +1333,13 @@ TEST(Matcher, ConstructorArgumentCount) { Constructor1Arg)); } +TEST(Matcher,ThisExpr) { + EXPECT_TRUE( + matches("struct X { int a; int f () { return a; } };", thisExpr())); + EXPECT_TRUE( + notMatches("struct X { int f () { int a; return a; } };", thisExpr())); +} + TEST(Matcher, BindTemporaryExpression) { StatementMatcher TempExpression = bindTemporaryExpr(); -- 2.7.4