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] dump: Emit visibility when dumping items Date: Thu, 6 Oct 2022 20:05:33 +0000 (GMT) [thread overview] Message-ID: <20221006200533.2D6013943409@sourceware.org> (raw) https://gcc.gnu.org/g:040c5f8933f58bcac170e0eb42f2c2279cab832b commit 040c5f8933f58bcac170e0eb42f2c2279cab832b Author: Arthur Cohen <arthur.cohen@embecosm.com> Date: Tue Sep 27 15:50:39 2022 +0200 dump: Emit visibility when dumping items Diff: --- gcc/rust/ast/rust-ast-dump.cc | 44 +++++++++++++++++++++++++++++++++++++++++-- gcc/rust/ast/rust-ast-dump.h | 9 +++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 8ad00b5929f..3d1b42d70e3 100644 --- a/gcc/rust/ast/rust-ast-dump.cc +++ b/gcc/rust/ast/rust-ast-dump.cc @@ -108,6 +108,31 @@ Dump::emit_attrib (const Attribute &attrib) stream << "]"; } +void +Dump::emit_visibility (const Visibility &vis) +{ + switch (vis.get_vis_type ()) + { + case Visibility::PUB: + stream << "pub "; + break; + case Visibility::PUB_CRATE: + stream << "pub(crate) "; + break; + case Visibility::PUB_SELF: + stream << "pub(self) "; + break; + case Visibility::PUB_SUPER: + stream << "pub(super) "; + break; + case Visibility::PUB_IN_PATH: + stream << "pub(in " << vis.get_path ().as_string () << ") "; + break; + case Visibility::PRIV: + break; + } +} + std::ostream & Dump::emit_indented_string (const std::string &value, const std::string &comment) @@ -522,7 +547,10 @@ Dump::visit (TypeBoundWhereClauseItem &item) void Dump::visit (Method &method) { - stream << indentation << "fn " << method.get_method_name () << '('; + // FIXME: Do we really need to dump the indentation here? + stream << indentation; + emit_visibility (method.get_visibility ()); + stream << "fn " << method.get_method_name () << '('; auto &self = method.get_self_param (); stream << self.as_string (); @@ -579,6 +607,7 @@ Dump::visit (UseDeclaration &use_decl) void Dump::visit (Function &function) { + emit_visibility (function.get_visibility ()); stream << "fn " << function.get_function_name (); if (function.has_generics ()) @@ -674,6 +703,7 @@ void Dump::format_function_common (std::unique_ptr<Type> &return_type, std::unique_ptr<BlockExpr> &block) { + // FIXME: This should format the `<vis> fn <name> ( [args] )` as well if (return_type) { stream << "-> "; @@ -714,7 +744,13 @@ void Dump::visit (TraitItemMethod &item) { auto method = item.get_trait_method_decl (); - stream << indentation << "fn " << method.get_identifier () << '('; + + // FIXME: Do we really need to dump the indentation here? + stream << indentation; + + // FIXME: Can we have visibility here? + // emit_visibility (method.get_visibility ()); + stream << "fn " << method.get_identifier () << '('; auto &self = method.get_self_param (); stream << self.as_string (); @@ -754,6 +790,8 @@ Dump::visit (Trait &trait) stream << "\n" << indentation; } + emit_visibility (trait.get_visibility ()); + stream << "trait " << trait.get_identifier (); // Traits actually have an implicit Self thrown at the start so we must expect @@ -834,6 +872,8 @@ Dump::visit (ExternalStaticItem &item) void Dump::visit (ExternalFunctionItem &function) { + emit_visibility (function.get_visibility ()); + stream << "fn " << function.get_identifier () << '('; for (size_t i = 0; i < function.get_function_params ().size (); i++) diff --git a/gcc/rust/ast/rust-ast-dump.h b/gcc/rust/ast/rust-ast-dump.h index a72bd4d1ff5..a5a99f2b03e 100644 --- a/gcc/rust/ast/rust-ast-dump.h +++ b/gcc/rust/ast/rust-ast-dump.h @@ -80,8 +80,17 @@ private: * Format a function's definition parameter */ void format_function_param (FunctionParam ¶m); + + /** + * Emit an attribute + */ void emit_attrib (const Attribute &attrib); + /** + * Emit an item's visibility + */ + void emit_visibility (const Visibility &vis); + /** * Emit an indented string with an optional extra comment */
next reply other threads:[~2022-10-06 20:05 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-10-06 20:05 Thomas Schwinge [this message] 2022-10-15 9:16 Thomas Schwinge
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=20221006200533.2D6013943409@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).