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

https://gcc.gnu.org/g:bfe8ffef8668a0fc7be973f3b9de6e148019f94e

commit bfe8ffef8668a0fc7be973f3b9de6e148019f94e
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date:   Thu Apr 21 16:13:05 2022 +0200

    privacy: Add ModuleVisibility class

Diff:
---
 gcc/rust/privacy/rust-privacy-check.h  |  1 -
 gcc/rust/privacy/rust-privacy-common.h | 61 ++++++++++++++++++++++++++++++++++
 gcc/rust/util/rust-hir-map.h           |  4 +++
 3 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/privacy/rust-privacy-check.h b/gcc/rust/privacy/rust-privacy-check.h
index 47fe7dfcf48..290b5eacb6c 100644
--- a/gcc/rust/privacy/rust-privacy-check.h
+++ b/gcc/rust/privacy/rust-privacy-check.h
@@ -19,7 +19,6 @@
 #ifndef RUST_PRIVACY_CHECK_H
 #define RUST_PRIVACY_CHECK_H
 
-#include "rust-hir-map.h"
 #include "rust-hir.h"
 #include "rust-hir-expr.h"
 #include "rust-hir-stmt.h"
diff --git a/gcc/rust/privacy/rust-privacy-common.h b/gcc/rust/privacy/rust-privacy-common.h
new file mode 100644
index 00000000000..8f818fc3d5c
--- /dev/null
+++ b/gcc/rust/privacy/rust-privacy-common.h
@@ -0,0 +1,61 @@
+// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-mapping-common.h"
+
+namespace Rust {
+namespace Privacy {
+
+/**
+ * Visibility class related specifically to DefIds. This class allows defining
+ * the visibility of an item with regard to a specific module.
+ */
+class ModuleVisibility
+{
+public:
+  enum Type
+  {
+    Private,
+    Public,
+    Restricted,
+  };
+
+  static ModuleVisibility create_restricted (DefId module_id)
+  {
+    return ModuleVisibility (Type::Restricted, module_id);
+  }
+
+  static ModuleVisibility create_public ()
+  {
+    return ModuleVisibility (Type::Public, UNKNOWN_DEFID);
+  }
+
+  Type get_kind () { return kind; }
+
+  DefId &get_module_id () { return module_id; }
+
+private:
+  ModuleVisibility (Type kind, DefId module_id)
+    : kind (kind), module_id (module_id)
+  {}
+
+  Type kind;
+  DefId module_id;
+};
+} // namespace Privacy
+} // namespace Rust
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index 9bac328ee0f..600acc027c9 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -26,6 +26,7 @@
 #include "rust-ast-full-decls.h"
 #include "rust-hir-full-decls.h"
 #include "rust-lang-item.h"
+#include "rust-privacy-common.h"
 
 namespace Rust {
 namespace Analysis {
@@ -353,6 +354,9 @@ private:
 
   // crate names
   std::map<CrateNum, std::string> crate_names;
+
+  // Low level visibility map for each DefId
+  std::map<DefId, Privacy::ModuleVisibility> visibility_map;
 };
 
 } // namespace Analysis


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

only message in thread, other threads:[~2022-06-08 12:35 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:35 [gcc/devel/rust/master] privacy: Add ModuleVisibility class 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).