[lldb-dap] Ensure the IO forwarding threads are managed by the DAP object lifecycle...
[llvm-project.git] / flang / lib / Parser / tools.cpp
blob6e5f1ed2fc66f035ca65c306a604408303149788
1 //===-- lib/Parser/tools.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 //===----------------------------------------------------------------------===//
9 #include "flang/Parser/tools.h"
11 namespace Fortran::parser {
13 const Name &GetLastName(const Name &x) { return x; }
15 const Name &GetLastName(const StructureComponent &x) {
16 return GetLastName(x.component);
19 const Name &GetLastName(const DataRef &x) {
20 return common::visit(
21 common::visitors{
22 [](const Name &name) -> const Name & { return name; },
23 [](const common::Indirection<StructureComponent> &sc)
24 -> const Name & { return GetLastName(sc.value()); },
25 [](const common::Indirection<ArrayElement> &sc) -> const Name & {
26 return GetLastName(sc.value().base);
28 [](const common::Indirection<CoindexedNamedObject> &ci)
29 -> const Name & { return GetLastName(ci.value().base); },
31 x.u);
34 const Name &GetLastName(const Substring &x) {
35 return GetLastName(std::get<DataRef>(x.t));
38 const Name &GetLastName(const Designator &x) {
39 return common::visit(
40 [](const auto &y) -> const Name & { return GetLastName(y); }, x.u);
43 const Name &GetLastName(const ProcComponentRef &x) {
44 return GetLastName(x.v.thing);
47 const Name &GetLastName(const ProcedureDesignator &x) {
48 return common::visit(
49 [](const auto &y) -> const Name & { return GetLastName(y); }, x.u);
52 const Name &GetLastName(const Call &x) {
53 return GetLastName(std::get<ProcedureDesignator>(x.t));
56 const Name &GetLastName(const FunctionReference &x) { return GetLastName(x.v); }
58 const Name &GetLastName(const Variable &x) {
59 return common::visit(
60 [](const auto &indirection) -> const Name & {
61 return GetLastName(indirection.value());
63 x.u);
66 const Name &GetLastName(const AllocateObject &x) {
67 return common::visit(
68 [](const auto &y) -> const Name & { return GetLastName(y); }, x.u);
71 const Name &GetFirstName(const Name &x) { return x; }
73 const Name &GetFirstName(const StructureComponent &x) {
74 return GetFirstName(x.base);
77 const Name &GetFirstName(const DataRef &x) {
78 return common::visit(
79 common::visitors{
80 [](const Name &name) -> const Name & { return name; },
81 [](const common::Indirection<StructureComponent> &sc)
82 -> const Name & { return GetFirstName(sc.value()); },
83 [](const common::Indirection<ArrayElement> &sc) -> const Name & {
84 return GetFirstName(sc.value().base);
86 [](const common::Indirection<CoindexedNamedObject> &ci)
87 -> const Name & { return GetFirstName(ci.value().base); },
89 x.u);
92 const Name &GetFirstName(const Substring &x) {
93 return GetFirstName(std::get<DataRef>(x.t));
96 const Name &GetFirstName(const Designator &x) {
97 return common::visit(
98 [](const auto &y) -> const Name & { return GetFirstName(y); }, x.u);
101 const Name &GetFirstName(const ProcComponentRef &x) {
102 return GetFirstName(x.v.thing);
105 const Name &GetFirstName(const ProcedureDesignator &x) {
106 return common::visit(
107 [](const auto &y) -> const Name & { return GetFirstName(y); }, x.u);
110 const Name &GetFirstName(const Call &x) {
111 return GetFirstName(std::get<ProcedureDesignator>(x.t));
114 const Name &GetFirstName(const FunctionReference &x) {
115 return GetFirstName(x.v);
118 const Name &GetFirstName(const Variable &x) {
119 return common::visit(
120 [](const auto &indirect) -> const Name & {
121 return GetFirstName(indirect.value());
123 x.u);
126 const Name &GetFirstName(const EntityDecl &x) {
127 return std::get<ObjectName>(x.t);
130 const CoindexedNamedObject *GetCoindexedNamedObject(const DataRef &base) {
131 return common::visit(
132 common::visitors{
133 [](const Name &) -> const CoindexedNamedObject * { return nullptr; },
134 [](const common::Indirection<CoindexedNamedObject> &x)
135 -> const CoindexedNamedObject * { return &x.value(); },
136 [](const auto &x) -> const CoindexedNamedObject * {
137 return GetCoindexedNamedObject(x.value().base);
140 base.u);
142 const CoindexedNamedObject *GetCoindexedNamedObject(
143 const Designator &designator) {
144 return common::visit(
145 common::visitors{
146 [](const DataRef &x) -> const CoindexedNamedObject * {
147 return GetCoindexedNamedObject(x);
149 [](const Substring &x) -> const CoindexedNamedObject * {
150 return GetCoindexedNamedObject(std::get<DataRef>(x.t));
153 designator.u);
155 const CoindexedNamedObject *GetCoindexedNamedObject(const Variable &variable) {
156 return common::visit(
157 common::visitors{
158 [](const common::Indirection<Designator> &designator)
159 -> const CoindexedNamedObject * {
160 return GetCoindexedNamedObject(designator.value());
162 [](const auto &) -> const CoindexedNamedObject * { return nullptr; },
164 variable.u);
166 const CoindexedNamedObject *GetCoindexedNamedObject(
167 const AllocateObject &allocateObject) {
168 return common::visit(
169 common::visitors{
170 [](const StructureComponent &x) -> const CoindexedNamedObject * {
171 return GetCoindexedNamedObject(x.base);
173 [](const auto &) -> const CoindexedNamedObject * { return nullptr; },
175 allocateObject.u);
177 } // namespace Fortran::parser