From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 2D6013943409; Thu, 6 Oct 2022 20:05:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D6013943409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665086733; bh=r+7+gdnyLypJ2HJLQVl6YNG+cMFzKLCMt8ZNVOjngCo=; h=From:To:Subject:Date:From; b=szYIL/JdTRNfYeM6aCoF8ITohJf/vx0iZjRPOk28t2q2D/NO6mCBvOAu8inzNk6a4 6DMhe4+z5922Te2HP5nmna72BUY4Kq9xtjWidUjGj/9zISjzgl6ra3EP3/Sf7Kl57O ljggEMPQfAJeAG7RQ09ini/PnH5vgr8wWkinH1XM= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] dump: Emit visibility when dumping items X-Act-Checkin: gcc X-Git-Author: Arthur Cohen X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 960d9d289e47ecad67a32f6cf5ace0c11ab84191 X-Git-Newrev: 040c5f8933f58bcac170e0eb42f2c2279cab832b Message-Id: <20221006200533.2D6013943409@sourceware.org> Date: Thu, 6 Oct 2022 20:05:33 +0000 (GMT) List-Id: https://gcc.gnu.org/g:040c5f8933f58bcac170e0eb42f2c2279cab832b commit 040c5f8933f58bcac170e0eb42f2c2279cab832b Author: Arthur Cohen 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 &return_type, std::unique_ptr &block) { + // FIXME: This should format the ` fn ( [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 */