aboutsummaryrefslogtreecommitdiff
path: root/src/comp/middle/trans.rs
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2011-03-14 16:59:04 -0700
committerGraydon Hoare <[email protected]>2011-03-14 16:59:04 -0700
commit7f5bffc3ea8545be1916dd089e4f25a360c83950 (patch)
tree877d7e430339360c8645a1983707d04088d1cba2 /src/comp/middle/trans.rs
parentRename check_assignment_like to check_assignment since it turned out not to b... (diff)
parentMerge branch 'master' into recursive-elseif (diff)
downloadrust-7f5bffc3ea8545be1916dd089e4f25a360c83950.tar.xz
rust-7f5bffc3ea8545be1916dd089e4f25a360c83950.zip
Merge remote branch 'brson/recursive-elseif'
Diffstat (limited to 'src/comp/middle/trans.rs')
-rw-r--r--src/comp/middle/trans.rs40
1 files changed, 9 insertions, 31 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index de19a01a..4fab3454 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -2833,9 +2833,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);
@@ -2845,25 +2844,11 @@ 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);
- }
- case (_) { /* fall through */ }
+ alt (els) {
+ case (some[@ast.expr](?elexpr)) {
+ else_res = trans_expr(else_cx, elexpr);
}
+ case (_) { /* fall through */ }
}
cond_res.bcx.build.CondBr(cond_res.val,
@@ -4303,8 +4288,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, _)) {
@@ -4328,14 +4313,7 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
}
case (ast.expr_block(?blk, _)) {
- auto sub_cx = new_scope_block_ctxt(cx, "block-expr body");
- auto next_cx = new_sub_block_ctxt(cx, "next");
- auto sub = trans_block(sub_cx, blk);
-
- cx.build.Br(sub_cx.llbb);
- sub.bcx.build.Br(next_cx.llbb);
-
- ret res(next_cx, sub.val);
+ ret trans_block(cx, blk);
}
case (ast.expr_assign(?dst, ?src, ?ann)) {