Skip to content

Commit 0696f73

Browse files
committed
---
yaml --- r: 7347 b: refs/heads/master c: 439a28a h: refs/heads/master i: 7345: 3908ed7 7343: f364ae5 v: v3
1 parent e8415cd commit 0696f73

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
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: d455d46b150d261b627afbc32ed809aaf6770ed5
2+
refs/heads/master: 439a28abe0d5d18a17ec194ea0155a43786cdb9b

trunk/src/rustdoc/astsrv.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#[doc = "Provides all access to AST-related, non-sendable info"];
2+
3+
import rustc::syntax::ast;
4+
import rustc::middle::ast_map;
5+
6+
export ctxt;
7+
export ctxt_handler;
8+
export srv, seq_srv;
9+
export mk_seq_srv_from_str;
10+
export mk_seq_srv_from_file;
11+
12+
type ctxt = {
13+
ast: @ast::crate,
14+
map: ast_map::map
15+
};
16+
17+
type ctxt_handler<T> = fn~(ctxt: ctxt) -> T;
18+
19+
iface srv {
20+
fn exec<T>(f: ctxt_handler<T>) -> T;
21+
}
22+
23+
#[doc = "The single-task service"]
24+
tag seq_srv = ctxt;
25+
26+
impl seq_srv of srv for seq_srv {
27+
fn exec<T>(f: ctxt_handler<T>) -> T {
28+
f(*self)
29+
}
30+
}
31+
32+
fn mk_seq_srv_from_str(source: str) -> seq_srv {
33+
seq_srv(build_ctxt(parse::from_str(source)))
34+
}
35+
36+
fn mk_seq_srv_from_file(file: str) -> seq_srv {
37+
seq_srv(build_ctxt(parse::from_file(file)))
38+
}
39+
40+
fn build_ctxt(ast: @ast::crate) -> ctxt {
41+
{
42+
ast: ast,
43+
map: ast_map::map_crate(*ast)
44+
}
45+
}
46+
47+
#[cfg(test)]
48+
mod tests {
49+
50+
#[test]
51+
fn seq_srv_should_build_ast_map() {
52+
let source = "fn a() { }";
53+
let srv = mk_seq_srv_from_str(source);
54+
srv.exec {|ctxt|
55+
assert ctxt.map.size() != 0u
56+
};
57+
}
58+
59+
#[test]
60+
fn seq_srv_should_return_request_result() {
61+
let source = "fn a() { }";
62+
let srv = mk_seq_srv_from_str(source);
63+
let result = srv.exec {|_ctxt| 1000};
64+
assert result == 1000;
65+
}
66+
}

trunk/src/rustdoc/rustdoc.rc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ mod doc;
1414
mod gen;
1515
mod fold;
1616
mod attr_pass;
17-
mod tystr_pass;
17+
mod tystr_pass;
18+
mod astsrv;

0 commit comments

Comments
 (0)