diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-10-06 10:38:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-06 10:38:39 +0000 |
commit | 6e0ba5f8a58fc4fc70818162ca560c4b94df3688 (patch) | |
tree | 51e0c3726afb5ffb0e39a098001fa0588fc83da9 /gcc | |
parent | 40f8c333fe94906eedf792cfd1c74ea52e74caab (diff) | |
parent | 040c5f8933f58bcac170e0eb42f2c2279cab832b (diff) | |
download | gcc-6e0ba5f8a58fc4fc70818162ca560c4b94df3688.zip gcc-6e0ba5f8a58fc4fc70818162ca560c4b94df3688.tar.gz gcc-6e0ba5f8a58fc4fc70818162ca560c4b94df3688.tar.bz2 |
Merge #1547
1547: Dump item visibility r=CohenArthur a=CohenArthur
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-ast-dump.cc | 44 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast-dump.h | 9 | ||||
-rw-r--r-- | gcc/rust/ast/rust-item.h | 2 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower.cc | 2 |
4 files changed, 53 insertions, 4 deletions
diff --git a/gcc/rust/ast/rust-ast-dump.cc b/gcc/rust/ast/rust-ast-dump.cc index 48497b7..bc4f7a3 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) @@ -590,7 +615,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 (); @@ -647,6 +675,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 ()) @@ -742,6 +771,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 << "-> "; @@ -782,7 +812,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 (); @@ -822,6 +858,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 @@ -902,6 +940,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 ¶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 */ std::ostream &emit_indented_string (const std::string &value, diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 4987674..20f1b93 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -634,7 +634,7 @@ public: : vis_type (vis_type), in_path (std::move (in_path)) {} - VisType get_public_vis_type () const { return vis_type; } + VisType get_vis_type () const { return vis_type; } // Returns whether visibility is in an error state. bool is_error () const diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index 0bec8b0..fa3a83d 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -36,7 +36,7 @@ translate_visibility (const AST::Visibility &vis) if (vis.is_error ()) return Visibility::create_error (); - switch (vis.get_public_vis_type ()) + switch (vis.get_vis_type ()) { case AST::Visibility::PUB: return Visibility (Visibility::VisType::PUBLIC); |