From: Jakub Dupak Date: Wed, 18 Oct 2023 20:38:30 +0000 (+0200) Subject: gccrs: borrowck: Dump: proper comma separation X-Git-Tag: basepoints/gcc-15~2057 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47bd9c95ceb545c6b4136a0f19872dfa7e880902;p=thirdparty%2Fgcc.git 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 --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc index cebed2485a31..4571b2fe8577 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 << "}"; }