1616
1717#include < memory>
1818#include < optional>
19+ #include < string>
1920#include < variant>
2021#include < vector>
2122
@@ -38,6 +39,43 @@ class DumpEvaluateExpr {
3839 }
3940
4041private:
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+
4179 template <typename A, bool C> void Show (const common::Indirection<A, C> &x) {
4280 Show (x.value ());
4381 }
@@ -76,15 +114,15 @@ class DumpEvaluateExpr {
76114 void Show (const evaluate::NullPointer &);
77115 template <typename T> void Show (const evaluate::Constant<T> &x) {
78116 if constexpr (T::category == common::TypeCategory::Derived) {
79- Indent (" derived constant" );
117+ Indent (" derived constant " s + std::string (TypeOf<T>::name) );
80118 for (const auto &map : x.values ()) {
81119 for (const auto &pair : map) {
82120 Show (pair.second .value ());
83121 }
84122 }
85123 Outdent ();
86124 } else {
87- Print (" constant" );
125+ Print (" constant " s + std::string (TypeOf<T>::name) );
88126 }
89127 }
90128 void Show (const Symbol &symbol);
@@ -102,7 +140,7 @@ class DumpEvaluateExpr {
102140 void Show (const evaluate::Substring &x);
103141 void Show (const evaluate::ComplexPart &x);
104142 template <typename T> void Show (const evaluate::Designator<T> &x) {
105- Indent (" designator" );
143+ Indent (" designator " s + std::string (TypeOf<T>::name) );
106144 Show (x.u );
107145 Outdent ();
108146 }
@@ -117,7 +155,7 @@ class DumpEvaluateExpr {
117155 Outdent ();
118156 }
119157 template <typename T> void Show (const evaluate::FunctionRef<T> &x) {
120- Indent (" function ref" );
158+ Indent (" function ref " s + std::string (TypeOf<T>::name) );
121159 Show (x.proc ());
122160 Show (x.arguments ());
123161 Outdent ();
@@ -127,14 +165,14 @@ class DumpEvaluateExpr {
127165 }
128166 template <typename T>
129167 void Show (const evaluate::ArrayConstructorValues<T> &x) {
130- Indent (" array constructor value" );
168+ Indent (" array constructor value " s + std::string (TypeOf<T>::name) );
131169 for (auto &v : x) {
132170 Show (v);
133171 }
134172 Outdent ();
135173 }
136174 template <typename T> void Show (const evaluate::ImpliedDo<T> &x) {
137- Indent (" implied do" );
175+ Indent (" implied do " s + std::string (TypeOf<T>::name) );
138176 Show (x.lower ());
139177 Show (x.upper ());
140178 Show (x.stride ());
@@ -148,20 +186,20 @@ class DumpEvaluateExpr {
148186 void Show (const evaluate::StructureConstructor &x);
149187 template <typename D, typename R, typename O>
150188 void Show (const evaluate::Operation<D, R, O> &op) {
151- Indent (" unary op" );
189+ Indent (" unary op " s + std::string (TypeOf<D>::name) );
152190 Show (op.left ());
153191 Outdent ();
154192 }
155193 template <typename D, typename R, typename LO, typename RO>
156194 void Show (const evaluate::Operation<D, R, LO, RO> &op) {
157- Indent (" binary op" );
195+ Indent (" binary op " s + std::string (TypeOf<D>::name) );
158196 Show (op.left ());
159197 Show (op.right ());
160198 Outdent ();
161199 }
162200 void Show (const evaluate::Relational<evaluate::SomeType> &x);
163201 template <typename T> void Show (const evaluate::Expr<T> &x) {
164- Indent (" expr T " );
202+ Indent (" expr < " + std::string (TypeOf<T>::name) + " > " );
165203 Show (x.u );
166204 Outdent ();
167205 }
0 commit comments