diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-04-21 16:13:05 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-04-22 12:23:21 +0200 |
commit | bfe8ffef8668a0fc7be973f3b9de6e148019f94e (patch) | |
tree | cfccaf98f2046535b928ada05f0bc1e1b1059d53 | |
parent | 14dbac9a8bbc7f3cf37679e91ea56e449a64bde7 (diff) | |
download | gcc-bfe8ffef8668a0fc7be973f3b9de6e148019f94e.zip gcc-bfe8ffef8668a0fc7be973f3b9de6e148019f94e.tar.gz gcc-bfe8ffef8668a0fc7be973f3b9de6e148019f94e.tar.bz2 |
privacy: Add ModuleVisibility class
-rw-r--r-- | gcc/rust/privacy/rust-privacy-check.h | 1 | ||||
-rw-r--r-- | gcc/rust/privacy/rust-privacy-common.h | 61 | ||||
-rw-r--r-- | gcc/rust/util/rust-hir-map.h | 4 |
3 files changed, 65 insertions, 1 deletions
diff --git a/gcc/rust/privacy/rust-privacy-check.h b/gcc/rust/privacy/rust-privacy-check.h index 47fe7df..290b5ea 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 0000000..8f818fc --- /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 9bac328..600acc0 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 |