public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Arthur Cohen <cohenarthur@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8082] gccrs: borrowck: Dump: proper comma separation Date: Tue, 16 Jan 2024 18:17:06 +0000 (GMT) [thread overview] Message-ID: <20240116181706.7BFF53860778@sourceware.org> (raw) 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 << "}"; }
reply other threads:[~2024-01-16 18:17 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240116181706.7BFF53860778@sourceware.org \ --to=cohenarthur@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).