[PATCH] D42185: [ASTMatcher] Add isScoped matcher for enumDecl.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 17 07:52:57 PST 2018


hokein created this revision.
hokein added a reviewer: bkramer.
Herald added a subscriber: klimek.

No doc update on the LibASTMatchersReference.html - The dump_ast_matchers.py
script has been broken since r318304.


Repository:
  rC Clang

https://reviews.llvm.org/D42185

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp


Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2029,5 +2029,12 @@
                       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: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -5864,6 +5864,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
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42185.130188.patch
Type: text/x-patch
Size: 1154 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180117/09b74892/attachment.bin>


More information about the cfe-commits mailing list