From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id 7BFF53860778; Tue, 16 Jan 2024 18:17:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BFF53860778 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705429026; bh=eadvfvLpApZyKh+aj8sfTr+5yJlswMCDPI3wiok6qDE=; h=From:To:Subject:Date:From; b=l7ffjkn2gF9rR6CEaXMOmmJAr+W0ddJeK981BQA0qbXWqz7cnbtBSdmuJFsDZQDhH ++hENCh1FjG/6bqzJO7AsHzdi3KN65Ema5SUXyQ2rcBgdIQtRw3F4yZIUWi8VJFJUK ZC8NpTZawKODQTFVDVvd2lIxahn+QGEj8jl/bZLg= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8082] gccrs: borrowck: Dump: proper comma separation X-Act-Checkin: gcc X-Git-Author: Jakub Dupak X-Git-Refname: refs/heads/trunk X-Git-Oldrev: db6d4bac68e0f7babf93b3f26183e7f353869a9b X-Git-Newrev: 47bd9c95ceb545c6b4136a0f19872dfa7e880902 Message-Id: <20240116181706.7BFF53860778@sourceware.org> Date: Tue, 16 Jan 2024 18:17:06 +0000 (GMT) List-Id: https://gcc.gnu.org/g:47bd9c95ceb545c6b4136a0f19872dfa7e880902 commit r14-8082-g47bd9c95ceb545c6b4136a0f19872dfa7e880902 Author: Jakub Dupak 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 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 void -Dump::go () +print_comma_separated (std::ostream &stream, const std::vector &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 << "}"; }