diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-04-14 10:50:02 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-04-14 10:50:02 +0200 |
commit | c4443ca3b2e1e0847bcb1a7d858d4bb0de16fdb3 (patch) | |
tree | afd6e0b6d0d38e2ab6b98287d9010d74bf80a84c /gcc | |
parent | 126f7aecdcdf1bf3044e0a0165324ed3ce258a78 (diff) | |
download | gcc-c4443ca3b2e1e0847bcb1a7d858d4bb0de16fdb3.zip gcc-c4443ca3b2e1e0847bcb1a7d858d4bb0de16fdb3.tar.gz gcc-c4443ca3b2e1e0847bcb1a7d858d4bb0de16fdb3.tar.bz2 |
privacy: reachability: Visit all variants of an Enum and their fields
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/privacy/rust-reachability.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/gcc/rust/privacy/rust-reachability.cc b/gcc/rust/privacy/rust-reachability.cc index 826a465..bf2480b 100644 --- a/gcc/rust/privacy/rust-reachability.cc +++ b/gcc/rust/privacy/rust-reachability.cc @@ -150,6 +150,38 @@ ReachabilityVisitor::visit (HIR::Enum &enum_item) enum_reach = ctx.update_reachability (enum_item.get_mappings (), enum_reach); visit_generic_predicates (enum_item.get_generic_params (), enum_reach); + + for (const auto &variant : enum_item.get_variants ()) + { + auto variant_reach + = ctx.update_reachability (variant->get_mappings (), enum_reach); + + switch (variant->get_enum_item_kind ()) + { + case HIR::EnumItem::Tuple: { + // Should we update the fields only if they are public? Similarly to + // what we do in the ReachabilityVisitor for HIR::TupleStruct? + auto tuple_variant + = static_cast<HIR::EnumItemTuple *> (variant.get ()); + for (const auto &field : tuple_variant->get_tuple_fields ()) + ctx.update_reachability (field.get_mappings (), variant_reach); + break; + } + case HIR::EnumItem::Struct: { + // Should we update the fields only if they are public? Similarly to + // what we do in the ReachabilityVisitor for HIR::StructStruct? + auto struct_variant + = static_cast<HIR::EnumItemStruct *> (variant.get ()); + for (const auto &field : struct_variant->get_struct_fields ()) + ctx.update_reachability (field.get_mappings (), variant_reach); + break; + } + // Nothing nested to visit in that case + case HIR::EnumItem::Named: + case HIR::EnumItem::Discriminant: + break; + } + } } void |