16
16
17
17
#include < memory>
18
18
#include < optional>
19
+ #include < string>
19
20
#include < variant>
20
21
#include < vector>
21
22
@@ -38,6 +39,43 @@ class DumpEvaluateExpr {
38
39
}
39
40
40
41
private:
42
+ template <typename T> struct TypeOf {
43
+ static constexpr std::string_view get () {
44
+ #if defined(__GNUC__)
45
+ #define DUMP_EXPR_SHOW_TYPE
46
+ std::string_view v (__PRETTY_FUNCTION__);
47
+ // Extract the "xyz" from the "pretty function" string:
48
+ // "... [with T = xyz; std::string_view = ...]"
49
+ std::string_view front (" with T = " );
50
+ std::string_view back (" ; std::string_view =" );
51
+
52
+ #elif defined(_MSC_VER)
53
+ #define DUMP_EXPR_SHOW_TYPE
54
+ std::string_view v (__FUNCSIG__);
55
+ // Extract the "xyz" from the "pretty function" string:
56
+ // "...TypeOf<xyz>::get(void)"
57
+ std::string_view front (" TypeOf<" );
58
+ std::string_view back (" >::get(void)" );
59
+
60
+ #endif
61
+
62
+ #if defined(DUMP_EXPR_SHOW_TYPE)
63
+ #undef DUMP_EXPR_SHOW_TYPE
64
+ if (auto fpos{v.find (front)}; fpos != v.npos ) {
65
+ v.remove_prefix (fpos + front.size ());
66
+ if (auto bpos{v.find (back)}; bpos != v.npos ) {
67
+ v.remove_suffix (v.size () - bpos);
68
+ return v;
69
+ }
70
+ }
71
+ #endif
72
+
73
+ return " " ;
74
+ }
75
+
76
+ static constexpr std::string_view name{TypeOf<T>::get ()};
77
+ };
78
+
41
79
template <typename A, bool C> void Show (const common::Indirection<A, C> &x) {
42
80
Show (x.value ());
43
81
}
@@ -76,15 +114,15 @@ class DumpEvaluateExpr {
76
114
void Show (const evaluate::NullPointer &);
77
115
template <typename T> void Show (const evaluate::Constant<T> &x) {
78
116
if constexpr (T::category == common::TypeCategory::Derived) {
79
- Indent (" derived constant" );
117
+ Indent (" derived constant " s + std::string (TypeOf<T>::name) );
80
118
for (const auto &map : x.values ()) {
81
119
for (const auto &pair : map) {
82
120
Show (pair.second .value ());
83
121
}
84
122
}
85
123
Outdent ();
86
124
} else {
87
- Print (" constant" );
125
+ Print (" constant " s + std::string (TypeOf<T>::name) );
88
126
}
89
127
}
90
128
void Show (const Symbol &symbol);
@@ -102,7 +140,7 @@ class DumpEvaluateExpr {
102
140
void Show (const evaluate::Substring &x);
103
141
void Show (const evaluate::ComplexPart &x);
104
142
template <typename T> void Show (const evaluate::Designator<T> &x) {
105
- Indent (" designator" );
143
+ Indent (" designator " s + std::string (TypeOf<T>::name) );
106
144
Show (x.u );
107
145
Outdent ();
108
146
}
@@ -117,7 +155,7 @@ class DumpEvaluateExpr {
117
155
Outdent ();
118
156
}
119
157
template <typename T> void Show (const evaluate::FunctionRef<T> &x) {
120
- Indent (" function ref" );
158
+ Indent (" function ref " s + std::string (TypeOf<T>::name) );
121
159
Show (x.proc ());
122
160
Show (x.arguments ());
123
161
Outdent ();
@@ -127,14 +165,14 @@ class DumpEvaluateExpr {
127
165
}
128
166
template <typename T>
129
167
void Show (const evaluate::ArrayConstructorValues<T> &x) {
130
- Indent (" array constructor value" );
168
+ Indent (" array constructor value " s + std::string (TypeOf<T>::name) );
131
169
for (auto &v : x) {
132
170
Show (v);
133
171
}
134
172
Outdent ();
135
173
}
136
174
template <typename T> void Show (const evaluate::ImpliedDo<T> &x) {
137
- Indent (" implied do" );
175
+ Indent (" implied do " s + std::string (TypeOf<T>::name) );
138
176
Show (x.lower ());
139
177
Show (x.upper ());
140
178
Show (x.stride ());
@@ -148,20 +186,20 @@ class DumpEvaluateExpr {
148
186
void Show (const evaluate::StructureConstructor &x);
149
187
template <typename D, typename R, typename O>
150
188
void Show (const evaluate::Operation<D, R, O> &op) {
151
- Indent (" unary op" );
189
+ Indent (" unary op " s + std::string (TypeOf<D>::name) );
152
190
Show (op.left ());
153
191
Outdent ();
154
192
}
155
193
template <typename D, typename R, typename LO, typename RO>
156
194
void Show (const evaluate::Operation<D, R, LO, RO> &op) {
157
- Indent (" binary op" );
195
+ Indent (" binary op " s + std::string (TypeOf<D>::name) );
158
196
Show (op.left ());
159
197
Show (op.right ());
160
198
Outdent ();
161
199
}
162
200
void Show (const evaluate::Relational<evaluate::SomeType> &x);
163
201
template <typename T> void Show (const evaluate::Expr<T> &x) {
164
- Indent (" expr T " );
202
+ Indent (" expr < " + std::string (TypeOf<T>::name) + " > " );
165
203
Show (x.u );
166
204
Outdent ();
167
205
}
0 commit comments