From 897e78defb43cc831349b9b71dbebd19a0bca6f6 Mon Sep 17 00:00:00 2001 From: peter klausler Date: Thu, 5 Jul 2018 09:39:39 -0700 Subject: [PATCH] [flang] clean up dumping code Original-commit: flang-compiler/f18@29698883601984a16c48e4b5b3a1b314930ad47a Reviewed-on: https://github.com/flang-compiler/f18/pull/117 Tree-same-pre-rewrite: false --- flang/lib/evaluate/expression.cc | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/flang/lib/evaluate/expression.cc b/flang/lib/evaluate/expression.cc index 1927fbc..88b8b28 100644 --- a/flang/lib/evaluate/expression.cc +++ b/flang/lib/evaluate/expression.cc @@ -22,37 +22,41 @@ using namespace Fortran::parser::literals; namespace Fortran::evaluate { -template -std::ostream &DumpExprWithType(std::ostream &o, const A &x) { - using Ty = typename A::Result; - return x.Dump(o << '(' << Ty::Dump() << ' ') << ')'; +template +std::ostream &DumpExprWithType(std::ostream &o, const std::variant &u) { + std::visit( + [&](const auto &x) { + using Ty = typename std::remove_reference_t::Result; + x.Dump(o << '(' << Ty::Dump() << ' ') << ')'; + }, + u); + return o; } std::ostream &AnyIntegerExpr::Dump(std::ostream &o) const { - std::visit([&](const auto &x) { DumpExprWithType(o, x); }, u); - return o; + return DumpExprWithType(o, u); } std::ostream &AnyRealExpr::Dump(std::ostream &o) const { - std::visit([&](const auto &x) { DumpExprWithType(o, x); }, u); - return o; + return DumpExprWithType(o, u); } -std::ostream &AnyCharacterExpr::Dump(std::ostream &o) const { +template +std::ostream &DumpExpr(std::ostream &o, const std::variant &u) { std::visit([&](const auto &x) { x.Dump(o); }, u); return o; } -std::ostream &AnyComplexExpr::Dump(std::ostream &o) const { - std::visit([&](const auto &x) { x.Dump(o); }, u); - return o; +std::ostream &AnyCharacterExpr::Dump(std::ostream &o) const { + return DumpExpr(o, u); } -std::ostream &AnyExpr::Dump(std::ostream &o) const { - std::visit([&](const auto &x) { x.Dump(o); }, u); - return o; +std::ostream &AnyComplexExpr::Dump(std::ostream &o) const { + return DumpExpr(o, u); } +std::ostream &AnyExpr::Dump(std::ostream &o) const { return DumpExpr(o, u); } + template std::ostream &Unary::Dump(std::ostream &o, const char *opr) const { return x->Dump(o << opr) << ')'; -- 2.7.4