Skip to content

Commit a0fd732

Browse files
committed
---
yaml --- r: 7309 b: refs/heads/master c: 77690ba h: refs/heads/master i: 7307: a1cc16d v: v3
1 parent df6ed0f commit a0fd732

File tree

5 files changed

+37
-14
lines changed

5 files changed

+37
-14
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 7a9ba240a07e7e9494fa53b0001282d795d1be52
2+
refs/heads/master: 77690baa7049cf636ff5dd6124f7b1550fe42acc

trunk/src/rustdoc/attr_parser.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
export parse_fn;
22

3-
fn parse_fn(name: str, attrs: [ast::attribute]) -> doc::fndoc {
3+
fn parse_fn(
4+
name: str,
5+
id: ast::node_id,
6+
attrs: [ast::attribute]
7+
) -> doc::fndoc {
48
let noargdocs = map::new_str_hash::<str>();
59
let _fndoc = none;
610
for attr: ast::attribute in attrs {
711
alt attr.node.value.node {
812
ast::meta_name_value(
913
"doc", {node: ast::lit_str(value), span: _}) {
1014
_fndoc = some(~{
15+
id: id,
1116
name: name,
1217
brief: value,
1318
desc: none,
@@ -17,7 +22,7 @@ fn parse_fn(name: str, attrs: [ast::attribute]) -> doc::fndoc {
1722
}
1823
ast::meta_list("doc", docs) {
1924
_fndoc = some(
20-
parse_fn_(name, docs));
25+
parse_fn_(name, id, docs));
2126
}
2227
}
2328
}
@@ -26,6 +31,7 @@ fn parse_fn(name: str, attrs: [ast::attribute]) -> doc::fndoc {
2631
some(_d) { _d }
2732
none. {
2833
~{
34+
id: id,
2935
name: name,
3036
brief: "_undocumented_",
3137
desc: none,
@@ -50,7 +56,11 @@ fn parse_fn(name: str, attrs: [ast::attribute]) -> doc::fndoc {
5056
args(items = "Doc attribute contents"),
5157
return = "Parsed function docs."
5258
)]
53-
fn parse_fn_(name: str, items: [@ast::meta_item]) -> doc::fndoc {
59+
fn parse_fn_(
60+
name: str,
61+
id: ast::node_id,
62+
items: [@ast::meta_item]
63+
) -> doc::fndoc {
5464
let brief = none;
5565
let desc = none;
5666
let return = none;
@@ -97,6 +107,7 @@ fn parse_fn_(name: str, items: [@ast::meta_item]) -> doc::fndoc {
97107
};
98108

99109
~{
110+
id: id,
100111
name: name,
101112
brief: _brief,
102113
desc: desc,
@@ -128,7 +139,7 @@ mod tests {
128139
fn parse_fn_should_handle_undocumented_functions() {
129140
let source = "";
130141
let attrs = parse_attributes(source);
131-
let doc = parse_fn("f", attrs);
142+
let doc = parse_fn("f", 0, attrs);
132143
assert doc.brief == "_undocumented_";
133144
assert doc.desc == none;
134145
assert doc.return == none;
@@ -139,39 +150,39 @@ mod tests {
139150
fn parse_fn_should_parse_simple_doc_attributes() {
140151
let source = "#[doc = \"basic\"]";
141152
let attrs = parse_attributes(source);
142-
let doc = parse_fn("f", attrs);
153+
let doc = parse_fn("f", 0, attrs);
143154
assert doc.brief == "basic";
144155
}
145156

146157
#[test]
147158
fn parse_fn_should_parse_the_brief_description() {
148159
let source = "#[doc(brief = \"short\")]";
149160
let attrs = parse_attributes(source);
150-
let doc = parse_fn("f", attrs);
161+
let doc = parse_fn("f", 0, attrs);
151162
assert doc.brief == "short";
152163
}
153164

154165
#[test]
155166
fn parse_fn_should_parse_the_long_description() {
156167
let source = "#[doc(desc = \"description\")]";
157168
let attrs = parse_attributes(source);
158-
let doc = parse_fn("f", attrs);
169+
let doc = parse_fn("f", 0, attrs);
159170
assert doc.desc == some("description");
160171
}
161172

162173
#[test]
163174
fn parse_fn_should_parse_the_return_value_description() {
164175
let source = "#[doc(return = \"return value\")]";
165176
let attrs = parse_attributes(source);
166-
let doc = parse_fn("f", attrs);
177+
let doc = parse_fn("f", 0, attrs);
167178
assert doc.return == some("return value");
168179
}
169180

170181
#[test]
171182
fn parse_fn_should_parse_the_argument_descriptions() {
172183
let source = "#[doc(args(a = \"arg a\", b = \"arg b\"))]";
173184
let attrs = parse_attributes(source);
174-
let doc = parse_fn("f", attrs);
185+
let doc = parse_fn("f", 0, attrs);
175186
assert doc.args.get("a") == "arg a";
176187
assert doc.args.get("b") == "arg b";
177188
}
@@ -180,7 +191,7 @@ mod tests {
180191
fn parse_fn_should_set_brief_desc_to_undocumented_if_not_exists() {
181192
let source = "#[doc(desc = \"long desc\")]";
182193
let attrs = parse_attributes(source);
183-
let doc = parse_fn("f", attrs);
194+
let doc = parse_fn("f", 0, attrs);
184195
assert doc.brief == "_undocumented_";
185196
}
186197
}

trunk/src/rustdoc/doc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
type ast_id = int;
2+
13
type cratedoc = ~{
24
topmod: moddoc,
35
};
@@ -9,6 +11,7 @@ type moddoc = ~{
911
};
1012

1113
type fndoc = ~{
14+
id: ast_id,
1215
name: str,
1316
brief: str,
1417
desc: option::t<str>,

trunk/src/rustdoc/extract.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn moddoc_from_mod(
4242
alt item.node {
4343
ast::item_fn(decl, typarams, _) {
4444
some(fndoc_from_fn(
45-
decl, typarams, item.ident, item.attrs))
45+
decl, typarams, item.ident, item.id, item.attrs))
4646
}
4747
_ {
4848
none
@@ -56,9 +56,10 @@ fn fndoc_from_fn(
5656
_decl: ast::fn_decl,
5757
_typarams: [ast::ty_param],
5858
name: ast::ident,
59+
id: ast::node_id,
5960
attrs: [ast::attribute]
6061
) -> doc::fndoc {
61-
attr_parser::parse_fn(name, attrs)
62+
attr_parser::parse_fn(name, id, attrs)
6263
}
6364

6465
#[cfg(test)]
@@ -102,4 +103,12 @@ mod tests {
102103
assert doc.topmod.fns[0].name == "a";
103104
assert doc.topmod.mods[0].fns[0].name == "c";
104105
}
106+
107+
#[test]
108+
fn extract_should_set_fn_ast_id() {
109+
let source = "fn a() { }";
110+
let ast = parse::from_str(source);
111+
let doc = extract(ast);
112+
assert doc.topmod.fns[0].id != 0;
113+
}
105114
}

trunk/src/rustdoc/rustdoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import std::map;
2323
item = "AST item to document")
2424
)]
2525
fn doc_item(ctxt: gen::ctxt, item: @ast::item) {
26-
let _fndoc0 = attr_parser::parse_fn(item.ident, item.attrs);
26+
let _fndoc0 = attr_parser::parse_fn(item.ident, item.id, item.attrs);
2727

2828
alt item.node {
2929
ast::item_const(ty, expr) { }

0 commit comments

Comments
 (0)