From d466ca087aae958d1c0a965c561be07d2cb3e7e2 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Sun, 6 Jun 2021 07:28:08 -0500 Subject: [PATCH] [Clang][OpenMP] Add static version of getSingleClause. NFC. The current method getSingleClause requires an instance of OMPExecutableDirective to be called. Introduce a static version taking a list of clauses as argument instead that can be used during parsing/Sema before any OMPExecutableDirective has been created. This is the same approach as taken for getClausesOfKind for getting more more than a single clause of a type which also has a method and static version. NFC patch extracted out of D99459 by request. Reviewed By: ABataev Differential Revision: https://reviews.llvm.org/D103665 --- clang/include/clang/AST/StmtOpenMP.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/AST/StmtOpenMP.h b/clang/include/clang/AST/StmtOpenMP.h index 4d6774c..67ba77a 100644 --- a/clang/include/clang/AST/StmtOpenMP.h +++ b/clang/include/clang/AST/StmtOpenMP.h @@ -460,17 +460,22 @@ public: /// directive). Returns nullptr if no clause of this kind is associated with /// the directive. template - const SpecificClause *getSingleClause() const { - auto Clauses = getClausesOfKind(); + static const SpecificClause *getSingleClause(ArrayRef Clauses) { + auto ClausesOfKind = getClausesOfKind(Clauses); - if (Clauses.begin() != Clauses.end()) { - assert(std::next(Clauses.begin()) == Clauses.end() && + if (ClausesOfKind.begin() != ClausesOfKind.end()) { + assert(std::next(ClausesOfKind.begin()) == ClausesOfKind.end() && "There are at least 2 clauses of the specified kind"); - return *Clauses.begin(); + return *ClausesOfKind.begin(); } return nullptr; } + template + const SpecificClause *getSingleClause() const { + return getSingleClause(clauses()); + } + /// Returns true if the current directive has one or more clauses of a /// specific kind. template -- 2.7.4