From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 3A56A382B25A; Wed, 8 Jun 2022 12:35:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A56A382B25A Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] privacy: Add ModuleVisibility class X-Act-Checkin: gcc X-Git-Author: Arthur Cohen X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 14dbac9a8bbc7f3cf37679e91ea56e449a64bde7 X-Git-Newrev: bfe8ffef8668a0fc7be973f3b9de6e148019f94e Message-Id: <20220608123500.3A56A382B25A@sourceware.org> Date: Wed, 8 Jun 2022 12:35:00 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jun 2022 12:35:00 -0000 https://gcc.gnu.org/g:bfe8ffef8668a0fc7be973f3b9de6e148019f94e commit bfe8ffef8668a0fc7be973f3b9de6e148019f94e Author: Arthur Cohen 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 +// . + +#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 crate_names; + + // Low level visibility map for each DefId + std::map visibility_map; }; } // namespace Analysis