rustc: Implement pointer dereference; add a test case

This commit is contained in:
Patrick Walton 2011-07-11 15:14:07 -07:00
parent 4618e802db
commit 79ce5a4614
5 changed files with 30 additions and 4 deletions

View file

@ -573,6 +573,7 @@ fn expr_root(&ctx cx, @ast::expr ex, bool autoderef) ->
case (ty::ty_box(?mt)) { mut = mt.mut != ast::imm; }
case (ty::ty_res(_, _, _)) {}
case (ty::ty_tag(_, _)) {}
case (ty::ty_ptr(?mt)) { mut = mt.mut != ast::imm; }
}
vec::push(ds, rec(mut=mut, kind=unbox, outer_t=base_t));
ex = base;

View file

@ -5263,11 +5263,11 @@ fn trans_lval_gen(&@block_ctxt cx, &@ast::expr e) -> lval_result {
auto t = ty::expr_ty(ccx.tcx, base);
auto val = alt (ty::struct(ccx.tcx, t)) {
case (ty::ty_box(_)) {
sub.bcx.build.GEP
sub.bcx.build.InBoundsGEP
(sub.val, ~[C_int(0), C_int(abi::box_rc_field_body)])
}
case (ty::ty_res(_, _, _)) {
sub.bcx.build.GEP(sub.val, ~[C_int(0), C_int(1)])
sub.bcx.build.InBoundsGEP(sub.val, ~[C_int(0), C_int(1)])
}
case (ty::ty_tag(_, _)) {
auto ety = ty::expr_ty(ccx.tcx, e);
@ -5279,6 +5279,7 @@ fn trans_lval_gen(&@block_ctxt cx, &@ast::expr e) -> lval_result {
};
sub.bcx.build.PointerCast(sub.val, ellty)
}
case (ty::ty_ptr(_)) { sub.val }
};
ret lval_mem(sub.bcx, val);
}

View file

@ -1712,6 +1712,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
oper_t = ty::substitute_type_params
(fcx.ccx.tcx, tps, variants.(0).args.(0));
}
case (ty::ty_ptr(?inner)) { oper_t = inner.ty; }
case (_) {
fcx.ccx.tcx.sess.span_fatal
(expr.span, "dereferencing non-" +