[flang] clean up dumping code
authorpeter klausler <pklausler@nvidia.com>
Thu, 5 Jul 2018 16:39:39 +0000 (09:39 -0700)
committerpeter klausler <pklausler@nvidia.com>
Mon, 9 Jul 2018 23:25:58 +0000 (16:25 -0700)
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

index 1927fbc..88b8b28 100644 (file)
@@ -22,37 +22,41 @@ using namespace Fortran::parser::literals;
 
 namespace Fortran::evaluate {
 
-template<typename A>
-std::ostream &DumpExprWithType(std::ostream &o, const A &x) {
-  using Ty = typename A::Result;
-  return x.Dump(o << '(' << Ty::Dump() << ' ') << ')';
+template<typename... A>
+std::ostream &DumpExprWithType(std::ostream &o, const std::variant<A...> &u) {
+  std::visit(
+      [&](const auto &x) {
+        using Ty = typename std::remove_reference_t<decltype(x)>::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<typename... A>
+std::ostream &DumpExpr(std::ostream &o, const std::variant<A...> &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<typename A>
 std::ostream &Unary<A>::Dump(std::ostream &o, const char *opr) const {
   return x->Dump(o << opr) << ')';