]> granicus.if.org Git - clang/commitdiff
[ASTMatcher] Add isScoped matcher for enumDecl.
authorHaojian Wu <hokein@google.com>
Thu, 18 Jan 2018 09:47:57 +0000 (09:47 +0000)
committerHaojian Wu <hokein@google.com>
Thu, 18 Jan 2018 09:47:57 +0000 (09:47 +0000)
Summary:

Reviewers: bkramer, aaron.ballman

Subscribers: aaron.ballman, cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D42185

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@322826 91177308-0d34-0410-b5e6-96231b3b80d8

docs/LibASTMatchersReference.html
include/clang/ASTMatchers/ASTMatchers.h
lib/ASTMatchers/Dynamic/Registry.cpp
unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

index 8e41489e1b6636c6c91de5ab007ced0fe0da4e96..95d95546ffde2e57eb403e5735a10c03a3744f80 100644 (file)
@@ -2644,6 +2644,15 @@ designatorCountIs(2)
 </pre></td></tr>
 
 
+<tr><td>Matcher&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1EnumDecl.html">EnumDecl</a>&gt;</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&lt;<a href="http://clang.llvm.org/doxygen/classclang_1_1FieldDecl.html">FieldDecl</a>&gt;</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 f1eabdec6a9e047f47903469d11457f894aabc87..b153b8463beb7af9246c0ed4bfa322ad6e6f7334 100644 (file)
@@ -5880,6 +5880,17 @@ AST_MATCHER(CXXRecordDecl, hasDefinition) {
   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 410922514df19fa5716175f7a1bb549c1dad07d7..784581fc45bae0cc3236b380d934c2d061ddf71c 100644 (file)
@@ -361,6 +361,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(isProtected);
   REGISTER_MATCHER(isPublic);
   REGISTER_MATCHER(isPure);
+  REGISTER_MATCHER(isScoped);
   REGISTER_MATCHER(isSignedInteger);
   REGISTER_MATCHER(isStaticStorageClass);
   REGISTER_MATCHER(isStruct);
index 5ebcc62c939507eb62b6869e864f6ca0df50d808..eea4e6f4f23b82ba188b6dbb331aebce739a0fb9 100644 (file)
@@ -2107,5 +2107,10 @@ TEST(HasDefinition, MatchesUnionDefinition) {
                       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