From 0739849e9fe9013d87ec6bc7f026143a10079703 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 13 May 2011 16:40:21 -0700 Subject: rustc: Make all type lookups go through the one ty::ann_to_ty_param_substs_opt_and_ty() function --- src/comp/middle/ty.rs | 66 +++++++++++++++++---------------------------------- 1 file changed, 22 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index 5957c1fd..fcee03bf 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -1440,35 +1440,7 @@ fn eq_raw_ty(&raw_t a, &raw_t b) -> bool { fn eq_ty(&t a, &t b) -> bool { ret a == b; } -fn ann_to_type(&node_type_table ntt, &ast::ann ann) -> t { - alt (ann) { - case (ast::ann_none(_)) { - log_err "ann_to_type() called on node with no type"; - fail; - } - case (ast::ann_type(_, ?ty, _, _)) { - ret ty; - } - } -} - -fn ann_to_type_params(&node_type_table ntt, &ast::ann ann) -> vec[t] { - alt (ann) { - case (ast::ann_none(_)) { - log_err "ann_to_type_params() called on node with no type params"; - fail; - } - case (ast::ann_type(_, _, ?tps, _)) { - alt (tps) { - case (none[vec[t]]) { - let vec[t] result = vec(); - ret result; - } - case (some[vec[t]](?tps)) { ret tps; } - } - } - } -} +// Type lookups fn ann_to_ty_param_substs_opt_and_ty(&node_type_table ntt, &ast::ann ann) -> ty_param_substs_opt_and_ty { @@ -1482,27 +1454,33 @@ fn ann_to_ty_param_substs_opt_and_ty(&node_type_table ntt, &ast::ann ann) } } +fn ann_to_type(&node_type_table ntt, &ast::ann ann) -> t { + ret ann_to_ty_param_substs_opt_and_ty(ntt, ann)._1; +} + +fn ann_to_type_params(&node_type_table ntt, &ast::ann ann) -> vec[t] { + alt (ann_to_ty_param_substs_opt_and_ty(ntt, ann)._0) { + case (none[vec[t]]) { + let vec[t] result = vec(); + ret result; + } + case (some[vec[t]](?tps)) { ret tps; } + } +} + // Returns the type of an annotation, with type parameter substitutions // performed if applicable. -fn ann_to_monotype(ctxt cx, &node_type_table ntt, ast::ann a) -> t { - // TODO: Refactor to use recursive pattern matching when we're more - // confident that it works. - alt (a) { - case (ast::ann_none(_)) { - log_err "ann_to_monotype() called on expression with no type!"; - fail; - } - case (ast::ann_type(_, ?typ, ?tps_opt, _)) { - alt (tps_opt) { - case (none[vec[t]]) { ret typ; } - case (some[vec[t]](?tps)) { - ret substitute_type_params(cx, tps, typ); - } - } +fn ann_to_monotype(ctxt cx, &node_type_table ntt, ast::ann a) -> t { + auto tpot = ann_to_ty_param_substs_opt_and_ty(ntt, a); + alt (tpot._0) { + case (none[vec[t]]) { ret tpot._1; } + case (some[vec[t]](?tps)) { + ret substitute_type_params(cx, tps, tpot._1); } } } + // Turns a type into an ann_type, using defaults for other fields. fn triv_ann(uint node_id, t typ) -> ast::ann { ret ast::ann_type(node_id, typ, none[vec[t]], none[@ts_ann]); -- cgit v1.2.3