Skip to content

Commit 36aad22

Browse files
committed
[flang] Move DumpEvaluateExpr from Lower to Semantics
Since evaluate::Expr can show up in the parse tree in the semantic analysis step, make it possible to dump its structure in the Semantics module. The Lower module depends on Semantics, so the code is still accessible in it.
1 parent 1e0e416 commit 36aad22

File tree

5 files changed

+51
-51
lines changed

5 files changed

+51
-51
lines changed

flang/include/flang/Lower/DumpEvaluateExpr.h renamed to flang/include/flang/Semantics/dump-expr.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
//===-- Lower/DumpEvaluateExpr.h --------------------------------*- C++ -*-===//
1+
//===-- Semantics/DumpEvaluateExpr.h ----------------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef FORTRAN_LOWER_DUMPEVALUATEEXPR_H
10-
#define FORTRAN_LOWER_DUMPEVALUATEEXPR_H
9+
#ifndef FORTRAN_SEMANTICS_DUMPEVALUATEEXPR_H
10+
#define FORTRAN_SEMANTICS_DUMPEVALUATEEXPR_H
1111

1212
#include "flang/Evaluate/tools.h"
13-
#include "flang/Lower/Support/Utils.h"
1413
#include "llvm/ADT/StringRef.h"
1514
#include "llvm/ADT/Twine.h"
1615

17-
namespace Fortran::lower {
16+
namespace Fortran::semantics {
1817

1918
/// Class to dump Fortran::evaluate::Expr trees out in a user readable way.
2019
///
@@ -207,6 +206,6 @@ LLVM_DUMP_METHOD void dumpEvExpr(
207206
const Fortran::evaluate::Designator<
208207
Fortran::evaluate::Type<Fortran::common::TypeCategory::Integer, 4>> &x);
209208

210-
} // namespace Fortran::lower
209+
} // namespace Fortran::semantics
211210

212-
#endif // FORTRAN_LOWER_DUMPEVALUATEEXPR_H
211+
#endif // FORTRAN_SEMANTICS_DUMPEVALUATEEXPR_H

