r342407 - [ASTMatchers] Let isArrow also support UnresolvedMemberExpr, CXXDependentScopeMemberExpr
Shuai Wang via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 17 11:48:43 PDT 2018
Author: shuaiwang
Date: Mon Sep 17 11:48:43 2018
New Revision: 342407
URL: http://llvm.org/viewvc/llvm-project?rev=342407&view=rev
Log:
[ASTMatchers] Let isArrow also support UnresolvedMemberExpr, CXXDependentScopeMemberExpr
Reviewers: aaron.ballman
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D52157
Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
cfe/trunk/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=342407&r1=342406&r2=342407&view=diff
==============================================================================
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Mon Sep 17 11:48:43 2018
@@ -2235,6 +2235,32 @@ cxxConstructorDecl(hasAnyConstructorInit
</pre></td></tr>
+<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXDependentScopeMemberExpr.html">CXXDependentScopeMemberExpr</a>></td><td class="name" onclick="toggle('isArrow2')"><a name="isArrow2Anchor">isArrow</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="isArrow2"><pre>Matches member expressions that are called with '->' as opposed
+to '.'.
+
+Member calls on the implicit this pointer match as called with '->'.
+
+Given
+ class Y {
+ void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
+ template <class T> void f() { this->f<T>(); f<T>(); }
+ int a;
+ static int b;
+ };
+ template <class T>
+ class Z {
+ void x() { this->m; }
+ };
+memberExpr(isArrow())
+ matches this->x, x, y.x, a, this->b
+cxxDependentScopeMemberExpr(isArrow())
+ matches this->m
+unresolvedMemberExpr(isArrow())
+ matches this->f<T>, f<T>
+</pre></td></tr>
+
+
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('isConst0')"><a name="isConst0Anchor">isConst</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="isConst0"><pre>Matches if the given method declaration is const.
@@ -3228,11 +3254,20 @@ Member calls on the implicit this pointe
Given
class Y {
void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
+ template <class T> void f() { this->f<T>(); f<T>(); }
int a;
static int b;
};
+ template <class T>
+ class Z {
+ void x() { this->m; }
+ };
memberExpr(isArrow())
matches this->x, x, y.x, a, this->b
+cxxDependentScopeMemberExpr(isArrow())
+ matches this->m
+unresolvedMemberExpr(isArrow())
+ matches this->f<T>, f<T>
</pre></td></tr>
@@ -3886,6 +3921,32 @@ Example matches a || b (matcher = binary
</pre></td></tr>
+<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1UnresolvedMemberExpr.html">UnresolvedMemberExpr</a>></td><td class="name" onclick="toggle('isArrow1')"><a name="isArrow1Anchor">isArrow</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="isArrow1"><pre>Matches member expressions that are called with '->' as opposed
+to '.'.
+
+Member calls on the implicit this pointer match as called with '->'.
+
+Given
+ class Y {
+ void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
+ template <class T> void f() { this->f<T>(); f<T>(); }
+ int a;
+ static int b;
+ };
+ template <class T>
+ class Z {
+ void x() { this->m; }
+ };
+memberExpr(isArrow())
+ matches this->x, x, y.x, a, this->b
+cxxDependentScopeMemberExpr(isArrow())
+ matches this->m
+unresolvedMemberExpr(isArrow())
+ matches this->f<T>, f<T>
+</pre></td></tr>
+
+
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1VarDecl.html">VarDecl</a>></td><td class="name" onclick="toggle('hasAutomaticStorageDuration0')"><a name="hasAutomaticStorageDuration0Anchor">hasAutomaticStorageDuration</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="hasAutomaticStorageDuration0"><pre>Matches a variable declaration that has automatic storage duration.
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=342407&r1=342406&r2=342407&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Mon Sep 17 11:48:43 2018
@@ -4697,13 +4697,24 @@ AST_MATCHER(CXXMethodDecl, isUserProvide
/// \code
/// class Y {
/// void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; }
+/// template <class T> void f() { this->f<T>(); f<T>(); }
/// int a;
/// static int b;
/// };
+/// template <class T>
+/// class Z {
+/// void x() { this->m; }
+/// };
/// \endcode
/// memberExpr(isArrow())
/// matches this->x, x, y.x, a, this->b
-AST_MATCHER(MemberExpr, isArrow) {
+/// cxxDependentScopeMemberExpr(isArrow())
+/// matches this->m
+/// unresolvedMemberExpr(isArrow())
+/// matches this->f<T>, f<T>
+AST_POLYMORPHIC_MATCHER(
+ isArrow, AST_POLYMORPHIC_SUPPORTED_TYPES(MemberExpr, UnresolvedMemberExpr,
+ CXXDependentScopeMemberExpr)) {
return Node.isArrow();
}
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp?rev=342407&r1=342406&r2=342407&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Mon Sep 17 11:48:43 2018
@@ -765,6 +765,11 @@ TEST(IsArrow, MatchesMemberVariablesViaA
memberExpr(isArrow())));
EXPECT_TRUE(notMatches("class Y { void x() { (*this).y; } int y; };",
memberExpr(isArrow())));
+ EXPECT_TRUE(matches("template <class T> class Y { void x() { this->m; } };",
+ cxxDependentScopeMemberExpr(isArrow())));
+ EXPECT_TRUE(
+ notMatches("template <class T> class Y { void x() { (*this).m; } };",
+ cxxDependentScopeMemberExpr(isArrow())));
}
TEST(IsArrow, MatchesStaticMemberVariablesViaArrow) {
@@ -783,6 +788,14 @@ TEST(IsArrow, MatchesMemberCallsViaArrow
memberExpr(isArrow())));
EXPECT_TRUE(notMatches("class Y { void x() { Y y; y.x(); } };",
memberExpr(isArrow())));
+ EXPECT_TRUE(
+ matches("class Y { template <class T> void x() { this->x<T>(); } };",
+ unresolvedMemberExpr(isArrow())));
+ EXPECT_TRUE(matches("class Y { template <class T> void x() { x<T>(); } };",
+ unresolvedMemberExpr(isArrow())));
+ EXPECT_TRUE(
+ notMatches("class Y { template <class T> void x() { (*this).x<T>(); } };",
+ unresolvedMemberExpr(isArrow())));
}
TEST(ConversionDeclaration, IsExplicit) {
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp?rev=342407&r1=342406&r2=342407&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp Mon Sep 17 11:48:43 2018
@@ -27,7 +27,7 @@ TEST(Finder, DynamicOnlyAcceptsSomeMatch
nullptr));
// Do not accept non-toplevel matchers.
- EXPECT_FALSE(Finder.addDynamicMatcher(isArrow(), nullptr));
+ EXPECT_FALSE(Finder.addDynamicMatcher(isMain(), nullptr));
EXPECT_FALSE(Finder.addDynamicMatcher(hasName("x"), nullptr));
}
Modified: cfe/trunk/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/Dynamic/RegistryTest.cpp?rev=342407&r1=342406&r2=342407&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/Dynamic/RegistryTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/Dynamic/RegistryTest.cpp Mon Sep 17 11:48:43 2018
@@ -440,7 +440,8 @@ TEST_F(RegistryTest, Errors) {
Error.get()).isNull());
EXPECT_EQ("Incorrect type for arg 1. "
"(Expected = Matcher<CXXRecordDecl>) != "
- "(Actual = Matcher<CXXRecordDecl>&Matcher<MemberExpr>)",
+ "(Actual = Matcher<CXXRecordDecl>&Matcher"
+ "<MemberExpr|UnresolvedMemberExpr|CXXDependentScopeMemberExpr>)",
Error->toString());
}
More information about the cfe-commits
mailing list