r181522 - Adding isConst() ASTMatcher for CXXMethodDecl nodes
Edwin Vane
edwin.vane at intel.com
Thu May 9 10:00:17 PDT 2013
Author: revane
Date: Thu May 9 12:00:17 2013
New Revision: 181522
URL: http://llvm.org/viewvc/llvm-project?rev=181522&view=rev
Log:
Adding isConst() ASTMatcher for CXXMethodDecl nodes
Updated reference and unit tests.
Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
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=181522&r1=181521&r2=181522&view=diff
==============================================================================
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Thu May 9 12:00:17 2013
@@ -1524,6 +1524,19 @@ Usable as: Matcher<<a href="http://cla
</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.
+
+Given
+struct A {
+ void foo() const;
+ void bar();
+};
+
+methodDecl(isConst()) matches A::foo() but not A::bar()
+</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=181522&r1=181521&r2=181522&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Thu May 9 12:00:17 2013
@@ -2542,6 +2542,21 @@ AST_MATCHER(CXXMethodDecl, isVirtual) {
return Node.isVirtual();
}
+/// \brief Matches if the given method declaration is const.
+///
+/// Given
+/// \code
+/// struct A {
+/// void foo() const;
+/// void bar();
+/// };
+/// \endcode
+///
+/// methodDecl(isConst()) matches A::foo() but not A::bar()
+AST_MATCHER(CXXMethodDecl, isConst) {
+ return Node.isConst();
+}
+
/// \brief Matches if the given method declaration overrides another method.
///
/// Given
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=181522&r1=181521&r2=181522&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Thu May 9 12:00:17 2013
@@ -1507,6 +1507,13 @@ TEST(Matcher, MatchesVirtualMethod) {
methodDecl(isVirtual())));
}
+TEST(Matcher, MatchesConstMethod) {
+ EXPECT_TRUE(matches("struct A { void foo() const; };",
+ methodDecl(isConst())));
+ EXPECT_TRUE(notMatches("struct A { void foo(); };",
+ methodDecl(isConst())));
+}
+
TEST(Matcher, MatchesOverridingMethod) {
EXPECT_TRUE(matches("class X { virtual int f(); }; "
"class Y : public X { int f(); };",
More information about the cfe-commits
mailing list