This revision was not accepted when it landed; it landed in state "Needs Review". This revision was automatically updated to reflect the committed changes. hokein marked an inline comment as done. Closed by commit rC322826: [ASTMatcher] Add isScoped matcher for enumDecl. (authored by hokein, committed by ).
Changed prior to commit: https://reviews.llvm.org/D42185?vs=130370&id=130371#toc Repository: rC Clang https://reviews.llvm.org/D42185 Files: docs/LibASTMatchersReference.html include/clang/ASTMatchers/ASTMatchers.h lib/ASTMatchers/Dynamic/Registry.cpp unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -2107,5 +2107,10 @@ cxxRecordDecl(hasDefinition()))); } +TEST(IsScopedEnum, MatchesScopedEnum) { + EXPECT_TRUE(matches("enum class X {};", enumDecl(isScoped()))); + EXPECT_TRUE(notMatches("enum X {};", enumDecl(isScoped()))); +} + } // namespace ast_matchers } // namespace clang Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -2644,6 +2644,15 @@ </pre></td></tr> +<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumDecl.html">EnumDecl</a>></td><td class="name" onclick="toggle('isScoped0')"><a name="isScoped0Anchor">isScoped</a></td><td></td></tr> +<tr><td colspan="4" class="doc" id="isScoped0"><pre>Matches C++11 scoped enum declaration. + +Example matches Y (matcher = enumDecl(isScoped())) +enum X {}; +enum class Y {}; +</pre></td></tr> + + <tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>></td><td class="name" onclick="toggle('hasBitWidth0')"><a name="hasBitWidth0Anchor">hasBitWidth</a></td><td>unsigned Width</td></tr> <tr><td colspan="4" class="doc" id="hasBitWidth0"><pre>Matches non-static data members that are bit-fields of the specified bit width. Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -5880,6 +5880,17 @@ return Node.hasDefinition(); } +/// \brief Matches C++11 scoped enum declaration. +/// +/// Example matches Y (matcher = enumDecl(isScoped())) +/// \code +/// enum X {}; +/// enum class Y {}; +/// \endcode +AST_MATCHER(EnumDecl, isScoped) { + return Node.isScoped(); +} + } // namespace ast_matchers } // namespace clang Index: lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- lib/ASTMatchers/Dynamic/Registry.cpp +++ lib/ASTMatchers/Dynamic/Registry.cpp @@ -361,6 +361,7 @@ REGISTER_MATCHER(isProtected); REGISTER_MATCHER(isPublic); REGISTER_MATCHER(isPure); + REGISTER_MATCHER(isScoped); REGISTER_MATCHER(isSignedInteger); REGISTER_MATCHER(isStaticStorageClass); REGISTER_MATCHER(isStruct);
Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -2107,5 +2107,10 @@ cxxRecordDecl(hasDefinition()))); } +TEST(IsScopedEnum, MatchesScopedEnum) { + EXPECT_TRUE(matches("enum class X {};", enumDecl(isScoped()))); + EXPECT_TRUE(notMatches("enum X {};", enumDecl(isScoped()))); +} + } // namespace ast_matchers } // namespace clang Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -2644,6 +2644,15 @@ </pre></td></tr> +<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumDecl.html">EnumDecl</a>></td><td class="name" onclick="toggle('isScoped0')"><a name="isScoped0Anchor">isScoped</a></td><td></td></tr> +<tr><td colspan="4" class="doc" id="isScoped0"><pre>Matches C++11 scoped enum declaration. + +Example matches Y (matcher = enumDecl(isScoped())) +enum X {}; +enum class Y {}; +</pre></td></tr> + + <tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>></td><td class="name" onclick="toggle('hasBitWidth0')"><a name="hasBitWidth0Anchor">hasBitWidth</a></td><td>unsigned Width</td></tr> <tr><td colspan="4" class="doc" id="hasBitWidth0"><pre>Matches non-static data members that are bit-fields of the specified bit width. Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -5880,6 +5880,17 @@ return Node.hasDefinition(); } +/// \brief Matches C++11 scoped enum declaration. +/// +/// Example matches Y (matcher = enumDecl(isScoped())) +/// \code +/// enum X {}; +/// enum class Y {}; +/// \endcode +AST_MATCHER(EnumDecl, isScoped) { + return Node.isScoped(); +} + } // namespace ast_matchers } // namespace clang Index: lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- lib/ASTMatchers/Dynamic/Registry.cpp +++ lib/ASTMatchers/Dynamic/Registry.cpp @@ -361,6 +361,7 @@ REGISTER_MATCHER(isProtected); REGISTER_MATCHER(isPublic); REGISTER_MATCHER(isPure); + REGISTER_MATCHER(isScoped); REGISTER_MATCHER(isSignedInteger); REGISTER_MATCHER(isStaticStorageClass); REGISTER_MATCHER(isStruct);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits