From: Stephen Kelly Date: Fri, 6 Nov 2020 16:05:16 +0000 (+0000) Subject: Change algorithms to return iterators X-Git-Tag: llvmorg-13-init~6657 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8f354711ae92be1319190d8ede8992168a682f4e;p=platform%2Fupstream%2Fllvm.git Change algorithms to return iterators Make it possible to inspect the matched node, possibly to ignore it. Differential Revision: https://reviews.llvm.org/D90983 --- diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index fea7b83..f10baf5 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -768,7 +768,7 @@ AST_POLYMORPHIC_MATCHER_P( ArrayRef List = internal::getTemplateSpecializationArgs(Node); return matchesFirstInRange(InnerMatcher, List.begin(), List.end(), Finder, - Builder); + Builder) != List.end(); } /// Causes all nested matchers to be matched with the specified traversal kind. @@ -3107,7 +3107,8 @@ AST_POLYMORPHIC_MATCHER_P_OVERLOAD( AST_MATCHER_P(CXXRecordDecl, hasMethod, internal::Matcher, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.method_begin(), - Node.method_end(), Finder, Builder); + Node.method_end(), Finder, + Builder) != Node.method_end(); } /// Matches the generated class of lambda expressions. @@ -3883,7 +3884,8 @@ AST_MATCHER_P(DeclRefExpr, throughUsingDecl, AST_MATCHER_P(OverloadExpr, hasAnyDeclaration, internal::Matcher, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.decls_begin(), - Node.decls_end(), Finder, Builder); + Node.decls_end(), Finder, + Builder) != Node.decls_end(); } /// Matches the Decl of a DeclStmt which has a single declaration. @@ -4153,7 +4155,8 @@ AST_MATCHER(CXXCatchStmt, isCatchAll) { AST_MATCHER_P(CXXConstructorDecl, hasAnyConstructorInitializer, internal::Matcher, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.init_begin(), - Node.init_end(), Finder, Builder); + Node.init_end(), Finder, + Builder) != Node.init_end(); } /// Matches the field declaration of a constructor initializer. @@ -4599,7 +4602,8 @@ AST_POLYMORPHIC_MATCHER_P(hasAnyParameter, internal::Matcher, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.param_begin(), - Node.param_end(), Finder, Builder); + Node.param_end(), Finder, + Builder) != Node.param_end(); } /// Matches \c FunctionDecls and \c FunctionProtoTypes that have a @@ -5040,7 +5044,8 @@ AST_POLYMORPHIC_MATCHER_P(hasAnySubstatement, internal::Matcher, InnerMatcher) { const CompoundStmt *CS = CompoundStmtMatcher::get(Node); return CS && matchesFirstInPointerRange(InnerMatcher, CS->body_begin(), - CS->body_end(), Finder, Builder); + CS->body_end(), Finder, + Builder) != CS->body_end(); } /// Checks that a compound statement contains a specific number of @@ -5882,7 +5887,8 @@ AST_POLYMORPHIC_MATCHER_P( AST_MATCHER_P(UsingDecl, hasAnyUsingShadowDecl, internal::Matcher, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.shadow_begin(), - Node.shadow_end(), Finder, Builder); + Node.shadow_end(), Finder, + Builder) != Node.shadow_end(); } /// Matches a using shadow declaration where the target declaration is @@ -7438,7 +7444,8 @@ AST_MATCHER_P(OMPExecutableDirective, hasAnyClause, internal::Matcher, InnerMatcher) { ArrayRef Clauses = Node.clauses(); return matchesFirstInPointerRange(InnerMatcher, Clauses.begin(), - Clauses.end(), Finder, Builder); + Clauses.end(), Finder, + Builder) != Clauses.end(); } /// Matches OpenMP ``default`` clause. diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h index bd81741..b6934c6 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -636,33 +636,33 @@ inline Matcher DynTypedMatcher::convertTo() const { /// Finds the first node in a range that matches the given matcher. template -bool matchesFirstInRange(const MatcherT &Matcher, IteratorT Start, - IteratorT End, ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) { +IteratorT matchesFirstInRange(const MatcherT &Matcher, IteratorT Start, + IteratorT End, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) { for (IteratorT I = Start; I != End; ++I) { BoundNodesTreeBuilder Result(*Builder); if (Matcher.matches(*I, Finder, &Result)) { *Builder = std::move(Result); - return true; + return I; } } - return false; + return End; } /// Finds the first node in a pointer range that matches the given /// matcher. template -bool matchesFirstInPointerRange(const MatcherT &Matcher, IteratorT Start, - IteratorT End, ASTMatchFinder *Finder, - BoundNodesTreeBuilder *Builder) { +IteratorT matchesFirstInPointerRange(const MatcherT &Matcher, IteratorT Start, + IteratorT End, ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) { for (IteratorT I = Start; I != End; ++I) { BoundNodesTreeBuilder Result(*Builder); if (Matcher.matches(**I, Finder, &Result)) { *Builder = std::move(Result); - return true; + return I; } } - return false; + return End; } // Metafunction to determine if type T has a member called getDecl.