[clang] 8f35471 - Change algorithms to return iterators
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 9 11:28:36 PST 2020
Author: Stephen Kelly
Date: 2020-11-09T19:12:38Z
New Revision: 8f354711ae92be1319190d8ede8992168a682f4e
URL: https://github.com/llvm/llvm-project/commit/8f354711ae92be1319190d8ede8992168a682f4e
DIFF: https://github.com/llvm/llvm-project/commit/8f354711ae92be1319190d8ede8992168a682f4e.diff
LOG: Change algorithms to return iterators
Make it possible to inspect the matched node, possibly to ignore it.
Differential Revision: https://reviews.llvm.org/D90983
Added:
Modified:
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/include/clang/ASTMatchers/ASTMatchersInternal.h
Removed:
################################################################################
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index fea7b83904e9e..f10baf5c3b5e5 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -768,7 +768,7 @@ AST_POLYMORPHIC_MATCHER_P(
ArrayRef<TemplateArgument> 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<CXXMethodDecl>,
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<Decl>,
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<CXXCtorInitializer>, 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<ParmVarDecl>,
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<Stmt>, InnerMatcher) {
const CompoundStmt *CS = CompoundStmtMatcher<NodeType>::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<UsingShadowDecl>, 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<OMPClause>, InnerMatcher) {
ArrayRef<OMPClause *> 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 bd81741109104..b6934c6349b71 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -636,33 +636,33 @@ inline Matcher<QualType> DynTypedMatcher::convertTo<QualType>() const {
/// Finds the first node in a range that matches the given matcher.
template <typename MatcherT, typename IteratorT>
-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 <typename MatcherT, typename IteratorT>
-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.
More information about the cfe-commits
mailing list