1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
//===-- lib/Parser/tools.cpp ----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "flang/Parser/tools.h"
namespace Fortran::parser {
const Name &GetLastName(const Name &x) { return x; }
const Name &GetLastName(const StructureComponent &x) {
return GetLastName(x.component);
}
const Name &GetLastName(const DataRef &x) {
return std::visit(
common::visitors{
[](const Name &name) -> const Name & { return name; },
[](const common::Indirection<StructureComponent> &sc)
-> const Name & { return GetLastName(sc.value()); },
[](const common::Indirection<ArrayElement> &sc) -> const Name & {
return GetLastName(sc.value().base);
},
[](const common::Indirection<CoindexedNamedObject> &ci)
-> const Name & { return GetLastName(ci.value().base); },
},
x.u);
}
const Name &GetLastName(const Substring &x) {
return GetLastName(std::get<DataRef>(x.t));
}
const Name &GetLastName(const Designator &x) {
return std::visit(
[](const auto &y) -> const Name & { return GetLastName(y); }, x.u);
}
const Name &GetLastName(const ProcComponentRef &x) {
return GetLastName(x.v.thing);
}
const Name &GetLastName(const ProcedureDesignator &x) {
return std::visit(
[](const auto &y) -> const Name & { return GetLastName(y); }, x.u);
}
const Name &GetLastName(const Call &x) {
return GetLastName(std::get<ProcedureDesignator>(x.t));
}
const Name &GetLastName(const FunctionReference &x) { return GetLastName(x.v); }
const Name &GetLastName(const Variable &x) {
return std::visit(
[](const auto &indirection) -> const Name & {
return GetLastName(indirection.value());
},
x.u);
}
const Name &GetLastName(const AllocateObject &x) {
return std::visit(
[](const auto &y) -> const Name & { return GetLastName(y); }, x.u);
}
const Name &GetFirstName(const Name &x) { return x; }
const Name &GetFirstName(const StructureComponent &x) {
return GetFirstName(x.base);
}
const Name &GetFirstName(const DataRef &x) {
return std::visit(
common::visitors{
[](const Name &name) -> const Name & { return name; },
[](const common::Indirection<StructureComponent> &sc)
-> const Name & { return GetFirstName(sc.value()); },
[](const common::Indirection<ArrayElement> &sc) -> const Name & {
return GetFirstName(sc.value().base);
},
[](const common::Indirection<CoindexedNamedObject> &ci)
-> const Name & { return GetFirstName(ci.value().base); },
},
x.u);
}
const Name &GetFirstName(const Substring &x) {
return GetFirstName(std::get<DataRef>(x.t));
}
const Name &GetFirstName(const Designator &x) {
return std::visit(
[](const auto &y) -> const Name & { return GetFirstName(y); }, x.u);
}
const Name &GetFirstName(const ProcComponentRef &x) {
return GetFirstName(x.v.thing);
}
const Name &GetFirstName(const ProcedureDesignator &x) {
return std::visit(
[](const auto &y) -> const Name & { return GetFirstName(y); }, x.u);
}
const Name &GetFirstName(const Call &x) {
return GetFirstName(std::get<ProcedureDesignator>(x.t));
}
const Name &GetFirstName(const FunctionReference &x) {
return GetFirstName(x.v);
}
const Name &GetFirstName(const Variable &x) {
return std::visit(
[](const auto &indirect) -> const Name & {
return GetFirstName(indirect.value());
},
x.u);
}
const CoindexedNamedObject *GetCoindexedNamedObject(const DataRef &base) {
return std::visit(
common::visitors{
[](const Name &) -> const CoindexedNamedObject * { return nullptr; },
[](const common::Indirection<CoindexedNamedObject> &x)
-> const CoindexedNamedObject * { return &x.value(); },
[](const auto &x) -> const CoindexedNamedObject * {
return GetCoindexedNamedObject(x.value().base);
},
},
base.u);
}
const CoindexedNamedObject *GetCoindexedNamedObject(
const Designator &designator) {
return std::visit(common::visitors{
[](const DataRef &x) -> const CoindexedNamedObject * {
return GetCoindexedNamedObject(x);
},
[](const Substring &x) -> const CoindexedNamedObject * {
return GetCoindexedNamedObject(
std::get<DataRef>(x.t));
},
},
designator.u);
}
const CoindexedNamedObject *GetCoindexedNamedObject(const Variable &variable) {
return std::visit(
common::visitors{
[](const common::Indirection<Designator> &designator)
-> const CoindexedNamedObject * {
return GetCoindexedNamedObject(designator.value());
},
[](const auto &) -> const CoindexedNamedObject * { return nullptr; },
},
variable.u);
}
const CoindexedNamedObject *GetCoindexedNamedObject(
const AllocateObject &allocateObject) {
return std::visit(
common::visitors{
[](const StructureComponent &x) -> const CoindexedNamedObject * {
return GetCoindexedNamedObject(x.base);
},
[](const auto &) -> const CoindexedNamedObject * { return nullptr; },
},
allocateObject.u);
}
} // namespace Fortran::parser
|