diff options
author | Jakub Dupak <dev@jakubdupak.com> | 2023-10-18 22:38:30 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 19:09:27 +0100 |
commit | 47bd9c95ceb545c6b4136a0f19872dfa7e880902 (patch) | |
tree | 5400fc0ba89804e3e350bdd8050b9777588528c5 | |
parent | db6d4bac68e0f7babf93b3f26183e7f353869a9b (diff) | |
download | gcc-47bd9c95ceb545c6b4136a0f19872dfa7e880902.zip gcc-47bd9c95ceb545c6b4136a0f19872dfa7e880902.tar.gz gcc-47bd9c95ceb545c6b4136a0f19872dfa7e880902.tar.bz2 |
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>
-rw-r--r-- | gcc/rust/checks/errors/borrowck/rust-bir-dump.cc | 34 |
1 files 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 cebed24..4571b2f 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 << "}"; } |