public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8082] gccrs: borrowck: Dump: proper comma separation
@ 2024-01-16 18:17 Arthur Cohen
  0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 18:17 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:47bd9c95ceb545c6b4136a0f19872dfa7e880902

commit r14-8082-g47bd9c95ceb545c6b4136a0f19872dfa7e880902
Author: Jakub Dupak <dev@jakubdupak.com>
Date:   Wed Oct 18 22:38:30 2023 +0200

    gccrs: borrowck: Dump: proper comma separation
    
    gcc/rust/ChangeLog:
    
            * checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Use new print.
            (print_comma_separated): Comma separation print.
            (Dump::visit): Use new print.
    
    Signed-off-by: Jakub Dupak <dev@jakubdupak.com>

Diff:
---
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc | 34 +++++++++++++++++-------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index cebed2485a3..4571b2fe857 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -28,15 +28,31 @@ get_tyty_name (TyTy::BaseType *tyty)
   return "unknown";
 }
 
+template <typename T, typename FN>
 void
-Dump::go ()
+print_comma_separated (std::ostream &stream, const std::vector<T> &collection,
+		       FN printer)
 {
-  stream << "fn " << name << "(";
-  for (PlaceId arg : func.arguments)
+  if (collection.empty ())
+    return;
+  printer (collection[0]);
+  for (auto it = collection.begin () + 1; it != collection.end (); ++it)
     {
-      stream << "_" << get_place_name (arg) << ": "
-	     << get_tyty_name (place_db[arg].tyty) << ", ";
+      stream << ", ";
+      printer (*it);
     }
+}
+
+static constexpr bool FOLD_CFG = true;
+
+void
+Dump::go ()
+{
+  stream << "fn " << name << "(";
+  print_comma_separated (stream, func.arguments, [this] (PlaceId place_id) {
+    stream << "_" << get_place_name (place_id) << ": "
+	   << get_tyty_name (place_db[place_id].tyty);
+  });
   stream << ") -> " << get_tyty_name (place_db[RETURN_VALUE_PLACE].tyty)
 	 << " {\n";
 
@@ -182,11 +198,9 @@ void
 Dump::visit (InitializerExpr &expr)
 {
   stream << "{";
-  for (auto &place : expr.get_values ())
-    {
-      visit_move_place (place);
-      stream << ", ";
-    }
+  print_comma_separated (stream, expr.get_values (), [this] (PlaceId place_id) {
+    visit_move_place (place_id);
+  });
   stream << "}";
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-16 18:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 18:17 [gcc r14-8082] gccrs: borrowck: Dump: proper comma separation Arthur Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).