diff --git a/src/rustdoc/rustdoc.rc b/src/rustdoc/rustdoc.rc index 8fc39afbd07..5be7a7d3432 100644 --- a/src/rustdoc/rustdoc.rc +++ b/src/rustdoc/rustdoc.rc @@ -12,4 +12,5 @@ mod extract; mod attr_parser; mod doc; mod gen; -mod fold; \ No newline at end of file +mod fold; +mod tystr_pass; \ No newline at end of file diff --git a/src/rustdoc/tystr_pass.rs b/src/rustdoc/tystr_pass.rs new file mode 100644 index 00000000000..8894fe88ca8 --- /dev/null +++ b/src/rustdoc/tystr_pass.rs @@ -0,0 +1,69 @@ +import rustc::syntax::ast; + +export run; + +fn run(doc: doc::cratedoc, crate: @ast::crate) -> doc::cratedoc { + let fold = fold::fold({ + fold_fn: fn~( + f: fold::fold<@ast::crate>, + d: doc::fndoc + ) -> doc::fndoc { + fold_fn(f, d) + } + with *fold::default_seq_fold(crate) + }); + fold.fold_crate(fold, doc) +} + +fn fold_fn( + fold: fold::fold<@ast::crate>, + doc: doc::fndoc +) -> doc::fndoc { + import rustc::middle::ast_map; + import rustc::syntax::print::pprust; + + let crate = fold.ctxt; + + let map = ast_map::map_crate(*crate); + + fn add_ret_ty( + doc: option, + tystr: str + ) -> option { + alt doc { + some(doc) { + fail "unimplemented"; + } + none. { + some({ + desc: none, + ty: some(tystr) + }) + } + } + } + + ~{ + return: alt map.get(doc.id) { + ast_map::node_item(@{ + node: ast::item_fn(decl, _, _), _ + }) { + add_ret_ty(doc.return, pprust::ty_to_str(decl.output)) + } + } + with *doc + } +} + +#[cfg(test)] +mod tests { + + #[test] + fn should_add_fn_ret_types() { + let source = "fn a() -> int { }"; + let ast = parse::from_str(source); + let doc = extract::extract(ast, ""); + let doc = run(doc, ast); + assert option::get(doc.topmod.fns[0].return).ty == some("int"); + } +}