Split up DefCollector::root().

This commit is contained in:
Jeffrey Seyfried 2016-09-20 00:42:47 +00:00
parent 1ee64e44a9
commit 173d5b339f
2 changed files with 15 additions and 21 deletions

View File

@ -30,19 +30,12 @@ pub struct DefCollector<'ast> {
}
impl<'ast> DefCollector<'ast> {
pub fn root(definitions: &'ast mut Definitions) -> DefCollector<'ast> {
let mut collector = DefCollector {
pub fn new(definitions: &'ast mut Definitions) -> DefCollector<'ast> {
DefCollector {
hir_crate: None,
definitions: definitions,
parent_def: None,
};
let root = collector.create_def_with_parent(None, CRATE_NODE_ID, DefPathData::CrateRoot);
assert_eq!(root, CRATE_DEF_INDEX);
collector.parent_def = Some(root);
collector.create_def_with_parent(Some(CRATE_DEF_INDEX), DUMMY_NODE_ID, DefPathData::Misc);
collector
}
}
pub fn extend(parent_node: NodeId,
@ -50,11 +43,7 @@ impl<'ast> DefCollector<'ast> {
parent_def_id: DefId,
definitions: &'ast mut Definitions)
-> DefCollector<'ast> {
let mut collector = DefCollector {
hir_crate: None,
parent_def: None,
definitions: definitions,
};
let mut collector = DefCollector::new(definitions);
assert_eq!(parent_def_path.krate, parent_def_id.krate);
let root_path = Box::new(InlinedRootPath {
@ -68,17 +57,21 @@ impl<'ast> DefCollector<'ast> {
collector
}
pub fn collect_root(&mut self) {
let root = self.create_def_with_parent(None, CRATE_NODE_ID, DefPathData::CrateRoot);
assert_eq!(root, CRATE_DEF_INDEX);
self.parent_def = Some(root);
self.create_def_with_parent(Some(CRATE_DEF_INDEX), DUMMY_NODE_ID, DefPathData::Misc);
}
pub fn walk_item(&mut self, ii: &'ast InlinedItem, krate: &'ast hir::Crate) {
self.hir_crate = Some(krate);
ii.visit(self);
}
fn parent_def(&self) -> Option<DefIndex> {
self.parent_def
}
fn create_def(&mut self, node_id: NodeId, data: DefPathData) -> DefIndex {
let parent_def = self.parent_def();
let parent_def = self.parent_def;
debug!("create_def(node_id={:?}, data={:?}, parent_def={:?})", node_id, data, parent_def);
self.definitions.create_def_with_parent(parent_def, node_id, data)
}

View File

@ -225,7 +225,8 @@ impl Definitions {
}
pub fn collect(&mut self, krate: &ast::Crate) {
let mut def_collector = DefCollector::root(self);
let mut def_collector = DefCollector::new(self);
def_collector.collect_root();
visit::walk_crate(&mut def_collector, krate);
}