Add valueDecl() matcher.
authorSamuel Benzaquen <sbenza@google.com>
Tue, 28 Oct 2014 13:33:58 +0000 (13:33 +0000)
committerSamuel Benzaquen <sbenza@google.com>
Tue, 28 Oct 2014 13:33:58 +0000 (13:33 +0000)
Summary: Add valueDecl() matcher.

Reviewers: klimek

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D6005

llvm-svn: 220776

clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersTest.cpp

index 93cb0ef..4537c47 100644 (file)
@@ -586,6 +586,15 @@ AST_MATCHER_P(TemplateArgument, equalsIntegralValue,
   return Node.getAsIntegral().toString(10) == Value;
 }
 
+/// \brief Matches any value declaration.
+///
+/// Example matches A, B, C and F
+/// \code
+///   enum X { A, B, C };
+///   void F();
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<Decl, ValueDecl> valueDecl;
+
 /// \brief Matches C++ constructor declarations.
 ///
 /// Example matches Foo::Foo() and Foo::Foo(int)
index b92e8ef..dab4187 100644 (file)
@@ -325,6 +325,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(userDefinedLiteral);
   REGISTER_MATCHER(usingDecl);
   REGISTER_MATCHER(usingDirectiveDecl);
+  REGISTER_MATCHER(valueDecl);
   REGISTER_MATCHER(varDecl);
   REGISTER_MATCHER(variableArrayType);
   REGISTER_MATCHER(whileStmt);
index 5a8f42a..c88a197 100644 (file)
@@ -827,6 +827,13 @@ TEST(Has, MatchesChildTypes) {
       varDecl(hasName("i"), hasType(qualType(has(pointerType()))))));
 }
 
+TEST(ValueDecl, Matches) {
+  EXPECT_TRUE(matches("enum EnumType { EnumValue };",
+                      valueDecl(hasType(asString("enum EnumType")))));
+  EXPECT_TRUE(matches("void FunctionDecl();",
+                      valueDecl(hasType(asString("void (void)")))));
+}
+
 TEST(Enum, DoesNotMatchClasses) {
   EXPECT_TRUE(notMatches("class X {};", enumDecl(hasName("X"))));
 }