Update pretty printer for ports, channels, send and receive

This commit is contained in:
Brian Anderson 2011-03-24 23:03:12 -04:00 committed by Graydon Hoare
parent ebc4df3c7a
commit 9ca7acb1f3
2 changed files with 35 additions and 1 deletions

View file

@ -1621,6 +1621,8 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
case (ast.expr_assign(_,_,_)) { ret true; }
case (ast.expr_assign_op(_,_,_,_))
{ ret true; }
case (ast.expr_send(_,_,_)) { ret true; }
case (ast.expr_recv(_,_,_)) { ret true; }
case (ast.expr_field(_,_,_)) { ret true; }
case (ast.expr_index(_,_,_)) { ret true; }
case (ast.expr_path(_,_,_)) { ret true; }

View file

@ -78,6 +78,8 @@ impure fn print_type(ps s, &@ast.ty ty) {
case (ast.ty_str) {wrd(s, "str");}
case (ast.ty_box(?mt)) {wrd(s, "@"); print_mt(s, mt);}
case (ast.ty_vec(?mt)) {wrd(s, "vec["); print_mt(s, mt); wrd(s, "]");}
case (ast.ty_port(?t)) {wrd(s, "port["); print_type(s, t); wrd(s, "]");}
case (ast.ty_chan(?t)) {wrd(s, "chan["); print_type(s, t); wrd(s, "]");}
case (ast.ty_type) {wrd(s, "type");}
case (ast.ty_tup(?elts)) {
wrd(s, "tup");
@ -481,6 +483,18 @@ impure fn print_expr(ps s, &@ast.expr expr) {
wrd1(s, "=");
print_expr(s, rhs);
}
case (ast.expr_send(?lhs, ?rhs, _)) {
print_expr(s, lhs);
space(s);
wrd1(s, "<|");
print_expr(s, rhs);
}
case (ast.expr_recv(?lhs, ?rhs, _)) {
print_expr(s, lhs);
space(s);
wrd1(s, "<-");
print_expr(s, rhs);
}
case (ast.expr_field(?expr,?id,_)) {
print_expr(s, expr);
wrd(s, ".");
@ -541,6 +555,17 @@ impure fn print_expr(ps s, &@ast.expr expr) {
}
// TODO: extension 'body'
}
case (ast.expr_port(_)) {
wrd(s, "port");
popen(s);
pclose(s);
}
case (ast.expr_chan(?expr, _)) {
wrd(s, "chan");
popen(s);
print_expr(s, expr);
pclose(s);
}
}
end(s);
}
@ -563,7 +588,14 @@ impure fn print_decl(ps s, @ast.decl decl) {
alt (loc.init) {
case (option.some[ast.initializer](?init)) {
space(s);
wrd1(s, "=");
alt (init.op) {
case (ast.init_assign) {
wrd1(s, "=");
}
case (ast.init_recv) {
wrd1(s, "<-");
}
}
print_expr(s, init.expr);
}
case (_) {}