Skip to content

Commit 40510a3

Browse files
committed
DumpEvExpr: show type
1 parent 7eec417 commit 40510a3

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

flang/include/flang/Semantics/dump-expr.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <memory>
1818
#include <optional>
19+
#include <string>
1920
#include <variant>
2021
#include <vector>
2122

@@ -38,6 +39,17 @@ class DumpEvaluateExpr {
3839
}
3940

4041
private:
42+
template <typename T>
43+
struct TypeOf {
44+
static constexpr std::string_view name{TypeOf<T>::get()};
45+
static constexpr std::string_view get() {
46+
std::string_view v(__PRETTY_FUNCTION__);
47+
v.remove_prefix(99); // Strip the part "... [with T = "
48+
v.remove_suffix(50); // Strip the ending "; string_view = ...]"
49+
return v;
50+
}
51+
};
52+
4153
template <typename A, bool C> void Show(const common::Indirection<A, C> &x) {
4254
Show(x.value());
4355
}
@@ -76,15 +88,15 @@ class DumpEvaluateExpr {
7688
void Show(const evaluate::NullPointer &);
7789
template <typename T> void Show(const evaluate::Constant<T> &x) {
7890
if constexpr (T::category == common::TypeCategory::Derived) {
79-
Indent("derived constant");
91+
Indent("derived constant "s + std::string(TypeOf<T>::name));
8092
for (const auto &map : x.values()) {
8193
for (const auto &pair : map) {
8294
Show(pair.second.value());
8395
}
8496
}
8597
Outdent();
8698
} else {
87-
Print("constant");
99+
Print("constant "s + std::string(TypeOf<T>::name));
88100
}
89101
}
90102
void Show(const Symbol &symbol);
@@ -102,7 +114,7 @@ class DumpEvaluateExpr {
102114
void Show(const evaluate::Substring &x);
103115
void Show(const evaluate::ComplexPart &x);
104116
template <typename T> void Show(const evaluate::Designator<T> &x) {
105-
Indent("designator");
117+
Indent("designator "s + std::string(TypeOf<T>::name));
106118
Show(x.u);
107119
Outdent();
108120
}
@@ -117,7 +129,7 @@ class DumpEvaluateExpr {
117129
Outdent();
118130
}
119131
template <typename T> void Show(const evaluate::FunctionRef<T> &x) {
120-
Indent("function ref");
132+
Indent("function ref "s + std::string(TypeOf<T>::name));
121133
Show(x.proc());
122134
Show(x.arguments());
123135
Outdent();
@@ -127,14 +139,14 @@ class DumpEvaluateExpr {
127139
}
128140
template <typename T>
129141
void Show(const evaluate::ArrayConstructorValues<T> &x) {
130-
Indent("array constructor value");
142+
Indent("array constructor value "s + std::string(TypeOf<T>::name));
131143
for (auto &v : x) {
132144
Show(v);
133145
}
134146
Outdent();
135147
}
136148
template <typename T> void Show(const evaluate::ImpliedDo<T> &x) {
137-
Indent("implied do");
149+
Indent("implied do "s + std::string(TypeOf<T>::name));
138150
Show(x.lower());
139151
Show(x.upper());
140152
Show(x.stride());
@@ -148,20 +160,20 @@ class DumpEvaluateExpr {
148160
void Show(const evaluate::StructureConstructor &x);
149161
template <typename D, typename R, typename O>
150162
void Show(const evaluate::Operation<D, R, O> &op) {
151-
Indent("unary op");
163+
Indent("unary op "s + std::string(TypeOf<D>::name));
152164
Show(op.left());
153165
Outdent();
154166
}
155167
template <typename D, typename R, typename LO, typename RO>
156168
void Show(const evaluate::Operation<D, R, LO, RO> &op) {
157-
Indent("binary op");
169+
Indent("binary op "s + std::string(TypeOf<D>::name));
158170
Show(op.left());
159171
Show(op.right());
160172
Outdent();
161173
}
162174
void Show(const evaluate::Relational<evaluate::SomeType> &x);
163175
template <typename T> void Show(const evaluate::Expr<T> &x) {
164-
Indent("expr T");
176+
Indent("expr <" + std::string(TypeOf<T>::name) + ">");
165177
Show(x.u);
166178
Outdent();
167179
}

flang/lib/Semantics/dump-expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void DumpEvaluateExpr::Show(const evaluate::StructureConstructor &x) {
151151
}
152152

153153
void DumpEvaluateExpr::Show(const evaluate::Relational<evaluate::SomeType> &x) {
154-
Indent("expr some type");
154+
Indent("relational some type");
155155
Show(x.u);
156156
Outdent();
157157
}

0 commit comments

Comments
 (0)