public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] privacy: reachability: Add `maybe_get_vis_item` helper static function
@ 2022-06-08 12:29 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:29 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3bb4d746a037f9ebea8f91a32b8785223c4e2d33

commit 3bb4d746a037f9ebea8f91a32b8785223c4e2d33
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Tue Apr 12 15:25:37 2022 +0200

    privacy: reachability: Add `maybe_get_vis_item` helper static function

Diff:
---
 gcc/rust/privacy/rust-reachability.cc | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/gcc/rust/privacy/rust-reachability.cc b/gcc/rust/privacy/rust-reachability.cc
index 1876222e1b4..bbd04341b59 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 12:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:29 [gcc/devel/rust/master] privacy: reachability: Add `maybe_get_vis_item` helper static function 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).