aboutsummaryrefslogtreecommitdiff
path: root/src/comp/middle/trans.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/comp/middle/trans.rs')
-rw-r--r--src/comp/middle/trans.rs40
1 files changed, 18 insertions, 22 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 723a845d..728f20dd 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -2670,9 +2670,8 @@ fn join_results(@block_ctxt parent_cx,
ret res(join_cx, phi);
}
-fn trans_if(@block_ctxt cx, @ast.expr cond, &ast.block thn,
- &vec[tup(@ast.expr, ast.block)] elifs,
- &option.t[ast.block] els) -> result {
+fn trans_if(@block_ctxt cx, @ast.expr cond,
+ &ast.block thn, &option.t[@ast.expr] els) -> result {
auto cond_res = trans_expr(cx, cond);
@@ -2682,25 +2681,22 @@ fn trans_if(@block_ctxt cx, @ast.expr cond, &ast.block thn,
auto else_cx = new_scope_block_ctxt(cx, "else");
auto else_res = res(else_cx, C_nil());
- auto num_elifs = _vec.len[tup(@ast.expr, ast.block)](elifs);
- if (num_elifs > 0u) {
- auto next_elif = elifs.(0u);
- auto next_elifthn = next_elif._0;
- auto next_elifcnd = next_elif._1;
- auto rest_elifs = _vec.shift[tup(@ast.expr, ast.block)](elifs);
- else_res = trans_if(else_cx, next_elifthn, next_elifcnd,
- rest_elifs, els);
- }
-
- /* else: FIXME: rustboot has a problem here
- with preconditions inside an else block */
- if (num_elifs == 0u) {
- alt (els) {
- case (some[ast.block](?eblk)) {
- else_res = trans_block(else_cx, eblk);
+ alt (els) {
+ case (some[@ast.expr](?elexpr)) {
+ // FIXME: Shouldn't need to unwrap the block here,
+ // instead just use 'else_res = trans_expr(else_cx, elexpr)',
+ // but either a) trans_expr doesn't handle expr_block
+ // correctly or b) I have no idea what I'm doing...
+ alt (elexpr.node) {
+ case (ast.expr_if(_, _, _, _)) {
+ else_res = trans_expr(else_cx, elexpr);
+ }
+ case (ast.expr_block(?b, _)) {
+ else_res = trans_block(else_cx, b);
+ }
}
- case (_) { /* fall through */ }
}
+ case (_) { /* fall through */ }
}
cond_res.bcx.build.CondBr(cond_res.val,
@@ -3921,8 +3917,8 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
ret trans_binary(cx, op, x, y);
}
- case (ast.expr_if(?cond, ?thn, ?elifs, ?els, _)) {
- ret trans_if(cx, cond, thn, elifs, els);
+ case (ast.expr_if(?cond, ?thn, ?els, _)) {
+ ret trans_if(cx, cond, thn, els);
}
case (ast.expr_for(?decl, ?seq, ?body, _)) {