| 1 |
// Copyright (C) 2020-2025 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 |
#ifndef RUST_VISIBILITY_H |
| 20 |
#define RUST_VISIBILITY_H |
| 21 |
|
| 22 |
#include "rust-hir.h" |
| 23 |
#include "rust-hir-expr.h" |
| 24 |
#include "rust-hir-stmt.h" |
| 25 |
#include "rust-hir-item.h" |
| 26 |
#include "rust-hir-map.h" |
| 27 |
#include "rust-name-resolver.h" |
| 28 |
#include "rust-hir-visitor.h" |
| 29 |
|
| 30 |
namespace Rust { |
| 31 |
namespace Privacy { |
| 32 |
|
| 33 |
class VisibilityResolver : public HIR::HIRVisItemVisitor |
| 34 |
{ |
| 35 |
public: |
| 36 |
VisibilityResolver (Analysis::Mappings &mappings, |
| 37 |
Rust::Resolver::Resolver &resolver); |
| 38 |
|
| 39 |
/** |
| 40 |
* Perform visibility resolving on an entire crate |
| 41 |
*/ |
| 42 |
void go (HIR::Crate &crate); |
| 43 |
|
| 44 |
/** |
| 45 |
* Resolve a path to the module it refers |
| 46 |
*/ |
| 47 |
bool resolve_module_path (const HIR::SimplePath &restriction, |
| 48 |
DefId &to_resolve); |
| 49 |
|
| 50 |
/** |
| 51 |
* Resolve the visibility of an item to its ModuleVisibility. This function |
| 52 |
* emits errors if necessary. The contents of the to_resolve parameter will be |
| 53 |
* overwritten on success. |
| 54 |
* |
| 55 |
* @param visibility Visibility of the item to resolve |
| 56 |
* @param to_resolve ModuleVisibility reference to fill on success. |
| 57 |
* |
| 58 |
* @return false on error, true if the resolving was successful. |
| 59 |
*/ |
| 60 |
bool resolve_visibility (const HIR::Visibility &visibility, |
| 61 |
ModuleVisibility &to_resolve); |
| 62 |
|
| 63 |
/** |
| 64 |
* Resolve the visibility of an item and updates it. This is useful for |
| 65 |
* vis-items who need to be resolved but do not care about their module |
| 66 |
* visibility - const items, static items, etc. For items with an impact on |
| 67 |
* their children (enums, traits), this cannot be used |
| 68 |
*/ |
| 69 |
void resolve_and_update (const HIR::VisItem *item); |
| 70 |
|
| 71 |
/** |
| 72 |
* Get the DefId of the parent module we are currently visiting. |
| 73 |
* |
| 74 |
* @return UNKNOWN_DEFID if the module stack is empty, a valid `DefId` |
| 75 |
* otherwise |
| 76 |
*/ |
| 77 |
DefId peek_module (); |
| 78 |
|
| 79 |
virtual void visit (HIR::Module &mod); |
| 80 |
virtual void visit (HIR::ExternCrate &crate); |
| 81 |
virtual void visit (HIR::UseDeclaration &use_decl); |
| 82 |
virtual void visit (HIR::Function &func); |
| 83 |
virtual void visit (HIR::TypeAlias &type_alias); |
| 84 |
virtual void visit (HIR::StructStruct &struct_item); |
| 85 |
virtual void visit (HIR::TupleStruct &tuple_struct); |
| 86 |
virtual void visit (HIR::Enum &enum_item); |
| 87 |
virtual void visit (HIR::Union &union_item); |
| 88 |
virtual void visit (HIR::ConstantItem &const_item); |
| 89 |
virtual void visit (HIR::StaticItem &static_item); |
| 90 |
virtual void visit (HIR::Trait &trait); |
| 91 |
virtual void visit (HIR::ImplBlock &impl); |
| 92 |
virtual void visit (HIR::ExternBlock &block); |
| 93 |
|
| 94 |
private: |
| 95 |
Analysis::Mappings &mappings; |
| 96 |
Rust::Resolver::Resolver &resolver; |
| 97 |
DefId current_module; |
| 98 |
}; |
| 99 |
|
| 100 |
} // namespace Privacy |
| 101 |
} // namespace Rust |
| 102 |
|
| 103 |
#endif // !RUST_VISIBILITY_H |