aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2022-04-12 15:25:37 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2022-04-12 15:25:37 +0200
commit3bb4d746a037f9ebea8f91a32b8785223c4e2d33 (patch)
tree837d3b7e3a3fcf7e10ee610e7fbdd9cd49c42999
parent23fc3ff7fe9405797d5961f7792540d3f487a287 (diff)
downloadgcc-3bb4d746a037f9ebea8f91a32b8785223c4e2d33.zip
gcc-3bb4d746a037f9ebea8f91a32b8785223c4e2d33.tar.gz
gcc-3bb4d746a037f9ebea8f91a32b8785223c4e2d33.tar.bz2
privacy: reachability: Add `maybe_get_vis_item` helper static function
-rw-r--r--gcc/rust/privacy/rust-reachability.cc24
1 files changed, 16 insertions, 8 deletions
diff --git a/gcc/rust/privacy/rust-reachability.cc b/gcc/rust/privacy/rust-reachability.cc
index 1876222..bbd0434 100644
--- a/gcc/rust/privacy/rust-reachability.cc
+++ b/gcc/rust/privacy/rust-reachability.cc
@@ -20,20 +20,28 @@
namespace Rust {
namespace Privacy {
+
+static HIR::VisItem *
+maybe_get_vis_item (std::unique_ptr<HIR::Item> &item)
+{
+ if (item->get_hir_kind () != HIR::VIS_ITEM)
+ return nullptr;
+
+ return static_cast<HIR::VisItem *> (item.get ());
+}
+
void
ReachabilityVisitor::visit (HIR::Module &mod)
{
for (auto &item : mod.get_items ())
{
- // FIXME: How do we refactor this pattern into something more ergonomic?
- // FIXME: Add helper functions
// FIXME: Is that what we want to do? Yes? Only visit the items with
// visibility?
- if (item->get_hir_kind () == HIR::VIS_ITEM)
- {
- auto vis_item = static_cast<HIR::VisItem *> (item.get ());
- vis_item->accept_vis (*this);
- }
+ //
+ // Imagine if we had `maybe_get_vis_item(item)?->accept_vis(*this)` ;)
+ auto vis_item = maybe_get_vis_item (item);
+ if (vis_item)
+ vis_item->accept_vis (*this);
}
}
@@ -60,7 +68,7 @@ ReachabilityVisitor::visit (HIR::StructStruct &struct_item)
// FIXME: This feels very wrong. Should we check for `has_visibility`
// beforehand? Is it just private otherwise? Should the `HIR::Visibility` also
// keep variants for private items?
- if (struct_item.get_visibility ().get_vis_type () == HIR::Visibility::NONE)
+ if (struct_item.get_visibility ().is_public ())
struct_reach = ReachLevel::Reachable;
struct_reach