diff options
| author | Patrick Walton <[email protected]> | 2011-05-13 17:06:00 -0700 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2011-05-13 17:06:30 -0700 |
| commit | fac13425138bdadae8ab738efa538641af33c12e (patch) | |
| tree | 170541c377365702f376506ffe3718a70705d8dc /src/comp | |
| parent | rustc: Fix long lines in typeck.rs (diff) | |
| download | rust-fac13425138bdadae8ab738efa538641af33c12e.tar.xz rust-fac13425138bdadae8ab738efa538641af33c12e.zip | |
rustc: Move replace_expr_type() from ty to typeck, as it's only used in the latter
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/middle/ty.rs | 44 | ||||
| -rw-r--r-- | src/comp/middle/typeck.rs | 53 |
2 files changed, 52 insertions, 45 deletions
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index 34d62b7d..a0c3a724 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -1721,50 +1721,6 @@ fn expr_has_ty_params(&node_type_table ntt, &@ast::expr expr) -> bool { ret ann_has_type_params(ntt, expr_ann(expr)); } -// FIXME: At the moment this works only for call, bind, and path expressions. -fn replace_expr_type(&node_type_table ntt, - &@ast::expr expr, - &tup(vec[t], t) new_tyt) -> @ast::expr { - auto new_tps; - if (expr_has_ty_params(ntt, expr)) { - new_tps = some[vec[t]](new_tyt._0); - } else { - new_tps = none[vec[t]]; - } - - fn mkann_fn(t tyt, option::t[vec[t]] tps, &ast::ann old_ann) -> ast::ann { - ret ast::ann_type(ast::ann_tag(old_ann), tyt, tps, none[@ts_ann]); - } - auto mkann = bind mkann_fn(new_tyt._1, new_tps, _); - - alt (expr.node) { - case (ast::expr_call(?callee, ?args, ?a)) { - ret @fold::respan(expr.span, - ast::expr_call(callee, args, mkann(a))); - } - case (ast::expr_self_method(?ident, ?a)) { - ret @fold::respan(expr.span, - ast::expr_self_method(ident, mkann(a))); - } - case (ast::expr_bind(?callee, ?args, ?a)) { - ret @fold::respan(expr.span, - ast::expr_bind(callee, args, mkann(a))); - } - case (ast::expr_field(?e, ?i, ?a)) { - ret @fold::respan(expr.span, - ast::expr_field(e, i, mkann(a))); - } - case (ast::expr_path(?p, ?a)) { - ret @fold::respan(expr.span, - ast::expr_path(p, mkann(a))); - } - case (_) { - log_err "unhandled expr type in replace_expr_type(): " + - util::common::expr_to_str(expr); - fail; - } - } -} // Expression utilities diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 911dbd05..1966cfb2 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -1709,6 +1709,57 @@ fn resolve_local_types_in_block(&@fn_ctxt fcx, &ast::block block) ret fold::fold_block[option::t[@fn_ctxt]](some(fcx), fld, block); } + +// AST fragment utilities + +// FIXME: At the moment this works only for call, bind, and path expressions. +fn replace_expr_type(&node_type_table ntt, + &@ast::expr expr, + &tup(vec[ty::t], ty::t) new_tyt) -> @ast::expr { + auto new_tps; + if (ty::expr_has_ty_params(ntt, expr)) { + new_tps = some[vec[ty::t]](new_tyt._0); + } else { + new_tps = none[vec[ty::t]]; + } + + fn mkann_fn(ty::t tyt, option::t[vec[ty::t]] tps, &ast::ann old_ann) + -> ast::ann { + ret ast::ann_type(ast::ann_tag(old_ann), tyt, tps, none[@ts_ann]); + } + + auto mkann = bind mkann_fn(new_tyt._1, new_tps, _); + + alt (expr.node) { + case (ast::expr_call(?callee, ?args, ?a)) { + ret @fold::respan(expr.span, + ast::expr_call(callee, args, mkann(a))); + } + case (ast::expr_self_method(?ident, ?a)) { + ret @fold::respan(expr.span, + ast::expr_self_method(ident, mkann(a))); + } + case (ast::expr_bind(?callee, ?args, ?a)) { + ret @fold::respan(expr.span, + ast::expr_bind(callee, args, mkann(a))); + } + case (ast::expr_field(?e, ?i, ?a)) { + ret @fold::respan(expr.span, + ast::expr_field(e, i, mkann(a))); + } + case (ast::expr_path(?p, ?a)) { + ret @fold::respan(expr.span, + ast::expr_path(p, mkann(a))); + } + case (_) { + log_err "unhandled expr type in replace_expr_type(): " + + util::common::expr_to_str(expr); + fail; + } + } +} + + // AST fragment checking fn check_lit(@crate_ctxt ccx, &@ast::lit lit) -> ty::t { @@ -1935,7 +1986,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) -> @ast::expr { fcx.ccx.node_types, f_0); auto tpt_1 = Demand::full(fcx, f.span, tpt_0._1, t_0, tpt_0._0, NO_AUTODEREF); - auto f_1 = ty::replace_expr_type(fcx.ccx.node_types, f_0, tpt_1); + auto f_1 = replace_expr_type(fcx.ccx.node_types, f_0, tpt_1); ret tup(f_1, args_0); } |