Skip to content

Commit cae1e87

Browse files
committed
privacy: visibility: Handle modules properly
1 parent 7be856f commit cae1e87

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

gcc/rust/privacy/rust-visibility-resolver.cc

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ namespace Privacy {
2525

2626
VisibilityResolver::VisibilityResolver (Analysis::Mappings &mappings)
2727
: mappings (mappings)
28-
{
29-
// FIXME: Insert a top module (crate) inside the module_stack
30-
// FIXME: Insert the visibility of the crate in the mappings maybe?
31-
}
28+
{}
3229

3330
void
3431
VisibilityResolver::go (HIR::Crate &crate)
3532
{
33+
module_stack.push_back (crate.get_mappings ().get_defid ());
34+
mappings.insert_visibility (crate.get_mappings ().get_defid (),
35+
ModuleVisibility::create_public ());
36+
3637
for (auto &item : crate.items)
3738
{
3839
if (item->get_hir_kind () == HIR::Node::VIS_ITEM)
@@ -74,7 +75,20 @@ VisibilityResolver::peek_module ()
7475

7576
void
7677
VisibilityResolver::visit (HIR::Module &mod)
77-
{}
78+
{
79+
module_stack.push_back (mod.get_mappings ().get_defid ());
80+
81+
for (auto &item : mod.get_items ())
82+
{
83+
if (item->get_hir_kind () == HIR::Node::VIS_ITEM)
84+
{
85+
auto vis_item = static_cast<HIR::VisItem *> (item.get ());
86+
vis_item->accept_vis (*this);
87+
}
88+
}
89+
90+
module_stack.pop_back ();
91+
}
7892

7993
void
8094
VisibilityResolver::visit (HIR::ExternCrate &crate)

0 commit comments

Comments
 (0)