r258573 - Add am AST matcher for isMoveAssignmentOperator.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 22 14:37:09 PST 2016
Author: aaronballman
Date: Fri Jan 22 16:37:09 2016
New Revision: 258573
URL: http://llvm.org/viewvc/llvm-project?rev=258573&view=rev
Log:
Add am AST matcher for isMoveAssignmentOperator.
Patch by Jonathan Coe.
Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=258573&r1=258572&r2=258573&view=diff
==============================================================================
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Fri Jan 22 16:37:09 2016
@@ -1815,6 +1815,21 @@ matches A and C::f, but not B, C, or B::
</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('isMoveAssignmentOperator0')"><a name="isMoveAssignmentOperator0Anchor">isMoveAssignmentOperator</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="isMoveAssignmentOperator0"><pre>Matches if the given method declaration declares a move assignment
+operator.
+
+Given
+struct A {
+ A &operator=(const A &);
+ A &operator=(A &&);
+};
+
+cxxMethodDecl(isMoveAssignmentOperator()) matches the second method but not
+the first one.
+</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('isOverride0')"><a name="isOverride0Anchor">isOverride</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="isOverride0"><pre>Matches if the given method declaration overrides another method.
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=258573&r1=258572&r2=258573&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri Jan 22 16:37:09 2016
@@ -3576,6 +3576,21 @@ AST_MATCHER(CXXMethodDecl, isCopyAssignm
return Node.isCopyAssignmentOperator();
}
+/// \brief Matches if the given method declaration declares a move assignment
+/// operator.
+///
+/// Given
+/// \code
+/// struct S {
+/// S(const S &); // #1
+/// S& operator=(S &&); // #2
+/// };
+/// \endcode
+/// cxxMethodDecl(isMoveAssignmentOperator()) will match #2, but not #1.
+AST_MATCHER(CXXMethodDecl, isMoveAssignmentOperator) {
+ return Node.isMoveAssignmentOperator();
+}
+
/// \brief Matches if the given method declaration overrides another method.
///
/// Given
Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=258573&r1=258572&r2=258573&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Fri Jan 22 16:37:09 2016
@@ -291,6 +291,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(isInTemplateInstantiation);
REGISTER_MATCHER(isListInitialization);
REGISTER_MATCHER(isMemberInitializer);
+ REGISTER_MATCHER(isMoveAssignmentOperator);
REGISTER_MATCHER(isMoveConstructor);
REGISTER_MATCHER(isNoThrow);
REGISTER_MATCHER(isOverride);
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=258573&r1=258572&r2=258573&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Fri Jan 22 16:37:09 2016
@@ -2059,6 +2059,21 @@ TEST(Matcher, MatchesCopyAssignmentOpera
cxxMethodDecl(isCopyAssignmentOperator())));
}
+TEST(Matcher, MatchesMoveAssignmentOperator) {
+ EXPECT_TRUE(notMatches("class X { X &operator=(X); };",
+ cxxMethodDecl(isMoveAssignmentOperator())));
+ EXPECT_TRUE(matches("class X { X &operator=(X &&); };",
+ cxxMethodDecl(isMoveAssignmentOperator())));
+ EXPECT_TRUE(matches("class X { X &operator=(const X &&); };",
+ cxxMethodDecl(isMoveAssignmentOperator())));
+ EXPECT_TRUE(matches("class X { X &operator=(volatile X &&); };",
+ cxxMethodDecl(isMoveAssignmentOperator())));
+ EXPECT_TRUE(matches("class X { X &operator=(const volatile X &&); };",
+ cxxMethodDecl(isMoveAssignmentOperator())));
+ EXPECT_TRUE(notMatches("class X { X &operator=(X &); };",
+ cxxMethodDecl(isMoveAssignmentOperator())));
+}
+
TEST(Matcher, MatchesConstMethod) {
EXPECT_TRUE(
matches("struct A { void foo() const; };", cxxMethodDecl(isConst())));
More information about the cfe-commits
mailing list