[cfe-commits] r166477 - in /cfe/trunk: include/clang/ASTMatchers/ASTMatchers.h unittests/ASTMatchers/ASTMatchersTest.cpp

Manuel Klimek klimek at google.com
Tue Oct 23 03:40:51 PDT 2012


Author: klimek
Date: Tue Oct 23 05:40:50 2012
New Revision: 166477

URL: http://llvm.org/viewvc/llvm-project?rev=166477&view=rev
Log:
Implements the thisExpr matcher.
Patch by Gabor Horvath.

Modified:
    cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
    cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=166477&r1=166476&r2=166477&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Tue Oct 23 05:40:50 2012
@@ -546,6 +546,18 @@
   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())

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=166477&r1=166476&r2=166477&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Tue Oct 23 05:40:50 2012
@@ -1333,6 +1333,13 @@
                  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();
 





More information about the cfe-commits mailing list