use NameBindings;
use ParentLink::{mod, ModuleParentLink, BlockParentLink};
use Resolver;
-use ReducedGraphParent::{mod, ModuleReducedGraphParent};
use RibKind::*;
use Shadowable;
use TypeNsDef;
impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
/// Constructs the reduced graph for the entire crate.
fn build_reduced_graph(self, krate: &ast::Crate) {
- let parent = ModuleReducedGraphParent(self.graph_root.get_module());
+ let parent = self.graph_root.get_module();
let mut visitor = BuildReducedGraphVisitor {
builder: self,
parent: parent
/// a block.
fn add_child(&self,
name: Name,
- reduced_graph_parent: ReducedGraphParent,
+ parent: Rc<Module>,
duplicate_checking_mode: DuplicateCheckingMode,
// For printing errors
sp: Span)
// child name directly. Otherwise, we create or reuse an anonymous
// module and add the child to that.
- let module_ = reduced_graph_parent.module();
-
- self.check_for_conflicts_between_external_crates_and_items(&*module_,
+ self.check_for_conflicts_between_external_crates_and_items(&*parent,
name,
sp);
// Add or reuse the child.
- let child = module_.children.borrow().get(&name).cloned();
+ let child = parent.children.borrow().get(&name).cloned();
match child {
None => {
let child = Rc::new(NameBindings::new());
- module_.children.borrow_mut().insert(name, child.clone());
+ parent.children.borrow_mut().insert(name, child.clone());
child
}
Some(child) => {
return false;
}
- fn get_parent_link(&mut self, parent: ReducedGraphParent, name: Name)
+ fn get_parent_link(&mut self, parent: Rc<Module>, name: Name)
-> ParentLink {
- match parent {
- ModuleReducedGraphParent(module_) => {
- return ModuleParentLink(module_.downgrade(), name);
- }
- }
+ ModuleParentLink(parent.downgrade(), name)
}
/// Constructs the reduced graph for one item.
fn build_reduced_graph_for_item(&mut self,
item: &Item,
- parent: ReducedGraphParent)
- -> ReducedGraphParent
+ parent: Rc<Module>)
+ -> Rc<Module>
{
let name = item.ident.name;
let sp = item.span;
item.vis == ast::Public,
sp);
- ModuleReducedGraphParent(name_bindings.get_module())
+ name_bindings.get_module()
}
ItemForeignMod(..) => parent,
self.build_reduced_graph_for_variant(
&**variant,
local_def(item.id),
- ModuleReducedGraphParent(name_bindings.get_module()));
+ name_bindings.get_module());
}
parent
}
}
Some(mod_name) => {
// Create the module and add all methods.
- let parent_opt = parent.module().children.borrow()
- .get(&mod_name).cloned();
+ let parent_opt = parent.children.borrow().get(&mod_name).cloned();
let new_parent = match parent_opt {
// It already exists
Some(ref child) if child.get_module_if_available()
.is_some() &&
(child.get_module().kind.get() == ImplModuleKind ||
child.get_module().kind.get() == TraitModuleKind) => {
- ModuleReducedGraphParent(child.get_module())
+ child.get_module()
}
Some(ref child) if child.get_module_if_available()
.is_some() &&
child.get_module().kind.get() ==
- EnumModuleKind => {
- ModuleReducedGraphParent(child.get_module())
- }
+ EnumModuleKind => child.get_module(),
// Create the module
_ => {
let name_bindings =
is_public,
sp);
- ModuleReducedGraphParent(
- name_bindings.get_module())
+ name_bindings.get_module()
}
};
false,
item.vis == ast::Public,
sp);
- let module_parent = ModuleReducedGraphParent(name_bindings.
- get_module());
+ let module_parent = name_bindings.get_module();
let def_id = local_def(item.id);
fn build_reduced_graph_for_variant(&mut self,
variant: &Variant,
item_id: DefId,
- parent: ReducedGraphParent) {
+ parent: Rc<Module>) {
let name = variant.node.name.name;
let is_exported = match variant.node.kind {
TupleVariantKind(_) => false,
/// Constructs the reduced graph for one 'view item'. View items consist
/// of imports and use directives.
- fn build_reduced_graph_for_view_item(&mut self, view_item: &ViewItem,
- parent: ReducedGraphParent) {
+ fn build_reduced_graph_for_view_item(&mut self, view_item: &ViewItem, parent: Rc<Module>) {
match view_item.node {
ViewItemUse(ref view_path) => {
// Extract and intern the module part of the path. For
};
// Build up the import directives.
- let module_ = parent.module();
let is_public = view_item.vis == ast::Public;
let shadowable =
view_item.attrs
let subclass = SingleImport(binding.name,
source_name);
- self.build_import_directive(&*module_,
+ self.build_import_directive(&*parent,
module_path,
subclass,
view_path.span,
}
};
self.build_import_directive(
- &*module_,
+ &*parent,
module_path,
SingleImport(name, name),
source_item.span,
}
}
ViewPathGlob(_, id) => {
- self.build_import_directive(&*module_,
+ self.build_import_directive(&*parent,
module_path,
GlobImport,
view_path.span,
.find_extern_mod_stmt_cnum(node_id).iter() {
let def_id = DefId { krate: crate_id, node: 0 };
self.external_exports.insert(def_id);
- let parent_link =
- ModuleParentLink(parent.module().downgrade(), name.name);
+ let parent_link = ModuleParentLink(parent.downgrade(), name.name);
let external_module = Rc::new(Module::new(parent_link,
Some(def_id),
NormalModuleKind,
debug!("(build reduced graph for item) found extern `{}`",
self.module_to_string(&*external_module));
self.check_for_conflicts_between_external_crates(
- &*parent.module(),
+ &*parent,
name.name,
view_item.span);
- parent.module().external_module_children.borrow_mut()
- .insert(name.name, external_module.clone());
+ parent.external_module_children.borrow_mut()
+ .insert(name.name, external_module.clone());
self.build_reduced_graph_for_external_crate(external_module);
}
}
/// Constructs the reduced graph for one foreign item.
fn build_reduced_graph_for_foreign_item<F>(&mut self,
foreign_item: &ForeignItem,
- parent: ReducedGraphParent,
+ parent: Rc<Module>,
f: F) where
F: FnOnce(&mut Resolver),
{
}
}
- fn build_reduced_graph_for_block(&mut self,
- block: &Block,
- parent: ReducedGraphParent)
- -> ReducedGraphParent
- {
+ fn build_reduced_graph_for_block(&mut self, block: &Block, parent: Rc<Module>) -> Rc<Module> {
if self.block_needs_anonymous_module(block) {
let block_id = block.id;
anonymous module for block {}",
block_id);
- let parent_module = parent.module();
let new_module = Rc::new(Module::new(
- BlockParentLink(parent_module.downgrade(), block_id),
+ BlockParentLink(parent.downgrade(), block_id),
None,
AnonymousModuleKind,
false,
false));
- parent_module.anonymous_children.borrow_mut()
- .insert(block_id, new_module.clone());
- ModuleReducedGraphParent(new_module)
+ parent.anonymous_children.borrow_mut().insert(block_id, new_module.clone());
+ new_module
} else {
parent
}
child_name_bindings: &NameBindings,
final_ident: &str,
name: Name,
- new_parent: ReducedGraphParent) {
+ new_parent: Rc<Module>) {
debug!("(building reduced graph for \
external crate) building external def, priv {}",
vis);
let is_public = vis == ast::Public;
let modifiers = if is_public { PUBLIC } else { DefModifiers::empty() } | IMPORTABLE;
- let is_exported = is_public && match new_parent {
- ModuleReducedGraphParent(ref module) => {
- match module.def_id.get() {
- None => true,
- Some(did) => self.external_exports.contains(&did)
- }
- }
+ let is_exported = is_public && match new_parent.def_id.get() {
+ None => true,
+ Some(did) => self.external_exports.contains(&did)
};
if is_exported {
self.external_exports.insert(def.def_id());
Some(ref def) => (modifiers & !IMPORTABLE) | (def.modifiers & IMPORTABLE),
None => modifiers
};
- if new_parent.module().kind.get() != NormalModuleKind {
+ if new_parent.kind.get() != NormalModuleKind {
modifiers = modifiers & !IMPORTABLE;
}
child_name_bindings.define_value(def, DUMMY_SP, modifiers);
_ => {
let child_name_bindings =
self.add_child(name,
- ModuleReducedGraphParent(root.clone()),
+ root.clone(),
OverwriteDuplicates,
DUMMY_SP);
&*child_name_bindings,
token::get_name(name).get(),
name,
- ModuleReducedGraphParent(root));
+ root);
}
}
}
let child_name_bindings =
self.add_child(
final_name,
- ModuleReducedGraphParent(root.clone()),
+ root.clone(),
OverwriteDuplicates,
DUMMY_SP);
}
Some(_) | None => {
let parent_link =
- self.get_parent_link(ModuleReducedGraphParent(root),
- final_name);
+ self.get_parent_link(root, final_name);
child_name_bindings.define_module(
parent_link,
Some(def),
}
// Add each static method to the module.
- let new_parent =
- ModuleReducedGraphParent(type_module);
+ let new_parent = type_module;
for method_info in methods.iter() {
let name = method_info.name;
debug!("(building reduced graph for \
struct BuildReducedGraphVisitor<'a, 'b:'a, 'tcx:'b> {
builder: GraphBuilder<'a, 'b, 'tcx>,
- parent: ReducedGraphParent
+ parent: Rc<Module>
}
impl<'a, 'b, 'v, 'tcx> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {