[PATCH] D25600: [ASTMatcher] Add isStaticDataMember matcher for varDecl.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 14 02:56:12 PDT 2016
hokein created this revision.
hokein added a reviewer: klimek.
hokein added a subscriber: cfe-commits.
https://reviews.llvm.org/D25600
Files:
docs/LibASTMatchersReference.html
include/clang/ASTMatchers/ASTMatchers.h
unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -692,6 +692,15 @@
EXPECT_TRUE(notMatches(T, varDecl(hasName("a"), hasThreadStorageDuration())));
}
+TEST(Matcher, VarDecl_StaticDataMember) {
+ EXPECT_TRUE(matches(
+ "class A {static int x; int y;};",
+ varDecl(hasName("x"), isStaticDataMember())));
+ EXPECT_TRUE(notMatches(
+ "class A {int x;};",
+ varDecl(isStaticDataMember())));
+}
+
TEST(Matcher, FindsVarDeclInFunctionParameter) {
EXPECT_TRUE(matches(
"void f(int i) {}",
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2993,6 +2993,19 @@
return Node.isExceptionVariable();
}
+/// \brief Matches a variable declaration that is a static data member.
+///
+/// Example matches x (matcher = varDecl(isStaticDataMember())
+/// \code
+/// class A {
+/// static int x;
+/// int y;
+/// };
+/// \endcode
+AST_MATCHER(VarDecl, isStaticDataMember) {
+ return Node.isStaticDataMember();
+}
+
/// \brief Checks that a call expression or a constructor call expression has
/// a specific number of arguments (including absent default arguments).
///
Index: docs/LibASTMatchersReference.html
===================================================================
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -3493,6 +3493,17 @@
</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('isStaticDataMember0')"><a name="isStaticDataMember0Anchor">isStaticDataMember</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="isStaticDataMember0"><pre>Matches a variable declaration that is a static data member.
+
+Example matches x (matcher = varDecl(isStaticDataMember())
+class A {
+ static int x;
+ int y;
+};
+</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('isStaticStorageClass1')"><a name="isStaticStorageClass1Anchor">isStaticStorageClass</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="isStaticStorageClass1"><pre>Matches variablefunction declarations that have "static" storage
class specifier ("static" keyword) written in the source.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25600.74640.patch
Type: text/x-patch
Size: 2591 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161014/44944fca/attachment.bin>
More information about the cfe-commits
mailing list