From 4b3dea1d38ca31d0270c576300c7b89bf76a84d7 Mon Sep 17 00:00:00 2001 From: peter klausler Date: Thu, 21 Jun 2018 12:54:46 -0700 Subject: [PATCH] [flang] Dump complex expressions Original-commit: flang-compiler/f18@da25b870d32bebc2b3055ede771efaf6701e8a3f Reviewed-on: https://github.com/flang-compiler/f18/pull/111 Tree-same-pre-rewrite: false --- flang/lib/evaluate/expression.cc | 31 ++++++++++++++++++++++++++----- flang/lib/evaluate/expression.h | 2 +- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/flang/lib/evaluate/expression.cc b/flang/lib/evaluate/expression.cc index 3b324fd..1414c5a 100644 --- a/flang/lib/evaluate/expression.cc +++ b/flang/lib/evaluate/expression.cc @@ -103,11 +103,32 @@ template std::ostream &RealExpr::Dump(std::ostream &o) const { template std::ostream &ComplexExpr::Dump(std::ostream &o) const { - std::visit(common::visitors{[&](const Constant &n) { - o << '(' << n.REAL().DumpHexadecimal() << ',' - << n.AIMAG().DumpHexadecimal() << ')'; - }, - [&](const auto &) { o << "TODO"; }}, + std::visit( + common::visitors{[&](const Constant &n) { + o << '(' << n.REAL().DumpHexadecimal() << ',' + << n.AIMAG().DumpHexadecimal() << ')'; + }, + [&](const Parentheses &p) { p.x->Dump(o << '(') << ')'; }, + [&](const Negate &n) { n.x->Dump(o << "(-") << ')'; }, + [&](const Add &a) { a.y->Dump(a.x->Dump(o << '(') << '+') << ')'; }, + [&](const Subtract &s) { + s.y->Dump(s.x->Dump(o << '(') << '-') << ')'; + }, + [&](const Multiply &m) { + m.y->Dump(m.x->Dump(o << '(') << '*') << ')'; + }, + [&](const Divide &d) { + d.y->Dump(d.x->Dump(o << '(') << '/') << ')'; + }, + [&](const Power &p) { + p.y->Dump(p.x->Dump(o << '(') << "**") << ')'; + }, + [&](const IntPower &p) { + p.y.Dump(p.x->Dump(o << '(') << "**") << ')'; + }, + [&](const CMPLX &c) { + c.im->Dump(c.re->Dump(o << '(') << ',') << ')'; + }}, u); return o; } diff --git a/flang/lib/evaluate/expression.h b/flang/lib/evaluate/expression.h index a2d1fb1..710396f 100644 --- a/flang/lib/evaluate/expression.h +++ b/flang/lib/evaluate/expression.h @@ -95,7 +95,7 @@ struct ConversionOperand { std::variant u; }; -template struct Expression < Type { +template struct Expression> { static constexpr Category category{Category::Integer}; static constexpr int kind{KIND}; using Result = Type; -- 2.7.4