]> granicus.if.org Git - clang/commitdiff
Implements the thisExpr matcher.
authorManuel Klimek <klimek@google.com>
Tue, 23 Oct 2012 10:40:50 +0000 (10:40 +0000)
committerManuel Klimek <klimek@google.com>
Tue, 23 Oct 2012 10:40:50 +0000 (10:40 +0000)
Patch by Gabor Horvath.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166477 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/ASTMatchers/ASTMatchers.h
unittests/ASTMatchers/ASTMatchersTest.cpp

index 712b324d754e16834050fa3de2b05c3a9fa20b39..b26bc62c99f12fc25c2dd028768d986ff1bcfb89 100644 (file)
@@ -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<Stmt, CXXThisExpr> thisExpr;
+
 /// \brief Matches nodes where temporaries are created.
 ///
 /// Example matches FunctionTakesString(GetStringByValue())
index 5c97f3abacd297e31769b08fd664d8839401e353..a97e90d74c5151c96c712d9cbd6ec1d51ce70814 100644 (file)
@@ -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();