提交 d730bb73 编写于 作者: M Marijn Haverbeke

Make it possible to use * to dereference a resource

上级 b3443eb0
......@@ -544,10 +544,14 @@ fn maybe_push_auto_unbox(&option::t[deref] d, &mutable vec[deref] ds) {
auto base_t = ty::expr_ty(*cx.tcx, base);
alt (ty::struct(*cx.tcx, base_t)) {
case (ty::ty_box(?mt)) {
vec::push(ds,
rec(mut=mt.mut != ast::imm,
kind=unbox,
outer_t=base_t));
vec::push(ds, rec(mut=mt.mut != ast::imm,
kind=unbox,
outer_t=base_t));
}
case (ty::ty_res(_, ?inner)) {
vec::push(ds, rec(mut=false,
kind=unbox,
outer_t=base_t));
}
}
ex = base;
......
......@@ -4511,8 +4511,7 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
cx.build.Store(llenvblobptr, env_cell);
// log "lliterbody: " + val_str(lcx.ccx.tn, lliterbody);
r =
trans_call(cx, f, some[ValueRef](cx.build.Load(pair)), args,
r = trans_call(cx, f, some[ValueRef](cx.build.Load(pair)), args,
seq.id);
ret rslt(r.bcx, C_nil());
}
......@@ -4993,9 +4992,12 @@ fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result {
case (ast::expr_unary(?unop, ?base)) {
assert (unop == ast::deref);
auto sub = trans_expr(cx, base);
auto val =
sub.bcx.build.GEP(sub.val,
[C_int(0), C_int(abi::box_rc_field_body)]);
auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, base);
auto offset = alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) {
case (ty::ty_box(_)) { abi::box_rc_field_body }
case (ty::ty_res(_, _)) { 1 }
};
auto val = sub.bcx.build.GEP(sub.val, [C_int(0), C_int(offset)]);
ret lval_mem(sub.bcx, val);
}
case (ast::expr_self_method(?ident)) {
......
......@@ -1526,6 +1526,7 @@ fn check_binop_type_compat(&@fn_ctxt fcx, common::span span,
case (ast::deref) {
alt (structure_of(fcx, expr.span, oper_t)) {
case (ty::ty_box(?inner)) { oper_t = inner.ty; }
case (ty::ty_res(_, ?inner)) { oper_t = inner; }
case (_) {
auto s = "dereferencing non-box type: " +
ty_to_str(fcx.ccx.tcx, oper_t);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册