Teach rustc to fail
This commit is contained in:
parent
3cac20dae3
commit
6b7cab3602
5 changed files with 31 additions and 11 deletions
|
|
@ -116,6 +116,7 @@ tag stmt_ {
|
|||
stmt_ret(option.t[@expr]);
|
||||
stmt_log(@expr);
|
||||
stmt_check_expr(@expr);
|
||||
stmt_fail;
|
||||
stmt_expr(@expr);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1158,6 +1158,11 @@ impure fn parse_stmt(parser p) -> @ast.stmt {
|
|||
}
|
||||
}
|
||||
|
||||
case (token.FAIL) {
|
||||
p.bump();
|
||||
ret @spanned(lo, p.get_span(), ast.stmt_fail);
|
||||
}
|
||||
|
||||
case (token.RET) {
|
||||
p.bump();
|
||||
alt (p.peek()) {
|
||||
|
|
@ -1315,6 +1320,7 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
|
|||
case (ast.stmt_ret(_)) { ret true; }
|
||||
case (ast.stmt_log(_)) { ret true; }
|
||||
case (ast.stmt_check_expr(_)) { ret true; }
|
||||
case (ast.stmt_fail) { ret true; }
|
||||
case (ast.stmt_expr(?e)) {
|
||||
alt (e.node) {
|
||||
case (ast.expr_vec(_,_)) { ret true; }
|
||||
|
|
|
|||
|
|
@ -615,6 +615,10 @@ fn fold_stmt[ENV](&ENV env, ast_fold[ENV] fld, &@stmt s) -> @stmt {
|
|||
ret fld.fold_stmt_check_expr(env_, s.span, ee);
|
||||
}
|
||||
|
||||
case (ast.stmt_fail) {
|
||||
ret s;
|
||||
}
|
||||
|
||||
case (ast.stmt_expr(?e)) {
|
||||
auto ee = fold_expr(env_, fld, e);
|
||||
ret fld.fold_stmt_expr(env_, s.span, ee);
|
||||
|
|
|
|||
|
|
@ -2251,11 +2251,7 @@ fn trans_index(@block_ctxt cx, &ast.span sp, @ast.expr base,
|
|||
ix.bcx.build.CondBr(bounds_check, next_cx.llbb, fail_cx.llbb);
|
||||
|
||||
// fail: bad bounds check.
|
||||
auto V_expr_str = p2i(C_cstr(cx.fcx.ccx, "out-of-bounds access"));
|
||||
auto V_filename = p2i(C_cstr(cx.fcx.ccx, sp.filename));
|
||||
auto V_line = sp.lo.line as int;
|
||||
auto args = vec(V_expr_str, V_filename, C_int(V_line));
|
||||
auto fail_res = trans_upcall(fail_cx, "upcall_fail", args);
|
||||
auto fail_res = trans_fail(fail_cx, sp, "bounds check");
|
||||
fail_res.bcx.build.Br(next_cx.llbb);
|
||||
|
||||
auto body = next_cx.build.GEP(v, vec(C_int(0), C_int(abi.vec_elt_data)));
|
||||
|
|
@ -2904,13 +2900,9 @@ fn trans_check_expr(@block_ctxt cx, @ast.expr e) -> result {
|
|||
auto cond_res = trans_expr(cx, e);
|
||||
|
||||
// FIXME: need pretty-printer.
|
||||
auto V_expr_str = p2i(C_cstr(cx.fcx.ccx, "<expr>"));
|
||||
auto V_filename = p2i(C_cstr(cx.fcx.ccx, e.span.filename));
|
||||
auto V_line = e.span.lo.line as int;
|
||||
auto args = vec(V_expr_str, V_filename, C_int(V_line));
|
||||
|
||||
auto expr_str = "<expr>";
|
||||
auto fail_cx = new_sub_block_ctxt(cx, "fail");
|
||||
auto fail_res = trans_upcall(fail_cx, "upcall_fail", args);
|
||||
auto fail_res = trans_fail(fail_cx, e.span, expr_str);
|
||||
|
||||
auto next_cx = new_sub_block_ctxt(cx, "next");
|
||||
fail_res.bcx.build.Br(next_cx.llbb);
|
||||
|
|
@ -2920,6 +2912,15 @@ fn trans_check_expr(@block_ctxt cx, @ast.expr e) -> result {
|
|||
ret res(next_cx, C_nil());
|
||||
}
|
||||
|
||||
fn trans_fail(@block_ctxt cx, common.span sp, str fail_str) -> result {
|
||||
auto V_fail_str = p2i(C_cstr(cx.fcx.ccx, fail_str));
|
||||
auto V_filename = p2i(C_cstr(cx.fcx.ccx, sp.filename));
|
||||
auto V_line = sp.lo.line as int;
|
||||
auto args = vec(V_fail_str, V_filename, C_int(V_line));
|
||||
|
||||
ret trans_upcall(cx, "upcall_fail", args);
|
||||
}
|
||||
|
||||
fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
|
||||
auto bcx = cx;
|
||||
auto val = C_nil();
|
||||
|
|
@ -3035,6 +3036,10 @@ fn trans_stmt(@block_ctxt cx, &ast.stmt s) -> result {
|
|||
bcx = trans_check_expr(cx, a).bcx;
|
||||
}
|
||||
|
||||
case (ast.stmt_fail) {
|
||||
bcx = trans_fail(cx, s.span, "explicit failure").bcx;
|
||||
}
|
||||
|
||||
case (ast.stmt_ret(?e)) {
|
||||
bcx = trans_ret(cx, e).bcx;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1682,6 +1682,10 @@ fn check_stmt(&@fn_ctxt fcx, &@ast.stmt stmt) -> @ast.stmt {
|
|||
ast.stmt_check_expr(expr_t));
|
||||
}
|
||||
|
||||
case (ast.stmt_fail) {
|
||||
ret stmt;
|
||||
}
|
||||
|
||||
case (ast.stmt_expr(?expr)) {
|
||||
auto expr_t = check_expr(fcx, expr);
|
||||
ret @fold.respan[ast.stmt_](stmt.span, ast.stmt_expr(expr_t));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue