X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc%2Fmiddle%2Fprivacy.rs;h=f464ea58c2d196f76a103d5e493791b2dc9f6ec7;hb=e6f0f7d52d69d0c4f290ac32c6eebf92bbf6dd81;hp=d8efb5655aaabc2c62ade363978214b7183ecc9a;hpb=edac3ce6fba1063b01ca0e83841c762909d4df5d;p=rust.git diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index d8efb5655aa..f464ea58c2d 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -16,22 +16,55 @@ pub use self::ImportUse::*; pub use self::LastPrivate::*; -use util::nodemap::{DefIdSet, NodeSet}; +use middle::def_id::DefId; +use util::nodemap::{DefIdSet, FnvHashMap}; -use syntax::ast; +use std::hash::Hash; +use syntax::ast::NodeId; -/// A set of AST nodes exported by the crate. -pub type ExportedItems = NodeSet; +// Accessibility levels, sorted in ascending order +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +pub enum AccessLevel { + // Exported items + items participating in various kinds of public interfaces, + // but not directly nameable. For example, if function `fn f() -> T {...}` is + // public, then type `T` is exported. Its values can be obtained by other crates + // even if the type itseld is not nameable. + // FIXME: Mostly unimplemented. Only `type` aliases export items currently. + Reachable, + // Public items + items accessible to other crates with help of `pub use` reexports + Exported, + // Items accessible to other crates directly, without help of reexports + Public, +} + +// Accessibility levels for reachable HIR nodes +#[derive(Clone)] +pub struct AccessLevels { + pub map: FnvHashMap +} + +impl AccessLevels { + pub fn is_reachable(&self, id: Id) -> bool { + self.map.contains_key(&id) + } + pub fn is_exported(&self, id: Id) -> bool { + self.map.get(&id) >= Some(&AccessLevel::Exported) + } + pub fn is_public(&self, id: Id) -> bool { + self.map.get(&id) >= Some(&AccessLevel::Public) + } +} + +impl Default for AccessLevels { + fn default() -> Self { + AccessLevels { map: Default::default() } + } +} /// A set containing all exported definitions from external crates. /// The set does not contain any entries from local crates. pub type ExternalExports = DefIdSet; -/// A set of AST nodes that are fully public in the crate. This map is used for -/// documentation purposes (reexporting a private struct inlines the doc, -/// reexporting a public struct doesn't inline the doc). -pub type PublicItems = NodeSet; - #[derive(Copy, Clone, Debug)] pub enum LastPrivate { LastMod(PrivateDep), @@ -49,7 +82,7 @@ pub enum LastPrivate { #[derive(Copy, Clone, Debug)] pub enum PrivateDep { AllPublic, - DependsOn(ast::DefId), + DependsOn(DefId), } // How an import is used.