public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] dump: Emit visibility when dumping items
@ 2022-10-15 9:16 Thomas Schwinge
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Schwinge @ 2022-10-15 9:16 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:85651630ad66b1e561453cdb28603eead88dd2ad
commit 85651630ad66b1e561453cdb28603eead88dd2ad
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 | 1 +
1 file changed, 1 insertion(+)
diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc
index 7cbdfa21fcb..24dc808707f 100644
--- a/gcc/rust/ast/rust-ast-dump.cc
+++ b/gcc/rust/ast/rust-ast-dump.cc
@@ -709,6 +709,7 @@ void
Dump::visit (Function &function)
{
emit_visibility (function.get_visibility ());
+
stream << "fn " << function.get_function_name ();
if (function.has_generics ())
^ permalink raw reply [flat|nested] 2+ messages in thread
* [gcc/devel/rust/master] dump: Emit visibility when dumping items
@ 2022-10-06 20:05 Thomas Schwinge
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Schwinge @ 2022-10-06 20:05 UTC (permalink / raw)
To: gcc-cvs
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
*/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-10-15 9:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-15 9:16 [gcc/devel/rust/master] dump: Emit visibility when dumping items Thomas Schwinge
-- strict thread matches above, loose matches on Subject: below --
2022-10-06 20:05 Thomas Schwinge
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).