rustdoc: Refactor reexport_pass
This commit is contained in:
parent
651aeea961
commit
1695148b5d
@ -9,6 +9,7 @@ import rustc::util::common;
|
||||
import rustc::middle::ast_map;
|
||||
import rustc::syntax::visit;
|
||||
import rustc::syntax::codemap;
|
||||
import rustc::middle::resolve;
|
||||
|
||||
export mk_pass;
|
||||
|
||||
@ -98,50 +99,10 @@ fn build_reexport_def_set(srv: astsrv::srv) -> def_set {
|
||||
|
||||
fn find_reexport_impls(ctxt: astsrv::ctxt) -> [ast::def_id] {
|
||||
let defs = @mut [];
|
||||
let visitor = @{
|
||||
visit_mod: bind visit_mod(ctxt, defs, _, _, _)
|
||||
with *visit::default_simple_visitor()
|
||||
};
|
||||
let visitor = visit::mk_simple_visitor(visitor);
|
||||
visit::visit_crate(*ctxt.ast, (), visitor);
|
||||
for_each_reexported_impl(ctxt) {|_mod_id, i|
|
||||
*defs += [i.did]
|
||||
}
|
||||
ret *defs;
|
||||
|
||||
fn visit_mod(
|
||||
ctxt: astsrv::ctxt,
|
||||
defs: @mut [ast::def_id],
|
||||
m: ast::_mod,
|
||||
_sp: codemap::span,
|
||||
mod_id: ast::node_id
|
||||
) {
|
||||
let all_impls = all_impls(m);
|
||||
alt check ctxt.impl_map.get(mod_id) {
|
||||
list::cons(impls, @list::nil) {
|
||||
for i in *impls {
|
||||
// This impl is not an item in the current mod
|
||||
if !all_impls.contains_key(i.did) {
|
||||
// Ignore external impls because I don't
|
||||
// know what to do with them yet
|
||||
if i.did.crate == ast::local_crate {
|
||||
*defs += [i.did]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn all_impls(m: ast::_mod) -> map::set<ast::def_id> {
|
||||
let all_impls = common::new_def_hash();
|
||||
for item in m.items {
|
||||
alt item.node {
|
||||
ast::item_impl(_, _, _, _) {
|
||||
all_impls.insert(ast_util::local_def(item.id), ());
|
||||
}
|
||||
_ { }
|
||||
}
|
||||
}
|
||||
ret all_impls;
|
||||
}
|
||||
|
||||
fn build_reexport_def_map(
|
||||
@ -264,18 +225,46 @@ fn find_reexport_impl_docs(
|
||||
def_map: def_map
|
||||
) -> [(str, (str, doc::itemtag))] {
|
||||
let docs = @mut [];
|
||||
|
||||
for_each_reexported_impl(ctxt) {|mod_id, i|
|
||||
let path = alt ctxt.ast_map.find(mod_id) {
|
||||
some(ast_map::node_item(item, path)) {
|
||||
let path = ast_map::path_to_str(*path);
|
||||
if str::is_empty(path) {
|
||||
item.ident
|
||||
} else {
|
||||
path + "::" + item.ident
|
||||
}
|
||||
}
|
||||
_ {
|
||||
assert mod_id == ast::crate_node_id;
|
||||
""
|
||||
}
|
||||
};
|
||||
let ident = i.ident;
|
||||
let doc = alt check def_map.find(i.did) {
|
||||
some(doc) { doc }
|
||||
};
|
||||
*docs += [(path, (ident, doc))];
|
||||
}
|
||||
|
||||
ret *docs;
|
||||
}
|
||||
|
||||
fn for_each_reexported_impl(
|
||||
ctxt: astsrv::ctxt,
|
||||
f: fn@(ast::node_id, resolve::_impl)
|
||||
) {
|
||||
let visitor = @{
|
||||
visit_mod: bind visit_mod(ctxt, def_map, docs, _, _, _)
|
||||
visit_mod: bind visit_mod(ctxt, f, _, _, _)
|
||||
with *visit::default_simple_visitor()
|
||||
};
|
||||
let visitor = visit::mk_simple_visitor(visitor);
|
||||
visit::visit_crate(*ctxt.ast, (), visitor);
|
||||
ret *docs;
|
||||
|
||||
fn visit_mod(
|
||||
ctxt: astsrv::ctxt,
|
||||
def_map: def_map,
|
||||
docs: @mut [(str, (str, doc::itemtag))],
|
||||
f: fn@(ast::node_id, resolve::_impl),
|
||||
m: ast::_mod,
|
||||
_sp: codemap::span,
|
||||
mod_id: ast::node_id
|
||||
@ -289,25 +278,7 @@ fn find_reexport_impl_docs(
|
||||
// Ignore external impls because I don't
|
||||
// know what to do with them yet
|
||||
if i.did.crate == ast::local_crate {
|
||||
let path = alt ctxt.ast_map.find(mod_id) {
|
||||
some(ast_map::node_item(item, path)) {
|
||||
let path = ast_map::path_to_str(*path);
|
||||
if str::is_empty(path) {
|
||||
item.ident
|
||||
} else {
|
||||
path + "::" + item.ident
|
||||
}
|
||||
}
|
||||
_ {
|
||||
assert mod_id == ast::crate_node_id;
|
||||
""
|
||||
}
|
||||
};
|
||||
let ident = i.ident;
|
||||
let doc = alt check def_map.find(i.did) {
|
||||
some(doc) { doc }
|
||||
};
|
||||
*docs += [(path, (ident, doc))];
|
||||
f(mod_id, *i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -316,6 +287,19 @@ fn find_reexport_impl_docs(
|
||||
}
|
||||
}
|
||||
|
||||
fn all_impls(m: ast::_mod) -> map::set<ast::def_id> {
|
||||
let all_impls = common::new_def_hash();
|
||||
for item in m.items {
|
||||
alt item.node {
|
||||
ast::item_impl(_, _, _, _) {
|
||||
all_impls.insert(ast_util::local_def(item.id), ());
|
||||
}
|
||||
_ { }
|
||||
}
|
||||
}
|
||||
ret all_impls;
|
||||
}
|
||||
|
||||
fn merge_reexports(
|
||||
doc: doc::doc,
|
||||
path_map: path_map
|
||||
|
Loading…
x
Reference in New Issue
Block a user