public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] ast: dump: add emit_generic_params helper Date: Mon, 10 Oct 2022 07:33:38 +0000 (GMT) [thread overview] Message-ID: <20221010073338.50B753858293@sourceware.org> (raw) https://gcc.gnu.org/g:b64b889e15ee6119605f4d52b2b3703083b835cc commit b64b889e15ee6119605f4d52b2b3703083b835cc Author: David Faust <david.faust@oracle.com> Date: Thu Oct 6 11:32:02 2022 -0700 ast: dump: add emit_generic_params helper Diff: --- gcc/rust/ast/rust-ast-dump.cc | 30 +++++++++++++++++------------- gcc/rust/ast/rust-ast-dump.h | 3 +++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index bc4f7a3a5c1..b192556647c 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -140,6 +140,22 @@ Dump::emit_indented_string (const std::string &value, return stream << indentation << value << comment; } +void +Dump::emit_generic_params (std::vector<std::unique_ptr<GenericParam>> ¶ms) +{ + stream << "<"; + for (size_t i = 0; i < params.size (); i++) + { + auto ¶m = params.at (i); + param->accept_vis (*this); + + bool has_next = (i + 1) < params.size (); + if (has_next) + stream << ", "; + } + stream << ">"; +} + void Dump::visit (Token &tok) {} @@ -679,19 +695,7 @@ Dump::visit (Function &function) stream << "fn " << function.get_function_name (); if (function.has_generics ()) - { - stream << "<"; - for (size_t i = 0; i < function.get_generic_params ().size (); i++) - { - auto ¶m = function.get_generic_params ().at (i); - param->accept_vis (*this); - - bool has_next = (i + 1) < function.get_generic_params ().size (); - if (has_next) - stream << ", "; - } - stream << ">"; - } + emit_generic_params (function.get_generic_params ()); stream << '('; auto ¶ms = function.get_function_params (); diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index a5a99f2b03e..1bbefb38454 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -97,6 +97,9 @@ private: std::ostream &emit_indented_string (const std::string &value, const std::string &comment = ""); + // Emit formatted string for generic parameters. + void emit_generic_params (std::vector<std::unique_ptr<GenericParam>> ¶ms); + // rust-ast.h void visit (Token &tok); void visit (DelimTokenTree &delim_tok_tree);
reply other threads:[~2022-10-10 7:33 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=20221010073338.50B753858293@sourceware.org \ --to=tschwinge@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).