Skip to content

Commit bfe8ffe

Browse files
committed
privacy: Add ModuleVisibility class
1 parent 14dbac9 commit bfe8ffe

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

gcc/rust/privacy/rust-privacy-check.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#ifndef RUST_PRIVACY_CHECK_H
2020
#define RUST_PRIVACY_CHECK_H
2121

22-
#include "rust-hir-map.h"
2322
#include "rust-hir.h"
2423
#include "rust-hir-expr.h"
2524
#include "rust-hir-stmt.h"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (C) 2020-2022 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+
class ModuleVisibility
29+
{
30+
public:
31+
enum Type
32+
{
33+
Private,
34+
Public,
35+
Restricted,
36+
};
37+
38+
static ModuleVisibility create_restricted (DefId module_id)
39+
{
40+
return ModuleVisibility (Type::Restricted, module_id);
41+
}
42+
43+
static ModuleVisibility create_public ()
44+
{
45+
return ModuleVisibility (Type::Public, UNKNOWN_DEFID);
46+
}
47+
48+
Type get_kind () { return kind; }
49+
50+
DefId &get_module_id () { return module_id; }
51+
52+
private:
53+
ModuleVisibility (Type kind, DefId module_id)
54+
: kind (kind), module_id (module_id)
55+
{}
56+
57+
Type kind;
58+
DefId module_id;
59+
};
60+
} // namespace Privacy
61+
} // namespace Rust

gcc/rust/util/rust-hir-map.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "rust-ast-full-decls.h"
2727
#include "rust-hir-full-decls.h"
2828
#include "rust-lang-item.h"
29+
#include "rust-privacy-common.h"
2930

3031
namespace Rust {
3132
namespace Analysis {
@@ -353,6 +354,9 @@ class Mappings
353354

354355
// crate names
355356
std::map<CrateNum, std::string> crate_names;
357+
358+
// Low level visibility map for each DefId
359+
std::map<DefId, Privacy::ModuleVisibility> visibility_map;
356360
};
357361

358362
} // namespace Analysis

0 commit comments

Comments
 (0)