Skip to content

Commit d5a0df9

Browse files
committed
---
yaml --- r: 7927 b: refs/heads/snap-stage3 c: dd1564a h: refs/heads/master i: 7925: 534225d 7923: 1b04b92 7919: 64cea62 v: v3
1 parent c96474a commit d5a0df9

File tree

2 files changed

+186
-12
lines changed

2 files changed

+186
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: c77579812460c2b3bf473bd560a1beed32d5fdf5
4+
refs/heads/snap-stage3: dd1564a6d34ccc80152a0b609022da03f5f5bfa8
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/rustdoc/tystr_pass.rs

Lines changed: 185 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ fn run(
1919
fold_fn: fold_fn,
2020
fold_const: fold_const,
2121
fold_enum: fold_enum,
22-
fold_res: fold_res
22+
fold_res: fold_res,
23+
fold_iface: fold_iface
2324
with *fold::default_seq_fold(srv)
2425
});
2526
fold.fold_crate(fold, doc)
@@ -84,17 +85,21 @@ fn get_ret_ty(srv: astsrv::srv, fn_id: doc::ast_id) -> option<str> {
8485
ast_map::node_item(@{
8586
node: ast::item_fn(decl, _, _), _
8687
}) {
87-
if decl.output.node != ast::ty_nil {
88-
some(pprust::ty_to_str(decl.output))
89-
} else {
90-
// Nil-typed return values are not interesting
91-
none
92-
}
88+
ret_ty_to_str(decl)
9389
}
9490
}
9591
}
9692
}
9793

94+
fn ret_ty_to_str(decl: ast::fn_decl) -> option<str> {
95+
if decl.output.node != ast::ty_nil {
96+
some(pprust::ty_to_str(decl.output))
97+
} else {
98+
// Nil-typed return values are not interesting
99+
none
100+
}
101+
}
102+
98103
#[test]
99104
fn should_add_fn_ret_types() {
100105
let source = "fn a() -> int { }";
@@ -138,14 +143,18 @@ fn get_arg_tys(srv: astsrv::srv, fn_id: doc::ast_id) -> [(str, str)] {
138143
ast_map::node_item(@{
139144
node: ast::item_res(decl, _, _, _, _), _
140145
}) {
141-
vec::map(decl.inputs) {|arg|
142-
(arg.ident, pprust::ty_to_str(arg.ty))
143-
}
146+
decl_arg_tys(decl)
144147
}
145148
}
146149
}
147150
}
148151

