aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2022-09-27 15:50:39 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2022-09-28 11:54:59 +0200
commit040c5f8933f58bcac170e0eb42f2c2279cab832b (patch)
tree47013a7d4f0adb3a12ebf5667dfd97fb7e16d159
parent960d9d289e47ecad67a32f6cf5ace0c11ab84191 (diff)
downloadgcc-040c5f8933f58bcac170e0eb42f2c2279cab832b.zip
gcc-040c5f8933f58bcac170e0eb42f2c2279cab832b.tar.gz
gcc-040c5f8933f58bcac170e0eb42f2c2279cab832b.tar.bz2
dump: Emit visibility when dumping items
-rw-r--r--gcc/rust/ast/rust-ast-dump.cc44
-rw-r--r--gcc/rust/ast/rust-ast-dump.h9
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 8ad00b5..3d1b42d 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 a72bd4d..a5a99f2 100644
--- a/gcc/rust/ast/rust-ast-dump.h
+++ b/gcc/rust/ast/rust-ast-dump.h
@@ -80,9 +80,18 @@ private:
* Format a function's definition parameter
*/
void format_function_param (FunctionParam &param);
+
+ /**
+ * 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
*/
std::ostream &emit_indented_string (const std::string &value,