Remove ternary operator
`expr_ternary`, `ternary_to_if`, and all parses & lexer definitions have been removed.
This commit is contained in:
parent
a02493b969
commit
6ba3d24355
15 changed files with 5 additions and 82 deletions
|
@ -473,13 +473,6 @@ The comparison operators are the traditional `==`, `!=`, `<`, `>`,
|
|||
`<=`, and `>=`. Short-circuiting (lazy) boolean operators are written
|
||||
`&&` (and) and `||` (or).
|
||||
|
||||
Rust has a ternary conditional operator `?:`, as in:
|
||||
|
||||
~~~~
|
||||
let badness = 12;
|
||||
let message = badness < 10 ? "error" : "FATAL ERROR";
|
||||
~~~~
|
||||
|
||||
For type casting, Rust uses the binary `as` operator, which has a
|
||||
precedence between the bitwise combination operators (`&`, `|`, `^`)
|
||||
and the comparison operators. It takes an expression on the left side,
|
||||
|
|
|
@ -188,7 +188,6 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
|
|||
none {}
|
||||
}
|
||||
}
|
||||
expr_ternary(_, a, b) { maybe_copy(cx, a); maybe_copy(cx, b); }
|
||||
expr_fn(_, _, _, cap_clause) {
|
||||
check_fn_cap_clause(cx, e.id, *cap_clause);
|
||||
}
|
||||
|
|
|
@ -88,9 +88,6 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
|
|||
v.visit_expr(coll, cx, v);
|
||||
visit_block(loop, cx) {|| visit::visit_block(blk, cx, v);}
|
||||
}
|
||||
expr_ternary(_, _, _) {
|
||||
v.visit_expr(ast_util::ternary_to_if(ex), cx, v);
|
||||
}
|
||||
expr_alt(input, arms) {
|
||||
v.visit_expr(input, cx, v);
|
||||
let before = cx.current, sets = [];
|
||||
|
|
|
@ -3478,9 +3478,6 @@ fn trans_expr(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
|
|||
ast::expr_if(cond, thn, els) | ast::expr_if_check(cond, thn, els) {
|
||||
ret trans_if(bcx, cond, thn, els, dest);
|
||||
}
|
||||
ast::expr_ternary(_, _, _) {
|
||||
ret trans_expr(bcx, ast_util::ternary_to_if(e), dest);
|
||||
}
|
||||
ast::expr_alt(expr, arms) {
|
||||
// tcx.sess.span_note(e.span, "about to call trans_alt");
|
||||
ret alt::trans_alt(bcx, expr, arms, dest);
|
||||
|
|
|
@ -415,7 +415,6 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
|
|||
expr_if(antec, conseq, maybe_alt) {
|
||||
join_then_else(fcx, antec, conseq, maybe_alt, e.id, plain_if);
|
||||
}
|
||||
expr_ternary(_, _, _) { find_pre_post_expr(fcx, ternary_to_if(e)); }
|
||||
expr_binary(bop, l, r) {
|
||||
if lazy_binop(bop) {
|
||||
find_pre_post_expr(fcx, l);
|
||||
|
|
|
@ -466,9 +466,6 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
|
|||
ret join_then_else(fcx, antec, conseq, maybe_alt, e.id, plain_if,
|
||||
pres);
|
||||
}
|
||||
expr_ternary(_, _, _) {
|
||||
ret find_pre_post_state_expr(fcx, pres, ternary_to_if(e));
|
||||
}
|
||||
expr_binary(bop, l, r) {
|
||||
if lazy_binop(bop) {
|
||||
let changed = find_pre_post_state_expr(fcx, pres, l);
|
||||
|
|
|
@ -1921,9 +1921,6 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
|
|||
check_pred_expr(fcx, cond) |
|
||||
check_then_else(fcx, thn, elsopt, id, expr.span);
|
||||
}
|
||||
ast::expr_ternary(_, _, _) {
|
||||
bot = check_expr(fcx, ast_util::ternary_to_if(expr));
|
||||
}
|
||||
ast::expr_assert(e) {
|
||||
bot = check_expr_with(fcx, e, ty::mk_bool(tcx));
|
||||
write_nil(tcx, id);
|
||||
|
|
|
@ -213,7 +213,6 @@ enum expr_ {
|
|||
expr_lit(@lit),
|
||||
expr_cast(@expr, @ty),
|
||||
expr_if(@expr, blk, option::t<@expr>),
|
||||
expr_ternary(@expr, @expr, @expr),
|
||||
expr_while(@expr, blk),
|
||||
expr_for(@local, @expr, blk),
|
||||
expr_do_while(blk, @expr),
|
||||
|
|
|
@ -205,23 +205,6 @@ fn default_block(stmts1: [@stmt], expr1: option::t<@expr>, id1: node_id) ->
|
|||
{view_items: [], stmts: stmts1, expr: expr1, id: id1, rules: default_blk}
|
||||
}
|
||||
|
||||
// This is a convenience function to transfor ternary expressions to if
|
||||
// expressions so that they can be treated the same
|
||||
fn ternary_to_if(e: @expr) -> @expr {
|
||||
alt e.node {
|
||||
expr_ternary(cond, then, els) {
|
||||
let then_blk = block_from_expr(then);
|
||||
let els_blk = block_from_expr(els);
|
||||
let els_expr =
|
||||
@{id: els.id, node: expr_block(els_blk), span: els.span};
|
||||
ret @{id: e.id,
|
||||
node: expr_if(cond, then_blk, option::some(els_expr)),
|
||||
span: e.span};
|
||||
}
|
||||
_ { fail; }
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME this doesn't handle big integer/float literals correctly (nor does
|
||||
// the rest of our literal handling)
|
||||
enum const_val {
|
||||
|
|
|
@ -352,10 +352,6 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
|
|||
expr_if(fld.fold_expr(cond), fld.fold_block(tr),
|
||||
option::map(fl, fld.fold_expr))
|
||||
}
|
||||
expr_ternary(cond, tr, fl) {
|
||||
expr_ternary(fld.fold_expr(cond), fld.fold_expr(tr),
|
||||
fld.fold_expr(fl))
|
||||
}
|
||||
expr_while(cond, body) {
|
||||
expr_while(fld.fold_expr(cond), fld.fold_block(body))
|
||||
}
|
||||
|
|
|
@ -328,10 +328,6 @@ fn next_token_inner(rdr: reader) -> token::token {
|
|||
|
||||
|
||||
// One-byte tokens.
|
||||
'?' {
|
||||
rdr.bump();
|
||||
ret token::QUES;
|
||||
}
|
||||
';' { rdr.bump(); ret token::SEMI; }
|
||||
',' { rdr.bump(); ret token::COMMA; }
|
||||
'.' {
|
||||
|
|
|
@ -1097,18 +1097,6 @@ fn parse_prefix_expr(p: parser) -> pexpr {
|
|||
ret mk_pexpr(p, lo, hi, ex);
|
||||
}
|
||||
|
||||
fn parse_ternary(p: parser) -> @ast::expr {
|
||||
let cond_expr = parse_binops(p);
|
||||
if p.token == token::QUES {
|
||||
p.bump();
|
||||
let then_expr = parse_expr(p);
|
||||
expect(p, token::COLON);
|
||||
let else_expr = parse_expr(p);
|
||||
ret mk_expr(p, cond_expr.span.lo, else_expr.span.hi,
|
||||
ast::expr_ternary(cond_expr, then_expr, else_expr));
|
||||
} else { ret cond_expr; }
|
||||
}
|
||||
|
||||
type op_spec = {tok: token::token, op: ast::binop, prec: int};
|
||||
|
||||
|
||||
|
@ -1143,7 +1131,6 @@ fn parse_binops(p: parser) -> @ast::expr {
|
|||
const unop_prec: int = 100;
|
||||
|
||||
const as_prec: int = 5;
|
||||
const ternary_prec: int = 0;
|
||||
|
||||
fn parse_more_binops(p: parser, plhs: pexpr, min_prec: int) ->
|
||||
@ast::expr {
|
||||
|
@ -1174,7 +1161,7 @@ fn parse_more_binops(p: parser, plhs: pexpr, min_prec: int) ->
|
|||
|
||||
fn parse_assign_expr(p: parser) -> @ast::expr {
|
||||
let lo = p.span.lo;
|
||||
let lhs = parse_ternary(p);
|
||||
let lhs = parse_binops(p);
|
||||
alt p.token {
|
||||
token::EQ {
|
||||
p.bump();
|
||||
|
|
|
@ -43,7 +43,6 @@ enum token {
|
|||
SEMI,
|
||||
COLON,
|
||||
MOD_SEP,
|
||||
QUES,
|
||||
RARROW,
|
||||
LARROW,
|
||||
DARROW,
|
||||
|
@ -114,7 +113,6 @@ fn to_str(r: reader, t: token) -> str {
|
|||
SEMI { ret ";"; }
|
||||
COLON { ret ":"; }
|
||||
MOD_SEP { ret "::"; }
|
||||
QUES { ret "?"; }
|
||||
RARROW { ret "->"; }
|
||||
LARROW { ret "<-"; }
|
||||
DARROW { ret "<->"; }
|
||||
|
|
|
@ -855,15 +855,6 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
|
|||
ast::expr_if_check(test, blk, elseopt) {
|
||||
print_if(s, test, blk, elseopt, true);
|
||||
}
|
||||
ast::expr_ternary(test, then, els) {
|
||||
print_expr(s, test);
|
||||
space(s.s);
|
||||
word_space(s, "?");
|
||||
print_expr(s, then);
|
||||
space(s.s);
|
||||
word_space(s, ":");
|
||||
print_expr(s, els);
|
||||
}
|
||||
ast::expr_while(test, blk) {
|
||||
head(s, "while");
|
||||
print_maybe_parens_discrim(s, test);
|
||||
|
@ -1044,8 +1035,8 @@ fn print_expr_parens_if_not_bot(s: ps, ex: @ast::expr) {
|
|||
let parens = alt ex.node {
|
||||
ast::expr_fail(_) | ast::expr_ret(_) |
|
||||
ast::expr_binary(_, _, _) | ast::expr_unary(_, _) |
|
||||
ast::expr_ternary(_, _, _) | ast::expr_move(_, _) |
|
||||
ast::expr_copy(_) | ast::expr_assign(_, _) | ast::expr_be(_) |
|
||||
ast::expr_move(_, _) | ast::expr_copy(_) |
|
||||
ast::expr_assign(_, _) | ast::expr_be(_) |
|
||||
ast::expr_assign_op(_, _, _) | ast::expr_swap(_, _) |
|
||||
ast::expr_log(_, _, _) | ast::expr_assert(_) |
|
||||
ast::expr_call(_, _, true) |
|
||||
|
@ -1395,7 +1386,6 @@ fn need_parens(expr: @ast::expr, outer_prec: int) -> bool {
|
|||
alt expr.node {
|
||||
ast::expr_binary(op, _, _) { operator_prec(op) < outer_prec }
|
||||
ast::expr_cast(_, _) { parse::parser::as_prec < outer_prec }
|
||||
ast::expr_ternary(_, _, _) { parse::parser::ternary_prec < outer_prec }
|
||||
// This may be too conservative in some cases
|
||||
ast::expr_assign(_, _) { true }
|
||||
ast::expr_move(_, _) { true }
|
||||
|
@ -1757,8 +1747,8 @@ fn ends_in_lit_int(ex: @ast::expr) -> bool {
|
|||
alt ex.node {
|
||||
ast::expr_lit(@{node: ast::lit_int(_, ast::ty_i), _}) { true }
|
||||
ast::expr_binary(_, _, sub) | ast::expr_unary(_, sub) |
|
||||
ast::expr_ternary(_, _, sub) | ast::expr_move(_, sub) |
|
||||
ast::expr_copy(sub) | ast::expr_assign(_, sub) | ast::expr_be(sub) |
|
||||
ast::expr_move(_, sub) | ast::expr_copy(sub) |
|
||||
ast::expr_assign(_, sub) | ast::expr_be(sub) |
|
||||
ast::expr_assign_op(_, _, sub) | ast::expr_swap(_, sub) |
|
||||
ast::expr_log(_, _, sub) | ast::expr_assert(sub) |
|
||||
ast::expr_check(_, sub) { ends_in_lit_int(sub) }
|
||||
|
|
|
@ -312,11 +312,6 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
|
|||
v.visit_block(b, e, v);
|
||||
visit_expr_opt(eo, e, v);
|
||||
}
|
||||
expr_ternary(c, t, el) {
|
||||
v.visit_expr(c, e, v);
|
||||
v.visit_expr(t, e, v);
|
||||
v.visit_expr(el, e, v);
|
||||
}
|
||||
expr_while(x, b) { v.visit_expr(x, e, v); v.visit_block(b, e, v); }
|
||||
expr_for(dcl, x, b) {
|
||||
v.visit_local(dcl, e, v);
|
||||
|
|
Loading…
Add table
Reference in a new issue