about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-06-23 22:04:42 -0700
committerBrian Anderson <banderson@mozilla.com>2011-06-23 22:16:16 -0700
commitb9fc4dfc549ba6268a30209cd75f8a043e2f61fc (patch)
tree3e5d1ca678cc6ae17d1c87f72a8e1eabbc9a369b /src/comp
parent05c0216654999e3d33373914b10aebf9dd7d4907 (diff)
downloadrust-b9fc4dfc549ba6268a30209cd75f8a043e2f61fc.tar.gz
rust-b9fc4dfc549ba6268a30209cd75f8a043e2f61fc.zip
rustc: Cleanup trans_if, trans_alt
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/trans.rs42
1 files changed, 6 insertions, 36 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 913c9d968b9..3f3bf9f665a 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -4101,9 +4101,7 @@ fn trans_if(&@block_ctxt cx, &@ast::expr cond, &ast::block thn,
     auto then_cx = new_scope_block_ctxt(cx, "then");
     auto then_res = trans_block(then_cx, thn, output);
     auto else_cx = new_scope_block_ctxt(cx, "else");
-    auto else_res;
-    auto expr_llty;
-    alt (els) {
+    auto else_res =  alt (els) {
         case (some(?elexpr)) {
             alt (elexpr.node) {
                 case (ast::expr_if(_, _, _)) {
@@ -4111,13 +4109,8 @@ fn trans_if(&@block_ctxt cx, &@ast::expr cond, &ast::block thn,
                     // containing an if expression. Needed in order for the
                     // else scope to behave like a normal block scope. A tad
                     // ugly.
-
-                    let ast::block_ elseif_blk_ =
-                        rec(stmts=[],
-                            expr=some[@ast::expr](elexpr),
-                            id=elexpr.id);
-                    auto elseif_blk = rec(node=elseif_blk_, span=elexpr.span);
-                    else_res = trans_block(else_cx, elseif_blk, output);
+                    auto elseif_blk = ast::block_from_expr(elexpr);
+                    trans_block(else_cx, elseif_blk, output)
                 }
                 case (ast::expr_block(?blk)) {
                     // Calling trans_block directly instead of trans_expr
@@ -4125,23 +4118,12 @@ fn trans_if(&@block_ctxt cx, &@ast::expr cond, &ast::block thn,
                     // context for the block, but we've already got the
                     // 'else' context
 
-                    else_res = trans_block(else_cx, blk, output);
-                }
-            }
-            // FIXME: This isn't quite right, particularly re: dynamic types
-
-            auto expr_ty = ty::node_id_to_type(cx.fcx.lcx.ccx.tcx, id);
-            if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, expr_ty)) {
-                expr_llty = T_typaram_ptr(cx.fcx.lcx.ccx.tn);
-            } else {
-                expr_llty = type_of(cx.fcx.lcx.ccx, elexpr.span, expr_ty);
-                if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, expr_ty)) {
-                    expr_llty = T_ptr(expr_llty);
+                    trans_block(else_cx, blk, output)
                 }
             }
         }
-        case (_) { else_res = res(else_cx, C_nil()); expr_llty = T_nil(); }
-    }
+        case (_) { res(else_cx, C_nil()) }
+    };
     cond_res.bcx.build.CondBr(cond_res.val, then_cx.llbb, else_cx.llbb);
     ret res(join_branches(cx, [then_res, else_res]), C_nil());
 }
@@ -4599,18 +4581,6 @@ fn trans_alt(&@block_ctxt cx, &@ast::expr expr, &vec[ast::arm] arms,
     auto default_res =
         trans_fail(default_cx, some[common::span](expr.span),
                    "non-exhaustive match failure");
-    // FIXME: This isn't quite right, particularly re: dynamic types
-
-    auto expr_ty = ty::node_id_to_type(cx.fcx.lcx.ccx.tcx, id);
-    auto expr_llty;
-    if (ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, expr_ty)) {
-        expr_llty = T_typaram_ptr(cx.fcx.lcx.ccx.tn);
-    } else {
-        expr_llty = type_of(cx.fcx.lcx.ccx, expr.span, expr_ty);
-        if (ty::type_is_structural(cx.fcx.lcx.ccx.tcx, expr_ty)) {
-            expr_llty = T_ptr(expr_llty);
-        }
-    }
     ret res(join_branches(cx, arm_results), C_nil());
 }