From f8742b476f136e002627c68822d207315d9c9558 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 2 Mar 2012 18:33:25 -0800 Subject: [PATCH] rustdoc: Introduce the concept of a 'page' --- src/rustdoc/attr_pass.rs | 75 +++++++++++++------------ src/rustdoc/desc_pass.rs | 54 +++++++++--------- src/rustdoc/desc_to_brief_pass.rs | 48 ++++++++-------- src/rustdoc/doc.rs | 24 ++++++++ src/rustdoc/extract.rs | 74 ++++++++++++------------ src/rustdoc/fold.rs | 32 +++++++++-- src/rustdoc/markdown_index_pass.rs | 10 ++-- src/rustdoc/markdown_pass.rs | 38 +++++++------ src/rustdoc/path_pass.rs | 16 +++--- src/rustdoc/prune_undoc_details_pass.rs | 22 ++++---- src/rustdoc/prune_undoc_items_pass.rs | 54 +++++++++--------- src/rustdoc/prune_unexported_pass.rs | 40 ++++++------- src/rustdoc/reexport_pass.rs | 32 +++++------ src/rustdoc/rustdoc.rs | 56 ++++++++++-------- src/rustdoc/sort_item_name_pass.rs | 4 +- src/rustdoc/sort_item_type_pass.rs | 18 +++--- src/rustdoc/sort_pass.rs | 24 ++++---- src/rustdoc/trim_pass.rs | 20 +++---- src/rustdoc/tystr_pass.rs | 54 +++++++++--------- 19 files changed, 381 insertions(+), 314 deletions(-) diff --git a/src/rustdoc/attr_pass.rs b/src/rustdoc/attr_pass.rs index 9c2f3fa13fd..237a8d7de77 100644 --- a/src/rustdoc/attr_pass.rs +++ b/src/rustdoc/attr_pass.rs @@ -20,8 +20,8 @@ fn mk_pass() -> pass { fn run( srv: astsrv::srv, - doc: doc::cratedoc -) -> doc::cratedoc { + doc: doc::doc +) -> doc::doc { let fold = fold::fold({ fold_crate: fold_crate, fold_item: fold_item, @@ -32,7 +32,7 @@ fn run( fold_impl: fold_impl with *fold::default_any_fold(srv) }); - fold.fold_crate(fold, doc) + fold.fold_doc(fold, doc) } fn fold_crate( @@ -62,7 +62,7 @@ fn fold_crate( #[test] fn should_replace_top_module_name_with_crate_name() { let doc = test::mk_doc("#[link(name = \"bond\")];"); - assert doc.topmod.name() == "bond"; + assert doc.cratemod().name() == "bond"; } fn fold_item( @@ -108,25 +108,25 @@ fn parse_item_attrs( #[test] fn should_should_extract_mod_attributes() { let doc = test::mk_doc("#[doc = \"test\"] mod a { }"); - assert doc.topmod.mods()[0].desc() == some("test"); + assert doc.cratemod().mods()[0].desc() == some("test"); } #[test] fn should_extract_top_mod_attributes() { let doc = test::mk_doc("#[doc = \"test\"];"); - assert doc.topmod.desc() == some("test"); + assert doc.cratemod().desc() == some("test"); } #[test] fn should_extract_native_mod_attributes() { let doc = test::mk_doc("#[doc = \"test\"] native mod a { }"); - assert doc.topmod.nmods()[0].desc() == some("test"); + assert doc.cratemod().nmods()[0].desc() == some("test"); } #[test] fn should_extract_native_fn_attributes() { let doc = test::mk_doc("native mod a { #[doc = \"test\"] fn a(); }"); - assert doc.topmod.nmods()[0].fns[0].desc() == some("test"); + assert doc.cratemod().nmods()[0].fns[0].desc() == some("test"); } fn fold_fn( @@ -187,13 +187,13 @@ fn merge_ret_attrs( #[test] fn should_extract_fn_attributes() { let doc = test::mk_doc("#[doc = \"test\"] fn a() -> int { }"); - assert doc.topmod.fns()[0].desc() == some("test"); + assert doc.cratemod().fns()[0].desc() == some("test"); } #[test] fn should_extract_fn_arg_attributes() { let doc = test::mk_doc("#[doc(args(a = \"b\"))] fn c(a: bool) { }"); - assert doc.topmod.fns()[0].args[0].desc == some("b"); + assert doc.cratemod().fns()[0].args[0].desc == some("b"); } #[test] @@ -203,7 +203,7 @@ fn should_extract_fn_return_attributes() { let doc = extract::from_srv(srv, ""); let doc = tystr_pass::mk_pass().f(srv, doc); let fold = fold::default_any_fold(srv); - let doc = fold_fn(fold, doc.topmod.fns()[0]); + let doc = fold_fn(fold, doc.cratemod().fns()[0]); assert doc.return.desc == some("what"); } } @@ -215,7 +215,7 @@ fn should_preserve_fn_sig() { let doc = extract::from_srv(srv, ""); let doc = tystr_pass::mk_pass().f(srv, doc); let fold = fold::default_any_fold(srv); - let doc = fold_fn(fold, doc.topmod.fns()[0]); + let doc = fold_fn(fold, doc.cratemod().fns()[0]); assert doc.sig == some("fn a() -> int"); } } @@ -223,15 +223,15 @@ fn should_preserve_fn_sig() { #[test] fn should_extract_fn_failure_conditions() { let doc = test::mk_doc("#[doc(failure = \"what\")] fn a() { }"); - assert doc.topmod.fns()[0].failure == some("what"); + assert doc.cratemod().fns()[0].failure == some("what"); } #[test] fn should_extract_const_docs() { let doc = test::mk_doc("#[doc(brief = \"foo\", desc = \"bar\")]\ const a: bool = true;"); - assert doc.topmod.consts()[0].brief() == some("foo"); - assert doc.topmod.consts()[0].desc() == some("bar"); + assert doc.cratemod().consts()[0].brief() == some("foo"); + assert doc.cratemod().consts()[0].desc() == some("bar"); } fn fold_enum( @@ -273,14 +273,14 @@ fn fold_enum( fn should_extract_enum_docs() { let doc = test::mk_doc("#[doc(brief = \"a\", desc = \"b\")]\ enum a { v }"); - assert doc.topmod.enums()[0].brief() == some("a"); - assert doc.topmod.enums()[0].desc() == some("b"); + assert doc.cratemod().enums()[0].brief() == some("a"); + assert doc.cratemod().enums()[0].desc() == some("b"); } #[test] fn should_extract_variant_docs() { let doc = test::mk_doc("enum a { #[doc = \"c\"] v }"); - assert doc.topmod.enums()[0].variants[0].desc == some("c"); + assert doc.cratemod().enums()[0].variants[0].desc == some("c"); } fn fold_res( @@ -314,16 +314,16 @@ fn fold_res( fn should_extract_res_docs() { let doc = test::mk_doc("#[doc(brief = \"a\", desc = \"b\")]\ resource r(b: bool) { }"); - assert doc.topmod.resources()[0].brief() == some("a"); - assert doc.topmod.resources()[0].desc() == some("b"); + assert doc.cratemod().resources()[0].brief() == some("a"); + assert doc.cratemod().resources()[0].desc() == some("b"); } #[test] fn should_extract_res_arg_docs() { let doc = test::mk_doc("#[doc(args(a = \"b\"))]\ resource r(a: bool) { }"); - assert doc.topmod.resources()[0].args[0].name == "a"; - assert doc.topmod.resources()[0].args[0].desc == some("b"); + assert doc.cratemod().resources()[0].args[0].name == "a"; + assert doc.cratemod().resources()[0].args[0].desc == some("b"); } fn fold_iface( @@ -394,7 +394,7 @@ fn merge_method_attrs( #[test] fn should_extract_iface_docs() { let doc = test::mk_doc("#[doc = \"whatever\"] iface i { fn a(); }"); - assert doc.topmod.ifaces()[0].desc() == some("whatever"); + assert doc.cratemod().ifaces()[0].desc() == some("whatever"); } #[test] @@ -409,11 +409,12 @@ fn should_extract_iface_method_docs() { failure = \"failure\")]\ fn f(a: bool) -> bool;\ }"); - assert doc.topmod.ifaces()[0].methods[0].brief == some("brief"); - assert doc.topmod.ifaces()[0].methods[0].desc == some("desc"); - assert doc.topmod.ifaces()[0].methods[0].args[0].desc == some("a"); - assert doc.topmod.ifaces()[0].methods[0].return.desc == some("return"); - assert doc.topmod.ifaces()[0].methods[0].failure == some("failure"); + assert doc.cratemod().ifaces()[0].methods[0].brief == some("brief"); + assert doc.cratemod().ifaces()[0].methods[0].desc == some("desc"); + assert doc.cratemod().ifaces()[0].methods[0].args[0].desc == some("a"); + assert doc.cratemod().ifaces()[0].methods[0].return.desc + == some("return"); + assert doc.cratemod().ifaces()[0].methods[0].failure == some("failure"); } @@ -434,7 +435,7 @@ fn fold_impl( fn should_extract_impl_docs() { let doc = test::mk_doc( "#[doc = \"whatever\"] impl i for int { fn a() { } }"); - assert doc.topmod.impls()[0].desc() == some("whatever"); + assert doc.cratemod().impls()[0].desc() == some("whatever"); } #[test] @@ -449,11 +450,11 @@ fn should_extract_impl_method_docs() { failure = \"failure\")]\ fn f(a: bool) -> bool { }\ }"); - assert doc.topmod.impls()[0].methods[0].brief == some("brief"); - assert doc.topmod.impls()[0].methods[0].desc == some("desc"); - assert doc.topmod.impls()[0].methods[0].args[0].desc == some("a"); - assert doc.topmod.impls()[0].methods[0].return.desc == some("return"); - assert doc.topmod.impls()[0].methods[0].failure == some("failure"); + assert doc.cratemod().impls()[0].methods[0].brief == some("brief"); + assert doc.cratemod().impls()[0].methods[0].desc == some("desc"); + assert doc.cratemod().impls()[0].methods[0].args[0].desc == some("a"); + assert doc.cratemod().impls()[0].methods[0].return.desc == some("return"); + assert doc.cratemod().impls()[0].methods[0].failure == some("failure"); } #[test] @@ -461,13 +462,13 @@ fn should_extract_type_docs() { let doc = test::mk_doc( "#[doc(brief = \"brief\", desc = \"desc\")]\ type t = int;"); - assert doc.topmod.types()[0].brief() == some("brief"); - assert doc.topmod.types()[0].desc() == some("desc"); + assert doc.cratemod().types()[0].brief() == some("brief"); + assert doc.cratemod().types()[0].desc() == some("desc"); } #[cfg(test)] mod test { - fn mk_doc(source: str) -> doc::cratedoc { + fn mk_doc(source: str) -> doc::doc { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); run(srv, doc) diff --git a/src/rustdoc/desc_pass.rs b/src/rustdoc/desc_pass.rs index 43754b636a3..847c99803b6 100644 --- a/src/rustdoc/desc_pass.rs +++ b/src/rustdoc/desc_pass.rs @@ -5,7 +5,7 @@ fn mk_pass(name: str, op: fn~(str) -> str) -> pass { { name: name, - f: fn~(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc { + f: fn~(srv: astsrv::srv, doc: doc::doc) -> doc::doc { run(srv, doc, op) } } @@ -15,9 +15,9 @@ fn mk_pass(name: str, op: fn~(str) -> str) -> pass { fn run( _srv: astsrv::srv, - doc: doc::cratedoc, + doc: doc::doc, op: op -) -> doc::cratedoc { +) -> doc::doc { let fold = fold::fold({ fold_item: fold_item, fold_fn: fold_fn, @@ -27,7 +27,7 @@ fn run( fold_impl: fold_impl with *fold::default_any_fold(op) }); - fold.fold_crate(fold, doc) + fold.fold_doc(fold, doc) } fn maybe_apply_op(op: op, s: option) -> option { @@ -136,135 +136,135 @@ fn fold_impl(fold: fold::fold, doc: doc::impldoc) -> doc::impldoc { #[test] fn should_execute_op_on_enum_brief() { let doc = test::mk_doc("#[doc(brief = \" a \")] enum a { b }"); - assert doc.topmod.enums()[0].brief() == some("a"); + assert doc.cratemod().enums()[0].brief() == some("a"); } #[test] fn should_execute_op_on_enum_desc() { let doc = test::mk_doc("#[doc(desc = \" a \")] enum a { b }"); - assert doc.topmod.enums()[0].desc() == some("a"); + assert doc.cratemod().enums()[0].desc() == some("a"); } #[test] fn should_execute_op_on_variant_desc() { let doc = test::mk_doc("enum a { #[doc = \" a \"] b }"); - assert doc.topmod.enums()[0].variants[0].desc == some("a"); + assert doc.cratemod().enums()[0].variants[0].desc == some("a"); } #[test] fn should_execute_op_on_resource_brief() { let doc = test::mk_doc("#[doc(brief = \" a \")] resource r(a: bool) { }"); - assert doc.topmod.resources()[0].brief() == some("a"); + assert doc.cratemod().resources()[0].brief() == some("a"); } #[test] fn should_execute_op_on_resource_desc() { let doc = test::mk_doc("#[doc(desc = \" a \")] resource r(a: bool) { }"); - assert doc.topmod.resources()[0].desc() == some("a"); + assert doc.cratemod().resources()[0].desc() == some("a"); } #[test] fn should_execute_op_on_resource_args() { let doc = test::mk_doc( "#[doc(args(a = \" a \"))] resource r(a: bool) { }"); - assert doc.topmod.resources()[0].args[0].desc == some("a"); + assert doc.cratemod().resources()[0].args[0].desc == some("a"); } #[test] fn should_execute_op_on_iface_brief() { let doc = test::mk_doc( "#[doc(brief = \" a \")] iface i { fn a(); }"); - assert doc.topmod.ifaces()[0].brief() == some("a"); + assert doc.cratemod().ifaces()[0].brief() == some("a"); } #[test] fn should_execute_op_on_iface_desc() { let doc = test::mk_doc( "#[doc(desc = \" a \")] iface i { fn a(); }"); - assert doc.topmod.ifaces()[0].desc() == some("a"); + assert doc.cratemod().ifaces()[0].desc() == some("a"); } #[test] fn should_execute_op_on_iface_method_brief() { let doc = test::mk_doc( "iface i { #[doc(brief = \" a \")] fn a(); }"); - assert doc.topmod.ifaces()[0].methods[0].brief == some("a"); + assert doc.cratemod().ifaces()[0].methods[0].brief == some("a"); } #[test] fn should_execute_op_on_iface_method_desc() { let doc = test::mk_doc( "iface i { #[doc(desc = \" a \")] fn a(); }"); - assert doc.topmod.ifaces()[0].methods[0].desc == some("a"); + assert doc.cratemod().ifaces()[0].methods[0].desc == some("a"); } #[test] fn should_execute_op_on_iface_method_args() { let doc = test::mk_doc( "iface i { #[doc(args(a = \" a \"))] fn a(a: bool); }"); - assert doc.topmod.ifaces()[0].methods[0].args[0].desc == some("a"); + assert doc.cratemod().ifaces()[0].methods[0].args[0].desc == some("a"); } #[test] fn should_execute_op_on_iface_method_return() { let doc = test::mk_doc( "iface i { #[doc(return = \" a \")] fn a() -> int; }"); - assert doc.topmod.ifaces()[0].methods[0].return.desc == some("a"); + assert doc.cratemod().ifaces()[0].methods[0].return.desc == some("a"); } #[test] fn should_execute_op_on_iface_method_failure_condition() { let doc = test::mk_doc("iface i { #[doc(failure = \" a \")] fn a(); }"); - assert doc.topmod.ifaces()[0].methods[0].failure == some("a"); + assert doc.cratemod().ifaces()[0].methods[0].failure == some("a"); } #[test] fn should_execute_op_on_impl_brief() { let doc = test::mk_doc( "#[doc(brief = \" a \")] impl i for int { fn a() { } }"); - assert doc.topmod.impls()[0].brief() == some("a"); + assert doc.cratemod().impls()[0].brief() == some("a"); } #[test] fn should_execute_op_on_impl_desc() { let doc = test::mk_doc( "#[doc(desc = \" a \")] impl i for int { fn a() { } }"); - assert doc.topmod.impls()[0].desc() == some("a"); + assert doc.cratemod().impls()[0].desc() == some("a"); } #[test] fn should_execute_op_on_impl_method_brief() { let doc = test::mk_doc( "impl i for int { #[doc(brief = \" a \")] fn a() { } }"); - assert doc.topmod.impls()[0].methods[0].brief == some("a"); + assert doc.cratemod().impls()[0].methods[0].brief == some("a"); } #[test] fn should_execute_op_on_impl_method_desc() { let doc = test::mk_doc( "impl i for int { #[doc(desc = \" a \")] fn a() { } }"); - assert doc.topmod.impls()[0].methods[0].desc == some("a"); + assert doc.cratemod().impls()[0].methods[0].desc == some("a"); } #[test] fn should_execute_op_on_impl_method_args() { let doc = test::mk_doc( "impl i for int { #[doc(args(a = \" a \"))] fn a(a: bool) { } }"); - assert doc.topmod.impls()[0].methods[0].args[0].desc == some("a"); + assert doc.cratemod().impls()[0].methods[0].args[0].desc == some("a"); } #[test] fn should_execute_op_on_impl_method_return() { let doc = test::mk_doc( "impl i for int { #[doc(return = \" a \")] fn a() -> int { fail } }"); - assert doc.topmod.impls()[0].methods[0].return.desc == some("a"); + assert doc.cratemod().impls()[0].methods[0].return.desc == some("a"); } #[test] fn should_execute_op_on_impl_method_failure_condition() { let doc = test::mk_doc( "impl i for int { #[doc(failure = \" a \")] fn a() { } }"); - assert doc.topmod.impls()[0].methods[0].failure == some("a"); + assert doc.cratemod().impls()[0].methods[0].failure == some("a"); } @@ -272,19 +272,19 @@ fn should_execute_op_on_impl_method_failure_condition() { fn should_execute_op_on_type_brief() { let doc = test::mk_doc( "#[doc(brief = \" a \")] type t = int;"); - assert doc.topmod.types()[0].brief() == some("a"); + assert doc.cratemod().types()[0].brief() == some("a"); } #[test] fn should_execute_op_on_type_desc() { let doc = test::mk_doc( "#[doc(desc = \" a \")] type t = int;"); - assert doc.topmod.types()[0].desc() == some("a"); + assert doc.cratemod().types()[0].desc() == some("a"); } #[cfg(test)] mod test { - fn mk_doc(source: str) -> doc::cratedoc { + fn mk_doc(source: str) -> doc::doc { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = attr_pass::mk_pass().f(srv, doc); diff --git a/src/rustdoc/desc_to_brief_pass.rs b/src/rustdoc/desc_to_brief_pass.rs index bf53cdcdca6..695742cbebc 100644 --- a/src/rustdoc/desc_to_brief_pass.rs +++ b/src/rustdoc/desc_to_brief_pass.rs @@ -18,15 +18,15 @@ fn mk_pass() -> pass { fn run( _srv: astsrv::srv, - doc: doc::cratedoc -) -> doc::cratedoc { + doc: doc::doc +) -> doc::doc { let fold = fold::fold({ fold_item: fold_item, fold_iface: fold_iface, fold_impl: fold_impl with *fold::default_any_fold(()) }); - fold.fold_crate(fold, doc) + fold.fold_doc(fold, doc) } fn fold_item(fold: fold::fold<()>, doc: doc::itemdoc) -> doc::itemdoc { @@ -77,79 +77,79 @@ fn fold_impl(fold: fold::fold<()>, doc: doc::impldoc) -> doc::impldoc { #[test] fn should_promote_mod_desc() { let doc = test::mk_doc("#[doc(desc = \"desc\")] mod m { }"); - assert doc.topmod.mods()[0].brief() == some("desc"); - assert doc.topmod.mods()[0].desc() == none; + assert doc.cratemod().mods()[0].brief() == some("desc"); + assert doc.cratemod().mods()[0].desc() == none; } #[test] fn should_promote_const_desc() { let doc = test::mk_doc("#[doc(desc = \"desc\")] const a: bool = true;"); - assert doc.topmod.consts()[0].brief() == some("desc"); - assert doc.topmod.consts()[0].desc() == none; + assert doc.cratemod().consts()[0].brief() == some("desc"); + assert doc.cratemod().consts()[0].desc() == none; } #[test] fn should_promote_fn_desc() { let doc = test::mk_doc("#[doc(desc = \"desc\")] fn a() { }"); - assert doc.topmod.fns()[0].brief() == some("desc"); - assert doc.topmod.fns()[0].desc() == none; + assert doc.cratemod().fns()[0].brief() == some("desc"); + assert doc.cratemod().fns()[0].desc() == none; } #[test] fn should_promote_enum_desc() { let doc = test::mk_doc("#[doc(desc = \"desc\")] enum a { b }"); - assert doc.topmod.enums()[0].brief() == some("desc"); - assert doc.topmod.enums()[0].desc() == none; + assert doc.cratemod().enums()[0].brief() == some("desc"); + assert doc.cratemod().enums()[0].desc() == none; } #[test] fn should_promote_resource_desc() { let doc = test::mk_doc( "#[doc(desc = \"desc\")] resource r(a: bool) { }"); - assert doc.topmod.resources()[0].brief() == some("desc"); - assert doc.topmod.resources()[0].desc() == none; + assert doc.cratemod().resources()[0].brief() == some("desc"); + assert doc.cratemod().resources()[0].desc() == none; } #[test] fn should_promote_iface_desc() { let doc = test::mk_doc("#[doc(desc = \"desc\")] iface i { fn a(); }"); - assert doc.topmod.ifaces()[0].brief() == some("desc"); - assert doc.topmod.ifaces()[0].desc() == none; + assert doc.cratemod().ifaces()[0].brief() == some("desc"); + assert doc.cratemod().ifaces()[0].desc() == none; } #[test] fn should_promote_iface_method_desc() { let doc = test::mk_doc("iface i { #[doc(desc = \"desc\")] fn a(); }"); - assert doc.topmod.ifaces()[0].methods[0].brief == some("desc"); - assert doc.topmod.ifaces()[0].methods[0].desc == none; + assert doc.cratemod().ifaces()[0].methods[0].brief == some("desc"); + assert doc.cratemod().ifaces()[0].methods[0].desc == none; } #[test] fn should_promote_impl_desc() { let doc = test::mk_doc( "#[doc(desc = \"desc\")] impl i for int { fn a() { } }"); - assert doc.topmod.impls()[0].brief() == some("desc"); - assert doc.topmod.impls()[0].desc() == none; + assert doc.cratemod().impls()[0].brief() == some("desc"); + assert doc.cratemod().impls()[0].desc() == none; } #[test] fn should_promote_impl_method_desc() { let doc = test::mk_doc( "impl i for int { #[doc(desc = \"desc\")] fn a() { } }"); - assert doc.topmod.impls()[0].methods[0].brief == some("desc"); - assert doc.topmod.impls()[0].methods[0].desc == none; + assert doc.cratemod().impls()[0].methods[0].brief == some("desc"); + assert doc.cratemod().impls()[0].methods[0].desc == none; } #[test] fn should_promote_type_desc() { let doc = test::mk_doc("#[doc(desc = \"desc\")] type t = int;"); - assert doc.topmod.types()[0].brief() == some("desc"); - assert doc.topmod.types()[0].desc() == none; + assert doc.cratemod().types()[0].brief() == some("desc"); + assert doc.cratemod().types()[0].desc() == none; } #[cfg(test)] mod test { - fn mk_doc(source: str) -> doc::cratedoc { + fn mk_doc(source: str) -> doc::doc { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = attr_pass::mk_pass().f(srv, doc); diff --git a/src/rustdoc/doc.rs b/src/rustdoc/doc.rs index ceca4cb5a72..b7a7fb4dd88 100644 --- a/src/rustdoc/doc.rs +++ b/src/rustdoc/doc.rs @@ -2,6 +2,15 @@ type ast_id = int; +type doc = { + pages: [page] +}; + +enum page { + cratepage(cratedoc), + itempage(itemtag) +} + // FIXME: We currently give topmod the name of the crate. There would // probably be fewer special cases if the crate had its own name and // topmod's name was the empty string. @@ -131,6 +140,21 @@ enum itemtag { link: str }; +impl util for doc { + fn cratedoc() -> cratedoc { + option::get(vec::foldl(none, self.pages) {|_m, page| + alt page { + doc::cratepage(doc) { some(doc) } + _ { none } + } + }) + } + + fn cratemod() -> moddoc { + self.cratedoc().topmod + } +} + #[doc = "Some helper methods on moddoc, mostly for testing"] impl util for moddoc { diff --git a/src/rustdoc/extract.rs b/src/rustdoc/extract.rs index 27ad5fe51ba..9340d15d474 100644 --- a/src/rustdoc/extract.rs +++ b/src/rustdoc/extract.rs @@ -7,7 +7,7 @@ fn from_srv( srv: astsrv::srv, default_name: str -) -> doc::cratedoc { +) -> doc::doc { #[doc = "Use the AST service to create a document tree"]; @@ -19,9 +19,13 @@ fn from_srv( fn extract( crate: @ast::crate, default_name: str -) -> doc::cratedoc { +) -> doc::doc { { - topmod: top_moddoc_from_crate(crate, default_name), + pages: [ + doc::cratepage({ + topmod: top_moddoc_from_crate(crate, default_name), + }) + ] } } @@ -145,7 +149,7 @@ fn should_extract_fn_args() { let source = "fn a(b: int, c: int) { }"; let ast = parse::from_str(source); let doc = extract(ast, ""); - let fn_ = doc.topmod.fns()[0]; + let fn_ = doc.cratemod().fns()[0]; assert fn_.args[0].name == "b"; assert fn_.args[1].name == "c"; } @@ -172,8 +176,8 @@ fn constdoc_from_const(itemdoc: doc::itemdoc) -> doc::constdoc { #[test] fn should_extract_const_name_and_id() { let doc = test::mk_doc("const a: int = 0;"); - assert doc.topmod.consts()[0].id() != 0; - assert doc.topmod.consts()[0].name() == "a"; + assert doc.cratemod().consts()[0].id() != 0; + assert doc.cratemod().consts()[0].name() == "a"; } fn enumdoc_from_enum( @@ -203,14 +207,14 @@ fn variantdoc_from_variant(variant: ast::variant) -> doc::variantdoc { #[test] fn should_extract_enums() { let doc = test::mk_doc("enum e { v }"); - assert doc.topmod.enums()[0].id() != 0; - assert doc.topmod.enums()[0].name() == "e"; + assert doc.cratemod().enums()[0].id() != 0; + assert doc.cratemod().enums()[0].name() == "e"; } #[test] fn should_extract_enum_variants() { let doc = test::mk_doc("enum e { v }"); - assert doc.topmod.enums()[0].variants[0].name == "v"; + assert doc.cratemod().enums()[0].variants[0].name == "v"; } fn resdoc_from_resource( @@ -227,14 +231,14 @@ fn resdoc_from_resource( #[test] fn should_extract_resources() { let doc = test::mk_doc("resource r(b: bool) { }"); - assert doc.topmod.resources()[0].id() != 0; - assert doc.topmod.resources()[0].name() == "r"; + assert doc.cratemod().resources()[0].id() != 0; + assert doc.cratemod().resources()[0].name() == "r"; } #[test] fn should_extract_resource_args() { let doc = test::mk_doc("resource r(b: bool) { }"); - assert doc.topmod.resources()[0].args[0].name == "b"; + assert doc.cratemod().resources()[0].args[0].name == "b"; } fn ifacedoc_from_iface( @@ -263,19 +267,19 @@ fn ifacedoc_from_iface( #[test] fn should_extract_ifaces() { let doc = test::mk_doc("iface i { fn f(); }"); - assert doc.topmod.ifaces()[0].name() == "i"; + assert doc.cratemod().ifaces()[0].name() == "i"; } #[test] fn should_extract_iface_methods() { let doc = test::mk_doc("iface i { fn f(); }"); - assert doc.topmod.ifaces()[0].methods[0].name == "f"; + assert doc.cratemod().ifaces()[0].methods[0].name == "f"; } #[test] fn should_extract_iface_method_args() { let doc = test::mk_doc("iface i { fn f(a: bool); }"); - assert doc.topmod.ifaces()[0].methods[0].args[0].name == "a"; + assert doc.cratemod().ifaces()[0].methods[0].args[0].name == "a"; } fn impldoc_from_impl( @@ -306,25 +310,25 @@ fn impldoc_from_impl( #[test] fn should_extract_impls_with_names() { let doc = test::mk_doc("impl i for int { fn a() { } }"); - assert doc.topmod.impls()[0].name() == "i"; + assert doc.cratemod().impls()[0].name() == "i"; } #[test] fn should_extract_impls_without_names() { let doc = test::mk_doc("impl of i for int { fn a() { } }"); - assert doc.topmod.impls()[0].name() == "i"; + assert doc.cratemod().impls()[0].name() == "i"; } #[test] fn should_extract_impl_methods() { let doc = test::mk_doc("impl i for int { fn f() { } }"); - assert doc.topmod.impls()[0].methods[0].name == "f"; + assert doc.cratemod().impls()[0].methods[0].name == "f"; } #[test] fn should_extract_impl_method_args() { let doc = test::mk_doc("impl i for int { fn f(a: bool) { } }"); - assert doc.topmod.impls()[0].methods[0].args[0].name == "a"; + assert doc.cratemod().impls()[0].methods[0].args[0].name == "a"; } fn tydoc_from_ty( @@ -339,13 +343,13 @@ fn tydoc_from_ty( #[test] fn should_extract_tys() { let doc = test::mk_doc("type a = int;"); - assert doc.topmod.types()[0].name() == "a"; + assert doc.cratemod().types()[0].name() == "a"; } #[cfg(test)] mod test { - fn mk_doc(source: str) -> doc::cratedoc { + fn mk_doc(source: str) -> doc::doc { let ast = parse::from_str(source); extract(ast, "") } @@ -353,40 +357,40 @@ fn mk_doc(source: str) -> doc::cratedoc { #[test] fn extract_empty_crate() { let doc = mk_doc(""); - assert vec::is_empty(doc.topmod.mods()); - assert vec::is_empty(doc.topmod.fns()); + assert vec::is_empty(doc.cratemod().mods()); + assert vec::is_empty(doc.cratemod().fns()); } #[test] fn extract_mods() { let doc = mk_doc("mod a { mod b { } mod c { } }"); - assert doc.topmod.mods()[0].name() == "a"; - assert doc.topmod.mods()[0].mods()[0].name() == "b"; - assert doc.topmod.mods()[0].mods()[1].name() == "c"; + assert doc.cratemod().mods()[0].name() == "a"; + assert doc.cratemod().mods()[0].mods()[0].name() == "b"; + assert doc.cratemod().mods()[0].mods()[1].name() == "c"; } #[test] fn extract_native_mods() { let doc = mk_doc("native mod a { }"); - assert doc.topmod.nmods()[0].name() == "a"; + assert doc.cratemod().nmods()[0].name() == "a"; } #[test] fn extract_fns_from_native_mods() { let doc = mk_doc("native mod a { fn a(); }"); - assert doc.topmod.nmods()[0].fns[0].name() == "a"; + assert doc.cratemod().nmods()[0].fns[0].name() == "a"; } #[test] fn extract_mods_deep() { let doc = mk_doc("mod a { mod b { mod c { } } }"); - assert doc.topmod.mods()[0].mods()[0].mods()[0].name() == "c"; + assert doc.cratemod().mods()[0].mods()[0].mods()[0].name() == "c"; } #[test] fn extract_should_set_mod_ast_id() { let doc = mk_doc("mod a { }"); - assert doc.topmod.mods()[0].id() != 0; + assert doc.cratemod().mods()[0].id() != 0; } #[test] @@ -394,14 +398,14 @@ fn extract_fns() { let doc = mk_doc( "fn a() { } \ mod b { fn c() { } }"); - assert doc.topmod.fns()[0].name() == "a"; - assert doc.topmod.mods()[0].fns()[0].name() == "c"; + assert doc.cratemod().fns()[0].name() == "a"; + assert doc.cratemod().mods()[0].fns()[0].name() == "c"; } #[test] fn extract_should_set_fn_ast_id() { let doc = mk_doc("fn a() { }"); - assert doc.topmod.fns()[0].id() != 0; + assert doc.cratemod().fns()[0].id() != 0; } #[test] @@ -409,7 +413,7 @@ fn extract_should_use_default_crate_name() { let source = ""; let ast = parse::from_str(source); let doc = extract(ast, "burp"); - assert doc.topmod.name() == "burp"; + assert doc.cratemod().name() == "burp"; } #[test] @@ -417,7 +421,7 @@ fn extract_from_seq_srv() { let source = ""; astsrv::from_str(source) {|srv| let doc = from_srv(srv, "name"); - assert doc.topmod.name() == "name"; + assert doc.cratemod().name() == "name"; } } } \ No newline at end of file diff --git a/src/rustdoc/fold.rs b/src/rustdoc/fold.rs index 6be24de0057..87b9d85637c 100644 --- a/src/rustdoc/fold.rs +++ b/src/rustdoc/fold.rs @@ -1,5 +1,6 @@ export fold; export default_seq_fold; +export default_seq_fold_doc; export default_seq_fold_crate; export default_seq_fold_item; export default_seq_fold_mod; @@ -20,6 +21,7 @@ enum fold = t; +type fold_doc = fn~(fold: fold, doc: doc::doc) -> doc::doc; type fold_crate = fn~(fold: fold, doc: doc::cratedoc) -> doc::cratedoc; type fold_item = fn~(fold: fold, doc: doc::itemdoc) -> doc::itemdoc; type fold_mod = fn~(fold: fold, doc: doc::moddoc) -> doc::moddoc; @@ -34,6 +36,7 @@ type t = { ctxt: T, + fold_doc: fold_doc, fold_crate: fold_crate, fold_item: fold_item, fold_mod: fold_mod, @@ -52,6 +55,7 @@ // initializers, but they do as function arguments fn mk_fold( ctxt: T, + fold_doc: fold_doc, fold_crate: fold_crate, fold_item: fold_item, fold_mod: fold_mod, @@ -66,6 +70,7 @@ fn mk_fold( ) -> fold { fold({ ctxt: ctxt, + fold_doc: fold_doc, fold_crate: fold_crate, fold_item: fold_item, fold_mod: fold_mod, @@ -83,6 +88,7 @@ fn mk_fold( fn default_any_fold(ctxt: T) -> fold { mk_fold( ctxt, + {|f, d| default_seq_fold_doc(f, d)}, {|f, d| default_seq_fold_crate(f, d)}, {|f, d| default_seq_fold_item(f, d)}, {|f, d| default_any_fold_mod(f, d)}, @@ -100,6 +106,7 @@ fn default_any_fold(ctxt: T) -> fold { fn default_seq_fold(ctxt: T) -> fold { mk_fold( ctxt, + {|f, d| default_seq_fold_doc(f, d)}, {|f, d| default_seq_fold_crate(f, d)}, {|f, d| default_seq_fold_item(f, d)}, {|f, d| default_seq_fold_mod(f, d)}, @@ -117,6 +124,7 @@ fn default_seq_fold(ctxt: T) -> fold { fn default_par_fold(ctxt: T) -> fold { mk_fold( ctxt, + {|f, d| default_seq_fold_doc(f, d)}, {|f, d| default_seq_fold_crate(f, d)}, {|f, d| default_seq_fold_item(f, d)}, {|f, d| default_par_fold_mod(f, d)}, @@ -131,6 +139,22 @@ fn default_par_fold(ctxt: T) -> fold { ) } +fn default_seq_fold_doc(fold: fold, doc: doc::doc) -> doc::doc { + { + pages: par::seqmap(doc.pages) {|page| + alt page { + doc::cratepage(doc) { + doc::cratepage(fold.fold_crate(fold, doc)) + } + doc::itempage(doc) { + doc::itempage(fold_itemtag(fold, doc)) + } + } + } + with doc + } +} + fn default_seq_fold_crate( fold: fold, doc: doc::cratedoc @@ -333,7 +357,7 @@ fn default_fold_should_produce_same_doc() { let ast = parse::from_str(source); let doc = extract::extract(ast, ""); let fld = default_seq_fold(()); - let folded = fld.fold_crate(fld, doc); + let folded = fld.fold_doc(fld, doc); assert doc == folded; } @@ -343,7 +367,7 @@ fn default_fold_should_produce_same_consts() { let ast = parse::from_str(source); let doc = extract::extract(ast, ""); let fld = default_seq_fold(()); - let folded = fld.fold_crate(fld, doc); + let folded = fld.fold_doc(fld, doc); assert doc == folded; } @@ -353,7 +377,7 @@ fn default_fold_should_produce_same_enums() { let ast = parse::from_str(source); let doc = extract::extract(ast, ""); let fld = default_seq_fold(()); - let folded = fld.fold_crate(fld, doc); + let folded = fld.fold_doc(fld, doc); assert doc == folded; } @@ -363,6 +387,6 @@ fn default_parallel_fold_should_produce_same_doc() { let ast = parse::from_str(source); let doc = extract::extract(ast, ""); let fld = default_par_fold(()); - let folded = fld.fold_crate(fld, doc); + let folded = fld.fold_doc(fld, doc); assert doc == folded; } diff --git a/src/rustdoc/markdown_index_pass.rs b/src/rustdoc/markdown_index_pass.rs index 021274f6052..09bc8fd0eae 100644 --- a/src/rustdoc/markdown_index_pass.rs +++ b/src/rustdoc/markdown_index_pass.rs @@ -9,12 +9,12 @@ fn mk_pass() -> pass { } } -fn run(_srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc { +fn run(_srv: astsrv::srv, doc: doc::doc) -> doc::doc { let fold = fold::fold({ fold_mod: fold_mod with *fold::default_any_fold(()) }); - fold.fold_crate(fold, doc) + fold.fold_doc(fold, doc) } fn fold_mod(fold: fold::fold<()>, doc: doc::moddoc) -> doc::moddoc { @@ -68,12 +68,12 @@ fn maybe_use_section_id(s: str) -> str { s } #[test] fn should_index_mod_contents() { let doc = test::mk_doc("mod a { } fn b() { }"); - assert option::get(doc.topmod.index).entries[0] == { + assert option::get(doc.cratemod().index).entries[0] == { kind: "Module", name: "a", link: "module-a" }; - assert option::get(doc.topmod.index).entries[1] == { + assert option::get(doc.cratemod().index).entries[1] == { kind: "Function", name: "b", link: "function-b" @@ -82,7 +82,7 @@ fn should_index_mod_contents() { #[cfg(test)] mod test { - fn mk_doc(source: str) -> doc::cratedoc { + fn mk_doc(source: str) -> doc::doc { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = path_pass::mk_pass().f(srv, doc); diff --git a/src/rustdoc/markdown_pass.rs b/src/rustdoc/markdown_pass.rs index e3cd2a77318..dcf81442620 100644 --- a/src/rustdoc/markdown_pass.rs +++ b/src/rustdoc/markdown_pass.rs @@ -17,7 +17,7 @@ fn mk_pass_( config: config::config, writer: writer ) -> pass { - let f = fn~(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc { + let f = fn~(srv: astsrv::srv, doc: doc::doc) -> doc::doc { run(srv, doc, config, writer) }; @@ -29,10 +29,10 @@ fn mk_pass_( fn run( srv: astsrv::srv, - doc: doc::cratedoc, + doc: doc::doc, _config: config::config, writer: writer -) -> doc::cratedoc { +) -> doc::doc { fn mods_last(item1: doc::itemtag, item2: doc::itemtag) -> bool { fn is_mod(item: doc::itemtag) -> bool { @@ -89,14 +89,14 @@ fn d() { }" }; fn write_markdown( - doc: doc::cratedoc, + doc: doc::doc, writer: writer ) { let ctxt = { w: writer }; - write_crate(ctxt, doc); + write_crate(ctxt, doc.cratedoc()); ctxt.w.write_done(); } @@ -378,14 +378,18 @@ fn should_insert_blank_line_after_fn_signature() { fn should_correctly_indent_fn_signature() { let doc = test::create_doc("fn a() { }"); let doc = { - topmod: { - items: [doc::fntag({ - sig: some("line 1\nline 2") - with doc.topmod.fns()[0] - })] - with doc.topmod - } - with doc + pages: [ + doc::cratepage({ + topmod: { + items: [doc::fntag({ + sig: some("line 1\nline 2") + with doc.cratemod().fns()[0] + })] + with doc.cratemod() + } + with doc.cratedoc() + }) + ] }; let markdown = test::write_markdown_str(doc); assert str::contains(markdown, " line 1\n line 2"); @@ -927,7 +931,7 @@ fn render(source: str) -> str { markdown } - fn create_doc_srv(source: str) -> (astsrv::srv, doc::cratedoc) { + fn create_doc_srv(source: str) -> (astsrv::srv, doc::doc) { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); #debug("doc (extract): %?", doc); @@ -943,13 +947,13 @@ fn create_doc_srv(source: str) -> (astsrv::srv, doc::cratedoc) { } } - fn create_doc(source: str) -> doc::cratedoc { + fn create_doc(source: str) -> doc::doc { let (_, doc) = create_doc_srv(source); doc } fn write_markdown_str( - doc: doc::cratedoc + doc: doc::doc ) -> str { let (writer, future) = markdown_writer::future_writer(); write_markdown(doc, writer); @@ -958,7 +962,7 @@ fn write_markdown_str( fn write_markdown_str_srv( srv: astsrv::srv, - doc: doc::cratedoc + doc: doc::doc ) -> str { let config = { output_style: config::doc_per_crate diff --git a/src/rustdoc/path_pass.rs b/src/rustdoc/path_pass.rs index 76f213b108a..9aa88774822 100644 --- a/src/rustdoc/path_pass.rs +++ b/src/rustdoc/path_pass.rs @@ -14,7 +14,7 @@ fn mk_pass() -> pass { mutable path: [str] }; -fn run(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc { +fn run(srv: astsrv::srv, doc: doc::doc) -> doc::doc { let ctxt = { srv: srv, mutable path: [] @@ -25,7 +25,7 @@ fn run(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc { fold_nmod: fold_nmod with *fold::default_any_fold(ctxt) }); - fold.fold_crate(fold, doc) + fold.fold_doc(fold, doc) } fn fold_item(fold: fold::fold, doc: doc::itemdoc) -> doc::itemdoc { @@ -65,8 +65,10 @@ fn should_record_mod_paths() { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = run(srv, doc); - assert doc.topmod.mods()[0].mods()[0].mods()[0].path() == ["a", "b"]; - assert doc.topmod.mods()[0].mods()[1].mods()[0].path() == ["a", "d"]; + assert doc.cratemod().mods()[0].mods()[0].mods()[0].path() + == ["a", "b"]; + assert doc.cratemod().mods()[0].mods()[1].mods()[0].path() + == ["a", "d"]; } } @@ -76,7 +78,7 @@ fn should_record_fn_paths() { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = run(srv, doc); - assert doc.topmod.mods()[0].fns()[0].path() == ["a"]; + assert doc.cratemod().mods()[0].fns()[0].path() == ["a"]; } } @@ -86,7 +88,7 @@ fn should_record_native_mod_paths() { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = run(srv, doc); - assert doc.topmod.mods()[0].nmods()[0].path() == ["a"]; + assert doc.cratemod().mods()[0].nmods()[0].path() == ["a"]; } } @@ -96,6 +98,6 @@ fn should_record_native_fn_paths() { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = run(srv, doc); - assert doc.topmod.nmods()[0].fns[0].path() == ["a"]; + assert doc.cratemod().nmods()[0].fns[0].path() == ["a"]; } } \ No newline at end of file diff --git a/src/rustdoc/prune_undoc_details_pass.rs b/src/rustdoc/prune_undoc_details_pass.rs index ea2be022899..24855db7872 100644 --- a/src/rustdoc/prune_undoc_details_pass.rs +++ b/src/rustdoc/prune_undoc_details_pass.rs @@ -12,8 +12,8 @@ fn mk_pass() -> pass { fn run( _srv: astsrv::srv, - doc: doc::cratedoc -) -> doc::cratedoc { + doc: doc::doc +) -> doc::doc { let fold = fold::fold({ fold_fn: fold_fn, fold_res: fold_res, @@ -21,7 +21,7 @@ fn run( fold_impl: fold_impl with *fold::default_any_fold(()) }); - fold.fold_crate(fold, doc) + fold.fold_doc(fold, doc) } fn fold_fn( @@ -61,7 +61,7 @@ fn prune_return(doc: doc::retdoc) -> doc::retdoc { #[test] fn should_elide_undocumented_arguments() { let doc = test::mk_doc("#[doc = \"hey\"] fn a(b: int) { }"); - assert vec::is_empty(doc.topmod.fns()[0].args); + assert vec::is_empty(doc.cratemod().fns()[0].args); } #[test] @@ -72,7 +72,7 @@ fn should_elide_undocumented_return_values() { let doc = tystr_pass::mk_pass().f(srv, doc); let doc = attr_pass::mk_pass().f(srv, doc); let doc = run(srv, doc); - assert doc.topmod.fns()[0].return.ty == none; + assert doc.cratemod().fns()[0].return.ty == none; } } @@ -92,7 +92,7 @@ fn fold_res( fn should_elide_undocumented_resource_args() { let doc = test::mk_doc("#[doc = \"drunk\"]\ resource r(a: bool) { }"); - assert vec::is_empty(doc.topmod.resources()[0].args); + assert vec::is_empty(doc.cratemod().resources()[0].args); } fn fold_iface( @@ -120,13 +120,13 @@ fn prune_methods(docs: [doc::methoddoc]) -> [doc::methoddoc] { #[test] fn should_elide_undocumented_iface_method_args() { let doc = test::mk_doc("#[doc = \"hey\"] iface i { fn a(); }"); - assert vec::is_empty(doc.topmod.ifaces()[0].methods[0].args); + assert vec::is_empty(doc.cratemod().ifaces()[0].methods[0].args); } #[test] fn should_elide_undocumented_iface_method_return_values() { let doc = test::mk_doc("#[doc = \"hey\"] iface i { fn a() -> int; }"); - assert doc.topmod.ifaces()[0].methods[0].return.ty == none; + assert doc.cratemod().ifaces()[0].methods[0].return.ty == none; } fn fold_impl( @@ -145,19 +145,19 @@ fn fold_impl( fn should_elide_undocumented_impl_method_args() { let doc = test::mk_doc( "#[doc = \"hey\"] impl i for int { fn a(b: bool) { } }"); - assert vec::is_empty(doc.topmod.impls()[0].methods[0].args); + assert vec::is_empty(doc.cratemod().impls()[0].methods[0].args); } #[test] fn should_elide_undocumented_impl_method_return_values() { let doc = test::mk_doc( "#[doc = \"hey\"] impl i for int { fn a() -> int { } }"); - assert doc.topmod.impls()[0].methods[0].return.ty == none; + assert doc.cratemod().impls()[0].methods[0].return.ty == none; } #[cfg(test)] mod test { - fn mk_doc(source: str) -> doc::cratedoc { + fn mk_doc(source: str) -> doc::doc { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = attr_pass::mk_pass().f(srv, doc); diff --git a/src/rustdoc/prune_undoc_items_pass.rs b/src/rustdoc/prune_undoc_items_pass.rs index a05754fd1d8..ca7287cb8fc 100644 --- a/src/rustdoc/prune_undoc_items_pass.rs +++ b/src/rustdoc/prune_undoc_items_pass.rs @@ -15,8 +15,8 @@ fn mk_pass() -> pass { fn run( _srv: astsrv::srv, - doc: doc::cratedoc -) -> doc::cratedoc { + doc: doc::doc +) -> doc::doc { let ctxt = { mutable have_docs: true }; @@ -31,7 +31,7 @@ fn run( fold_type: fold_type with *fold::default_any_fold(ctxt) }); - fold.fold_crate(fold, doc) + fold.fold_doc(fold, doc) } fn fold_mod( @@ -141,43 +141,43 @@ fn args_have_docs(docs: [doc::argdoc]) -> bool { #[test] fn should_elide_fns_with_undocumented_arguments() { let doc = test::mk_doc("fn a(a: int) { }"); - assert vec::is_empty(doc.topmod.fns()); + assert vec::is_empty(doc.cratemod().fns()); } #[test] fn should_not_elide_fns_with_documented_arguments() { let doc = test::mk_doc("#[doc(args(a = \"b\"))] fn a(a: int) { }"); - assert vec::is_not_empty(doc.topmod.fns()); + assert vec::is_not_empty(doc.cratemod().fns()); } #[test] fn should_not_elide_fns_with_documented_failure_conditions() { let doc = test::mk_doc("#[doc(failure = \"yup\")] fn a() { }"); - assert vec::is_not_empty(doc.topmod.fns()); + assert vec::is_not_empty(doc.cratemod().fns()); } #[test] fn should_elide_undocumented_mods() { let doc = test::mk_doc("mod a { }"); - assert vec::is_empty(doc.topmod.mods()); + assert vec::is_empty(doc.cratemod().mods()); } #[test] fn should_not_elide_undocument_mods_with_documented_mods() { let doc = test::mk_doc("mod a { #[doc = \"b\"] mod b { } }"); - assert vec::is_not_empty(doc.topmod.mods()); + assert vec::is_not_empty(doc.cratemod().mods()); } #[test] fn should_not_elide_undocument_mods_with_documented_fns() { let doc = test::mk_doc("mod a { #[doc = \"b\"] fn b() { } }"); - assert vec::is_not_empty(doc.topmod.mods()); + assert vec::is_not_empty(doc.cratemod().mods()); } #[test] fn should_elide_undocumented_fns() { let doc = test::mk_doc("fn a() { }"); - assert vec::is_empty(doc.topmod.fns()); + assert vec::is_empty(doc.cratemod().fns()); } fn fold_const( @@ -194,7 +194,7 @@ fn fold_const( #[test] fn should_elide_undocumented_consts() { let doc = test::mk_doc("const a: bool = true;"); - assert vec::is_empty(doc.topmod.consts()); + assert vec::is_empty(doc.cratemod().consts()); } fn fold_enum(fold: fold::fold, doc: doc::enumdoc) -> doc::enumdoc { @@ -218,19 +218,19 @@ fn fold_enum(fold: fold::fold, doc: doc::enumdoc) -> doc::enumdoc { #[test] fn should_elide_undocumented_enums() { let doc = test::mk_doc("enum a { b }"); - assert vec::is_empty(doc.topmod.enums()); + assert vec::is_empty(doc.cratemod().enums()); } #[test] fn should_elide_undocumented_variants() { let doc = test::mk_doc("#[doc = \"a\"] enum a { b }"); - assert vec::is_empty(doc.topmod.enums()[0].variants); + assert vec::is_empty(doc.cratemod().enums()[0].variants); } #[test] fn should_not_elide_enums_with_documented_variants() { let doc = test::mk_doc("enum a { #[doc = \"a\"] b }"); - assert vec::is_not_empty(doc.topmod.enums()); + assert vec::is_not_empty(doc.cratemod().enums()); } fn fold_res(fold: fold::fold, doc: doc::resdoc) -> doc::resdoc { @@ -246,14 +246,14 @@ fn fold_res(fold: fold::fold, doc: doc::resdoc) -> doc::resdoc { #[test] fn should_elide_undocumented_resources() { let doc = test::mk_doc("resource r(a: bool) { }"); - assert vec::is_empty(doc.topmod.resources()); + assert vec::is_empty(doc.cratemod().resources()); } #[test] fn should_not_elide_resources_with_documented_args() { let doc = test::mk_doc("#[doc(args(a = \"drunk\"))]\ resource r(a: bool) { }"); - assert vec::is_not_empty(doc.topmod.resources()); + assert vec::is_not_empty(doc.cratemod().resources()); } fn fold_iface( @@ -283,31 +283,31 @@ fn methods_have_docs(docs: [doc::methoddoc]) -> bool { #[test] fn should_elide_undocumented_ifaces() { let doc = test::mk_doc("iface i { fn a(); }"); - assert vec::is_empty(doc.topmod.ifaces()); + assert vec::is_empty(doc.cratemod().ifaces()); } #[test] fn should_not_elide_documented_ifaces() { let doc = test::mk_doc("#[doc = \"hey\"] iface i { fn a(); }"); - assert vec::is_not_empty(doc.topmod.ifaces()); + assert vec::is_not_empty(doc.cratemod().ifaces()); } #[test] fn should_elide_ifaces_with_undocumented_args() { let doc = test::mk_doc("iface i { fn a(b: bool); }"); - assert vec::is_empty(doc.topmod.ifaces()); + assert vec::is_empty(doc.cratemod().ifaces()); } #[test] fn should_not_elide_ifaces_with_documented_methods() { let doc = test::mk_doc("iface i { #[doc = \"hey\"] fn a(); }"); - assert vec::is_not_empty(doc.topmod.ifaces()); + assert vec::is_not_empty(doc.cratemod().ifaces()); } #[test] fn should_not_elide_undocumented_iface_methods() { let doc = test::mk_doc("#[doc = \"hey\"] iface i { fn a(); }"); - assert vec::is_not_empty(doc.topmod.ifaces()[0].methods); + assert vec::is_not_empty(doc.cratemod().ifaces()[0].methods); } fn fold_impl( @@ -326,25 +326,25 @@ fn fold_impl( #[test] fn should_elide_undocumented_impls() { let doc = test::mk_doc("impl i for int { fn a() { } }"); - assert vec::is_empty(doc.topmod.impls()); + assert vec::is_empty(doc.cratemod().impls()); } #[test] fn should_not_elide_documented_impls() { let doc = test::mk_doc("#[doc = \"hey\"] impl i for int { fn a() { } }"); - assert vec::is_not_empty(doc.topmod.impls()); + assert vec::is_not_empty(doc.cratemod().impls()); } #[test] fn should_not_elide_impls_with_documented_methods() { let doc = test::mk_doc("impl i for int { #[doc = \"hey\"] fn a() { } }"); - assert vec::is_not_empty(doc.topmod.impls()); + assert vec::is_not_empty(doc.cratemod().impls()); } #[test] fn should_not_elide_undocumented_impl_methods() { let doc = test::mk_doc("#[doc = \"hey\"] impl i for int { fn a() { } }"); - assert vec::is_not_empty(doc.topmod.impls()[0].methods); + assert vec::is_not_empty(doc.cratemod().impls()[0].methods); } fn fold_type( @@ -362,12 +362,12 @@ fn fold_type( #[test] fn should_elide_undocumented_types() { let doc = test::mk_doc("type t = int;"); - assert vec::is_empty(doc.topmod.types()); + assert vec::is_empty(doc.cratemod().types()); } #[cfg(test)] mod test { - fn mk_doc(source: str) -> doc::cratedoc { + fn mk_doc(source: str) -> doc::doc { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = attr_pass::mk_pass().f(srv, doc); diff --git a/src/rustdoc/prune_unexported_pass.rs b/src/rustdoc/prune_unexported_pass.rs index 6e1edc159c0..fcd24bebbb4 100644 --- a/src/rustdoc/prune_unexported_pass.rs +++ b/src/rustdoc/prune_unexported_pass.rs @@ -13,12 +13,12 @@ fn mk_pass() -> pass { } } -fn run(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc { +fn run(srv: astsrv::srv, doc: doc::doc) -> doc::doc { let fold = fold::fold({ fold_mod: fold_mod with *fold::default_any_fold(srv) }); - fold.fold_crate(fold, doc) + fold.fold_doc(fold, doc) } fn fold_mod(fold: fold::fold, doc: doc::moddoc) -> doc::moddoc { @@ -137,25 +137,25 @@ fn is_exported_from_crate( #[test] fn should_prune_unexported_fns() { let doc = test::mk_doc("mod b { export a; fn a() { } fn b() { } }"); - assert vec::len(doc.topmod.mods()[0].fns()) == 1u; + assert vec::len(doc.cratemod().mods()[0].fns()) == 1u; } #[test] fn should_prune_unexported_fns_from_top_mod() { let doc = test::mk_doc("export a; fn a() { } fn b() { }"); - assert vec::len(doc.topmod.fns()) == 1u; + assert vec::len(doc.cratemod().fns()) == 1u; } #[test] fn should_prune_unexported_modules() { let doc = test::mk_doc("mod a { export a; mod a { } mod b { } }"); - assert vec::len(doc.topmod.mods()[0].mods()) == 1u; + assert vec::len(doc.cratemod().mods()[0].mods()) == 1u; } #[test] fn should_prune_unexported_modules_from_top_mod() { let doc = test::mk_doc("export a; mod a { } mod b { }"); - assert vec::len(doc.topmod.mods()) == 1u; + assert vec::len(doc.cratemod().mods()) == 1u; } #[test] @@ -164,75 +164,75 @@ fn should_prune_unexported_consts() { "mod a { export a; \ const a: bool = true; \ const b: bool = true; }"); - assert vec::len(doc.topmod.mods()[0].consts()) == 1u; + assert vec::len(doc.cratemod().mods()[0].consts()) == 1u; } #[test] fn should_prune_unexported_consts_from_top_mod() { let doc = test::mk_doc( "export a; const a: bool = true; const b: bool = true;"); - assert vec::len(doc.topmod.consts()) == 1u; + assert vec::len(doc.cratemod().consts()) == 1u; } #[test] fn should_prune_unexported_enums_from_top_mod() { let doc = test::mk_doc("export a; mod a { } enum b { c }"); - assert vec::len(doc.topmod.enums()) == 0u; + assert vec::len(doc.cratemod().enums()) == 0u; } #[test] fn should_prune_unexported_enums() { let doc = test::mk_doc("mod a { export a; mod a { } enum b { c } }"); - assert vec::len(doc.topmod.mods()[0].enums()) == 0u; + assert vec::len(doc.cratemod().mods()[0].enums()) == 0u; } #[test] fn should_prune_unexported_variants_from_top_mod() { let doc = test::mk_doc("export b::{}; enum b { c }"); - assert vec::len(doc.topmod.enums()[0].variants) == 0u; + assert vec::len(doc.cratemod().enums()[0].variants) == 0u; } #[test] fn should_prune_unexported_variants() { let doc = test::mk_doc("mod a { export b::{}; enum b { c } }"); - assert vec::len(doc.topmod.mods()[0].enums()[0].variants) == 0u; + assert vec::len(doc.cratemod().mods()[0].enums()[0].variants) == 0u; } #[test] fn should_prune_unexported_resources_from_top_mod() { let doc = test::mk_doc("export a; mod a { } resource r(a: bool) { }"); - assert vec::is_empty(doc.topmod.resources()); + assert vec::is_empty(doc.cratemod().resources()); } #[test] fn should_prune_unexported_resources() { let doc = test::mk_doc( "mod a { export a; mod a { } resource r(a: bool) { } }"); - assert vec::is_empty(doc.topmod.mods()[0].resources()); + assert vec::is_empty(doc.cratemod().mods()[0].resources()); } #[test] fn should_prune_unexported_ifaces_from_top_mod() { let doc = test::mk_doc("export a; mod a { } iface b { fn c(); }"); - assert vec::is_empty(doc.topmod.ifaces()); + assert vec::is_empty(doc.cratemod().ifaces()); } #[test] fn should_prune_unexported_impls_from_top_mod() { let doc = test::mk_doc( "export a; mod a { } impl b for int { fn c() { } }"); - assert vec::is_empty(doc.topmod.impls()) + assert vec::is_empty(doc.cratemod().impls()) } #[test] fn should_prune_unexported_types() { let doc = test::mk_doc("export a; mod a { } type b = int;"); - assert vec::is_empty(doc.topmod.types()); + assert vec::is_empty(doc.cratemod().types()); } #[test] fn should_not_prune_reexports() { - fn mk_doc(source: str) -> doc::cratedoc { + fn mk_doc(source: str) -> doc::doc { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = reexport_pass::mk_pass().f(srv, doc); @@ -242,12 +242,12 @@ fn mk_doc(source: str) -> doc::cratedoc { let doc = mk_doc("import a::b; \ export b; \ mod a { fn b() { } }"); - assert vec::is_not_empty(doc.topmod.fns()); + assert vec::is_not_empty(doc.cratemod().fns()); } #[cfg(test)] mod test { - fn mk_doc(source: str) -> doc::cratedoc { + fn mk_doc(source: str) -> doc::doc { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); run(srv, doc) diff --git a/src/rustdoc/reexport_pass.rs b/src/rustdoc/reexport_pass.rs index 975bfb54dbf..d5e61692719 100644 --- a/src/rustdoc/reexport_pass.rs +++ b/src/rustdoc/reexport_pass.rs @@ -18,7 +18,7 @@ fn mk_pass() -> pass { type def_map = map::hashmap; type path_map = map::hashmap; -fn run(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc { +fn run(srv: astsrv::srv, doc: doc::doc) -> doc::doc { // First gather the set of defs that are used as reexports let def_set = build_reexport_def_set(srv); @@ -89,7 +89,7 @@ fn build_reexport_def_set(srv: astsrv::srv) -> def_set { fn build_reexport_def_map( srv: astsrv::srv, - doc: doc::cratedoc, + doc: doc::doc, def_set: def_set ) -> def_map { @@ -112,7 +112,7 @@ fn build_reexport_def_map( with *fold::default_seq_fold(ctxt) }); - fold.fold_crate(fold, doc); + fold.fold_doc(fold, doc); ret ctxt.def_map; @@ -190,16 +190,16 @@ fn build_reexport_path_map(srv: astsrv::srv, -def_map: def_map) -> path_map { } fn merge_reexports( - doc: doc::cratedoc, + doc: doc::doc, path_map: path_map -) -> doc::cratedoc { +) -> doc::doc { let fold = fold::fold({ fold_mod: fold_mod with *fold::default_seq_fold(path_map) }); - ret fold.fold_crate(fold, doc); + ret fold.fold_doc(fold, doc); fn fold_mod(fold: fold::fold, doc: doc::moddoc) -> doc::moddoc { let doc = fold::default_seq_fold_mod(fold, doc); @@ -304,7 +304,7 @@ fn should_duplicate_reexported_items() { let source = "mod a { export b; fn b() { } } \ mod c { import a::b; export b; }"; let doc = test::mk_doc(source); - assert doc.topmod.mods()[1].fns()[0].name() == "b"; + assert doc.cratemod().mods()[1].fns()[0].name() == "b"; } #[test] @@ -312,7 +312,7 @@ fn should_mark_reepxorts_as_such() { let source = "mod a { export b; fn b() { } } \ mod c { import a::b; export b; }"; let doc = test::mk_doc(source); - assert doc.topmod.mods()[1].fns()[0].item.reexport == true; + assert doc.cratemod().mods()[1].fns()[0].item.reexport == true; } #[test] @@ -320,7 +320,7 @@ fn should_duplicate_reexported_native_fns() { let source = "native mod a { fn b(); } \ mod c { import a::b; export b; }"; let doc = test::mk_doc(source); - assert doc.topmod.mods()[0].fns()[0].name() == "b"; + assert doc.cratemod().mods()[0].fns()[0].name() == "b"; } #[test] @@ -339,8 +339,8 @@ mod d { \ let doc = run(srv, doc); // Reexports may not be in any specific order let doc = sort_item_name_pass::mk_pass().f(srv, doc); - assert doc.topmod.mods()[1].fns()[0].name() == "b"; - assert doc.topmod.mods()[1].fns()[1].name() == "c"; + assert doc.cratemod().mods()[1].fns()[0].name() == "b"; + assert doc.cratemod().mods()[1].fns()[1].name() == "c"; } } @@ -349,12 +349,12 @@ fn should_rename_items_reexported_with_different_names() { let source = "mod a { export b; fn b() { } } \ mod c { import x = a::b; export x; }"; let doc = test::mk_doc(source); - assert doc.topmod.mods()[1].fns()[0].name() == "x"; + assert doc.cratemod().mods()[1].fns()[0].name() == "x"; } #[test] fn should_reexport_in_topmod() { - fn mk_doc(source: str) -> doc::cratedoc { + fn mk_doc(source: str) -> doc::doc { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, "core"); let doc = path_pass::mk_pass().f(srv, doc); @@ -368,7 +368,7 @@ mod option { \ enum t { some, none } \ }"; let doc = mk_doc(source); - assert doc.topmod.enums()[0].name() == "option"; + assert doc.cratemod().enums()[0].name() == "option"; } #[test] @@ -380,12 +380,12 @@ mod option { \ enum t { none, some } \ }"; let doc = test::mk_doc(source); - assert vec::len(doc.topmod.enums()) == 1u; + assert vec::len(doc.cratemod().enums()) == 1u; } #[cfg(test)] mod test { - fn mk_doc(source: str) -> doc::cratedoc { + fn mk_doc(source: str) -> doc::doc { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = path_pass::mk_pass().f(srv, doc); diff --git a/src/rustdoc/rustdoc.rs b/src/rustdoc/rustdoc.rs index df0e014eb41..db83b5c2ca5 100755 --- a/src/rustdoc/rustdoc.rs +++ b/src/rustdoc/rustdoc.rs @@ -9,14 +9,14 @@ #[doc = "A single operation on the document model"] type pass = { name: str, - f: fn~(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc + f: fn~(srv: astsrv::srv, doc: doc::doc) -> doc::doc }; fn run_passes( srv: astsrv::srv, - doc: doc::cratedoc, + doc: doc::doc, passes: [pass] -) -> doc::cratedoc { +) -> doc::doc { #[doc( brief = @@ -49,32 +49,40 @@ fn run_passes( fn test_run_passes() { fn pass1( _srv: astsrv::srv, - doc: doc::cratedoc - ) -> doc::cratedoc { + doc: doc::doc + ) -> doc::doc { { - topmod: { - item: { - name: doc.topmod.name() + "two" - with doc.topmod.item - }, - items: [], - index: none - } + pages: [ + doc::cratepage({ + topmod: { + item: { + name: doc.cratemod().name() + "two" + with doc.cratemod().item + }, + items: [], + index: none + } + }) + ] } } fn pass2( _srv: astsrv::srv, - doc: doc::cratedoc - ) -> doc::cratedoc { + doc: doc::doc + ) -> doc::doc { { - topmod: { - item: { - name: doc.topmod.name() + "three" - with doc.topmod.item - }, - items: [], - index: none - } + pages: [ + doc::cratepage({ + topmod: { + item: { + name: doc.cratemod().name() + "three" + with doc.cratemod().item + }, + items: [], + index: none + } + }) + ] } } let source = ""; @@ -91,7 +99,7 @@ fn pass2( ]; let doc = extract::from_srv(srv, "one"); let doc = run_passes(srv, doc, passes); - assert doc.topmod.name() == "onetwothree"; + assert doc.cratemod().name() == "onetwothree"; } } diff --git a/src/rustdoc/sort_item_name_pass.rs b/src/rustdoc/sort_item_name_pass.rs index 196f7badee8..8ed03f56d23 100644 --- a/src/rustdoc/sort_item_name_pass.rs +++ b/src/rustdoc/sort_item_name_pass.rs @@ -14,7 +14,7 @@ fn test() { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = mk_pass().f(srv, doc); - assert doc.topmod.items[0].name() == "y"; - assert doc.topmod.items[1].name() == "z"; + assert doc.cratemod().items[0].name() == "y"; + assert doc.cratemod().items[1].name() == "z"; } } diff --git a/src/rustdoc/sort_item_type_pass.rs b/src/rustdoc/sort_item_type_pass.rs index 5bd0fa150e0..a01c914b8a4 100644 --- a/src/rustdoc/sort_item_type_pass.rs +++ b/src/rustdoc/sort_item_type_pass.rs @@ -37,14 +37,14 @@ impl iimpl for int { fn a() { } } \ astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = mk_pass().f(srv, doc); - assert doc.topmod.items[0].name() == "iconst"; - assert doc.topmod.items[1].name() == "itype"; - assert doc.topmod.items[2].name() == "ienum"; - assert doc.topmod.items[3].name() == "ires"; - assert doc.topmod.items[4].name() == "iiface"; - assert doc.topmod.items[5].name() == "iimpl"; - assert doc.topmod.items[6].name() == "ifn"; - assert doc.topmod.items[7].name() == "imod"; - assert doc.topmod.items[8].name() == "inmod"; + assert doc.cratemod().items[0].name() == "iconst"; + assert doc.cratemod().items[1].name() == "itype"; + assert doc.cratemod().items[2].name() == "ienum"; + assert doc.cratemod().items[3].name() == "ires"; + assert doc.cratemod().items[4].name() == "iiface"; + assert doc.cratemod().items[5].name() == "iimpl"; + assert doc.cratemod().items[6].name() == "ifn"; + assert doc.cratemod().items[7].name() == "imod"; + assert doc.cratemod().items[8].name() == "inmod"; } } diff --git a/src/rustdoc/sort_pass.rs b/src/rustdoc/sort_pass.rs index dbe7a7e19db..53b9ca1fcfd 100644 --- a/src/rustdoc/sort_pass.rs +++ b/src/rustdoc/sort_pass.rs @@ -9,7 +9,7 @@ fn mk_pass(name: str, lteq: item_lteq) -> pass { { name: name, - f: fn~(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc { + f: fn~(srv: astsrv::srv, doc: doc::doc) -> doc::doc { run(srv, doc, lteq) } } @@ -17,14 +17,14 @@ fn mk_pass(name: str, lteq: item_lteq) -> pass { fn run( _srv: astsrv::srv, - doc: doc::cratedoc, + doc: doc::doc, lteq: item_lteq -) -> doc::cratedoc { +) -> doc::doc { let fold = fold::fold({ fold_mod: fold_mod with *fold::default_any_fold(lteq) }); - fold.fold_crate(fold, doc) + fold.fold_doc(fold, doc) } fn fold_mod( @@ -48,10 +48,10 @@ fn name_lteq(item1: doc::itemtag, item2: doc::itemtag) -> bool { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = mk_pass("", name_lteq).f(srv, doc); - assert doc.topmod.mods()[0].name() == "w"; - assert doc.topmod.mods()[1].items[0].name() == "x"; - assert doc.topmod.mods()[1].items[1].name() == "y"; - assert doc.topmod.mods()[1].name() == "z"; + assert doc.cratemod().mods()[0].name() == "w"; + assert doc.cratemod().mods()[1].items[0].name() == "x"; + assert doc.cratemod().mods()[1].items[1].name() == "y"; + assert doc.cratemod().mods()[1].name() == "z"; } } @@ -65,10 +65,10 @@ fn always_eq(_item1: doc::itemtag, _item2: doc::itemtag) -> bool { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = mk_pass("", always_eq).f(srv, doc); - assert doc.topmod.mods()[0].items[0].name() == "b"; - assert doc.topmod.mods()[1].items[0].name() == "d"; + assert doc.cratemod().mods()[0].items[0].name() == "b"; + assert doc.cratemod().mods()[1].items[0].name() == "d"; let doc = mk_pass("", always_eq).f(srv, doc); - assert doc.topmod.mods()[0].items[0].name() == "b"; - assert doc.topmod.mods()[1].items[0].name() == "d"; + assert doc.cratemod().mods()[0].items[0].name() == "b"; + assert doc.cratemod().mods()[1].items[0].name() == "d"; } } diff --git a/src/rustdoc/trim_pass.rs b/src/rustdoc/trim_pass.rs index df5f06fb871..d236821e6cb 100644 --- a/src/rustdoc/trim_pass.rs +++ b/src/rustdoc/trim_pass.rs @@ -18,8 +18,8 @@ fn should_trim_mod() { let doc = test::mk_doc("#[doc(brief = \"\nbrief\n\", \ desc = \"\ndesc\n\")] \ mod m { }"); - assert doc.topmod.mods()[0].brief() == some("brief"); - assert doc.topmod.mods()[0].desc() == some("desc"); + assert doc.cratemod().mods()[0].brief() == some("brief"); + assert doc.cratemod().mods()[0].desc() == some("desc"); } #[test] @@ -27,8 +27,8 @@ fn should_trim_const() { let doc = test::mk_doc("#[doc(brief = \"\nbrief\n\", \ desc = \"\ndesc\n\")] \ const a: bool = true;"); - assert doc.topmod.consts()[0].brief() == some("brief"); - assert doc.topmod.consts()[0].desc() == some("desc"); + assert doc.cratemod().consts()[0].brief() == some("brief"); + assert doc.cratemod().consts()[0].desc() == some("desc"); } #[test] @@ -36,31 +36,31 @@ fn should_trim_fn() { let doc = test::mk_doc("#[doc(brief = \"\nbrief\n\", \ desc = \"\ndesc\n\")] \ fn a() { }"); - assert doc.topmod.fns()[0].brief() == some("brief"); - assert doc.topmod.fns()[0].desc() == some("desc"); + assert doc.cratemod().fns()[0].brief() == some("brief"); + assert doc.cratemod().fns()[0].desc() == some("desc"); } #[test] fn should_trim_args() { let doc = test::mk_doc("#[doc(args(a = \"\na\n\"))] fn a(a: int) { }"); - assert doc.topmod.fns()[0].args[0].desc == some("a"); + assert doc.cratemod().fns()[0].args[0].desc == some("a"); } #[test] fn should_trim_ret() { let doc = test::mk_doc("#[doc(return = \"\na\n\")] fn a() -> int { }"); - assert doc.topmod.fns()[0].return.desc == some("a"); + assert doc.cratemod().fns()[0].return.desc == some("a"); } #[test] fn should_trim_failure_conditions() { let doc = test::mk_doc("#[doc(failure = \"\na\n\")] fn a() -> int { }"); - assert doc.topmod.fns()[0].failure == some("a"); + assert doc.cratemod().fns()[0].failure == some("a"); } #[cfg(test)] mod test { - fn mk_doc(source: str) -> doc::cratedoc { + fn mk_doc(source: str) -> doc::doc { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); let doc = attr_pass::mk_pass().f(srv, doc); diff --git a/src/rustdoc/tystr_pass.rs b/src/rustdoc/tystr_pass.rs index 94f02e4ddb5..a7af2bb13ba 100644 --- a/src/rustdoc/tystr_pass.rs +++ b/src/rustdoc/tystr_pass.rs @@ -16,8 +16,8 @@ fn mk_pass() -> pass { fn run( srv: astsrv::srv, - doc: doc::cratedoc -) -> doc::cratedoc { + doc: doc::doc +) -> doc::doc { let fold = fold::fold({ fold_fn: fold_fn, fold_const: fold_const, @@ -28,7 +28,7 @@ fn run( fold_type: fold_type with *fold::default_any_fold(srv) }); - fold.fold_crate(fold, doc) + fold.fold_doc(fold, doc) } fn fold_fn( @@ -66,13 +66,13 @@ fn get_fn_sig(srv: astsrv::srv, fn_id: doc::ast_id) -> option { #[test] fn should_add_fn_sig() { let doc = test::mk_doc("fn a() -> int { }"); - assert doc.topmod.fns()[0].sig == some("fn a() -> int"); + assert doc.cratemod().fns()[0].sig == some("fn a() -> int"); } #[test] fn should_add_native_fn_sig() { let doc = test::mk_doc("native mod a { fn a() -> int; }"); - assert doc.topmod.nmods()[0].fns[0].sig == some("fn a() -> int"); + assert doc.cratemod().nmods()[0].fns[0].sig == some("fn a() -> int"); } fn merge_ret_ty( @@ -118,19 +118,19 @@ fn ret_ty_to_str(decl: ast::fn_decl) -> option { #[test] fn should_add_fn_ret_types() { let doc = test::mk_doc("fn a() -> int { }"); - assert doc.topmod.fns()[0].return.ty == some("int"); + assert doc.cratemod().fns()[0].return.ty == some("int"); } #[test] fn should_not_add_nil_ret_type() { let doc = test::mk_doc("fn a() { }"); - assert doc.topmod.fns()[0].return.ty == none; + assert doc.cratemod().fns()[0].return.ty == none; } #[test] fn should_add_native_fn_ret_types() { let doc = test::mk_doc("native mod a { fn a() -> int; }"); - assert doc.topmod.nmods()[0].fns[0].return.ty == some("int"); + assert doc.cratemod().nmods()[0].fns[0].return.ty == some("int"); } fn merge_arg_tys( @@ -176,7 +176,7 @@ fn decl_arg_tys(decl: ast::fn_decl) -> [(str, str)] { #[test] fn should_add_arg_types() { let doc = test::mk_doc("fn a(b: int, c: bool) { }"); - let fn_ = doc.topmod.fns()[0]; + let fn_ = doc.cratemod().fns()[0]; assert fn_.args[0].ty == some("int"); assert fn_.args[1].ty == some("bool"); } @@ -184,7 +184,7 @@ fn should_add_arg_types() { #[test] fn should_add_native_fn_arg_types() { let doc = test::mk_doc("native mod a { fn a(b: int); }"); - assert doc.topmod.nmods()[0].fns[0].args[0].ty == some("int"); + assert doc.cratemod().nmods()[0].fns[0].args[0].ty == some("int"); } fn fold_const( @@ -210,7 +210,7 @@ fn fold_const( #[test] fn should_add_const_types() { let doc = test::mk_doc("const a: bool = true;"); - assert doc.topmod.consts()[0].ty == some("bool"); + assert doc.cratemod().consts()[0].ty == some("bool"); } fn fold_enum( @@ -249,7 +249,7 @@ fn fold_enum( #[test] fn should_add_variant_sigs() { let doc = test::mk_doc("enum a { b(int) }"); - assert doc.topmod.enums()[0].variants[0].sig == some("b(int)"); + assert doc.cratemod().enums()[0].variants[0].sig == some("b(int)"); } fn fold_res( @@ -276,13 +276,13 @@ fn fold_res( #[test] fn should_add_resource_sigs() { let doc = test::mk_doc("resource r(b: bool) { }"); - assert doc.topmod.resources()[0].sig == some("resource r(b: bool)"); + assert doc.cratemod().resources()[0].sig == some("resource r(b: bool)"); } #[test] fn should_add_resource_arg_tys() { let doc = test::mk_doc("resource r(a: bool) { }"); - assert doc.topmod.resources()[0].args[0].ty == some("bool"); + assert doc.cratemod().resources()[0].args[0].ty == some("bool"); } fn fold_iface( @@ -457,25 +457,25 @@ fn get_method_arg_tys( #[test] fn should_add_iface_method_sigs() { let doc = test::mk_doc("iface i { fn a() -> int; }"); - assert doc.topmod.ifaces()[0].methods[0].sig == some("fn a() -> int"); + assert doc.cratemod().ifaces()[0].methods[0].sig == some("fn a() -> int"); } #[test] fn should_add_iface_method_ret_types() { let doc = test::mk_doc("iface i { fn a() -> int; }"); - assert doc.topmod.ifaces()[0].methods[0].return.ty == some("int"); + assert doc.cratemod().ifaces()[0].methods[0].return.ty == some("int"); } #[test] fn should_not_add_iface_method_nil_ret_type() { let doc = test::mk_doc("iface i { fn a(); }"); - assert doc.topmod.ifaces()[0].methods[0].return.ty == none; + assert doc.cratemod().ifaces()[0].methods[0].return.ty == none; } #[test] fn should_add_iface_method_arg_types() { let doc = test::mk_doc("iface i { fn a(b: int, c: bool); }"); - let fn_ = doc.topmod.ifaces()[0].methods[0]; + let fn_ = doc.cratemod().ifaces()[0].methods[0]; assert fn_.args[0].ty == some("int"); assert fn_.args[1].ty == some("bool"); } @@ -512,43 +512,43 @@ fn fold_impl( #[test] fn should_add_impl_iface_ty() { let doc = test::mk_doc("impl i of j for int { fn a() { } }"); - assert doc.topmod.impls()[0].iface_ty == some("j"); + assert doc.cratemod().impls()[0].iface_ty == some("j"); } #[test] fn should_not_add_impl_iface_ty_if_none() { let doc = test::mk_doc("impl i for int { fn a() { } }"); - assert doc.topmod.impls()[0].iface_ty == none; + assert doc.cratemod().impls()[0].iface_ty == none; } #[test] fn should_add_impl_self_ty() { let doc = test::mk_doc("impl i for int { fn a() { } }"); - assert doc.topmod.impls()[0].self_ty == some("int"); + assert doc.cratemod().impls()[0].self_ty == some("int"); } #[test] fn should_add_impl_method_sigs() { let doc = test::mk_doc("impl i for int { fn a() -> int { fail } }"); - assert doc.topmod.impls()[0].methods[0].sig == some("fn a() -> int"); + assert doc.cratemod().impls()[0].methods[0].sig == some("fn a() -> int"); } #[test] fn should_add_impl_method_ret_types() { let doc = test::mk_doc("impl i for int { fn a() -> int { fail } }"); - assert doc.topmod.impls()[0].methods[0].return.ty == some("int"); + assert doc.cratemod().impls()[0].methods[0].return.ty == some("int"); } #[test] fn should_not_add_impl_method_nil_ret_type() { let doc = test::mk_doc("impl i for int { fn a() { } }"); - assert doc.topmod.impls()[0].methods[0].return.ty == none; + assert doc.cratemod().impls()[0].methods[0].return.ty == none; } #[test] fn should_add_impl_method_arg_types() { let doc = test::mk_doc("impl i for int { fn a(b: int, c: bool) { } }"); - let fn_ = doc.topmod.impls()[0].methods[0]; + let fn_ = doc.cratemod().impls()[0].methods[0]; assert fn_.args[0].ty == some("int"); assert fn_.args[1].ty == some("bool"); } @@ -584,12 +584,12 @@ fn fold_type( #[test] fn should_add_type_signatures() { let doc = test::mk_doc("type t = int;"); - assert doc.topmod.types()[0].sig == some("type t = int"); + assert doc.cratemod().types()[0].sig == some("type t = int"); } #[cfg(test)] mod test { - fn mk_doc(source: str) -> doc::cratedoc { + fn mk_doc(source: str) -> doc::doc { astsrv::from_str(source) {|srv| let doc = extract::from_srv(srv, ""); run(srv, doc)