Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions flang/include/flang/Semantics/dump-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <memory>
#include <optional>
#include <string>
#include <variant>
#include <vector>

Expand All @@ -38,6 +39,39 @@ class DumpEvaluateExpr {
}

private:
template <typename T> struct TypeOf {
static constexpr std::string_view get() {
#if defined(__GNUC__)
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)
std::string_view v(__FUNCSIG__);
// Extract the "xyz" from the "pretty function" string:
// "... TypeOf<xyz>::get(void)"
std::string_view front(" TypeOf<");
std::string_view back(">::get(void)");

#else
return "";
#endif

if (auto fpos{v.find(front)}; fpos != v.npos) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not an issue for the #else case to contain code referencing variables that were not defined even if that is after the return ""; statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is fixed now.

v.remove_prefix(fpos + front.size());
if (auto bpos{v.find(back)}; bpos != v.npos) {
v.remove_suffix(v.size() - bpos);
return v;
}
}
return "";
}

static constexpr std::string_view name{TypeOf<T>::get()};
};

template <typename A, bool C> void Show(const common::Indirection<A, C> &x) {
Show(x.value());
}
Expand Down Expand Up @@ -76,15 +110,15 @@ class DumpEvaluateExpr {
void Show(const evaluate::NullPointer &);
template <typename T> void Show(const evaluate::Constant<T> &x) {
if constexpr (T::category == common::TypeCategory::Derived) {
Indent("derived constant");
Indent("derived constant "s + std::string(TypeOf<T>::name));
for (const auto &map : x.values()) {
for (const auto &pair : map) {
Show(pair.second.value());
}
}
Outdent();
} else {
Print("constant");
Print("constant "s + std::string(TypeOf<T>::name));
}
}
void Show(const Symbol &symbol);
Expand All @@ -102,7 +136,7 @@ class DumpEvaluateExpr {
void Show(const evaluate::Substring &x);
void Show(const evaluate::ComplexPart &x);
template <typename T> void Show(const evaluate::Designator<T> &x) {
Indent("designator");
Indent("designator "s + std::string(TypeOf<T>::name));
Show(x.u);
Outdent();
}
Expand All @@ -117,7 +151,7 @@ class DumpEvaluateExpr {
Outdent();
}
template <typename T> void Show(const evaluate::FunctionRef<T> &x) {
Indent("function ref");
Indent("function ref "s + std::string(TypeOf<T>::name));
Show(x.proc());
Show(x.arguments());
Outdent();
Expand All @@ -127,14 +161,14 @@ class DumpEvaluateExpr {
}
template <typename T>
void Show(const evaluate::ArrayConstructorValues<T> &x) {
Indent("array constructor value");
Indent("array constructor value "s + std::string(TypeOf<T>::name));
for (auto &v : x) {
Show(v);
}
Outdent();
}
template <typename T> void Show(const evaluate::ImpliedDo<T> &x) {
Indent("implied do");
Indent("implied do "s + std::string(TypeOf<T>::name));
Show(x.lower());
Show(x.upper());
Show(x.stride());
Expand All @@ -148,20 +182,20 @@ class DumpEvaluateExpr {
void Show(const evaluate::StructureConstructor &x);
template <typename D, typename R, typename O>
void Show(const evaluate::Operation<D, R, O> &op) {
Indent("unary op");
Indent("unary op "s + std::string(TypeOf<D>::name));
Show(op.left());
Outdent();
}
template <typename D, typename R, typename LO, typename RO>
void Show(const evaluate::Operation<D, R, LO, RO> &op) {
Indent("binary op");
Indent("binary op "s + std::string(TypeOf<D>::name));
Show(op.left());
Show(op.right());
Outdent();
}
void Show(const evaluate::Relational<evaluate::SomeType> &x);
template <typename T> void Show(const evaluate::Expr<T> &x) {
Indent("expr T");
Indent("expr <" + std::string(TypeOf<T>::name) + ">");
Show(x.u);
Outdent();
}
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Semantics/dump-expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void DumpEvaluateExpr::Show(const evaluate::StructureConstructor &x) {
}

void DumpEvaluateExpr::Show(const evaluate::Relational<evaluate::SomeType> &x) {
Indent("expr some type");
Indent("relational some type");
Show(x.u);
Outdent();
}
Expand Down
Loading