FLANG
ClauseFinder.h
1//===-- Lower/OpenMP/ClauseFinder.h --------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
10//
11//===----------------------------------------------------------------------===//
12#ifndef FORTRAN_LOWER_CLAUSEFINDER_H
13#define FORTRAN_LOWER_CLAUSEFINDER_H
14
15#include "flang/Lower/OpenMP/Clauses.h"
16
17namespace Fortran {
18namespace lower {
19namespace omp {
20
22 using ClauseIterator = List<Clause>::const_iterator;
23
24public:
26 template <typename T>
27 static ClauseIterator findClause(ClauseIterator begin, ClauseIterator end) {
28 for (ClauseIterator it = begin; it != end; ++it) {
29 if (std::get_if<T>(&it->u))
30 return it;
31 }
32
33 return end;
34 }
35
39 template <typename T>
40 static const T *findUniqueClause(const List<Clause> &clauses,
41 const parser::CharBlock **source = nullptr) {
42 ClauseIterator it = findClause<T>(clauses.begin(), clauses.end());
43 if (it != clauses.end()) {
44 if (source)
45 *source = &it->source;
46 return &std::get<T>(it->u);
47 }
48 return nullptr;
49 }
50
53 template <typename T>
55 const List<Clause> &clauses,
56 std::function<void(const T &, const parser::CharBlock &source)>
57 callbackFn) {
58 bool found = false;
59 ClauseIterator nextIt, endIt = clauses.end();
60 for (ClauseIterator it = clauses.begin(); it != endIt; it = nextIt) {
61 nextIt = findClause<T>(it, endIt);
62
63 if (nextIt != endIt) {
64 callbackFn(std::get<T>(nextIt->u), nextIt->source);
65 found = true;
66 ++nextIt;
67 }
68 }
69 return found;
70 }
71};
72} // namespace omp
73} // namespace lower
74} // namespace Fortran
75
76#endif // FORTRAN_LOWER_CLAUSEFINDER_H
Definition ClauseFinder.h:21
static bool findRepeatableClause(const List< Clause > &clauses, std::function< void(const T &, const parser::CharBlock &source)> callbackFn)
Definition ClauseFinder.h:54
static const T * findUniqueClause(const List< Clause > &clauses, const parser::CharBlock **source=nullptr)
Definition ClauseFinder.h:40
static ClauseIterator findClause(ClauseIterator begin, ClauseIterator end)
Utility to find a clause within a range in the clause list.
Definition ClauseFinder.h:27
Definition char-block.h:28
Definition ParserActions.h:24
Definition bit-population-count.h:20