]> granicus.if.org Git - clang/commitdiff
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

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

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

index 93cb0ef6ec239e17f60a014765f369e84bd6b498..4537c4719c9069d3f86fc1732c68244d477ed75d 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 b92e8ef6bf317d307aef7b14189ae40c8217ed60..dab418717147bde4d9bb384abbb57ff0d599c298 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 5a8f42a87c9626b1d0f1334e759278fab7590eae..c88a197643a7d36ef5e8be7fe76ecb0abb3b28f8 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"))));
 }