From: Samuel Benzaquen Date: Fri, 17 Jul 2015 16:05:27 +0000 (+0000) Subject: [ASTMatchers] Use provided target NodeKind instead of inferring it from the matchers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d6a363a733682e145306fc1e42152e8519166b48;p=clang [ASTMatchers] Use provided target NodeKind instead of inferring it from the matchers. Individual matchers might not be convertible to each other's kind, but they might still all be convertible to the target kind. All the callers already know the target kind, so just pass it down. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242534 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/ASTMatchers/ASTMatchersInternal.h b/include/clang/ASTMatchers/ASTMatchersInternal.h index b494647d79..0d9a6b26ff 100644 --- a/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -281,6 +281,7 @@ public: }; static DynTypedMatcher constructVariadic(VariadicOperator Op, + ast_type_traits::ASTNodeKind SupportedKind, std::vector InnerMatchers); /// \brief Get a "true" matcher for \p NodeKind. @@ -1137,7 +1138,8 @@ public: template operator Matcher() const { return DynTypedMatcher::constructVariadic( - Op, getMatchers(llvm::index_sequence_for())) + Op, ast_type_traits::ASTNodeKind::getFromNodeKind(), + getMatchers(llvm::index_sequence_for())) .template unconditionalConvertTo(); } @@ -1191,8 +1193,10 @@ BindableMatcher makeAllOfComposite( std::vector DynMatchers(PI(InnerMatchers.begin()), PI(InnerMatchers.end())); return BindableMatcher( - DynTypedMatcher::constructVariadic(DynTypedMatcher::VO_AllOf, - std::move(DynMatchers)) + DynTypedMatcher::constructVariadic( + DynTypedMatcher::VO_AllOf, + ast_type_traits::ASTNodeKind::getFromNodeKind(), + std::move(DynMatchers)) .template unconditionalConvertTo()); } diff --git a/lib/ASTMatchers/ASTMatchersInternal.cpp b/lib/ASTMatchers/ASTMatchersInternal.cpp index 069fcba474..463cf0ba9d 100644 --- a/lib/ASTMatchers/ASTMatchersInternal.cpp +++ b/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -110,15 +110,15 @@ static llvm::ManagedStatic TrueMatcherInstance; DynTypedMatcher DynTypedMatcher::constructVariadic( DynTypedMatcher::VariadicOperator Op, + ast_type_traits::ASTNodeKind SupportedKind, std::vector InnerMatchers) { assert(InnerMatchers.size() > 0 && "Array must not be empty."); assert(std::all_of(InnerMatchers.begin(), InnerMatchers.end(), - [&InnerMatchers](const DynTypedMatcher &M) { - return InnerMatchers[0].canConvertTo(M.SupportedKind); - }) && - "SupportedKind must be convertible to a common type!"); + [SupportedKind](const DynTypedMatcher &M) { + return M.canConvertTo(SupportedKind); + }) && + "InnerMatchers must be convertible to SupportedKind!"); - auto SupportedKind = InnerMatchers[0].SupportedKind; // We must relax the restrict kind here. // The different operators might deal differently with a mismatch. // Make it the same as SupportedKind, since that is the broadest type we are diff --git a/lib/ASTMatchers/Dynamic/VariantValue.cpp b/lib/ASTMatchers/Dynamic/VariantValue.cpp index 9d8be47005..8f3c70c1a8 100644 --- a/lib/ASTMatchers/Dynamic/VariantValue.cpp +++ b/lib/ASTMatchers/Dynamic/VariantValue.cpp @@ -72,7 +72,7 @@ VariantMatcher::MatcherOps::constructVariadicOperator( return llvm::None; DynMatchers.push_back(*Inner); } - return DynTypedMatcher::constructVariadic(Op, DynMatchers); + return DynTypedMatcher::constructVariadic(Op, NodeKind, DynMatchers); } VariantMatcher::Payload::~Payload() {} diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 54aed8f3fc..5ac28e5d3e 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -453,6 +453,16 @@ TEST(AllOf, AllOverloadsWork) { hasArgument(3, integerLiteral(equals(4))))))); } +TEST(ConstructVariadic, MismatchedTypes_Regression) { + EXPECT_TRUE( + matches("const int a = 0;", + internal::DynTypedMatcher::constructVariadic( + internal::DynTypedMatcher::VO_AnyOf, + ast_type_traits::ASTNodeKind::getFromNodeKind(), + {isConstQualified(), arrayType()}) + .convertTo())); +} + TEST(DeclarationMatcher, MatchAnyOf) { DeclarationMatcher YOrZDerivedFromX = recordDecl(anyOf(hasName("Y"), allOf(isDerivedFrom("X"), hasName("Z"))));