diff --git a/src/rustdoc/attr_parser.rs b/src/rustdoc/attr_parser.rs index bd98912eb4a..a2a34537085 100644 --- a/src/rustdoc/attr_parser.rs +++ b/src/rustdoc/attr_parser.rs @@ -1,6 +1,10 @@ export parse_fn; -fn parse_fn(name: str, attrs: [ast::attribute]) -> doc::fndoc { +fn parse_fn( + name: str, + id: ast::node_id, + attrs: [ast::attribute] +) -> doc::fndoc { let noargdocs = map::new_str_hash::(); let _fndoc = none; for attr: ast::attribute in attrs { @@ -8,6 +12,7 @@ fn parse_fn(name: str, attrs: [ast::attribute]) -> doc::fndoc { ast::meta_name_value( "doc", {node: ast::lit_str(value), span: _}) { _fndoc = some(~{ + id: id, name: name, brief: value, desc: none, @@ -17,7 +22,7 @@ fn parse_fn(name: str, attrs: [ast::attribute]) -> doc::fndoc { } ast::meta_list("doc", docs) { _fndoc = some( - parse_fn_(name, docs)); + parse_fn_(name, id, docs)); } } } @@ -26,6 +31,7 @@ fn parse_fn(name: str, attrs: [ast::attribute]) -> doc::fndoc { some(_d) { _d } none. { ~{ + id: id, name: name, brief: "_undocumented_", desc: none, @@ -50,7 +56,11 @@ fn parse_fn(name: str, attrs: [ast::attribute]) -> doc::fndoc { args(items = "Doc attribute contents"), return = "Parsed function docs." )] -fn parse_fn_(name: str, items: [@ast::meta_item]) -> doc::fndoc { +fn parse_fn_( + name: str, + id: ast::node_id, + items: [@ast::meta_item] +) -> doc::fndoc { let brief = none; let desc = none; let return = none; @@ -97,6 +107,7 @@ fn parse_fn_(name: str, items: [@ast::meta_item]) -> doc::fndoc { }; ~{ + id: id, name: name, brief: _brief, desc: desc, @@ -128,7 +139,7 @@ mod tests { fn parse_fn_should_handle_undocumented_functions() { let source = ""; let attrs = parse_attributes(source); - let doc = parse_fn("f", attrs); + let doc = parse_fn("f", 0, attrs); assert doc.brief == "_undocumented_"; assert doc.desc == none; assert doc.return == none; @@ -139,7 +150,7 @@ mod tests { fn parse_fn_should_parse_simple_doc_attributes() { let source = "#[doc = \"basic\"]"; let attrs = parse_attributes(source); - let doc = parse_fn("f", attrs); + let doc = parse_fn("f", 0, attrs); assert doc.brief == "basic"; } @@ -147,7 +158,7 @@ mod tests { fn parse_fn_should_parse_the_brief_description() { let source = "#[doc(brief = \"short\")]"; let attrs = parse_attributes(source); - let doc = parse_fn("f", attrs); + let doc = parse_fn("f", 0, attrs); assert doc.brief == "short"; } @@ -155,7 +166,7 @@ mod tests { fn parse_fn_should_parse_the_long_description() { let source = "#[doc(desc = \"description\")]"; let attrs = parse_attributes(source); - let doc = parse_fn("f", attrs); + let doc = parse_fn("f", 0, attrs); assert doc.desc == some("description"); } @@ -163,7 +174,7 @@ mod tests { fn parse_fn_should_parse_the_return_value_description() { let source = "#[doc(return = \"return value\")]"; let attrs = parse_attributes(source); - let doc = parse_fn("f", attrs); + let doc = parse_fn("f", 0, attrs); assert doc.return == some("return value"); } @@ -171,7 +182,7 @@ mod tests { fn parse_fn_should_parse_the_argument_descriptions() { let source = "#[doc(args(a = \"arg a\", b = \"arg b\"))]"; let attrs = parse_attributes(source); - let doc = parse_fn("f", attrs); + let doc = parse_fn("f", 0, attrs); assert doc.args.get("a") == "arg a"; assert doc.args.get("b") == "arg b"; } @@ -180,7 +191,7 @@ mod tests { fn parse_fn_should_set_brief_desc_to_undocumented_if_not_exists() { let source = "#[doc(desc = \"long desc\")]"; let attrs = parse_attributes(source); - let doc = parse_fn("f", attrs); + let doc = parse_fn("f", 0, attrs); assert doc.brief == "_undocumented_"; } } \ No newline at end of file diff --git a/src/rustdoc/doc.rs b/src/rustdoc/doc.rs index f78dd5b54b6..b1324713e11 100644 --- a/src/rustdoc/doc.rs +++ b/src/rustdoc/doc.rs @@ -1,3 +1,5 @@ +type ast_id = int; + type cratedoc = ~{ topmod: moddoc, }; @@ -9,6 +11,7 @@ type moddoc = ~{ }; type fndoc = ~{ + id: ast_id, name: str, brief: str, desc: option::t, diff --git a/src/rustdoc/extract.rs b/src/rustdoc/extract.rs index 64a8a7389e2..0dbf1548208 100644 --- a/src/rustdoc/extract.rs +++ b/src/rustdoc/extract.rs @@ -42,7 +42,7 @@ fn moddoc_from_mod( alt item.node { ast::item_fn(decl, typarams, _) { some(fndoc_from_fn( - decl, typarams, item.ident, item.attrs)) + decl, typarams, item.ident, item.id, item.attrs)) } _ { none @@ -56,9 +56,10 @@ fn fndoc_from_fn( _decl: ast::fn_decl, _typarams: [ast::ty_param], name: ast::ident, + id: ast::node_id, attrs: [ast::attribute] ) -> doc::fndoc { - attr_parser::parse_fn(name, attrs) + attr_parser::parse_fn(name, id, attrs) } #[cfg(test)] @@ -102,4 +103,12 @@ mod tests { assert doc.topmod.fns[0].name == "a"; assert doc.topmod.mods[0].fns[0].name == "c"; } + + #[test] + fn extract_should_set_fn_ast_id() { + let source = "fn a() { }"; + let ast = parse::from_str(source); + let doc = extract(ast); + assert doc.topmod.fns[0].id != 0; + } } \ No newline at end of file diff --git a/src/rustdoc/rustdoc.rs b/src/rustdoc/rustdoc.rs index 58c2519b664..029eb1eed15 100755 --- a/src/rustdoc/rustdoc.rs +++ b/src/rustdoc/rustdoc.rs @@ -23,7 +23,7 @@ import std::map; item = "AST item to document") )] fn doc_item(ctxt: gen::ctxt, item: @ast::item) { - let _fndoc0 = attr_parser::parse_fn(item.ident, item.attrs); + let _fndoc0 = attr_parser::parse_fn(item.ident, item.id, item.attrs); alt item.node { ast::item_const(ty, expr) { }