Line data Source code
1 : // Copyright (C) 2020-2026 Free Software Foundation, Inc.
2 :
3 : // This file is part of GCC.
4 :
5 : // GCC is free software; you can redistribute it and/or modify it under
6 : // the terms of the GNU General Public License as published by the Free
7 : // Software Foundation; either version 3, or (at your option) any later
8 : // version.
9 :
10 : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : // for more details.
14 :
15 : // You should have received a copy of the GNU General Public License
16 : // along with GCC; see the file COPYING3. If not see
17 : // <http://www.gnu.org/licenses/>.
18 :
19 : #include "rust-mapping-common.h"
20 :
21 : namespace Rust {
22 : namespace Privacy {
23 :
24 : /**
25 : * Visibility class related specifically to DefIds. This class allows defining
26 : * the visibility of an item with regard to a specific module.
27 : *
28 : * Items are either public throughout a crate, or restricted to a specific
29 : * module. Private items are simply restricted to the current module.
30 : */
31 : class ModuleVisibility
32 : {
33 : public:
34 : enum Type
35 : {
36 : Unknown,
37 : Public,
38 : Restricted,
39 : };
40 :
41 20694 : ModuleVisibility () : kind (Unknown), module_id (UNKNOWN_DEFID) {}
42 :
43 14385 : static ModuleVisibility create_restricted (DefId module_id)
44 : {
45 14385 : return ModuleVisibility (Type::Restricted, module_id);
46 : }
47 :
48 10430 : static ModuleVisibility create_public ()
49 : {
50 10430 : return ModuleVisibility (Type::Public, UNKNOWN_DEFID);
51 : }
52 :
53 7778 : Type get_kind () const { return kind; }
54 :
55 : const DefId &get_module_id () const { return module_id; }
56 27 : DefId &get_module_id () { return module_id; }
57 :
58 : private:
59 24815 : ModuleVisibility (Type kind, DefId module_id)
60 : : kind (kind), module_id (module_id)
61 : {}
62 :
63 : Type kind;
64 : DefId module_id;
65 : };
66 : } // namespace Privacy
67 : } // namespace Rust
|