From ee45d54a4e14c8ae809b0b6c3111260a3f39ba40 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Fri, 1 Jul 2011 01:48:32 -0700 Subject: [PATCH] Move autoderefed_ty to ty.rs and rename it type_autoderef. --- src/comp/middle/trans.rs | 17 +++-------------- src/comp/middle/ty.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 6da9a578510..89b147bd473 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -3367,7 +3367,7 @@ fn trans_compare(&@block_ctxt cx0, ast::binop op, &ty::t t0, ValueRef lhs0, auto rhs_r = autoderef(cx, rhs0, t0); auto rhs = rhs_r.val; cx = rhs_r.bcx; - auto t = autoderefed_ty(cx.fcx.lcx.ccx, t0); + auto t = ty::type_autoderef(cx.fcx.lcx.ccx.tcx, t0); // Determine the operation we need. // FIXME: Use or-patterns when we have them. @@ -4126,17 +4126,6 @@ fn autoderef(&@block_ctxt cx, ValueRef v, &ty::t t) -> result { ret rslt(cx, v1); } -fn autoderefed_ty(&@crate_ctxt ccx, &ty::t t) -> ty::t { - let ty::t t1 = t; - while (true) { - alt (ty::struct(ccx.tcx, t1)) { - case (ty::ty_box(?mt)) { t1 = mt.ty; } - case (_) { break; } - } - } - ret t1; -} - fn trans_binary(&@block_ctxt cx, ast::binop op, &@ast::expr a, &@ast::expr b) -> result { @@ -4199,7 +4188,7 @@ fn trans_binary(&@block_ctxt cx, ast::binop op, &@ast::expr a, &@ast::expr b) auto rhty = ty::expr_ty(cx.fcx.lcx.ccx.tcx, b); rhs = autoderef(rhs.bcx, rhs.val, rhty); ret trans_eager_binop(rhs.bcx, op, - autoderefed_ty(cx.fcx.lcx.ccx, lhty), + ty::type_autoderef(cx.fcx.lcx.ccx.tcx,lhty), lhs.val, rhs.val); } } @@ -4910,7 +4899,7 @@ fn trans_path(&@block_ctxt cx, &ast::path p, ast::node_id id) -> lval_result { fn trans_field(&@block_ctxt cx, &span sp, ValueRef v, &ty::t t0, &ast::ident field, ast::node_id id) -> lval_result { auto r = autoderef(cx, v, t0); - auto t = autoderefed_ty(cx.fcx.lcx.ccx, t0); + auto t = ty::type_autoderef(cx.fcx.lcx.ccx.tcx, t0); alt (ty::struct(cx.fcx.lcx.ccx.tcx, t)) { case (ty::ty_tup(_)) { let uint ix = ty::field_num(cx.fcx.lcx.ccx.sess, sp, field); diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index 5022a1cb2e2..a1f006c64cc 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -176,6 +176,7 @@ export type_is_copyable; export type_is_tup_like; export type_is_str; export type_owns_heap_mem; +export type_autoderef; export type_param; export def_to_str; export unify; @@ -1281,6 +1282,17 @@ fn type_param(&ctxt cx, &t ty) -> option::t[uint] { ret none[uint]; } +fn type_autoderef(&ctxt cx, &ty::t t) -> ty::t { + let ty::t t1 = t; + while (true) { + alt (struct(cx, t1)) { + case (ty::ty_box(?mt)) { t1 = mt.ty; } + case (_) { break; } + } + } + ret t1; +} + fn def_to_str(&ast::def_id did) -> str { ret #fmt("%d:%d", did._0, did._1); }