diff options
author | Edwin Vane <edwin.vane@intel.com> | 2013-05-09 17:00:17 +0000 |
---|---|---|
committer | Edwin Vane <edwin.vane@intel.com> | 2013-05-09 17:00:17 +0000 |
commit | fc4f7dc0a6d3fe4e40eb0ac52f17ab1d9dc48ee6 (patch) | |
tree | e555381bafeb949449df3b2fdc9618057a73145d | |
parent | 395a6d48780ff68ef0944630232df05925c17e31 (diff) | |
download | bcm5719-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.html | 13 | ||||
-rw-r--r-- | clang/include/clang/ASTMatchers/ASTMatchers.h | 15 | ||||
-rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 7 |
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<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXOpe </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. 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(); };", |