summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Vane <edwin.vane@intel.com>2013-05-09 17:00:17 +0000
committerEdwin Vane <edwin.vane@intel.com>2013-05-09 17:00:17 +0000
commitfc4f7dc0a6d3fe4e40eb0ac52f17ab1d9dc48ee6 (patch)
treee555381bafeb949449df3b2fdc9618057a73145d
parent395a6d48780ff68ef0944630232df05925c17e31 (diff)
downloadbcm5719-llvm-fc4f7dc0a6d3fe4e40eb0ac52f17ab1d9dc48ee6.tar.gz
bcm5719-llvm-fc4f7dc0a6d3fe4e40eb0ac52f17ab1d9dc48ee6.zip
Adding isConst() ASTMatcher for CXXMethodDecl nodes
Updated reference and unit tests. llvm-svn: 181522
-rw-r--r--clang/docs/LibASTMatchersReference.html13
-rw-r--r--clang/include/clang/ASTMatchers/ASTMatchers.h15
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersTest.cpp7
3 files changed, 35 insertions, 0 deletions
diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html
index e571c0780c3..0ea55bfef54 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -1524,6 +1524,19 @@ Usable as: Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXOpe
</pre></td></tr>
+<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>&gt;</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&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>&gt;</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.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 70f539be794..2b04f8c2e4b 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -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
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
index cfa53868ed2..50aa583f940 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -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(); };",
OpenPOWER on IntegriCloud