1//===-- ComponentPath.cpp -------------------------------------------------===//
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#include "flang/Lower/ComponentPath.h"
10
11static std::function<
12 Fortran::lower::IterationSpace(const Fortran::lower::IterationSpace &)>
13getIdentityFunc() {
14 return [](const Fortran::lower::IterationSpace &s) { return s; };
15}
16
17static std::function<
18 Fortran::lower::IterationSpace(const Fortran::lower::IterationSpace &)>
19getNullaryFunc() {
20 return [](const Fortran::lower::IterationSpace &s) {
21 Fortran::lower::IterationSpace newIters(s);
22 newIters.clearIndices();
23 return newIters;
24 };
25}
26
27void Fortran::lower::ComponentPath::clear() {
28 reversePath.clear();
29 substring = nullptr;
30 applied = false;
31 prefixComponents.clear();
32 trips.clear();
33 suffixComponents.clear();
34 pc = getIdentityFunc();
35}
36
37bool Fortran::lower::isRankedArrayAccess(const Fortran::evaluate::ArrayRef &x) {
38 for (const Fortran::evaluate::Subscript &sub : x.subscript()) {
39 if (std::visit(
40 Fortran::common::visitors{
41 [&](const Fortran::evaluate::Triplet &) { return true; },
42 [&](const Fortran::evaluate::IndirectSubscriptIntegerExpr &e) {
43 return e.value().Rank() > 0;
44 }},
45 sub.u))
46 return true;
47 }
48 return false;
49}
50
51void Fortran::lower::ComponentPath::resetPC() { pc = getIdentityFunc(); }
52
53void Fortran::lower::ComponentPath::setPC(bool isImplicit) {
54 pc = isImplicit ? getIdentityFunc() : getNullaryFunc();
55 resetExtendCoorRef();
56}
57
58Fortran::lower::ComponentPath::ExtendRefFunc
59Fortran::lower::ComponentPath::getExtendCoorRef() const {
60 return hasExtendCoorRef() ? *extendCoorRef : [](mlir::Value v) { return v; };
61}
62

source code of flang/lib/Lower/ComponentPath.cpp