Bring swap through typechecking and typestate.

This commit is contained in:
Michael Sullivan 2011-06-13 17:34:54 -07:00 committed by Graydon Hoare
parent 066599104a
commit cfd1f74ebb
7 changed files with 34 additions and 0 deletions

View File

@ -292,6 +292,10 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
case (_) { find_pre_post_exprs(fcx, [lhs, rhs], a); }
}
}
case (expr_swap(?lhs, ?rhs, ?a)) {
// Both sides must already be initialized
find_pre_post_exprs(fcx, [lhs, rhs], a);
}
case (expr_assign(?lhs, ?rhs, ?a)) {
alt (lhs.node) {
case (expr_path(?p, ?a_lhs)) {

View File

@ -327,6 +327,20 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
}
ret changed;
}
case (expr_swap(?lhs, ?rhs, ?a)) {
/* quite similar to binary -- should abstract this */
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
changed = find_pre_post_state_expr(fcx, pres, lhs)
|| changed;
changed =
find_pre_post_state_expr(fcx,
expr_poststate(fcx.ccx, lhs),
rhs) || changed;
changed =
extend_poststate_ann(fcx.ccx, a,
expr_poststate(fcx.ccx, rhs)) || changed;
ret changed;
}
case (expr_recv(?lhs, ?rhs, ?a)) {
extend_prestate_ann(fcx.ccx, a, pres);
alt (lhs.node) {

View File

@ -1528,6 +1528,7 @@ fn expr_ann(&@ast::expr e) -> ast::ann {
case (ast::expr_block(_, ?a)) { ret a; }
case (ast::expr_move(_, _, ?a)) { ret a; }
case (ast::expr_assign(_, _, ?a)) { ret a; }
case (ast::expr_swap(_,_,?a)) { ret a; }
case (ast::expr_assign_op(_, _, _, ?a)) { ret a; }
case (ast::expr_send(_, _, ?a)) { ret a; }
case (ast::expr_recv(_, _, ?a)) { ret a; }

View File

@ -1637,6 +1637,10 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
check_assignment(fcx, expr.span, lhs, rhs, a);
}
case (ast::expr_swap(?lhs, ?rhs, ?a)) {
require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
check_assignment(fcx, expr.span, lhs, rhs, a);
}
case (ast::expr_assign_op(?op, ?lhs, ?rhs, ?a)) {
require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
check_assignment(fcx, expr.span, lhs, rhs, a);

View File

@ -314,6 +314,10 @@ fn visit_expr[E](&@expr ex, &E e, &vt[E] v) {
vt(v).visit_expr(b, e, v);
vt(v).visit_expr(a, e, v);
}
case (expr_swap(?a, ?b, _)) {
vt(v).visit_expr(a, e, v);
vt(v).visit_expr(b, e, v);
}
case (expr_assign_op(_, ?a, ?b, _)) {
vt(v).visit_expr(b, e, v);
vt(v).visit_expr(a, e, v);

View File

@ -347,6 +347,7 @@ fn walk_expr(&ast_visitor v, @ast::expr e) {
walk_expr(v, b);
}
case (ast::expr_move(?a, ?b, _)) { walk_expr(v, a); walk_expr(v, b); }
case (ast::expr_swap(?a, ?b, _)) { walk_expr(v, a); walk_expr(v, b); }
case (ast::expr_assign_op(_, ?a, ?b, _)) {
walk_expr(v, a);
walk_expr(v, b);

View File

@ -704,6 +704,12 @@ fn print_expr(&ps s, &@ast::expr expr) {
word_space(s, "=");
print_expr(s, rhs);
}
case (ast::expr_swap(?lhs, ?rhs, _)) {
print_expr(s, lhs);
space(s.s);
word_space(s, "<->");
print_expr(s, rhs);
}
case (ast::expr_assign_op(?op, ?lhs, ?rhs, _)) {
print_expr(s, lhs);
space(s.s);