diff --git a/flang/include/flang/Semantics/dump-expr.h b/flang/include/flang/Semantics/dump-expr.h index 2f445429a10b5..9cc52b4da487d 100644 --- a/flang/include/flang/Semantics/dump-expr.h +++ b/flang/include/flang/Semantics/dump-expr.h @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -38,6 +39,43 @@ class DumpEvaluateExpr { } private: + template struct TypeOf { + static constexpr std::string_view get() { +#if defined(__GNUC__) +#define DUMP_EXPR_SHOW_TYPE + std::string_view v(__PRETTY_FUNCTION__); + // Extract the "xyz" from the "pretty function" string: + // "... [with T = xyz; std::string_view = ...]" + std::string_view front("with T = "); + std::string_view back("; std::string_view ="); + +#elif defined(_MSC_VER) +#define DUMP_EXPR_SHOW_TYPE + std::string_view v(__FUNCSIG__); + // Extract the "xyz" from the "pretty function" string: + // "...TypeOf::get(void)" + std::string_view front("TypeOf<"); + std::string_view back(">::get(void)"); + +#endif + +#if defined(DUMP_EXPR_SHOW_TYPE) +#undef DUMP_EXPR_SHOW_TYPE + if (auto fpos{v.find(front)}; fpos != v.npos) { + v.remove_prefix(fpos + front.size()); + if (auto bpos{v.find(back)}; bpos != v.npos) { + v.remove_suffix(v.size() - bpos); + return v; + } + } +#endif + + return ""; + } + + static constexpr std::string_view name{TypeOf::get()}; + }; + template void Show(const common::Indirection &x) { Show(x.value()); } @@ -76,7 +114,7 @@ class DumpEvaluateExpr { void Show(const evaluate::NullPointer &); template void Show(const evaluate::Constant &x) { if constexpr (T::category == common::TypeCategory::Derived) { - Indent("derived constant"); + Indent("derived constant "s + std::string(TypeOf::name)); for (const auto &map : x.values()) { for (const auto &pair : map) { Show(pair.second.value()); @@ -84,7 +122,7 @@ class DumpEvaluateExpr { } Outdent(); } else { - Print("constant"); + Print("constant "s + std::string(TypeOf::name)); } } void Show(const Symbol &symbol); @@ -102,7 +140,7 @@ class DumpEvaluateExpr { void Show(const evaluate::Substring &x); void Show(const evaluate::ComplexPart &x); template void Show(const evaluate::Designator &x) { - Indent("designator"); + Indent("designator "s + std::string(TypeOf::name)); Show(x.u); Outdent(); } @@ -117,7 +155,7 @@ class DumpEvaluateExpr { Outdent(); } template void Show(const evaluate::FunctionRef &x) { - Indent("function ref"); + Indent("function ref "s + std::string(TypeOf::name)); Show(x.proc()); Show(x.arguments()); Outdent(); @@ -127,14 +165,14 @@ class DumpEvaluateExpr { } template void Show(const evaluate::ArrayConstructorValues &x) { - Indent("array constructor value"); + Indent("array constructor value "s + std::string(TypeOf::name)); for (auto &v : x) { Show(v); } Outdent(); } template void Show(const evaluate::ImpliedDo &x) { - Indent("implied do"); + Indent("implied do "s + std::string(TypeOf::name)); Show(x.lower()); Show(x.upper()); Show(x.stride()); @@ -148,20 +186,20 @@ class DumpEvaluateExpr { void Show(const evaluate::StructureConstructor &x); template void Show(const evaluate::Operation &op) { - Indent("unary op"); + Indent("unary op "s + std::string(TypeOf::name)); Show(op.left()); Outdent(); } template void Show(const evaluate::Operation &op) { - Indent("binary op"); + Indent("binary op "s + std::string(TypeOf::name)); Show(op.left()); Show(op.right()); Outdent(); } void Show(const evaluate::Relational &x); template void Show(const evaluate::Expr &x) { - Indent("expr T"); + Indent("expr <" + std::string(TypeOf::name) + ">"); Show(x.u); Outdent(); } diff --git a/flang/lib/Semantics/dump-expr.cpp b/flang/lib/Semantics/dump-expr.cpp index aa0b4e0f03398..66cedab94bfb4 100644 --- a/flang/lib/Semantics/dump-expr.cpp +++ b/flang/lib/Semantics/dump-expr.cpp @@ -151,7 +151,7 @@ void DumpEvaluateExpr::Show(const evaluate::StructureConstructor &x) { } void DumpEvaluateExpr::Show(const evaluate::Relational &x) { - Indent("expr some type"); + Indent("relational some type"); Show(x.u); Outdent(); }