aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/checks/errors/privacy/rust-privacy-common.h
blob: 1845da693fda67bd886dbc972b77584abd4a54ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (C) 2020-2025 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.
 *
 * Items are either public throughout a crate, or restricted to a specific
 * module. Private items are simply restricted to the current module.
 */
class ModuleVisibility
{
public:
  enum Type
  {
    Unknown,
    Public,
    Restricted,
  };

  ModuleVisibility () : kind (Unknown), module_id (UNKNOWN_DEFID) {}

  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 () const { return kind; }

  const DefId &get_module_id () const { return module_id; }
  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