aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-base.cc3
-rw-r--r--gcc/rust/backend/rust-compile-implitem.cc5
-rw-r--r--gcc/rust/hir/tree/rust-hir-full-test.cc16
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.h77
4 files changed, 24 insertions, 77 deletions
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index a705da7..602fc56 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -37,8 +37,7 @@ HIRCompileBase::setup_attributes_on_fndecl (
{
// if its the main fn or pub visibility mark its as DECL_PUBLIC
// please see https://github.com/Rust-GCC/gccrs/pull/137
- bool is_pub
- = visibility.get_vis_type () != HIR::Visibility::PublicVisType::NONE;
+ bool is_pub = visibility.get_vis_type () == HIR::Visibility::VisType::PUBLIC;
if (is_main_entry_point || is_pub)
{
TREE_PUBLIC (fndecl) = 1;
diff --git a/gcc/rust/backend/rust-compile-implitem.cc b/gcc/rust/backend/rust-compile-implitem.cc
index 8dc18d3..b44cdc9 100644
--- a/gcc/rust/backend/rust-compile-implitem.cc
+++ b/gcc/rust/backend/rust-compile-implitem.cc
@@ -84,9 +84,8 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func)
&canonical_path);
rust_assert (ok);
- // FIXME
- HIR::Visibility vis (HIR::Visibility::PublicVisType::NONE,
- AST::SimplePath::create_empty ());
+ // FIXME: Get from lowering the item's visibility instead
+ auto vis = HIR::Visibility::create_public ();
HIR::TraitFunctionDecl &function = func.get_decl ();
tree fndecl
= compile_function (ctx, function.get_function_name (),
diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc b/gcc/rust/hir/tree/rust-hir-full-test.cc
index 051e503..9b56086 100644
--- a/gcc/rust/hir/tree/rust-hir-full-test.cc
+++ b/gcc/rust/hir/tree/rust-hir-full-test.cc
@@ -118,18 +118,12 @@ Crate::as_string () const
std::string
Visibility::as_string () const
{
- switch (public_vis_type)
+ switch (vis_type)
{
- case NONE:
- return std::string ("pub");
- case CRATE:
- return std::string ("pub(crate)");
- case SELF:
- return std::string ("pub(self)");
- case SUPER:
- return std::string ("pub(super)");
- case IN_PATH:
- return std::string ("pub(in ") + in_path.as_string () + std::string (")");
+ case PRIVATE:
+ return std::string ("private");
+ case PUBLIC:
+ return std::string ("pub(in ") + path.as_string () + std::string (")");
default:
gcc_unreachable ();
}
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 6d65837..3d76180 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -553,91 +553,46 @@ public:
struct Visibility
{
public:
- enum PublicVisType
+ enum VisType
{
- NONE,
- CRATE,
- SELF,
- SUPER,
- IN_PATH
+ PRIVATE,
+ PUBLIC,
+ ERROR,
};
private:
- // if vis is public, one of these
- PublicVisType public_vis_type;
- // Only assigned if public_vis_type is IN_PATH
- AST::SimplePath in_path;
+ VisType vis_type;
+ AST::SimplePath path;
// should this store location info?
public:
// Creates a Visibility - TODO make constructor protected or private?
- Visibility (PublicVisType public_vis_type, AST::SimplePath in_path)
- : public_vis_type (public_vis_type), in_path (std::move (in_path))
+ Visibility (VisType vis_type,
+ AST::SimplePath path = AST::SimplePath::create_empty ())
+ : vis_type (vis_type), path (std::move (path))
{}
// Returns whether visibility is in an error state.
- bool is_error () const
- {
- return public_vis_type == IN_PATH && in_path.is_empty ();
- }
+ bool is_error () const { return vis_type == ERROR; }
// Creates an error visibility.
static Visibility create_error ()
{
- return Visibility (IN_PATH, AST::SimplePath::create_empty ());
+ return Visibility (ERROR, AST::SimplePath::create_empty ());
}
- // Unique pointer custom clone function
- /*std::unique_ptr<Visibility> clone_visibility() const {
- return std::unique_ptr<Visibility>(clone_visibility_impl());
- }*/
-
- /* TODO: think of a way to only allow valid Visibility states - polymorphism
- * is one idea but may be too resource-intensive. */
-
- // Creates a public visibility with no further features/arguments.
+ // Creates a public visibility.
+ // FIXME: Remove this function: We should not be calling it anymore and
+ // instead we should be using `translate_visibility`
static Visibility create_public ()
{
- return Visibility (NONE, AST::SimplePath::create_empty ());
- }
-
- // Creates a public visibility with crate-relative paths or whatever.
- static Visibility create_crate ()
- {
- return Visibility (CRATE, AST::SimplePath::create_empty ());
- }
-
- // Creates a public visibility with self-relative paths or whatever.
- static Visibility create_self ()
- {
- return Visibility (SELF, AST::SimplePath::create_empty ());
- }
-
- // Creates a public visibility with parent module-relative paths or
- // whatever.
- static Visibility create_super ()
- {
- return Visibility (SUPER, AST::SimplePath::create_empty ());
- }
-
- // Creates a public visibility with a given path or whatever.
- static Visibility create_in_path (AST::SimplePath in_path)
- {
- return Visibility (IN_PATH, std::move (in_path));
+ return Visibility (ERROR, AST::SimplePath::create_empty ());
}
- PublicVisType get_vis_type () const { return public_vis_type; }
+ VisType get_vis_type () const { return vis_type; }
std::string as_string () const;
-
-protected:
- // Clone function implementation - not currently virtual but may be if
- // polymorphism used
- /*virtual*/ Visibility *clone_visibility_impl () const
- {
- return new Visibility (*this);
- }
};
// Item that supports visibility - abstract base class