152+
fn decl_arg_tys(decl: ast::fn_decl) -> [(str, str)] {
153+
vec::map(decl.inputs) {|arg|
154+
(arg.ident, pprust::ty_to_str(arg.ty))
155+
}
156+
}
157+
149158
#[test]
150159
fn should_add_arg_types() {
151160
let source = "fn a(b: int, c: bool) { }";
@@ -264,4 +273,169 @@ fn should_add_resource_arg_tys() {
264273
let doc = extract::from_srv(srv, "");
265274
let doc = run(srv, doc);
266275
assert doc.topmod.resources()[0].args[0].ty == some("bool");
267-
}
276+
}
277+
278+
fn fold_iface(
279+
fold: fold::fold<astsrv::srv>,
280+
doc: doc::ifacedoc
281+
) -> doc::ifacedoc {
282+
283+
let srv = fold.ctxt;
284+
285+
{
286+
methods: vec::map(doc.methods) {|methoddoc|
287+
{
288+
args: merge_method_arg_tys(
289+
srv,
290+
doc.id,
291+
methoddoc.args,
292+
methoddoc.name),
293+
return: merge_method_ret_ty(
294+
srv,
295+
doc.id,
296+
methoddoc.return,
297+
methoddoc.name),
298+
sig: get_method_sig(srv, doc.id, methoddoc.name)
299+
with methoddoc
300+
}
301+
}
302+
with doc
303+
}
304+
}
305+
306+
fn merge_method_ret_ty(
307+
srv: astsrv::srv,
308+
item_id: doc::ast_id,
309+
doc: doc::retdoc,
310+
method_name: str
311+
) -> doc::retdoc {
312+
alt get_method_ret_ty(srv, item_id, method_name) {
313+
some(ty) {
314+
{
315+
ty: some(ty)
316+
with doc
317+
}
318+
}
319+
none { doc }
320+
}
321+
}
322+
323+
fn get_method_ret_ty(
324+
srv: astsrv::srv,
325+
item_id: doc::ast_id,
326+
method_name: str
327+
) -> option<str> {
328+
astsrv::exec(srv) {|ctxt|
329+
alt ctxt.ast_map.get(item_id) {
330+
ast_map::node_item(@{
331+
node: ast::item_iface(_, methods), _
332+
}) {
333+
alt vec::find(methods) {|method|
334+
method.ident == method_name
335+
} {
336+
some(method) {
337+
ret_ty_to_str(method.decl)
338+
}
339+
}
340+
}
341+
}
342+
}
343+
}
344+
345+
fn get_method_sig(
346+
srv: astsrv::srv,
347+
item_id: doc::ast_id,
348+
method_name: str
349+
) -> option<str> {
350+
astsrv::exec(srv) {|ctxt|
351+
alt ctxt.ast_map.get(item_id) {
352+
ast_map::node_item(@{
353+
node: ast::item_iface(_, methods), _
354+
}) {
355+
alt vec::find(methods) {|method|
356+
method.ident == method_name
357+
} {
358+
some(method) {
359+
some(pprust::fun_to_str(method.decl, method.ident, []))
360+
}
361+
}
362+
}
363+
}
364+
}
365+
}
366+
367+
fn merge_method_arg_tys(
368+
srv: astsrv::srv,
369+
item_id: doc::ast_id,
370+
args: [doc::argdoc],
371+
method_name: str
372+
) -> [doc::argdoc] {
373+
let tys = get_method_arg_tys(srv, item_id, method_name);
374+
vec::map2(args, tys) {|arg, ty|
375+
assert arg.name == tuple::first(ty);
376+
{
377+
ty: some(tuple::second(ty))
378+
with arg
379+
}
380+
}
381+
}
382+
383+
fn get_method_arg_tys(
384+
srv: astsrv::srv,
385+
item_id: doc::ast_id,
386+
method_name: str
387+
) -> [(str, str)] {
388+
astsrv::exec(srv) {|ctxt|
389+
alt ctxt.ast_map.get(item_id) {
390+
ast_map::node_item(@{
391+
node: ast::item_iface(_, methods), _
392+
}) {
393+
alt vec::find(methods) {|method|
394+
method.ident == method_name
395+
} {
396+
some(method) {
397+
decl_arg_tys(method.decl)
398+
}
399+
}
400+
}
401+
}
402+
}
403+
}
404+
405+
#[test]
406+
fn should_add_iface_method_sigs() {
407+
let source = "iface i { fn a() -> int; }";
408+
let srv = astsrv::mk_srv_from_str(source);
409+
let doc = extract::from_srv(srv, "");
410+
let doc = run(srv, doc);
411+
assert doc.topmod.ifaces()[0].methods[0].sig == some("fn a() -> int");
412+
}
413+
414+
#[test]
415+
fn should_add_iface_method_ret_types() {
416+
let source = "iface i { fn a() -> int; }";
417+
let srv = astsrv::mk_srv_from_str(source);
418+
let doc = extract::from_srv(srv, "");
419+
let doc = run(srv, doc);
420+
assert doc.topmod.ifaces()[0].methods[0].return.ty == some("int");
421+
}
422+
423+
#[test]
424+
fn should_not_add_iface_method_nil_ret_type() {
425+
let source = "iface i { fn a(); }";
426+
let srv = astsrv::mk_srv_from_str(source);
427+
let doc = extract::from_srv(srv, "");
428+
let doc = run(srv, doc);
429+
assert doc.topmod.ifaces()[0].methods[0].return.ty == none;
430+
}
431+
432+
#[test]
433+
fn should_add_iface_method_arg_types() {
434+
let source = "iface i { fn a(b: int, c: bool); }";
435+
let srv = astsrv::mk_srv_from_str(source);
436+
let doc = extract::from_srv(srv, "");
437+
let doc = run(srv, doc);
438+
let fn_ = doc.topmod.ifaces()[0].methods[0];
439+
assert fn_.args[0].ty == some("int");
440+
assert fn_.args[1].ty == some("bool");
441+
}

0 commit comments

Comments
 (0)