File tree Expand file tree Collapse file tree 3 files changed +72
-2
lines changed Expand file tree Collapse file tree 3 files changed +72
-2
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 497814642f2ce491baa79f310932f358757ad2fc
2
+ refs/heads/master: c4de718f378d6be0c52e77971045f1bff3af4664
Original file line number Diff line number Diff line change @@ -12,4 +12,5 @@ mod extract;
12
12
mod attr_parser;
13
13
mod doc;
14
14
mod gen;
15
- mod fold;
15
+ mod fold;
16
+ mod tystr_pass;
Original file line number Diff line number Diff line change
1
+ import rustc:: syntax:: ast;
2
+
3
+ export run;
4
+
5
+ fn run( doc : doc:: cratedoc , crate : @ast:: crate ) -> doc:: cratedoc {
6
+ let fold = fold:: fold ( {
7
+ fold_fn : fn ~(
8
+ f: fold:: fold<@ast:: crate>,
9
+ d: doc:: fndoc
10
+ ) -> doc:: fndoc {
11
+ fold_fn( f, d)
12
+ }
13
+ with * fold:: default_seq_fold ( crate )
14
+ } ) ;
15
+ fold. fold_crate ( fold, doc)
16
+ }
17
+
18
+ fn fold_fn (
19
+ fold: fold:: fold<@ast:: crate>,
20
+ doc: doc:: fndoc
21
+ ) -> doc:: fndoc {
22
+ import rustc:: middle:: ast_map;
23
+ import rustc:: syntax:: print:: pprust;
24
+
25
+ let crate = fold. ctxt ;
26
+
27
+ let map = ast_map:: map_crate ( * crate ) ;
28
+
29
+ fn add_ret_ty (
30
+ doc: option<doc:: retdoc>,
31
+ tystr: str
32
+ ) -> option<doc:: retdoc> {
33
+ alt doc {
34
+ some( doc) {
35
+ fail "unimplemented" ;
36
+ }
37
+ none. {
38
+ some ( {
39
+ desc: none,
40
+ ty: some ( tystr)
41
+ } )
42
+ }
43
+ }
44
+ }
45
+
46
+ ~{
47
+ return : alt map. get ( doc. id ) {
48
+ ast_map:: node_item( @{
49
+ node: ast:: item_fn( decl, _, _) , _
50
+ } ) {
51
+ add_ret_ty( doc. return , pprust:: ty_to_str ( decl. output ) )
52
+ }
53
+ }
54
+ with * doc
55
+ }
56
+ }
57
+
58
+ #[ cfg ( test) ]
59
+ mod tests {
60
+
61
+ #[ test]
62
+ fn should_add_fn_ret_types ( ) {
63
+ let source = "fn a() -> int { }" ;
64
+ let ast = parse:: from_str ( source) ;
65
+ let doc = extract:: extract ( ast, "" ) ;
66
+ let doc = run ( doc, ast) ;
67
+ assert option:: get ( doc. topmod . fns [ 0 ] . return ) . ty == some ( "int" ) ;
68
+ }
69
+ }
You can’t perform that action at this time.
0 commit comments