about summary refs log tree commit diff
path: root/src/rustdoc
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-03-20 14:54:18 -0700
committerBrian Anderson <banderson@mozilla.com>2012-03-20 14:54:40 -0700
commit1695148b5de9e801c4fbbbadce2f576e511c1cc2 (patch)
tree249f37b1c95d631fb5e0f2991794230eb38658f2 /src/rustdoc
parent651aeea96139d5f973410bc3405593c759c3f938 (diff)
downloadrust-1695148b5de9e801c4fbbbadce2f576e511c1cc2.tar.gz
rust-1695148b5de9e801c4fbbbadce2f576e511c1cc2.zip
rustdoc: Refactor reexport_pass
Diffstat (limited to 'src/rustdoc')
-rw-r--r--src/rustdoc/reexport_pass.rs116
1 files changed, 50 insertions, 66 deletions
diff --git a/src/rustdoc/reexport_pass.rs b/src/rustdoc/reexport_pass.rs
index 9f7af646fab..f711e7d7628 100644
--- a/src/rustdoc/reexport_pass.rs
+++ b/src/rustdoc/reexport_pass.rs
@@ -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);
-    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]
-                    }
-                }
-            }
-          }
-        }
+    for_each_reexported_impl(ctxt) {|_mod_id, i|
+        *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;
+    ret *defs;
 }
 
 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