1//===-- Semantics/dump-expr.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/Semantics/dump-expr.h"
10
11namespace Fortran::semantics {
12
13static constexpr char whiteSpacePadding[]{
14 ">> "};
15static constexpr auto whiteSize{sizeof(whiteSpacePadding) - 1};
16
17inline const char *DumpEvaluateExpr::GetIndentString() const {
18 auto count{(level_ * 2 >= whiteSize) ? whiteSize : level_ * 2};
19 return whiteSpacePadding + whiteSize - count;
20}
21
22void DumpEvaluateExpr::Show(const evaluate::CoarrayRef &x) {
23 Indent("coarray ref");
24 Show(x.base());
25 Show(x.cosubscript());
26 Show(x.stat());
27 Show(x.team());
28 Outdent();
29}
30
31void DumpEvaluateExpr::Show(const evaluate::BOZLiteralConstant &) {
32 Print("BOZ literal constant");
33}
34
35void DumpEvaluateExpr::Show(const evaluate::NullPointer &) {
36 Print("null pointer");
37}
38
39void DumpEvaluateExpr::Show(const Symbol &symbol) {
40 const auto &ultimate{symbol.GetUltimate()};
41 Print("symbol: "s + symbol.name().ToString());
42 if (const auto *assoc{ultimate.detailsIf<AssocEntityDetails>()}) {
43 Indent("assoc details");
44 Show(assoc->expr());
45 Outdent();
46 }
47}
48
49void DumpEvaluateExpr::Show(const evaluate::StaticDataObject &) {
50 Print("static data object");
51}
52
53void DumpEvaluateExpr::Show(const evaluate::ImpliedDoIndex &) {
54 Print("implied do index");
55}
56
57void DumpEvaluateExpr::Show(const evaluate::BaseObject &x) {
58 Indent("base object");
59 Show(x.u);
60 Outdent();
61}
62void DumpEvaluateExpr::Show(const evaluate::Component &x) {
63 Indent("component");
64 Show(x.base());
65 Show(x.GetLastSymbol());
66 Outdent();
67}
68
69void DumpEvaluateExpr::Show(const evaluate::NamedEntity &x) {
70 Indent("named entity");
71 if (const auto *component{x.UnwrapComponent()}) {
72 Show(*component);
73 } else {
74 Show(x.GetFirstSymbol());
75 }
76 Outdent();
77}
78
79void DumpEvaluateExpr::Show(const evaluate::TypeParamInquiry &x) {
80 Indent("type inquiry");
81 Show(x.base());
82 Outdent();
83}
84
85void DumpEvaluateExpr::Show(const evaluate::Triplet &x) {
86 Indent("triplet");
87 Show(x.lower());
88 Show(x.upper());
89 Show(x.stride());
90 Outdent();
91}
92
93void DumpEvaluateExpr::Show(const evaluate::Subscript &x) {
94 Indent("subscript");
95 Show(x.u);
96 Outdent();
97}
98
99void DumpEvaluateExpr::Show(const evaluate::ArrayRef &x) {
100 Indent("array ref");
101 Show(x.base());
102 Show(x.subscript());
103 Outdent();
104}
105
106void DumpEvaluateExpr::Show(const evaluate::DataRef &x) {
107 Indent("data ref");
108 Show(x.u);
109 Outdent();
110}
111
112void DumpEvaluateExpr::Show(const evaluate::Substring &x) {
113 Indent("substring");
114 Show(x.parent());
115 Show(x.lower());
116 Show(x.upper());
117 Outdent();
118}
119
120void DumpEvaluateExpr::Show(const ParamValue &x) {
121 Indent("param value");
122 Show(x.GetExplicit());
123 Outdent();
124}
125
126void DumpEvaluateExpr::Show(
127 const DerivedTypeSpec::ParameterMapType::value_type &x) {
128 Show(x.second);
129}
130
131void DumpEvaluateExpr::Show(const DerivedTypeSpec &x) {
132 Indent("derived type spec");
133 for (auto &v : x.parameters()) {
134 Show(v);
135 }
136 Outdent();
137}
138
139void DumpEvaluateExpr::Show(
140 const evaluate::StructureConstructorValues::value_type &x) {
141 Show(x.second);
142}
143
144void DumpEvaluateExpr::Show(const evaluate::StructureConstructor &x) {
145 Indent("structure constructor");
146 Show(x.derivedTypeSpec());
147 for (auto &v : x) {
148 Show(v);
149 }
150 Outdent();
151}
152
153void DumpEvaluateExpr::Show(const evaluate::Relational<evaluate::SomeType> &x) {
154 Indent("expr some type");
155 Show(x.u);
156 Outdent();
157}
158
159void DumpEvaluateExpr::Show(const evaluate::ComplexPart &x) {
160 Indent("complex part");
161 Show(x.complex());
162 Outdent();
163}
164
165void DumpEvaluateExpr::Show(const evaluate::ActualArgument &x) {
166 Indent("actual argument");
167 if (const auto *symbol{x.GetAssumedTypeDummy()}) {
168 Show(*symbol);
169 } else {
170 Show(x.UnwrapExpr());
171 }
172 Outdent();
173}
174
175void DumpEvaluateExpr::Show(const evaluate::ProcedureDesignator &x) {
176 Indent("procedure designator");
177 if (const auto *component{x.GetComponent()}) {
178 Show(*component);
179 } else if (const auto *symbol{x.GetSymbol()}) {
180 Show(*symbol);
181 } else {
182 Show(DEREF(x.GetSpecificIntrinsic()));
183 }
184 Outdent();
185}
186
187void DumpEvaluateExpr::Show(const evaluate::SpecificIntrinsic &) {
188 Print("specific intrinsic");
189}
190
191void DumpEvaluateExpr::Show(const evaluate::DescriptorInquiry &x) {
192 Indent("descriptor inquiry");
193 Show(x.base());
194 Outdent();
195}
196
197void DumpEvaluateExpr::Print(llvm::Twine twine) {
198 outs_ << GetIndentString() << twine << '\n';
199}
200
201void DumpEvaluateExpr::Indent(llvm::StringRef s) {
202 Print(s + " {");
203 level_++;
204}
205
206void DumpEvaluateExpr::Outdent() {
207 if (level_) {
208 level_--;
209 }
210 Print("}");
211}
212
213//===----------------------------------------------------------------------===//
214// Boilerplate entry points that the debugger can find.
215//===----------------------------------------------------------------------===//
216
217void DumpEvExpr(const SomeExpr &x) { DumpEvaluateExpr::Dump(x); }
218
219void DumpEvExpr(
220 const evaluate::Expr<evaluate::Type<common::TypeCategory::Integer, 4>> &x) {
221 DumpEvaluateExpr::Dump(x);
222}
223
224void DumpEvExpr(
225 const evaluate::Expr<evaluate::Type<common::TypeCategory::Integer, 8>> &x) {
226 DumpEvaluateExpr::Dump(x);
227}
228
229void DumpEvExpr(const evaluate::ArrayRef &x) { DumpEvaluateExpr::Dump(x); }
230
231void DumpEvExpr(const evaluate::DataRef &x) { DumpEvaluateExpr::Dump(x); }
232
233void DumpEvExpr(const evaluate::Substring &x) { DumpEvaluateExpr::Dump(x); }
234
235void DumpEvExpr(
236 const evaluate::Designator<evaluate::Type<common::TypeCategory::Integer, 4>>
237 &x) {
238 DumpEvaluateExpr::Dump(x);
239}
240
241} // namespace Fortran::semantics
242

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of flang/lib/Semantics/dump-expr.cpp