aboutsummaryrefslogtreecommitdiff
path: root/src/comp/middle/trans.rs
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2011-02-01 16:23:48 -0800
committerGraydon Hoare <[email protected]>2011-02-01 16:23:48 -0800
commit70bf54bcac587c0bc8a3a593bda75115e4c23aa8 (patch)
treefc04fe2f7bc4fa1dd902689e4db20e193bec9097 /src/comp/middle/trans.rs
parentUse dynamic GEP and silly offset-encoding on tydescs. Successful call into a ... (diff)
downloadrust-70bf54bcac587c0bc8a3a593bda75115e4c23aa8.tar.xz
rust-70bf54bcac587c0bc8a3a593bda75115e4c23aa8.zip
Implement 'else if'
Diffstat (limited to 'src/comp/middle/trans.rs')
-rw-r--r--src/comp/middle/trans.rs31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 446b4f10..c08147fe 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -1957,8 +1957,9 @@ fn join_results(@block_ctxt parent_cx,
ret res(join_cx, phi);
}
-fn trans_if(@block_ctxt cx, @ast.expr cond,
- &ast.block thn, &option.t[ast.block] els) -> result {
+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 {
auto cond_res = trans_expr(cx, cond);
@@ -1968,11 +1969,25 @@ fn trans_if(@block_ctxt cx, @ast.expr cond,
auto else_cx = new_scope_block_ctxt(cx, "else");
auto else_res = res(else_cx, C_nil());
- alt (els) {
- case (some[ast.block](?eblk)) {
- else_res = trans_block(else_cx, eblk);
+ 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 */ }
}
- case (_) { /* fall through */ }
}
cond_res.bcx.build.CondBr(cond_res.val,
@@ -2901,8 +2916,8 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
ret trans_binary(cx, op, x, y);
}
- case (ast.expr_if(?cond, ?thn, ?els, _)) {
- ret trans_if(cx, cond, thn, els);
+ case (ast.expr_if(?cond, ?thn, ?elifs, ?els, _)) {
+ ret trans_if(cx, cond, thn, elifs, els);
}
case (ast.expr_for(?decl, ?seq, ?body, _)) {