28class DumpEvaluateExpr {
30 DumpEvaluateExpr() : outs_(llvm::errs()) {}
31 DumpEvaluateExpr(llvm::raw_ostream &str) : outs_(str) {}
33 template <
typename A>
static void Dump(
const A &x) {
34 DumpEvaluateExpr{}.Show(x);
37 static void Dump(llvm::raw_ostream &stream,
const A &x) {
38 DumpEvaluateExpr{stream}.Show(x);
42 template <
typename T>
struct TypeOf {
43 static constexpr std::string_view get() {
45#define DUMP_EXPR_SHOW_TYPE
46 std::string_view v(__PRETTY_FUNCTION__);
50 std::string_view front(
"[T = ");
51 std::string_view back(
"]");
53 std::string_view front(
"[with T = ");
54 std::string_view back(
"; std::string_view =");
57#elif defined(_MSC_VER)
58#define DUMP_EXPR_SHOW_TYPE
59 std::string_view v(__FUNCSIG__);
62 std::string_view front(
"TypeOf<");
63 std::string_view back(
">::get(void)");
67#if defined(DUMP_EXPR_SHOW_TYPE)
68#undef DUMP_EXPR_SHOW_TYPE
69 if (
auto fpos{v.find(front)}; fpos != v.npos) {
70 v.remove_prefix(fpos + front.size());
71 if (
auto bpos{v.find(back)}; bpos != v.npos) {
72 v.remove_suffix(v.size() - bpos);
80 static constexpr std::string_view name{TypeOf<T>::get()};
86 template <
typename A>
void Show(
const SymbolRef x) { Show(*x); }
87 template <
typename A>
void Show(
const std::unique_ptr<A> &x) {
90 template <
typename A>
void Show(
const std::shared_ptr<A> &x) {
93 template <
typename A>
void Show(
const A *x) {
100 template <
typename A>
void Show(
const std::optional<A> &x) {
107 template <
typename... A>
void Show(
const std::variant<A...> &u) {
108 common::visit([&](
const auto &v) { Show(v); }, u);
110 template <
typename A>
void Show(
const std::vector<A> &x) {
112 for (
const auto &v : x) {
117 void Show(
const evaluate::BOZLiteralConstant &);
120 if constexpr (T::category == common::TypeCategory::Derived) {
121 Indent(
"derived constant "s + std::string(TypeOf<T>::name));
122 for (
const auto &map : x.values()) {
123 for (
const auto &pair : map) {
124 Show(pair.second.value());
129 Print(
"constant "s + std::string(TypeOf<T>::name));
132 void Show(
const Symbol &symbol);
147 Indent(
"designator "s + std::string(TypeOf<T>::name));
156 Indent(
"procedure ref");
162 Indent(
"function ref "s + std::string(TypeOf<T>::name));
170 template <
typename T>
172 Indent(
"array constructor value "s + std::string(TypeOf<T>::name));
179 Indent(
"implied do "s + std::string(TypeOf<T>::name));
187 void Show(
const DerivedTypeSpec::ParameterMapType::value_type &x);
189 void Show(
const evaluate::StructureConstructorValues::value_type &x);
191 template <
typename D,
typename R,
typename O>
193 Indent(
"unary op "s + std::string(TypeOf<D>::name));
197 template <
typename D,
typename R,
typename LO,
typename RO>
199 Indent(
"binary op "s + std::string(TypeOf<D>::name));
206 Indent(
"expr <" + std::string(TypeOf<T>::name) +
">");
211 const char *GetIndentString()
const;
212 void Print(llvm::Twine s);
213 void Indent(llvm::StringRef s);
216 llvm::raw_ostream &outs_;