forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump-expr.cpp
242 lines (201 loc) · 5.77 KB
/
dump-expr.cpp
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//===-- Semantics/dump-expr.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/Semantics/dump-expr.h"
namespace Fortran::semantics {
static constexpr char whiteSpacePadding[]{
">> "};
static constexpr auto whiteSize{sizeof(whiteSpacePadding) - 1};
inline const char *DumpEvaluateExpr::GetIndentString() const {
auto count{(level_ * 2 >= whiteSize) ? whiteSize : level_ * 2};
return whiteSpacePadding + whiteSize - count;
}
void DumpEvaluateExpr::Show(const evaluate::CoarrayRef &x) {
Indent("coarray ref");
Show(x.base());
Show(x.subscript());
Show(x.cosubscript());
Show(x.stat());
Show(x.team());
Outdent();
}
void DumpEvaluateExpr::Show(const evaluate::BOZLiteralConstant &) {
Print("BOZ literal constant");
}
void DumpEvaluateExpr::Show(const evaluate::NullPointer &) {
Print("null pointer");
}
void DumpEvaluateExpr::Show(const Symbol &symbol) {
const auto &ultimate{symbol.GetUltimate()};
Print("symbol: "s + symbol.name().ToString());
if (const auto *assoc{ultimate.detailsIf<AssocEntityDetails>()}) {
Indent("assoc details");
Show(assoc->expr());
Outdent();
}
}
void DumpEvaluateExpr::Show(const evaluate::StaticDataObject &) {
Print("static data object");
}
void DumpEvaluateExpr::Show(const evaluate::ImpliedDoIndex &) {
Print("implied do index");
}
void DumpEvaluateExpr::Show(const evaluate::BaseObject &x) {
Indent("base object");
Show(x.u);
Outdent();
}
void DumpEvaluateExpr::Show(const evaluate::Component &x) {
Indent("component");
Show(x.base());
Show(x.GetLastSymbol());
Outdent();
}
void DumpEvaluateExpr::Show(const evaluate::NamedEntity &x) {
Indent("named entity");
if (const auto *component{x.UnwrapComponent()}) {
Show(*component);
} else {
Show(x.GetFirstSymbol());
}
Outdent();
}
void DumpEvaluateExpr::Show(const evaluate::TypeParamInquiry &x) {
Indent("type inquiry");
Show(x.base());
Outdent();
}
void DumpEvaluateExpr::Show(const evaluate::Triplet &x) {
Indent("triplet");
Show(x.lower());
Show(x.upper());
Show(x.stride());
Outdent();
}
void DumpEvaluateExpr::Show(const evaluate::Subscript &x) {
Indent("subscript");
Show(x.u);
Outdent();
}
void DumpEvaluateExpr::Show(const evaluate::ArrayRef &x) {
Indent("array ref");
Show(x.base());
Show(x.subscript());
Outdent();
}
void DumpEvaluateExpr::Show(const evaluate::DataRef &x) {
Indent("data ref");
Show(x.u);
Outdent();
}
void DumpEvaluateExpr::Show(const evaluate::Substring &x) {
Indent("substring");
Show(x.parent());
Show(x.lower());
Show(x.upper());
Outdent();
}
void DumpEvaluateExpr::Show(const ParamValue &x) {
Indent("param value");
Show(x.GetExplicit());
Outdent();
}
void DumpEvaluateExpr::Show(
const DerivedTypeSpec::ParameterMapType::value_type &x) {
Show(x.second);
}
void DumpEvaluateExpr::Show(const DerivedTypeSpec &x) {
Indent("derived type spec");
for (auto &v : x.parameters()) {
Show(v);
}
Outdent();
}
void DumpEvaluateExpr::Show(
const evaluate::StructureConstructorValues::value_type &x) {
Show(x.second);
}
void DumpEvaluateExpr::Show(const evaluate::StructureConstructor &x) {
Indent("structure constructor");
Show(x.derivedTypeSpec());
for (auto &v : x) {
Show(v);
}
Outdent();
}
void DumpEvaluateExpr::Show(const evaluate::Relational<evaluate::SomeType> &x) {
Indent("expr some type");
Show(x.u);
Outdent();
}
void DumpEvaluateExpr::Show(const evaluate::ComplexPart &x) {
Indent("complex part");
Show(x.complex());
Outdent();
}
void DumpEvaluateExpr::Show(const evaluate::ActualArgument &x) {
Indent("actual argument");
if (const auto *symbol{x.GetAssumedTypeDummy()}) {
Show(*symbol);
} else {
Show(x.UnwrapExpr());
}
Outdent();
}
void DumpEvaluateExpr::Show(const evaluate::ProcedureDesignator &x) {
Indent("procedure designator");
if (const auto *component{x.GetComponent()}) {
Show(*component);
} else if (const auto *symbol{x.GetSymbol()}) {
Show(*symbol);
} else {
Show(DEREF(x.GetSpecificIntrinsic()));
}
Outdent();
}
void DumpEvaluateExpr::Show(const evaluate::SpecificIntrinsic &) {
Print("specific intrinsic");
}
void DumpEvaluateExpr::Show(const evaluate::DescriptorInquiry &x) {
Indent("descriptor inquiry");
Show(x.base());
Outdent();
}
void DumpEvaluateExpr::Print(llvm::Twine twine) {
outs_ << GetIndentString() << twine << '\n';
}
void DumpEvaluateExpr::Indent(llvm::StringRef s) {
Print(s + " {");
level_++;
}
void DumpEvaluateExpr::Outdent() {
if (level_) {
level_--;
}
Print("}");
}
//===----------------------------------------------------------------------===//
// Boilerplate entry points that the debugger can find.
//===----------------------------------------------------------------------===//
void DumpEvExpr(const SomeExpr &x) { DumpEvaluateExpr::Dump(x); }
void DumpEvExpr(
const evaluate::Expr<evaluate::Type<common::TypeCategory::Integer, 4>> &x) {
DumpEvaluateExpr::Dump(x);
}
void DumpEvExpr(
const evaluate::Expr<evaluate::Type<common::TypeCategory::Integer, 8>> &x) {
DumpEvaluateExpr::Dump(x);
}
void DumpEvExpr(const evaluate::ArrayRef &x) { DumpEvaluateExpr::Dump(x); }
void DumpEvExpr(const evaluate::DataRef &x) { DumpEvaluateExpr::Dump(x); }
void DumpEvExpr(const evaluate::Substring &x) { DumpEvaluateExpr::Dump(x); }
void DumpEvExpr(
const evaluate::Designator<evaluate::Type<common::TypeCategory::Integer, 4>>
&x) {
DumpEvaluateExpr::Dump(x);
}
} // namespace Fortran::semantics