mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 15:23:46 +00:00
Bring swap through typechecking and typestate.
This commit is contained in:
parent
066599104a
commit
cfd1f74ebb
@ -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)) {
|
||||
|
@ -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) {
|
||||
|
@ -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; }
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user