add cap clause to pretty printer, with a test
This commit is contained in:
parent
bfc9a499c2
commit
8319b5a252
@ -840,8 +840,13 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
|
||||
}
|
||||
bclose_(s, expr.span, alt_indent_unit);
|
||||
}
|
||||
ast::expr_fn(proto, decl, body, captures) { // NDM captures
|
||||
head(s, proto_to_str(proto));
|
||||
ast::expr_fn(proto, decl, body, cap_clause) {
|
||||
// containing cbox, will be closed by print-block at }
|
||||
cbox(s, indent_unit);
|
||||
// head-box, will be closed by print-block at start
|
||||
ibox(s, 0u);
|
||||
word(s.s, proto_to_str(proto));
|
||||
print_cap_clause(s, *cap_clause);
|
||||
print_fn_args_and_ret(s, decl);
|
||||
space(s.s);
|
||||
print_block(s, body);
|
||||
@ -1156,6 +1161,33 @@ fn print_fn(s: ps, decl: ast::fn_decl, name: ast::ident,
|
||||
print_fn_args_and_ret(s, decl);
|
||||
}
|
||||
|
||||
fn print_cap_clause(s: ps, cap_clause: ast::capture_clause) {
|
||||
fn print_cap_item(s: ps, &&cap_item: @ast::capture_item) {
|
||||
word(s.s, cap_item.name);
|
||||
}
|
||||
|
||||
let has_copies = vec::is_not_empty(cap_clause.copies);
|
||||
let has_moves = vec::is_not_empty(cap_clause.moves);
|
||||
if !has_copies && !has_moves { ret; }
|
||||
|
||||
word(s.s, "[");
|
||||
|
||||
if has_copies {
|
||||
word_nbsp(s, "copy");
|
||||
commasep(s, inconsistent, cap_clause.copies, print_cap_item);
|
||||
if has_moves {
|
||||
word_space(s, ";");
|
||||
}
|
||||
}
|
||||
|
||||
if has_moves {
|
||||
word_nbsp(s, "move");
|
||||
commasep(s, inconsistent, cap_clause.moves, print_cap_item);
|
||||
}
|
||||
|
||||
word(s.s, "]");
|
||||
}
|
||||
|
||||
fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl) {
|
||||
popen(s);
|
||||
fn print_arg(s: ps, x: ast::arg) {
|
||||
|
17
src/test/pretty/cap-clause.rs
Normal file
17
src/test/pretty/cap-clause.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// pp-exact
|
||||
|
||||
fn main() {
|
||||
let x = 1;
|
||||
let y = 2;
|
||||
let z = 3;
|
||||
let l1 = lambda[copy x]() -> int { x + y };
|
||||
let l2 = lambda[copy x; move y]() -> int { x + y };
|
||||
let l3 = lambda[move z]() -> int { z };
|
||||
|
||||
let x = 1;
|
||||
let y = 2;
|
||||
let z = 3;
|
||||
let s1 = sendfn[copy x]() -> int { x + y };
|
||||
let s2 = sendfn[copy x; move y]() -> int { x + y };
|
||||
let s3 = sendfn[move z]() -> int { z };
|
||||
}
|
Loading…
Reference in New Issue
Block a user