From: Samuel Benzaquen Date: Tue, 28 Oct 2014 13:33:58 +0000 (+0000) Subject: Add valueDecl() matcher. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=04ccb88f72207504c902d1440d21ca323351ea09;p=clang Add valueDecl() matcher. 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 --- diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index 93cb0ef6ec..4537c4719c 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -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 valueDecl; + /// \brief Matches C++ constructor declarations. /// /// Example matches Foo::Foo() and Foo::Foo(int) diff --git a/lib/ASTMatchers/Dynamic/Registry.cpp b/lib/ASTMatchers/Dynamic/Registry.cpp index b92e8ef6bf..dab4187171 100644 --- a/lib/ASTMatchers/Dynamic/Registry.cpp +++ b/lib/ASTMatchers/Dynamic/Registry.cpp @@ -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); diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 5a8f42a87c..c88a197643 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -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")))); }