Author: hokein Date: Mon Sep 26 11:01:52 2016 New Revision: 282415 URL: http://llvm.org/viewvc/llvm-project?rev=282415&view=rev Log: [ASTMatcher] Add isStaticStorageClass matcher for varDecl and functionDecl.
Reviewers: klimek Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D24821 Modified: cfe/trunk/docs/LibASTMatchersReference.html cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Modified: cfe/trunk/docs/LibASTMatchersReference.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=282415&r1=282414&r2=282415&view=diff ============================================================================== --- cfe/trunk/docs/LibASTMatchersReference.html (original) +++ cfe/trunk/docs/LibASTMatchersReference.html Mon Sep 26 11:01:52 2016 @@ -2610,6 +2610,20 @@ functionDecl(isNoThrow()) and functionPr </pre></td></tr> +<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isStaticStorageClass0')"><a name="isStaticStorageClass0Anchor">isStaticStorageClass</a></td><td></td></tr> +<tr><td colspan="4" class="doc" id="isStaticStorageClass0"><pre>Matches variablefunction declarations that have static storage class +(with "static" key word) written in the source. + +Given: + static void f() {} + static int i = 0; +functionDecl(isStaticStorageClass()) + matches the function declaration f. +varDecl(isStaticStorageClass()) + matches the variable declaration i. +</pre></td></tr> + + <tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html">FunctionDecl</a>></td><td class="name" onclick="toggle('isTemplateInstantiation0')"><a name="isTemplateInstantiation0Anchor">isTemplateInstantiation</a></td><td></td></tr> <tr><td colspan="4" class="doc" id="isTemplateInstantiation0"><pre>Matches template instantiations of function, class, or static member variable template instantiations. @@ -3473,6 +3487,20 @@ functionDecl(isExternC()) </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 +(with "static" key word) written in the source. + +Given: + static void f() {} + static int i = 0; +functionDecl(isStaticStorageClass()) + matches the function declaration f. +varDecl(isStaticStorageClass()) + matches the variable declaration i. +</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('isTemplateInstantiation1')"><a name="isTemplateInstantiation1Anchor">isTemplateInstantiation</a></td><td></td></tr> <tr><td colspan="4" class="doc" id="isTemplateInstantiation1"><pre>Matches template instantiations of function, class, or static member variable template instantiations. @@ -4092,7 +4120,7 @@ matcher, or is a pointer to a type that <tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>></td><td class="name" onclick="toggle('forEachOverridden0')"><a name="forEachOverridden0Anchor">forEachOverridden</a></td><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXMethodDecl.html">CXXMethodDecl</a>> InnerMatcher</td></tr> -<tr><td colspan="4" class="doc" id="forEachOverridden0"><pre>Matches each method overridden by the given method. This matcher may +<tr><td colspan="4" class="doc" id="forEachOverridden0"><pre>Matches each method overriden by the given method. This matcher may produce multiple matches. Given Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=282415&r1=282414&r2=282415&view=diff ============================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original) +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Mon Sep 26 11:01:52 2016 @@ -3387,6 +3387,24 @@ AST_POLYMORPHIC_MATCHER(isExternC, AST_P return Node.isExternC(); } +/// \brief Matches variable/function declarations that have static storage class +/// (with "static" key word) written in the source. +/// +/// Given: +/// \code +/// static void f() {} +/// static int i = 0; +/// \endcode +/// functionDecl(isStaticStorageClass()) +/// matches the function declaration f. +/// varDecl(isStaticStorageClass()) +/// matches the variable declaration i. +AST_POLYMORPHIC_MATCHER(isStaticStorageClass, + AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, + VarDecl)) { + return Node.getStorageClass() == SC_Static; +} + /// \brief Matches deleted function declarations. /// /// Given: Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp?rev=282415&r1=282414&r2=282415&view=diff ============================================================================== --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp (original) +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Mon Sep 26 11:01:52 2016 @@ -848,6 +848,14 @@ TEST(IsExternC, MatchesExternCVariableDe EXPECT_TRUE(notMatches("int i;", varDecl(isExternC()))); } +TEST(IsStaticStorageClass, MatchesStaticDeclarations) { + EXPECT_TRUE( + matches("static void f() {}", functionDecl(isStaticStorageClass()))); + EXPECT_TRUE(matches("static int i = 1;", varDecl(isStaticStorageClass()))); + EXPECT_TRUE(notMatches("int i = 1;", varDecl(isStaticStorageClass()))); + EXPECT_TRUE(notMatches("void f() {}", functionDecl(isStaticStorageClass()))); +} + TEST(IsDefaulted, MatchesDefaultedFunctionDeclarations) { EXPECT_TRUE(notMatches("class A { ~A(); };", functionDecl(hasName("~A"), isDefaulted()))); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits