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 
11 static std::function<
12     Fortran::lower::IterationSpace(const Fortran::lower::IterationSpace &)>
13 getIdentityFunc() {
14   return [](const Fortran::lower::IterationSpace &s) { return s; };
15 }
16 
17 static std::function<
18     Fortran::lower::IterationSpace(const Fortran::lower::IterationSpace &)>
19 getNullaryFunc() {
20   return [](const Fortran::lower::IterationSpace &s) {
21     Fortran::lower::IterationSpace newIters(s);
22     newIters.clearIndices();
23     return newIters;
24   };
25 }
26 
27 void 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 
37 bool 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 
51 void Fortran::lower::ComponentPath::setPC(bool isImplicit) {
52   pc = isImplicit ? getIdentityFunc() : getNullaryFunc();
53 }
54