flang/lib/Lower/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ add_flang_library(FortranLower
1616
ConvertType.cpp
1717
ConvertVariable.cpp
1818
CustomIntrinsicCall.cpp
19-
DumpEvaluateExpr.cpp
2019
HlfirIntrinsics.cpp
2120
HostAssociations.cpp
2221
IO.cpp

flang/lib/Lower/ConvertExpr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include "flang/Lower/ConvertType.h"
2828
#include "flang/Lower/ConvertVariable.h"
2929
#include "flang/Lower/CustomIntrinsicCall.h"
30-
#include "flang/Lower/DumpEvaluateExpr.h"
3130
#include "flang/Lower/Mangler.h"
3231
#include "flang/Lower/Runtime.h"
3332
#include "flang/Lower/Support/Utils.h"
@@ -47,6 +46,7 @@
4746
#include "flang/Optimizer/Dialect/FIROpsSupport.h"
4847
#include "flang/Optimizer/Support/FatalError.h"
4948
#include "flang/Runtime/support.h"
49+
#include "flang/Semantics/dump-expr.h"
5050
#include "flang/Semantics/expression.h"
5151
#include "flang/Semantics/symbol.h"
5252
#include "flang/Semantics/tools.h"
@@ -3925,7 +3925,7 @@ class ArrayExprLowering {
39253925
/// determine the actual number of iterations when slicing triples are
39263926
/// present. Lower these expressions here.
39273927
bool determineShapeWithSlice(const Fortran::lower::SomeExpr &lhs) {
3928-
LLVM_DEBUG(Fortran::lower::DumpEvaluateExpr::dump(
3928+
LLVM_DEBUG(Fortran::semantics::DumpEvaluateExpr::dump(
39293929
llvm::dbgs() << "determine shape of:\n", lhs));
39303930
// FIXME: We may not want to use ExtractDataRef here since it doesn't deal
39313931
// with substrings, etc.
@@ -5073,7 +5073,7 @@ class ArrayExprLowering {
50735073

50745074
template <typename A>
50755075
CC genarr(const Fortran::evaluate::Expr<A> &x) {
5076-
LLVM_DEBUG(Fortran::lower::DumpEvaluateExpr::dump(llvm::dbgs(), x));
5076+
LLVM_DEBUG(Fortran::semantics::DumpEvaluateExpr::dump(llvm::dbgs(), x));
50775077
if (isArray(x) || (explicitSpaceIsActive() && isLeftHandSide()) ||
50785078
isElementalProcWithArrayArgs(x))
50795079
return Fortran::common::visit([&](const auto &e) { return genarr(e); },

flang/lib/Semantics/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ add_flang_library(FortranSemantics
2929
compute-offsets.cpp
3030
data-to-inits.cpp
3131
definable.cpp
32+
dump-expr.cpp
3233
expression.cpp
3334
mod-file.cpp
3435
openmp-modifiers.cpp

flang/lib/Lower/DumpEvaluateExpr.cpp renamed to flang/lib/Semantics/dump-expr.cpp

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
//===-- Lower/DumpEvaluateExpr.cpp ----------------------------------------===//
1+
//===-- Semantics/DumpEvaluateExpr.cpp ------------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "flang/Lower/DumpEvaluateExpr.h"
9+
#include "flang/Semantics/dump-expr.h"
1010
#include <iostream>
1111

1212
static constexpr char whiteSpacePadding[] =
1313
">> ";
1414
static constexpr auto whiteSize = sizeof(whiteSpacePadding) - 1;
1515

16-
inline const char *Fortran::lower::DumpEvaluateExpr::getIndentString() const {
16+
inline const char *
17+
Fortran::semantics::DumpEvaluateExpr::getIndentString() const {
1718
auto count = (level * 2 >= whiteSize) ? whiteSize : level * 2;
1819
return whiteSpacePadding + whiteSize - count;
1920
}
2021

21-
void Fortran::lower::DumpEvaluateExpr::show(
22+
void Fortran::semantics::DumpEvaluateExpr::show(
2223
const Fortran::evaluate::CoarrayRef &x) {
2324
indent("coarray ref");
2425
show(x.base());
@@ -29,20 +30,20 @@ void Fortran::lower::DumpEvaluateExpr::show(
2930
outdent();
3031
}
3132

32-
void Fortran::lower::DumpEvaluateExpr::show(
33+
void Fortran::semantics::DumpEvaluateExpr::show(
3334
const Fortran::evaluate::BOZLiteralConstant &) {
3435
print("BOZ literal constant");
3536
}
3637

37-
void Fortran::lower::DumpEvaluateExpr::show(
38+
void Fortran::semantics::DumpEvaluateExpr::show(
3839
const Fortran::evaluate::NullPointer &) {
3940
print("null pointer");
4041
}
4142

42-
void Fortran::lower::DumpEvaluateExpr::show(
43+
void Fortran::semantics::DumpEvaluateExpr::show(
4344
const Fortran::semantics::Symbol &symbol) {
4445
const auto &ultimate{symbol.GetUltimate()};
45-
print("symbol: "s + std::string(toStringRef(symbol.name())));
46+
print("symbol: "s + symbol.name().ToString());
4647
if (const auto *assoc =
4748
ultimate.detailsIf<Fortran::semantics::AssocEntityDetails>()) {
4849
indent("assoc details");
@@ -51,31 +52,31 @@ void Fortran::lower::DumpEvaluateExpr::show(
5152
}
5253
}
5354

54-
void Fortran::lower::DumpEvaluateExpr::show(
55+
void Fortran::semantics::DumpEvaluateExpr::show(
5556
const Fortran::evaluate::StaticDataObject &) {
5657
print("static data object");
5758
}
5859

59-
void Fortran::lower::DumpEvaluateExpr::show(
60+
void Fortran::semantics::DumpEvaluateExpr::show(
6061
const Fortran::evaluate::ImpliedDoIndex &) {
6162
print("implied do index");
6263
}
6364

64-
void Fortran::lower::DumpEvaluateExpr::show(
65+
void Fortran::semantics::DumpEvaluateExpr::show(
6566
const Fortran::evaluate::BaseObject &x) {
6667
indent("base object");
6768
show(x.u);
6869
outdent();
6970
}
70-
void Fortran::lower::DumpEvaluateExpr::show(
71+
void Fortran::semantics::DumpEvaluateExpr::show(
7172
const Fortran::evaluate::Component &x) {
7273
indent("component");
7374
show(x.base());
7475
show(x.GetLastSymbol());
7576
outdent();
7677
}
7778

78-
void Fortran::lower::DumpEvaluateExpr::show(
79+
void Fortran::semantics::DumpEvaluateExpr::show(
7980
const Fortran::evaluate::NamedEntity &x) {
8081
indent("named entity");
8182
if (const auto *component = x.UnwrapComponent())
@@ -85,14 +86,14 @@ void Fortran::lower::DumpEvaluateExpr::show(
8586
outdent();
8687
}
8788

88-
void Fortran::lower::DumpEvaluateExpr::show(
89+
void Fortran::semantics::DumpEvaluateExpr::show(
8990
const Fortran::evaluate::TypeParamInquiry &x) {
9091
indent("type inquiry");
9192
show(x.base());
9293
outdent();
9394
}
9495

95-
void Fortran::lower::DumpEvaluateExpr::show(
96+
void Fortran::semantics::DumpEvaluateExpr::show(
9697
const Fortran::evaluate::Triplet &x) {
9798
indent("triplet");
9899
show(x.lower());
@@ -101,29 +102,29 @@ void Fortran::lower::DumpEvaluateExpr::show(
101102
outdent();
102103
}
103104

104-
void Fortran::lower::DumpEvaluateExpr::show(
105+
void Fortran::semantics::DumpEvaluateExpr::show(
105106
const Fortran::evaluate::Subscript &x) {
106107
indent("subscript");
107108
show(x.u);
108109
outdent();
109110
}
110111

111-
void Fortran::lower::DumpEvaluateExpr::show(
112+
void Fortran::semantics::DumpEvaluateExpr::show(
112113
const Fortran::evaluate::ArrayRef &x) {
113114
indent("array ref");
114115
show(x.base());
115116
show(x.subscript());
116117
outdent();
117118
}
118119

119-
void Fortran::lower::DumpEvaluateExpr::show(
120+
void Fortran::semantics::DumpEvaluateExpr::show(
120121
const Fortran::evaluate::DataRef &x) {
121122
indent("data ref");
122123
show(x.u);
123124
outdent();
124125
}
125126

126-
void Fortran::lower::DumpEvaluateExpr::show(
127+
void Fortran::semantics::DumpEvaluateExpr::show(
127128
const Fortran::evaluate::Substring &x) {
128129
indent("substring");
129130
show(x.parent());
@@ -132,33 +133,33 @@ void Fortran::lower::DumpEvaluateExpr::show(
132133
outdent();
133134
}
134135

135-
void Fortran::lower::DumpEvaluateExpr::show(
136+
void Fortran::semantics::DumpEvaluateExpr::show(
136137
const Fortran::semantics::ParamValue &x) {
137138
indent("param value");
138139
show(x.GetExplicit());
139140
outdent();
140141
}
141142

142-
void Fortran::lower::DumpEvaluateExpr::show(
143+
void Fortran::semantics::DumpEvaluateExpr::show(
143144
const Fortran::semantics::DerivedTypeSpec::ParameterMapType::value_type
144145
&x) {
145146
show(x.second);
146147
}
147148

148-
void Fortran::lower::DumpEvaluateExpr::show(
149+
void Fortran::semantics::DumpEvaluateExpr::show(
149150
const Fortran::semantics::DerivedTypeSpec &x) {
150151
indent("derived type spec");
151152
for (auto &v : x.parameters())
152153
show(v);
153154
outdent();
154155
}
155156

156-
void Fortran::lower::DumpEvaluateExpr::show(
157+
void Fortran::semantics::DumpEvaluateExpr::show(
157158
const Fortran::evaluate::StructureConstructorValues::value_type &x) {
158159
show(x.second);
159160
}
160161

161-
void Fortran::lower::DumpEvaluateExpr::show(
162+
void Fortran::semantics::DumpEvaluateExpr::show(
162163
const Fortran::evaluate::StructureConstructor &x) {
163164
indent("structure constructor");
164165
show(x.derivedTypeSpec());
@@ -167,21 +168,21 @@ void Fortran::lower::DumpEvaluateExpr::show(
167168
outdent();
168169
}
169170

170-
void Fortran::lower::DumpEvaluateExpr::show(
171+
void Fortran::semantics::DumpEvaluateExpr::show(
171172
const Fortran::evaluate::Relational<Fortran::evaluate::SomeType> &x) {
172173
indent("expr some type");
173174
show(x.u);
174175
outdent();
175176
}
176177

177-
void Fortran::lower::DumpEvaluateExpr::show(
178+
void Fortran::semantics::DumpEvaluateExpr::show(
178179
const Fortran::evaluate::ComplexPart &x) {
179180
indent("complex part");
180181
show(x.complex());
181182
outdent();
182183
}
183184

184-
void Fortran::lower::DumpEvaluateExpr::show(
185+
void Fortran::semantics::DumpEvaluateExpr::show(
185186
const Fortran::evaluate::ActualArgument &x) {
186187
indent("actual argument");
187188
if (const auto *symbol = x.GetAssumedTypeDummy())
@@ -191,7 +192,7 @@ void Fortran::lower::DumpEvaluateExpr::show(
191192
outdent();
192193
}
193194

194-
void Fortran::lower::DumpEvaluateExpr::show(
195+
void Fortran::semantics::DumpEvaluateExpr::show(
195196
const Fortran::evaluate::ProcedureDesignator &x) {
196197
indent("procedure designator");
197198
if (const auto *component = x.GetComponent())
@@ -203,28 +204,28 @@ void Fortran::lower::DumpEvaluateExpr::show(
203204
outdent();
204205
}
205206

206-
void Fortran::lower::DumpEvaluateExpr::show(
207+
void Fortran::semantics::DumpEvaluateExpr::show(
207208
const Fortran::evaluate::SpecificIntrinsic &) {
208209
print("specific intrinsic");
209210
}
210211

211-
void Fortran::lower::DumpEvaluateExpr::show(
212+
void Fortran::semantics::DumpEvaluateExpr::show(
212213
const Fortran::evaluate::DescriptorInquiry &x) {
213214
indent("descriptor inquiry");
214215
show(x.base());
215216
outdent();
216217
}
217218

218-
void Fortran::lower::DumpEvaluateExpr::print(llvm::Twine twine) {
219+
void Fortran::semantics::DumpEvaluateExpr::print(llvm::Twine twine) {
219220
outs << getIndentString() << twine << '\n';
220221
}
221222

222-
void Fortran::lower::DumpEvaluateExpr::indent(llvm::StringRef s) {
223+
void Fortran::semantics::DumpEvaluateExpr::indent(llvm::StringRef s) {
223224
print(s + " {");
224225
level++;
225226
}
226227

227-
void Fortran::lower::DumpEvaluateExpr::outdent() {
228+
void Fortran::semantics::DumpEvaluateExpr::outdent() {
228229
if (level)
229230
level--;
230231
print("}");
@@ -234,37 +235,37 @@ void Fortran::lower::DumpEvaluateExpr::outdent() {
234235
// Boilerplate entry points that the debugger can find.
235236
//===----------------------------------------------------------------------===//
236237

237-
void Fortran::lower::dumpEvExpr(const Fortran::semantics::SomeExpr &x) {
238+
void Fortran::semantics::dumpEvExpr(const Fortran::semantics::SomeExpr &x) {
238239
DumpEvaluateExpr::dump(x);
239240
}
240241

241-
void Fortran::lower::dumpEvExpr(
242+
void Fortran::semantics::dumpEvExpr(
242243
const Fortran::evaluate::Expr<
243244
Fortran::evaluate::Type<Fortran::common::TypeCategory::Integer, 4>>
244245
&x) {
245246
DumpEvaluateExpr::dump(x);
246247
}
247248

248-
void Fortran::lower::dumpEvExpr(
249+
void Fortran::semantics::dumpEvExpr(
249250
const Fortran::evaluate::Expr<
250251
Fortran::evaluate::Type<Fortran::common::TypeCategory::Integer, 8>>
251252
&x) {
252253
DumpEvaluateExpr::dump(x);
253254
}
254255

255-
void Fortran::lower::dumpEvExpr(const Fortran::evaluate::ArrayRef &x) {
256+
void Fortran::semantics::dumpEvExpr(const Fortran::evaluate::ArrayRef &x) {
256257
DumpEvaluateExpr::dump(x);
257258
}
258259

259-
void Fortran::lower::dumpEvExpr(const Fortran::evaluate::DataRef &x) {
260+
void Fortran::semantics::dumpEvExpr(const Fortran::evaluate::DataRef &x) {
260261
DumpEvaluateExpr::dump(x);
261262
}
262263

263-
void Fortran::lower::dumpEvExpr(const Fortran::evaluate::Substring &x) {
264+
void Fortran::semantics::dumpEvExpr(const Fortran::evaluate::Substring &x) {
264265
DumpEvaluateExpr::dump(x);
265266
}
266267

267-
void Fortran::lower::dumpEvExpr(
268+
void Fortran::semantics::dumpEvExpr(
268269
const Fortran::evaluate::Designator<
269270
Fortran::evaluate::Type<Fortran::common::TypeCategory::Integer, 4>>
270271
&x) {

0 commit comments

Comments
 (0)