rustc: Move replace_expr_type() from ty to typeck, as it's only used in the latter

This commit is contained in:
Patrick Walton 2011-05-13 17:06:00 -07:00
parent 843e9435ab
commit fac1342513
2 changed files with 52 additions and 45 deletions

View file

@ -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

View file

@ -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);
}