Move expr ids into the expr record type
This simplifies the tag variants a bit and makes expr_node_id obsolete.
This commit is contained in:
parent
edf73f0512
commit
c34e9b33d9
20 changed files with 814 additions and 938 deletions
|
@ -220,61 +220,63 @@ tag spawn_dom { dom_implicit; dom_thread; }
|
|||
// FIXME: temporary
|
||||
tag seq_kind { sk_unique; sk_rc; }
|
||||
|
||||
type expr = spanned[expr_];
|
||||
type expr = rec(node_id id,
|
||||
expr_ node,
|
||||
span span);
|
||||
|
||||
tag expr_ {
|
||||
expr_vec(vec[@expr], mutability, seq_kind, node_id);
|
||||
expr_tup(vec[elt], node_id);
|
||||
expr_rec(vec[field], option::t[@expr], node_id);
|
||||
expr_call(@expr, vec[@expr], node_id);
|
||||
expr_self_method(ident, node_id);
|
||||
expr_bind(@expr, vec[option::t[@expr]], node_id);
|
||||
expr_spawn(spawn_dom, option::t[str], @expr, vec[@expr], node_id);
|
||||
expr_binary(binop, @expr, @expr, node_id);
|
||||
expr_unary(unop, @expr, node_id);
|
||||
expr_lit(@lit, node_id);
|
||||
expr_cast(@expr, @ty, node_id);
|
||||
expr_if(@expr, block, option::t[@expr], node_id);
|
||||
expr_while(@expr, block, node_id);
|
||||
expr_for(@local, @expr, block, node_id);
|
||||
expr_for_each(@local, @expr, block, node_id);
|
||||
expr_do_while(block, @expr, node_id);
|
||||
expr_alt(@expr, vec[arm], node_id);
|
||||
expr_fn(_fn, node_id);
|
||||
expr_block(block, node_id);
|
||||
expr_vec(vec[@expr], mutability, seq_kind);
|
||||
expr_tup(vec[elt]);
|
||||
expr_rec(vec[field], option::t[@expr]);
|
||||
expr_call(@expr, vec[@expr]);
|
||||
expr_self_method(ident);
|
||||
expr_bind(@expr, vec[option::t[@expr]]);
|
||||
expr_spawn(spawn_dom, option::t[str], @expr, vec[@expr]);
|
||||
expr_binary(binop, @expr, @expr);
|
||||
expr_unary(unop, @expr);
|
||||
expr_lit(@lit);
|
||||
expr_cast(@expr, @ty);
|
||||
expr_if(@expr, block, option::t[@expr]);
|
||||
expr_while(@expr, block);
|
||||
expr_for(@local, @expr, block);
|
||||
expr_for_each(@local, @expr, block);
|
||||
expr_do_while(block, @expr);
|
||||
expr_alt(@expr, vec[arm]);
|
||||
expr_fn(_fn);
|
||||
expr_block(block);
|
||||
/*
|
||||
* FIXME: many of these @exprs should be constrained with
|
||||
* is_lval once we have constrained types working.
|
||||
*/
|
||||
expr_move(@expr, @expr, node_id);
|
||||
expr_assign(@expr,@expr, node_id);
|
||||
expr_swap(@expr, @expr, node_id);
|
||||
expr_assign_op(binop, @expr, @expr, node_id);
|
||||
expr_send(@expr, @expr, node_id);
|
||||
expr_recv(@expr, @expr, node_id);
|
||||
expr_field(@expr, ident, node_id);
|
||||
expr_index(@expr, @expr, node_id);
|
||||
expr_path(path, node_id);
|
||||
expr_ext(path, vec[@expr], option::t[str], @expr, node_id);
|
||||
expr_fail(node_id, option::t[str]);
|
||||
expr_break(node_id);
|
||||
expr_cont(node_id);
|
||||
expr_ret(option::t[@expr], node_id);
|
||||
expr_put(option::t[@expr], node_id);
|
||||
expr_be(@expr, node_id);
|
||||
expr_log(int, @expr, node_id);
|
||||
expr_move(@expr, @expr);
|
||||
expr_assign(@expr,@expr);
|
||||
expr_swap(@expr, @expr);
|
||||
expr_assign_op(binop, @expr, @expr);
|
||||
expr_send(@expr, @expr);
|
||||
expr_recv(@expr, @expr);
|
||||
expr_field(@expr, ident);
|
||||
expr_index(@expr, @expr);
|
||||
expr_path(path);
|
||||
expr_ext(path, vec[@expr], option::t[str], @expr);
|
||||
expr_fail(option::t[str]);
|
||||
expr_break;
|
||||
expr_cont;
|
||||
expr_ret(option::t[@expr]);
|
||||
expr_put(option::t[@expr]);
|
||||
expr_be(@expr);
|
||||
expr_log(int, @expr);
|
||||
|
||||
/* just an assert, no significance to typestate */
|
||||
expr_assert(@expr, node_id);
|
||||
expr_assert(@expr);
|
||||
|
||||
/* preds that typestate is aware of */
|
||||
expr_check(@expr, node_id);
|
||||
expr_check(@expr);
|
||||
/* FIXME Would be nice if expr_check desugared
|
||||
to expr_if_check. */
|
||||
expr_if_check(@expr, block, option::t[@expr], node_id);
|
||||
expr_port(node_id);
|
||||
expr_chan(@expr, node_id);
|
||||
expr_anon_obj(anon_obj, vec[ty_param], obj_def_ids, node_id);
|
||||
expr_if_check(@expr, block, option::t[@expr]);
|
||||
expr_port;
|
||||
expr_chan(@expr);
|
||||
expr_anon_obj(anon_obj, vec[ty_param], obj_def_ids);
|
||||
}
|
||||
|
||||
type lit = spanned[lit_];
|
||||
|
@ -527,15 +529,15 @@ fn is_exported(ident i, _mod m) -> bool {
|
|||
|
||||
fn is_call_expr(@expr e) -> bool {
|
||||
alt (e.node) {
|
||||
case (expr_call(_, _, _)) { ret true; }
|
||||
case (expr_call(_, _)) { ret true; }
|
||||
case (_) { ret false; }
|
||||
}
|
||||
}
|
||||
|
||||
fn is_constraint_arg(@expr e) -> bool {
|
||||
alt (e.node) {
|
||||
case (expr_lit(_, _)) { ret true; }
|
||||
case (expr_path(_, _)) { ret true; }
|
||||
case (expr_lit(_)) { ret true; }
|
||||
case (expr_path(_)) { ret true; }
|
||||
case (_) { ret false; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,15 +77,15 @@ fn eval_lit(ctx cx, span sp, @ast::lit lit) -> val {
|
|||
|
||||
fn eval_expr(ctx cx, env e, @ast::expr x) -> val {
|
||||
alt (x.node) {
|
||||
case (ast::expr_path(?pth, _)) {
|
||||
case (ast::expr_path(?pth)) {
|
||||
if (vec::len[ident](pth.node.idents) == 1u &&
|
||||
vec::len[@ast::ty](pth.node.types) == 0u) {
|
||||
ret lookup(cx.sess, e, x.span, pth.node.idents.(0));
|
||||
}
|
||||
cx.sess.span_fatal(x.span, "evaluating structured path-name");
|
||||
}
|
||||
case (ast::expr_lit(?lit, _)) { ret eval_lit(cx, x.span, lit); }
|
||||
case (ast::expr_unary(?op, ?a, _)) {
|
||||
case (ast::expr_lit(?lit)) { ret eval_lit(cx, x.span, lit); }
|
||||
case (ast::expr_unary(?op, ?a)) {
|
||||
auto av = eval_expr(cx, e, a);
|
||||
alt (op) {
|
||||
case (ast::not) {
|
||||
|
@ -97,7 +97,7 @@ fn eval_expr(ctx cx, env e, @ast::expr x) -> val {
|
|||
}
|
||||
}
|
||||
}
|
||||
case (ast::expr_binary(?op, ?a, ?b, _)) {
|
||||
case (ast::expr_binary(?op, ?a, ?b)) {
|
||||
auto av = eval_expr(cx, e, a);
|
||||
auto bv = eval_expr(cx, e, b);
|
||||
alt (op) {
|
||||
|
@ -214,7 +214,7 @@ fn eval_crate_directive_expr(ctx cx, env e, @ast::expr x, str prefix,
|
|||
&mutable vec[@ast::view_item] view_items,
|
||||
&mutable vec[@ast::item] items) {
|
||||
alt (x.node) {
|
||||
case (ast::expr_if(?cond, ?thn, ?elopt, _)) {
|
||||
case (ast::expr_if(?cond, ?thn, ?elopt)) {
|
||||
auto cv = eval_expr(cx, e, cond);
|
||||
if (!val_is_bool(cv)) {
|
||||
cx.sess.span_fatal(x.span, "bad cond type in 'if'");
|
||||
|
@ -234,7 +234,7 @@ fn eval_crate_directive_expr(ctx cx, env e, @ast::expr x, str prefix,
|
|||
}
|
||||
}
|
||||
}
|
||||
case (ast::expr_alt(?v, ?arms, _)) {
|
||||
case (ast::expr_alt(?v, ?arms)) {
|
||||
auto vv = eval_expr(cx, e, v);
|
||||
for (ast::arm arm in arms) {
|
||||
alt (arm.pat.node) {
|
||||
|
@ -259,7 +259,7 @@ fn eval_crate_directive_expr(ctx cx, env e, @ast::expr x, str prefix,
|
|||
}
|
||||
cx.sess.span_fatal(x.span, "no cases matched in 'alt'");
|
||||
}
|
||||
case (ast::expr_block(?block, _)) {
|
||||
case (ast::expr_block(?block)) {
|
||||
ret eval_crate_directive_block(cx, e, block, prefix, view_items,
|
||||
items);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ fn expand_syntax_ext(&ext_ctxt cx, common::span sp, &vec[@ast::expr] args,
|
|||
// FIXME: duplicate code copied from extfmt:
|
||||
fn expr_to_str(&ext_ctxt cx, @ast::expr expr) -> str {
|
||||
alt (expr.node) {
|
||||
case (ast::expr_lit(?l, _)) {
|
||||
case (ast::expr_lit(?l)) {
|
||||
alt (l.node) {
|
||||
case (ast::lit_str(?s, _)) { ret s; }
|
||||
case (_) { cx.span_fatal(l.span, "malformed #env call"); }
|
||||
|
@ -44,8 +44,7 @@ fn expr_to_str(&ext_ctxt cx, @ast::expr expr) -> str {
|
|||
|
||||
fn make_new_lit(&ext_ctxt cx, common::span sp, ast::lit_ lit) -> @ast::expr {
|
||||
auto sp_lit = @rec(node=lit, span=sp);
|
||||
auto expr = ast::expr_lit(sp_lit, cx.next_id());
|
||||
ret @rec(node=expr, span=sp);
|
||||
ret @rec(id=cx.next_id(), node=ast::expr_lit(sp_lit), span=sp);
|
||||
}
|
||||
|
||||
fn make_new_str(&ext_ctxt cx, common::span sp, str s) -> @ast::expr {
|
||||
|
|
|
@ -35,7 +35,7 @@ fn expand_syntax_ext(&ext_ctxt cx, common::span sp, &vec[@ast::expr] args,
|
|||
fn expr_to_str(&ext_ctxt cx, @ast::expr expr) -> str {
|
||||
auto err_msg = "first argument to #fmt must be a string literal";
|
||||
alt (expr.node) {
|
||||
case (ast::expr_lit(?l, _)) {
|
||||
case (ast::expr_lit(?l)) {
|
||||
alt (l.node) {
|
||||
case (ast::lit_str(?s, _)) { ret s; }
|
||||
case (_) { cx.span_fatal(l.span, err_msg); }
|
||||
|
@ -54,8 +54,7 @@ fn pieces_to_expr(&ext_ctxt cx, common::span sp, vec[piece] pieces,
|
|||
fn make_new_lit(&ext_ctxt cx, common::span sp, ast::lit_ lit) ->
|
||||
@ast::expr {
|
||||
auto sp_lit = @rec(node=lit, span=sp);
|
||||
auto expr = ast::expr_lit(sp_lit, cx.next_id());
|
||||
ret @rec(node=expr, span=sp);
|
||||
ret @rec(id=cx.next_id(), node=ast::expr_lit(sp_lit), span=sp);
|
||||
}
|
||||
fn make_new_str(&ext_ctxt cx, common::span sp, str s) -> @ast::expr {
|
||||
auto lit = ast::lit_str(s, ast::sk_rc);
|
||||
|
@ -71,31 +70,27 @@ fn pieces_to_expr(&ext_ctxt cx, common::span sp, vec[piece] pieces,
|
|||
}
|
||||
fn make_add_expr(&ext_ctxt cx, common::span sp, @ast::expr lhs,
|
||||
@ast::expr rhs) -> @ast::expr {
|
||||
auto binexpr = ast::expr_binary(ast::add, lhs, rhs, cx.next_id());
|
||||
ret @rec(node=binexpr, span=sp);
|
||||
auto binexpr = ast::expr_binary(ast::add, lhs, rhs);
|
||||
ret @rec(id=cx.next_id(), node=binexpr, span=sp);
|
||||
}
|
||||
fn make_path_expr(&ext_ctxt cx, common::span sp, vec[ast::ident] idents)
|
||||
-> @ast::expr {
|
||||
let vec[@ast::ty] types = [];
|
||||
auto path = rec(idents=idents, types=types);
|
||||
auto sp_path = rec(node=path, span=sp);
|
||||
auto pathexpr = ast::expr_path(sp_path, cx.next_id());
|
||||
auto sp_pathexpr = @rec(node=pathexpr, span=sp);
|
||||
ret sp_pathexpr;
|
||||
auto pathexpr = ast::expr_path(sp_path);
|
||||
ret @rec(id=cx.next_id(), node=pathexpr, span=sp);
|
||||
}
|
||||
fn make_vec_expr(&ext_ctxt cx, common::span sp, vec[@ast::expr] exprs) ->
|
||||
@ast::expr {
|
||||
auto vecexpr =
|
||||
ast::expr_vec(exprs, ast::imm, ast::sk_rc, cx.next_id());
|
||||
auto sp_vecexpr = @rec(node=vecexpr, span=sp);
|
||||
ret sp_vecexpr;
|
||||
auto vecexpr = ast::expr_vec(exprs, ast::imm, ast::sk_rc);
|
||||
ret @rec(id=cx.next_id(), node=vecexpr, span=sp);
|
||||
}
|
||||
fn make_call(&ext_ctxt cx, common::span sp, vec[ast::ident] fn_path,
|
||||
vec[@ast::expr] args) -> @ast::expr {
|
||||
auto pathexpr = make_path_expr(cx, sp, fn_path);
|
||||
auto callexpr = ast::expr_call(pathexpr, args, cx.next_id());
|
||||
auto sp_callexpr = @rec(node=callexpr, span=sp);
|
||||
ret sp_callexpr;
|
||||
auto callexpr = ast::expr_call(pathexpr, args);
|
||||
ret @rec(id=cx.next_id(), node=callexpr, span=sp);
|
||||
}
|
||||
fn make_rec_expr(&ext_ctxt cx, common::span sp,
|
||||
vec[tup(ast::ident, @ast::expr)] fields) -> @ast::expr {
|
||||
|
@ -107,10 +102,8 @@ fn pieces_to_expr(&ext_ctxt cx, common::span sp, vec[piece] pieces,
|
|||
rec(node=rec(mut=ast::imm, ident=ident, expr=val), span=sp);
|
||||
astfields += [astfield];
|
||||
}
|
||||
auto recexpr =
|
||||
ast::expr_rec(astfields, option::none[@ast::expr], cx.next_id());
|
||||
auto sp_recexpr = @rec(node=recexpr, span=sp);
|
||||
ret sp_recexpr;
|
||||
auto recexpr = ast::expr_rec(astfields, option::none[@ast::expr]);
|
||||
ret @rec(id=cx.next_id(), node=recexpr, span=sp);
|
||||
}
|
||||
fn make_path_vec(str ident) -> vec[str] {
|
||||
// FIXME: #fmt can't currently be used from within std
|
||||
|
|
|
@ -701,6 +701,12 @@ fn parse_field(&parser p) -> ast::field {
|
|||
ret spanned(lo, e.span.hi, rec(mut=m, ident=i, expr=e));
|
||||
}
|
||||
|
||||
fn mk_expr(&parser p, uint lo, uint hi, &ast::expr_ node) -> @ast::expr {
|
||||
ret @rec(id=p.get_id(),
|
||||
node=node,
|
||||
span=rec(lo=lo, hi=hi));
|
||||
}
|
||||
|
||||
fn parse_bottom_expr(&parser p) -> @ast::expr {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto hi = p.get_hi_pos();
|
||||
|
@ -708,7 +714,7 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
// alt-exhaustive-match checking are co-operating.
|
||||
|
||||
auto lit = @spanned(lo, hi, ast::lit_nil);
|
||||
let ast::expr_ ex = ast::expr_lit(lit, p.get_id());
|
||||
let ast::expr_ ex = ast::expr_lit(lit);
|
||||
if (p.peek() == token::LPAREN) {
|
||||
p.bump();
|
||||
alt (p.peek()) {
|
||||
|
@ -716,18 +722,17 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
hi = p.get_hi_pos();
|
||||
p.bump();
|
||||
auto lit = @spanned(lo, hi, ast::lit_nil);
|
||||
ret @spanned(lo, hi, ast::expr_lit(lit, p.get_id()));
|
||||
ret mk_expr(p, lo, hi, ast::expr_lit(lit));
|
||||
}
|
||||
case (_) {/* fall through */ }
|
||||
}
|
||||
auto e = parse_expr(p);
|
||||
hi = p.get_hi_pos();
|
||||
expect(p, token::RPAREN);
|
||||
ret @spanned(lo, hi, e.node);
|
||||
ret mk_expr(p, lo, hi, e.node);
|
||||
} else if (p.peek() == token::LBRACE) {
|
||||
auto blk = parse_block(p);
|
||||
ret @spanned(blk.span.lo, blk.span.hi,
|
||||
ast::expr_block(blk, p.get_id()));
|
||||
ret mk_expr(p, blk.span.lo, blk.span.hi, ast::expr_block(blk));
|
||||
} else if (eat_word(p, "if")) {
|
||||
ret parse_if_expr(p);
|
||||
} else if (eat_word(p, "for")) {
|
||||
|
@ -752,14 +757,14 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
|
||||
parse_elt, p);
|
||||
hi = es.span.hi;
|
||||
ex = ast::expr_tup(es.node, p.get_id());
|
||||
ex = ast::expr_tup(es.node);
|
||||
} else if (p.peek() == token::LBRACKET) {
|
||||
p.bump();
|
||||
auto mut = parse_mutability(p);
|
||||
auto es =
|
||||
parse_seq_to_end(token::RBRACKET, some(token::COMMA), parse_expr,
|
||||
p);
|
||||
ex = ast::expr_vec(es, mut, ast::sk_rc, p.get_id());
|
||||
ex = ast::expr_vec(es, mut, ast::sk_rc);
|
||||
} else if (p.peek() == token::TILDE) {
|
||||
p.bump();
|
||||
alt (p.peek()) {
|
||||
|
@ -770,14 +775,14 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
auto es =
|
||||
parse_seq_to_end(token::RBRACKET, some(token::COMMA),
|
||||
parse_expr, p);
|
||||
ex = ast::expr_vec(es, mut, ast::sk_unique, p.get_id());
|
||||
ex = ast::expr_vec(es, mut, ast::sk_unique);
|
||||
}
|
||||
case (token::LIT_STR(?s)) {
|
||||
p.bump();
|
||||
auto lit =
|
||||
@rec(node=ast::lit_str(p.get_str(s), ast::sk_unique),
|
||||
span=p.get_span());
|
||||
ex = ast::expr_lit(lit, p.get_id());
|
||||
ex = ast::expr_lit(lit);
|
||||
}
|
||||
case (_) {
|
||||
p.get_session().span_unimpl(p.get_span(),
|
||||
|
@ -819,7 +824,7 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
let ast::anon_obj ob =
|
||||
rec(fields=fields, methods=meths, with_obj=with_obj);
|
||||
auto odid = rec(ty=p.get_id(), ctor=p.get_id());
|
||||
ex = ast::expr_anon_obj(ob, ty_params, odid, p.get_id());
|
||||
ex = ast::expr_anon_obj(ob, ty_params, odid);
|
||||
} else if (eat_word(p, "rec")) {
|
||||
expect(p, token::LPAREN);
|
||||
auto fields = [parse_field(p)];
|
||||
|
@ -840,7 +845,7 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
fields += [parse_field(p)];
|
||||
} else { unexpected(p, p.peek()); }
|
||||
}
|
||||
ex = ast::expr_rec(fields, base, p.get_id());
|
||||
ex = ast::expr_rec(fields, base);
|
||||
} else if (eat_word(p, "bind")) {
|
||||
auto e = parse_expr_res(p, RESTRICT_NO_CALL_EXPRS);
|
||||
fn parse_expr_opt(&parser p) -> option::t[@ast::expr] {
|
||||
|
@ -853,7 +858,7 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
|
||||
parse_expr_opt, p);
|
||||
hi = es.span.hi;
|
||||
ex = ast::expr_bind(e, es.node, p.get_id());
|
||||
ex = ast::expr_bind(e, es.node);
|
||||
} else if (p.peek() == token::POUND) {
|
||||
auto ex_ext = parse_syntax_ext(p);
|
||||
lo = ex_ext.span.lo;
|
||||
|
@ -864,19 +869,19 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
case (token::LIT_STR(?s)) { msg = some(p.get_str(s)); p.bump(); }
|
||||
case (_) { msg = none; }
|
||||
}
|
||||
ex = ast::expr_fail(p.get_id(), msg);
|
||||
ex = ast::expr_fail(msg);
|
||||
} else if (eat_word(p, "log")) {
|
||||
auto e = parse_expr(p);
|
||||
auto hi = e.span.hi;
|
||||
ex = ast::expr_log(1, e, p.get_id());
|
||||
ex = ast::expr_log(1, e);
|
||||
} else if (eat_word(p, "log_err")) {
|
||||
auto e = parse_expr(p);
|
||||
auto hi = e.span.hi;
|
||||
ex = ast::expr_log(0, e, p.get_id());
|
||||
ex = ast::expr_log(0, e);
|
||||
} else if (eat_word(p, "assert")) {
|
||||
auto e = parse_expr(p);
|
||||
auto hi = e.span.hi;
|
||||
ex = ast::expr_assert(e, p.get_id());
|
||||
ex = ast::expr_assert(e);
|
||||
} else if (eat_word(p, "check")) {
|
||||
/* Should be a predicate (pure boolean function) applied to
|
||||
arguments that are all either slot variables or literals.
|
||||
|
@ -884,27 +889,27 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
|
||||
auto e = parse_expr(p);
|
||||
auto hi = e.span.hi;
|
||||
ex = ast::expr_check(e, p.get_id());
|
||||
ex = ast::expr_check(e);
|
||||
} else if (eat_word(p, "ret")) {
|
||||
alt (p.peek()) {
|
||||
case (token::SEMI) { ex = ast::expr_ret(none, p.get_id()); }
|
||||
case (token::SEMI) { ex = ast::expr_ret(none); }
|
||||
case (_) {
|
||||
auto e = parse_expr(p);
|
||||
hi = e.span.hi;
|
||||
ex = ast::expr_ret(some(e), p.get_id());
|
||||
ex = ast::expr_ret(some(e));
|
||||
}
|
||||
}
|
||||
} else if (eat_word(p, "break")) {
|
||||
ex = ast::expr_break(p.get_id());
|
||||
ex = ast::expr_break;
|
||||
} else if (eat_word(p, "cont")) {
|
||||
ex = ast::expr_cont(p.get_id());
|
||||
ex = ast::expr_cont;
|
||||
} else if (eat_word(p, "put")) {
|
||||
alt (p.peek()) {
|
||||
case (token::SEMI) { ex = ast::expr_put(none, p.get_id()); }
|
||||
case (token::SEMI) { ex = ast::expr_put(none); }
|
||||
case (_) {
|
||||
auto e = parse_expr(p);
|
||||
hi = e.span.hi;
|
||||
ex = ast::expr_put(some(e), p.get_id());
|
||||
ex = ast::expr_put(some(e));
|
||||
}
|
||||
}
|
||||
} else if (eat_word(p, "be")) {
|
||||
|
@ -913,19 +918,19 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
// FIXME: Is this the right place for this check?
|
||||
if (/*check*/ast::is_call_expr(e)) {
|
||||
hi = e.span.hi;
|
||||
ex = ast::expr_be(e, p.get_id());
|
||||
ex = ast::expr_be(e);
|
||||
} else { p.err("Non-call expression in tail call"); }
|
||||
} else if (eat_word(p, "port")) {
|
||||
expect(p, token::LPAREN);
|
||||
expect(p, token::RPAREN);
|
||||
hi = p.get_hi_pos();
|
||||
ex = ast::expr_port(p.get_id());
|
||||
ex = ast::expr_port;
|
||||
} else if (eat_word(p, "chan")) {
|
||||
expect(p, token::LPAREN);
|
||||
auto e = parse_expr(p);
|
||||
hi = e.span.hi;
|
||||
expect(p, token::RPAREN);
|
||||
ex = ast::expr_chan(e, p.get_id());
|
||||
ex = ast::expr_chan(e);
|
||||
} else if (eat_word(p, "self")) {
|
||||
log "parsing a self-call...";
|
||||
expect(p, token::DOT);
|
||||
|
@ -936,19 +941,19 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
|
||||
parse_expr, p);
|
||||
hi = es.span.hi;
|
||||
ex = ast::expr_call(f, es.node, p.get_id());
|
||||
ex = ast::expr_call(f, es.node);
|
||||
} else if (is_ident(p.peek()) && !is_word(p, "true") &&
|
||||
!is_word(p, "false")) {
|
||||
check_bad_word(p);
|
||||
auto pth = parse_path_and_ty_param_substs(p);
|
||||
hi = pth.span.hi;
|
||||
ex = ast::expr_path(pth, p.get_id());
|
||||
ex = ast::expr_path(pth);
|
||||
} else {
|
||||
auto lit = parse_lit(p);
|
||||
hi = lit.span.hi;
|
||||
ex = ast::expr_lit(@lit, p.get_id());
|
||||
ex = ast::expr_lit(@lit);
|
||||
}
|
||||
ret @spanned(lo, hi, ex);
|
||||
ret mk_expr(p, lo, hi, ex);
|
||||
}
|
||||
|
||||
fn parse_syntax_ext(&parser p) -> @ast::expr {
|
||||
|
@ -964,7 +969,7 @@ fn parse_syntax_ext_naked(&parser p, uint lo) -> @ast::expr {
|
|||
auto hi = es.span.hi;
|
||||
auto ext_span = rec(lo=lo, hi=hi);
|
||||
auto ex = expand_syntax_ext(p, ext_span, pth, es.node, none);
|
||||
ret @spanned(lo, hi, ex);
|
||||
ret mk_expr(p, lo, hi, ex);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -982,8 +987,7 @@ fn expand_syntax_ext(&parser p, common::span sp, &ast::path path,
|
|||
case (none) { p.err("unknown syntax expander: '" + extname + "'"); }
|
||||
case (some(ext::x(?ext))) {
|
||||
auto ext_cx = ext::mk_ctxt(p);
|
||||
ret ast::expr_ext(path, args, body, ext(ext_cx, sp, args, body),
|
||||
p.get_id());
|
||||
ret ast::expr_ext(path, args, body, ext(ext_cx, sp, args, body));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -991,8 +995,7 @@ fn expand_syntax_ext(&parser p, common::span sp, &ast::path path,
|
|||
fn parse_self_method(&parser p) -> @ast::expr {
|
||||
auto sp = p.get_span();
|
||||
let ast::ident f_name = parse_ident(p);
|
||||
auto hi = p.get_span();
|
||||
ret @rec(node=ast::expr_self_method(f_name, p.get_id()), span=sp);
|
||||
ret mk_expr(p, sp.lo, sp.hi, ast::expr_self_method(f_name));
|
||||
}
|
||||
|
||||
fn parse_dot_or_call_expr(&parser p) -> @ast::expr {
|
||||
|
@ -1014,8 +1017,7 @@ fn parse_dot_or_call_expr_with(&parser p, @ast::expr e) -> @ast::expr {
|
|||
parse_seq(token::LPAREN, token::RPAREN,
|
||||
some(token::COMMA), parse_expr, p);
|
||||
hi = es.span.hi;
|
||||
auto e_ = ast::expr_call(e, es.node, p.get_id());
|
||||
e = @spanned(lo, hi, e_);
|
||||
e = mk_expr(p, lo, hi, ast::expr_call(e, es.node));
|
||||
}
|
||||
}
|
||||
case (token::DOT) {
|
||||
|
@ -1024,17 +1026,15 @@ fn parse_dot_or_call_expr_with(&parser p, @ast::expr e) -> @ast::expr {
|
|||
case (token::IDENT(?i, _)) {
|
||||
hi = p.get_hi_pos();
|
||||
p.bump();
|
||||
auto e_ =
|
||||
ast::expr_field(e, p.get_str(i), p.get_id());
|
||||
e = @spanned(lo, hi, e_);
|
||||
e = mk_expr(p, lo, hi,
|
||||
ast::expr_field(e, p.get_str(i)));
|
||||
}
|
||||
case (token::LPAREN) {
|
||||
p.bump();
|
||||
auto ix = parse_expr(p);
|
||||
hi = ix.span.hi;
|
||||
expect(p, token::RPAREN);
|
||||
auto e_ = ast::expr_index(e, ix, p.get_id());
|
||||
e = @spanned(lo, hi, e_);
|
||||
e = mk_expr(p, lo, hi, ast::expr_index(e, ix));
|
||||
}
|
||||
case (?t) { unexpected(p, t); }
|
||||
}
|
||||
|
@ -1057,13 +1057,13 @@ fn parse_prefix_expr(&parser p) -> @ast::expr {
|
|||
// alt-exhaustive-match checking are co-operating.
|
||||
|
||||
auto lit = @spanned(lo, lo, ast::lit_nil);
|
||||
let ast::expr_ ex = ast::expr_lit(lit, p.get_id());
|
||||
let ast::expr_ ex = ast::expr_lit(lit);
|
||||
alt (p.peek()) {
|
||||
case (token::NOT) {
|
||||
p.bump();
|
||||
auto e = parse_prefix_expr(p);
|
||||
hi = e.span.hi;
|
||||
ex = ast::expr_unary(ast::not, e, p.get_id());
|
||||
ex = ast::expr_unary(ast::not, e);
|
||||
}
|
||||
case (token::BINOP(?b)) {
|
||||
alt (b) {
|
||||
|
@ -1071,13 +1071,13 @@ fn parse_prefix_expr(&parser p) -> @ast::expr {
|
|||
p.bump();
|
||||
auto e = parse_prefix_expr(p);
|
||||
hi = e.span.hi;
|
||||
ex = ast::expr_unary(ast::neg, e, p.get_id());
|
||||
ex = ast::expr_unary(ast::neg, e);
|
||||
}
|
||||
case (token::STAR) {
|
||||
p.bump();
|
||||
auto e = parse_prefix_expr(p);
|
||||
hi = e.span.hi;
|
||||
ex = ast::expr_unary(ast::deref, e, p.get_id());
|
||||
ex = ast::expr_unary(ast::deref, e);
|
||||
}
|
||||
case (_) { ret parse_dot_or_call_expr(p); }
|
||||
}
|
||||
|
@ -1087,11 +1087,11 @@ fn parse_prefix_expr(&parser p) -> @ast::expr {
|
|||
auto m = parse_mutability(p);
|
||||
auto e = parse_prefix_expr(p);
|
||||
hi = e.span.hi;
|
||||
ex = ast::expr_unary(ast::box(m), e, p.get_id());
|
||||
ex = ast::expr_unary(ast::box(m), e);
|
||||
}
|
||||
case (_) { ret parse_dot_or_call_expr(p); }
|
||||
}
|
||||
ret @spanned(lo, hi, ex);
|
||||
ret mk_expr(p, lo, hi, ex);
|
||||
}
|
||||
|
||||
type op_spec = rec(token::token tok, ast::binop op, int prec);
|
||||
|
@ -1135,16 +1135,16 @@ fn parse_more_binops(&parser p, @ast::expr lhs, int min_prec) -> @ast::expr {
|
|||
if (cur.prec > min_prec && cur.tok == peeked) {
|
||||
p.bump();
|
||||
auto rhs = parse_more_binops(p, parse_prefix_expr(p), cur.prec);
|
||||
auto bin = ast::expr_binary(cur.op, lhs, rhs, p.get_id());
|
||||
auto span = @spanned(lhs.span.lo, rhs.span.hi, bin);
|
||||
ret parse_more_binops(p, span, min_prec);
|
||||
auto bin = mk_expr(p, lhs.span.lo, rhs.span.hi,
|
||||
ast::expr_binary(cur.op, lhs, rhs));
|
||||
ret parse_more_binops(p, bin, min_prec);
|
||||
}
|
||||
}
|
||||
if (as_prec > min_prec && eat_word(p, "as")) {
|
||||
auto rhs = parse_ty(p);
|
||||
auto _as = ast::expr_cast(lhs, rhs, p.get_id());
|
||||
auto span = @spanned(lhs.span.lo, rhs.span.hi, _as);
|
||||
ret parse_more_binops(p, span, min_prec);
|
||||
auto _as = mk_expr(p, lhs.span.lo, rhs.span.hi,
|
||||
ast::expr_cast(lhs, rhs));
|
||||
ret parse_more_binops(p, _as, min_prec);
|
||||
}
|
||||
ret lhs;
|
||||
}
|
||||
|
@ -1156,8 +1156,7 @@ fn parse_assign_expr(&parser p) -> @ast::expr {
|
|||
case (token::EQ) {
|
||||
p.bump();
|
||||
auto rhs = parse_expr(p);
|
||||
ret @spanned(lo, rhs.span.hi,
|
||||
ast::expr_assign(lhs, rhs, p.get_id()));
|
||||
ret mk_expr(p, lo, rhs.span.hi, ast::expr_assign(lhs, rhs));
|
||||
}
|
||||
case (token::BINOPEQ(?op)) {
|
||||
p.bump();
|
||||
|
@ -1176,32 +1175,28 @@ fn parse_assign_expr(&parser p) -> @ast::expr {
|
|||
case (token::LSR) { aop = ast::lsr; }
|
||||
case (token::ASR) { aop = ast::asr; }
|
||||
}
|
||||
ret @spanned(lo, rhs.span.hi,
|
||||
ast::expr_assign_op(aop, lhs, rhs, p.get_id()));
|
||||
ret mk_expr(p, lo, rhs.span.hi,
|
||||
ast::expr_assign_op(aop, lhs, rhs));
|
||||
}
|
||||
case (token::LARROW) {
|
||||
p.bump();
|
||||
auto rhs = parse_expr(p);
|
||||
ret @spanned(lo, rhs.span.hi,
|
||||
ast::expr_move(lhs, rhs, p.get_id()));
|
||||
ret mk_expr(p, lo, rhs.span.hi, ast::expr_move(lhs, rhs));
|
||||
}
|
||||
case (token::SEND) {
|
||||
p.bump();
|
||||
auto rhs = parse_expr(p);
|
||||
ret @spanned(lo, rhs.span.hi,
|
||||
ast::expr_send(lhs, rhs, p.get_id()));
|
||||
ret mk_expr(p, lo, rhs.span.hi, ast::expr_send(lhs, rhs));
|
||||
}
|
||||
case (token::RECV) {
|
||||
p.bump();
|
||||
auto rhs = parse_expr(p);
|
||||
ret @spanned(lo, rhs.span.hi,
|
||||
ast::expr_recv(lhs, rhs, p.get_id()));
|
||||
ret mk_expr(p, lo, rhs.span.hi, ast::expr_recv(lhs, rhs));
|
||||
}
|
||||
case (token::DARROW) {
|
||||
p.bump();
|
||||
auto rhs = parse_expr(p);
|
||||
ret @spanned(lo, rhs.span.hi,
|
||||
ast::expr_swap(lhs, rhs, p.get_id()));
|
||||
ret mk_expr(p, lo, rhs.span.hi, ast::expr_swap(lhs, rhs));
|
||||
}
|
||||
case (_) {/* fall through */ }
|
||||
}
|
||||
|
@ -1210,7 +1205,7 @@ fn parse_assign_expr(&parser p) -> @ast::expr {
|
|||
|
||||
fn parse_if_expr_1(&parser p) -> tup(@ast::expr,
|
||||
ast::block, option::t[@ast::expr],
|
||||
ast::node_id, uint, uint) {
|
||||
uint, uint) {
|
||||
auto lo = p.get_last_lo_pos();
|
||||
expect(p, token::LPAREN);
|
||||
auto cond = parse_expr(p);
|
||||
|
@ -1223,19 +1218,18 @@ fn parse_if_expr_1(&parser p) -> tup(@ast::expr,
|
|||
els = some(elexpr);
|
||||
hi = elexpr.span.hi;
|
||||
}
|
||||
ret tup(cond, thn, els, p.get_id(), lo, hi);
|
||||
ret tup(cond, thn, els, lo, hi);
|
||||
}
|
||||
|
||||
fn parse_if_expr(&parser p) -> @ast::expr {
|
||||
auto lo = p.get_last_lo_pos();
|
||||
if (eat_word(p, "check")) {
|
||||
auto q = parse_if_expr_1(p);
|
||||
ret @spanned(q._4, q._5,
|
||||
ast::expr_if_check(q._0, q._1, q._2, q._3));
|
||||
ret mk_expr(p, q._3, q._4, ast::expr_if_check(q._0, q._1, q._2));
|
||||
}
|
||||
else {
|
||||
auto q = parse_if_expr_1(p);
|
||||
ret @spanned(q._4, q._5, ast::expr_if(q._0, q._1, q._2, q._3));
|
||||
ret mk_expr(p, q._3, q._4, ast::expr_if(q._0, q._1, q._2));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1244,7 +1238,7 @@ fn parse_fn_expr(&parser p) -> @ast::expr {
|
|||
auto decl = parse_fn_decl(p, ast::impure_fn);
|
||||
auto body = parse_block(p);
|
||||
auto _fn = rec(decl=decl, proto=ast::proto_fn, body=body);
|
||||
ret @spanned(lo, body.span.hi, ast::expr_fn(_fn, p.get_id()));
|
||||
ret mk_expr(p, lo, body.span.hi, ast::expr_fn(_fn));
|
||||
}
|
||||
|
||||
fn parse_else_expr(&parser p) -> @ast::expr {
|
||||
|
@ -1252,8 +1246,7 @@ fn parse_else_expr(&parser p) -> @ast::expr {
|
|||
ret parse_if_expr(p);
|
||||
} else {
|
||||
auto blk = parse_block(p);
|
||||
ret @spanned(blk.span.lo, blk.span.hi,
|
||||
ast::expr_block(blk, p.get_id()));
|
||||
ret mk_expr(p, blk.span.lo, blk.span.hi, ast::expr_block(blk));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1277,10 +1270,9 @@ fn parse_for_expr(&parser p) -> @ast::expr {
|
|||
auto body = parse_block(p);
|
||||
auto hi = body.span.hi;
|
||||
if (is_each) {
|
||||
ret @spanned(lo, hi,
|
||||
ast::expr_for_each(decl, seq, body, p.get_id()));
|
||||
ret mk_expr(p, lo, hi, ast::expr_for_each(decl, seq, body));
|
||||
} else {
|
||||
ret @spanned(lo, hi, ast::expr_for(decl, seq, body, p.get_id()));
|
||||
ret mk_expr(p, lo, hi, ast::expr_for(decl, seq, body));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1291,7 +1283,7 @@ fn parse_while_expr(&parser p) -> @ast::expr {
|
|||
expect(p, token::RPAREN);
|
||||
auto body = parse_block(p);
|
||||
auto hi = body.span.hi;
|
||||
ret @spanned(lo, hi, ast::expr_while(cond, body, p.get_id()));
|
||||
ret mk_expr(p, lo, hi, ast::expr_while(cond, body));
|
||||
}
|
||||
|
||||
fn parse_do_while_expr(&parser p) -> @ast::expr {
|
||||
|
@ -1302,7 +1294,7 @@ fn parse_do_while_expr(&parser p) -> @ast::expr {
|
|||
auto cond = parse_expr(p);
|
||||
expect(p, token::RPAREN);
|
||||
auto hi = cond.span.hi;
|
||||
ret @spanned(lo, hi, ast::expr_do_while(body, cond, p.get_id()));
|
||||
ret mk_expr(p, lo, hi, ast::expr_do_while(body, cond));
|
||||
}
|
||||
|
||||
fn parse_alt_expr(&parser p) -> @ast::expr {
|
||||
|
@ -1329,8 +1321,7 @@ fn parse_alt_expr(&parser p) -> @ast::expr {
|
|||
}
|
||||
auto hi = p.get_hi_pos();
|
||||
p.bump();
|
||||
auto expr = ast::expr_alt(discriminant, arms, p.get_id());
|
||||
ret @spanned(lo, hi, expr);
|
||||
ret mk_expr(p, lo, hi, ast::expr_alt(discriminant, arms));
|
||||
}
|
||||
|
||||
fn parse_spawn_expr(&parser p) -> @ast::expr {
|
||||
|
@ -1343,10 +1334,8 @@ fn parse_spawn_expr(&parser p) -> @ast::expr {
|
|||
parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
|
||||
parse_expr, p);
|
||||
auto hi = es.span.hi;
|
||||
auto spawn_expr =
|
||||
ast::expr_spawn(ast::dom_implicit, option::none, fn_expr, es.node,
|
||||
p.get_id());
|
||||
ret @spanned(lo, hi, spawn_expr);
|
||||
ret mk_expr(p, lo, hi, ast::expr_spawn
|
||||
(ast::dom_implicit, option::none, fn_expr, es.node));
|
||||
}
|
||||
|
||||
fn parse_expr(&parser p) -> @ast::expr {
|
||||
|
@ -1555,53 +1544,52 @@ fn stmt_to_expr(@ast::stmt stmt) -> option::t[@ast::expr] {
|
|||
fn stmt_ends_with_semi(&ast::stmt stmt) -> bool {
|
||||
alt (stmt.node) {
|
||||
case (ast::stmt_decl(?d, _)) {
|
||||
alt (d.node) {
|
||||
case (ast::decl_local(_)) { ret true; }
|
||||
case (ast::decl_item(_)) { ret false; }
|
||||
ret alt (d.node) {
|
||||
case (ast::decl_local(_)) { true }
|
||||
case (ast::decl_item(_)) { false }
|
||||
}
|
||||
}
|
||||
case (ast::stmt_expr(?e, _)) {
|
||||
alt (e.node) {
|
||||
case (ast::expr_vec(_, _, _, _)) { ret true; }
|
||||
case (ast::expr_tup(_, _)) { ret true; }
|
||||
case (ast::expr_rec(_, _, _)) { ret true; }
|
||||
case (ast::expr_call(_, _, _)) { ret true; }
|
||||
case (ast::expr_self_method(_, _)) { ret false; }
|
||||
case (ast::expr_binary(_, _, _, _)) { ret true; }
|
||||
case (ast::expr_unary(_, _, _)) { ret true; }
|
||||
case (ast::expr_lit(_, _)) { ret true; }
|
||||
case (ast::expr_cast(_, _, _)) { ret true; }
|
||||
case (ast::expr_if(_, _, _, _)) { ret false; }
|
||||
case (ast::expr_for(_, _, _, _)) { ret false; }
|
||||
case (ast::expr_for_each(_, _, _, _)) { ret false; }
|
||||
case (ast::expr_while(_, _, _)) { ret false; }
|
||||
case (ast::expr_do_while(_, _, _)) { ret false; }
|
||||
case (ast::expr_alt(_, _, _)) { ret false; }
|
||||
case (ast::expr_fn(_, _)) { ret false; }
|
||||
case (ast::expr_block(_, _)) { ret false; }
|
||||
case (ast::expr_move(_, _, _)) { ret true; }
|
||||
case (ast::expr_assign(_, _, _)) { ret true; }
|
||||
case (ast::expr_swap(_, _, _)) { ret true; }
|
||||
case (ast::expr_assign_op(_, _, _, _)) { ret true; }
|
||||
case (ast::expr_send(_, _, _)) { ret true; }
|
||||
case (ast::expr_recv(_, _, _)) { ret true; }
|
||||
case (ast::expr_field(_, _, _)) { ret true; }
|
||||
case (ast::expr_index(_, _, _)) { ret true; }
|
||||
case (ast::expr_path(_, _)) { ret true; }
|
||||
case (ast::expr_fail(_, _)) { ret true; }
|
||||
case (ast::expr_break(_)) { ret true; }
|
||||
case (ast::expr_cont(_)) { ret true; }
|
||||
case (ast::expr_ret(_, _)) { ret true; }
|
||||
case (ast::expr_put(_, _)) { ret true; }
|
||||
case (ast::expr_be(_, _)) { ret true; }
|
||||
case (ast::expr_log(_, _, _)) { ret true; }
|
||||
case (ast::expr_check(_, _)) { ret true; }
|
||||
case (ast::expr_assert(_, _)) { ret true; }
|
||||
ret alt (e.node) {
|
||||
case (ast::expr_vec(_, _, _)) { true }
|
||||
case (ast::expr_tup(_)) { true }
|
||||
case (ast::expr_rec(_, _)) { true }
|
||||
case (ast::expr_call(_, _)) { true }
|
||||
case (ast::expr_self_method(_)) { false }
|
||||
case (ast::expr_binary(_, _, _)) { true }
|
||||
case (ast::expr_unary(_, _)) { true }
|
||||
case (ast::expr_lit(_)) { true }
|
||||
case (ast::expr_cast(_, _)) { true }
|
||||
case (ast::expr_if(_, _, _)) { false }
|
||||
case (ast::expr_for(_, _, _)) { false }
|
||||
case (ast::expr_for_each(_, _, _)) { false }
|
||||
case (ast::expr_while(_, _)) { false }
|
||||
case (ast::expr_do_while(_, _)) { false }
|
||||
case (ast::expr_alt(_, _)) { false }
|
||||
case (ast::expr_fn(_)) { false }
|
||||
case (ast::expr_block(_)) { false }
|
||||
case (ast::expr_move(_, _)) { true }
|
||||
case (ast::expr_assign(_, _)) { true }
|
||||
case (ast::expr_swap(_, _)) { true }
|
||||
case (ast::expr_assign_op(_, _, _)) { true }
|
||||
case (ast::expr_send(_, _)) { true }
|
||||
case (ast::expr_recv(_, _)) { true }
|
||||
case (ast::expr_field(_, _)) { true }
|
||||
case (ast::expr_index(_, _)) { true }
|
||||
case (ast::expr_path(_)) { true }
|
||||
case (ast::expr_fail(_)) { true }
|
||||
case (ast::expr_break) { true }
|
||||
case (ast::expr_cont) { true }
|
||||
case (ast::expr_ret(_)) { true }
|
||||
case (ast::expr_put(_)) { true }
|
||||
case (ast::expr_be(_)) { true }
|
||||
case (ast::expr_log(_, _)) { true }
|
||||
case (ast::expr_check(_)) { true }
|
||||
case (ast::expr_assert(_)) { true }
|
||||
}
|
||||
}
|
||||
case (
|
||||
// We should not be calling this on a cdir.
|
||||
ast::stmt_crate_directive(?cdir)) {
|
||||
case (ast::stmt_crate_directive(?cdir)) {
|
||||
fail;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,18 +76,18 @@ fn visit_item(@ctx cx, &@ast::item i, &scope sc, &vt[scope] v) {
|
|||
fn visit_expr(@ctx cx, &@ast::expr ex, &scope sc, &vt[scope] v) {
|
||||
auto handled = true;
|
||||
alt (ex.node) {
|
||||
case (ast::expr_call(?f, ?args, _)) {
|
||||
case (ast::expr_call(?f, ?args)) {
|
||||
check_call(*cx, f, args, sc);
|
||||
handled = false;
|
||||
}
|
||||
case (ast::expr_be(?cl, _)) {
|
||||
case (ast::expr_be(?cl)) {
|
||||
check_tail_call(*cx, cl);
|
||||
visit::visit_expr(cl, sc, v);
|
||||
}
|
||||
case (ast::expr_alt(?input, ?arms, _)) {
|
||||
case (ast::expr_alt(?input, ?arms)) {
|
||||
check_alt(*cx, input, arms, sc, v);
|
||||
}
|
||||
case (ast::expr_put(?val, _)) {
|
||||
case (ast::expr_put(?val)) {
|
||||
alt (val) {
|
||||
case (some(?ex)) {
|
||||
auto root = expr_root(*cx, ex, false);
|
||||
|
@ -101,23 +101,23 @@ fn visit_expr(@ctx cx, &@ast::expr ex, &scope sc, &vt[scope] v) {
|
|||
case (_) { }
|
||||
}
|
||||
}
|
||||
case (ast::expr_for_each(?decl, ?call, ?block, _)) {
|
||||
case (ast::expr_for_each(?decl, ?call, ?block)) {
|
||||
check_for_each(*cx, decl, call, block, sc, v);
|
||||
}
|
||||
case (ast::expr_for(?decl, ?seq, ?block, _)) {
|
||||
case (ast::expr_for(?decl, ?seq, ?block)) {
|
||||
check_for(*cx, decl, seq, block, sc, v);
|
||||
}
|
||||
case (ast::expr_path(?pt, ?id)) {
|
||||
check_var(*cx, ex, pt, id, false, sc);
|
||||
case (ast::expr_path(?pt)) {
|
||||
check_var(*cx, ex, pt, ex.id, false, sc);
|
||||
handled = false;
|
||||
}
|
||||
case (ast::expr_move(?dest, ?src, _)) {
|
||||
case (ast::expr_move(?dest, ?src)) {
|
||||
check_assign(cx, dest, src, sc, v);
|
||||
}
|
||||
case (ast::expr_assign(?dest, ?src, _)) {
|
||||
case (ast::expr_assign(?dest, ?src)) {
|
||||
check_assign(cx, dest, src, sc, v);
|
||||
}
|
||||
case (ast::expr_assign_op(_, ?dest, ?src, _)) {
|
||||
case (ast::expr_assign_op(_, ?dest, ?src)) {
|
||||
check_assign(cx, dest, src, sc, v);
|
||||
}
|
||||
case (_) { handled = false; }
|
||||
|
@ -169,8 +169,8 @@ fn check_call(&ctx cx, &@ast::expr f, &vec[@ast::expr] args, &scope sc) ->
|
|||
}
|
||||
if (vec::len(unsafe_ts) > 0u) {
|
||||
alt (f.node) {
|
||||
case (ast::expr_path(_, ?id)) {
|
||||
if (def_is_local(cx.tcx.def_map.get(id), true)) {
|
||||
case (ast::expr_path(_)) {
|
||||
if (def_is_local(cx.tcx.def_map.get(f.id), true)) {
|
||||
cx.tcx.sess.span_fatal(f.span,
|
||||
#fmt("function may alias with \
|
||||
argument %u, which is not immutably rooted",
|
||||
|
@ -220,7 +220,7 @@ fn check_tail_call(&ctx cx, &@ast::expr call) {
|
|||
auto args;
|
||||
auto f =
|
||||
alt (call.node) {
|
||||
case (ast::expr_call(?f, ?args_, _)) { args = args_; f }
|
||||
case (ast::expr_call(?f, ?args_)) { args = args_; f }
|
||||
};
|
||||
auto i = 0u;
|
||||
for (ty::arg arg_t in fty_args(cx, ty::expr_ty(*cx.tcx, f))) {
|
||||
|
@ -228,8 +228,8 @@ fn check_tail_call(&ctx cx, &@ast::expr call) {
|
|||
auto mut_a = arg_t.mode == ty::mo_alias(true);
|
||||
auto ok = true;
|
||||
alt (args.(i).node) {
|
||||
case (ast::expr_path(_, ?id)) {
|
||||
auto def = cx.tcx.def_map.get(id);
|
||||
case (ast::expr_path(_)) {
|
||||
auto def = cx.tcx.def_map.get(args.(i).id);
|
||||
auto dnum = ast::def_id_of_def(def)._1;
|
||||
alt (cx.local_map.find(dnum)) {
|
||||
case (some(arg(ast::alias(?mut)))) {
|
||||
|
@ -301,7 +301,7 @@ fn check_for_each(&ctx cx, &@ast::local local, &@ast::expr call,
|
|||
&ast::block block, &scope sc, &vt[scope] v) {
|
||||
visit::visit_expr(call, sc, v);
|
||||
alt (call.node) {
|
||||
case (ast::expr_call(?f, ?args, _)) {
|
||||
case (ast::expr_call(?f, ?args)) {
|
||||
auto data = check_call(cx, f, args, sc);
|
||||
auto defnum = local.node.id;
|
||||
auto new_sc =
|
||||
|
@ -382,8 +382,8 @@ fn check_assign(&@ctx cx, &@ast::expr dest, &@ast::expr src, &scope sc,
|
|||
&vt[scope] v) {
|
||||
visit_expr(cx, src, sc, v);
|
||||
alt (dest.node) {
|
||||
case (ast::expr_path(?p, ?id)) {
|
||||
auto dnum = ast::def_id_of_def(cx.tcx.def_map.get(id))._1;
|
||||
case (ast::expr_path(?p)) {
|
||||
auto dnum = ast::def_id_of_def(cx.tcx.def_map.get(dest.id))._1;
|
||||
if (is_immutable_alias(cx, sc, dnum)) {
|
||||
cx.tcx.sess.span_fatal(dest.span,
|
||||
"assigning to immutable alias");
|
||||
|
@ -397,7 +397,7 @@ fn check_assign(&@ctx cx, &@ast::expr dest, &@ast::expr src, &scope sc,
|
|||
r.ok = overwritten(dest.span, p);
|
||||
}
|
||||
}
|
||||
check_var(*cx, dest, p, id, true, sc);
|
||||
check_var(*cx, dest, p, dest.id, true, sc);
|
||||
}
|
||||
case (_) {
|
||||
auto root = expr_root(*cx, dest, false);
|
||||
|
@ -496,7 +496,7 @@ fn expr_root(&ctx cx, @ast::expr ex, bool autoderef) ->
|
|||
let vec[deref] ds = [];
|
||||
while (true) {
|
||||
alt ({ ex.node }) {
|
||||
case (ast::expr_field(?base, ?ident, _)) {
|
||||
case (ast::expr_field(?base, ?ident)) {
|
||||
auto auto_unbox =
|
||||
maybe_auto_unbox(cx, ty::expr_ty(*cx.tcx, base));
|
||||
auto mut = false;
|
||||
|
@ -519,7 +519,7 @@ fn expr_root(&ctx cx, @ast::expr ex, bool autoderef) ->
|
|||
maybe_push_auto_unbox(auto_unbox.d, ds);
|
||||
ex = base;
|
||||
}
|
||||
case (ast::expr_index(?base, _, _)) {
|
||||
case (ast::expr_index(?base, _)) {
|
||||
auto auto_unbox =
|
||||
maybe_auto_unbox(cx, ty::expr_ty(*cx.tcx, base));
|
||||
alt (ty::struct(*cx.tcx, auto_unbox.t)) {
|
||||
|
@ -539,7 +539,7 @@ fn expr_root(&ctx cx, @ast::expr ex, bool autoderef) ->
|
|||
maybe_push_auto_unbox(auto_unbox.d, ds);
|
||||
ex = base;
|
||||
}
|
||||
case (ast::expr_unary(?op, ?base, _)) {
|
||||
case (ast::expr_unary(?op, ?base)) {
|
||||
if (op == ast::deref) {
|
||||
auto base_t = ty::expr_ty(*cx.tcx, base);
|
||||
alt (ty::struct(*cx.tcx, base_t)) {
|
||||
|
@ -575,8 +575,8 @@ fn inner_mut(&vec[deref] ds) -> option::t[ty::t] {
|
|||
|
||||
fn path_def_id(&ctx cx, &@ast::expr ex) -> option::t[ast::def_id] {
|
||||
alt (ex.node) {
|
||||
case (ast::expr_path(_, ?id)) {
|
||||
ret some(ast::def_id_of_def(cx.tcx.def_map.get(id)));
|
||||
case (ast::expr_path(_)) {
|
||||
ret some(ast::def_id_of_def(cx.tcx.def_map.get(ex.id)));
|
||||
}
|
||||
case (_) { ret none; }
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ fn map_native_item(&map map, &@native_item i, &() e, &vt[()] v) {
|
|||
}
|
||||
|
||||
fn map_expr(&map map, &@expr ex, &() e, &vt[()] v) {
|
||||
map.insert(ty::expr_node_id(ex), node_expr(ex));
|
||||
map.insert(ex.id, node_expr(ex));
|
||||
visit::visit_expr(ex, e, v);
|
||||
}
|
||||
|
||||
|
|
|
@ -269,8 +269,8 @@ fn resolve_names(&@env e, &@ast::crate c) {
|
|||
fn walk_expr(@env e, &@ast::expr exp, &scopes sc, &vt[scopes] v) {
|
||||
visit_expr_with_scope(exp, sc, v);
|
||||
alt (exp.node) {
|
||||
case (ast::expr_path(?p, ?id)) {
|
||||
maybe_insert(e, id,
|
||||
case (ast::expr_path(?p)) {
|
||||
maybe_insert(e, exp.id,
|
||||
lookup_path_strict(*e, sc, exp.span,
|
||||
p.node.idents, ns_value));
|
||||
}
|
||||
|
@ -366,13 +366,13 @@ fn visit_arm_with_scope(&ast::arm a, &scopes sc, &vt[scopes] v) {
|
|||
fn visit_expr_with_scope(&@ast::expr x, &scopes sc, &vt[scopes] v) {
|
||||
auto new_sc =
|
||||
alt (x.node) {
|
||||
case (ast::expr_for(?d, _, _, _)) {
|
||||
case (ast::expr_for(?d, _, _)) {
|
||||
cons[scope](scope_loop(d), @sc)
|
||||
}
|
||||
case (ast::expr_for_each(?d, _, _, _)) {
|
||||
case (ast::expr_for_each(?d, _, _)) {
|
||||
cons[scope](scope_loop(d), @sc)
|
||||
}
|
||||
case (ast::expr_fn(?f, _)) { cons(scope_fn(f.decl, []), @sc) }
|
||||
case (ast::expr_fn(?f)) { cons(scope_fn(f.decl, []), @sc) }
|
||||
case (_) { sc }
|
||||
};
|
||||
visit::visit_expr(x, new_sc, v);
|
||||
|
|
|
@ -4077,18 +4077,20 @@ fn trans_if(&@block_ctxt cx, &@ast::expr cond, &ast::block thn,
|
|||
alt (els) {
|
||||
case (some(?elexpr)) {
|
||||
alt (elexpr.node) {
|
||||
case (ast::expr_if(_, _, _, ?id)) {
|
||||
case (ast::expr_if(_, _, _)) {
|
||||
// Synthesize a block here to act as the else block
|
||||
// containing an if expression. Needed in order for the
|
||||
// else scope to behave like a normal block scope. A tad
|
||||
// ugly.
|
||||
|
||||
let ast::block_ elseif_blk_ =
|
||||
rec(stmts=[], expr=some[@ast::expr](elexpr), id=id);
|
||||
rec(stmts=[],
|
||||
expr=some[@ast::expr](elexpr),
|
||||
id=elexpr.id);
|
||||
auto elseif_blk = rec(node=elseif_blk_, span=elexpr.span);
|
||||
else_res = trans_block(else_cx, elseif_blk, output);
|
||||
}
|
||||
case (ast::expr_block(?blk, _)) {
|
||||
case (ast::expr_block(?blk)) {
|
||||
// Calling trans_block directly instead of trans_expr
|
||||
// because trans_expr will create another scope block
|
||||
// context for the block, but we've already got the
|
||||
|
@ -4155,8 +4157,8 @@ fn collect_upvars(&@block_ctxt cx, &ast::block bloc,
|
|||
|
||||
fn walk_expr(env e, &@ast::expr expr) {
|
||||
alt (expr.node) {
|
||||
case (ast::expr_path(?path, ?id)) {
|
||||
alt (e.def_map.get(id)) {
|
||||
case (ast::expr_path(?path)) {
|
||||
alt (e.def_map.get(expr.id)) {
|
||||
case (ast::def_arg(?did)) {
|
||||
vec::push(e.refs, did._1);
|
||||
}
|
||||
|
@ -4354,7 +4356,7 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
|
|||
|
||||
// Step 3: Call iter passing [lliterbody, llenv], plus other args.
|
||||
alt (seq.node) {
|
||||
case (ast::expr_call(?f, ?args, ?id)) {
|
||||
case (ast::expr_call(?f, ?args)) {
|
||||
auto pair = alloca(cx, T_fn_pair(lcx.ccx.tn, iter_body_llty));
|
||||
auto code_cell =
|
||||
cx.build.GEP(pair, [C_int(0), C_int(abi::fn_field_code)]);
|
||||
|
@ -4369,7 +4371,7 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
|
|||
|
||||
r =
|
||||
trans_call(cx, f, some[ValueRef](cx.build.Load(pair)), args,
|
||||
id);
|
||||
seq.id);
|
||||
ret res(r.bcx, C_nil());
|
||||
}
|
||||
}
|
||||
|
@ -4856,16 +4858,16 @@ fn trans_index(&@block_ctxt cx, &span sp, &@ast::expr base, &@ast::expr idx,
|
|||
// immediate).
|
||||
fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result {
|
||||
alt (e.node) {
|
||||
case (ast::expr_path(?p, ?id)) { ret trans_path(cx, p, id); }
|
||||
case (ast::expr_field(?base, ?ident, ?id)) {
|
||||
case (ast::expr_path(?p)) { ret trans_path(cx, p, e.id); }
|
||||
case (ast::expr_field(?base, ?ident)) {
|
||||
auto r = trans_expr(cx, base);
|
||||
auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, base);
|
||||
ret trans_field(r.bcx, e.span, r.val, t, ident, id);
|
||||
ret trans_field(r.bcx, e.span, r.val, t, ident, e.id);
|
||||
}
|
||||
case (ast::expr_index(?base, ?idx, ?id)) {
|
||||
ret trans_index(cx, e.span, base, idx, id);
|
||||
case (ast::expr_index(?base, ?idx)) {
|
||||
ret trans_index(cx, e.span, base, idx, e.id);
|
||||
}
|
||||
case (ast::expr_unary(?unop, ?base, ?id)) {
|
||||
case (ast::expr_unary(?unop, ?base)) {
|
||||
assert (unop == ast::deref);
|
||||
auto sub = trans_expr(cx, base);
|
||||
auto val =
|
||||
|
@ -4873,12 +4875,12 @@ fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result {
|
|||
[C_int(0), C_int(abi::box_rc_field_body)]);
|
||||
ret lval_mem(sub.bcx, val);
|
||||
}
|
||||
case (ast::expr_self_method(?ident, ?id)) {
|
||||
case (ast::expr_self_method(?ident)) {
|
||||
alt ({ cx.fcx.llself }) {
|
||||
case (some(?pair)) {
|
||||
auto r = pair.v;
|
||||
auto t = pair.t;
|
||||
ret trans_field(cx, e.span, r, t, ident, id);
|
||||
ret trans_field(cx, e.span, r, t, ident, e.id);
|
||||
}
|
||||
case (_) {
|
||||
// Shouldn't happen.
|
||||
|
@ -4999,10 +5001,9 @@ fn trans_bind_thunk(&@local_ctxt cx, &span sp, &ty::t incoming_fty,
|
|||
auto out_arg = outgoing_args.(outgoing_arg_index);
|
||||
auto llout_arg_ty = llout_arg_tys.(outgoing_arg_index);
|
||||
alt (arg) {
|
||||
case (
|
||||
// Arg provided at binding time; thunk copies it from
|
||||
// closure.
|
||||
some(?e)) {
|
||||
case (some(?e)) {
|
||||
auto e_ty = ty::expr_ty(cx.ccx.tcx, e);
|
||||
auto bound_arg =
|
||||
GEP_tup_like(bcx, closure_ty, llclosure,
|
||||
|
@ -5671,43 +5672,43 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
|
|||
// FIXME Fill in cx.sp
|
||||
|
||||
alt (e.node) {
|
||||
case (ast::expr_lit(?lit, ?id)) {
|
||||
ret res(cx, trans_lit(cx.fcx.lcx.ccx, *lit, id));
|
||||
case (ast::expr_lit(?lit)) {
|
||||
ret res(cx, trans_lit(cx.fcx.lcx.ccx, *lit, e.id));
|
||||
}
|
||||
case (ast::expr_unary(?op, ?x, ?id)) {
|
||||
if (op != ast::deref) { ret trans_unary(cx, op, x, id); }
|
||||
case (ast::expr_unary(?op, ?x)) {
|
||||
if (op != ast::deref) { ret trans_unary(cx, op, x, e.id); }
|
||||
}
|
||||
case (ast::expr_binary(?op, ?x, ?y, _)) {
|
||||
case (ast::expr_binary(?op, ?x, ?y)) {
|
||||
ret trans_binary(cx, op, x, y);
|
||||
}
|
||||
case (ast::expr_if(?cond, ?thn, ?els, ?id)) {
|
||||
ret with_out_method(bind trans_if(cx, cond, thn, els, id, _), cx,
|
||||
id, output);
|
||||
case (ast::expr_if(?cond, ?thn, ?els)) {
|
||||
ret with_out_method(bind trans_if(cx, cond, thn, els, e.id, _),
|
||||
cx, e.id, output);
|
||||
}
|
||||
case (ast::expr_if_check(?cond, ?thn, ?els, ?ann)) {
|
||||
ret with_out_method(bind trans_if(cx, cond, thn, els, ann, _), cx,
|
||||
ann, output);
|
||||
case (ast::expr_if_check(?cond, ?thn, ?els)) {
|
||||
ret with_out_method(bind trans_if(cx, cond, thn, els, e.id, _),
|
||||
cx, e.id, output);
|
||||
}
|
||||
case (ast::expr_for(?decl, ?seq, ?body, _)) {
|
||||
case (ast::expr_for(?decl, ?seq, ?body)) {
|
||||
ret trans_for(cx, decl, seq, body);
|
||||
}
|
||||
case (ast::expr_for_each(?decl, ?seq, ?body, _)) {
|
||||
case (ast::expr_for_each(?decl, ?seq, ?body)) {
|
||||
ret trans_for_each(cx, decl, seq, body);
|
||||
}
|
||||
case (ast::expr_while(?cond, ?body, _)) {
|
||||
case (ast::expr_while(?cond, ?body)) {
|
||||
ret trans_while(cx, cond, body);
|
||||
}
|
||||
case (ast::expr_do_while(?body, ?cond, _)) {
|
||||
case (ast::expr_do_while(?body, ?cond)) {
|
||||
ret trans_do_while(cx, body, cond);
|
||||
}
|
||||
case (ast::expr_alt(?expr, ?arms, ?id)) {
|
||||
ret with_out_method(bind trans_alt(cx, expr, arms, id, _), cx,
|
||||
id, output);
|
||||
case (ast::expr_alt(?expr, ?arms)) {
|
||||
ret with_out_method(bind trans_alt(cx, expr, arms, e.id, _),
|
||||
cx, e.id, output);
|
||||
}
|
||||
case (ast::expr_fn(?f, ?id)) {
|
||||
case (ast::expr_fn(?f)) {
|
||||
auto ccx = cx.fcx.lcx.ccx;
|
||||
let TypeRef llfnty =
|
||||
alt (ty::struct(ccx.tcx, node_id_type(ccx, id))) {
|
||||
alt (ty::struct(ccx.tcx, node_id_type(ccx, e.id))) {
|
||||
case (ty::ty_fn(?proto, ?inputs, ?output, _, _)) {
|
||||
type_of_fn_full(ccx, e.span, proto, none, inputs,
|
||||
output, 0u)
|
||||
|
@ -5716,20 +5717,20 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
|
|||
auto sub_cx = extend_path(cx.fcx.lcx, ccx.names.next("anon"));
|
||||
auto s = mangle_internal_name_by_path(ccx, sub_cx.path);
|
||||
auto llfn = decl_internal_fastcall_fn(ccx.llmod, s, llfnty);
|
||||
trans_fn(sub_cx, e.span, f, llfn, none, [], id);
|
||||
trans_fn(sub_cx, e.span, f, llfn, none, [], e.id);
|
||||
ret res(cx, create_fn_pair(ccx, s, llfnty, llfn, false));
|
||||
}
|
||||
case (ast::expr_block(?blk, ?id)) {
|
||||
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 =
|
||||
with_out_method(bind trans_block(sub_cx, blk, _), cx, id,
|
||||
with_out_method(bind trans_block(sub_cx, blk, _), cx, e.id,
|
||||
output);
|
||||
cx.build.Br(sub_cx.llbb);
|
||||
sub.bcx.build.Br(next_cx.llbb);
|
||||
ret res(next_cx, sub.val);
|
||||
}
|
||||
case (ast::expr_move(?dst, ?src, _)) {
|
||||
case (ast::expr_move(?dst, ?src)) {
|
||||
auto lhs_res = trans_lval(cx, dst);
|
||||
assert (lhs_res.is_mem);
|
||||
// FIXME Fill in lhs_res.res.bcx.sp
|
||||
|
@ -5743,7 +5744,7 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
|
|||
rhs_res.res.val, t);
|
||||
ret res(move_res.bcx, C_nil());
|
||||
}
|
||||
case (ast::expr_assign(?dst, ?src, _)) {
|
||||
case (ast::expr_assign(?dst, ?src)) {
|
||||
auto lhs_res = trans_lval(cx, dst);
|
||||
assert (lhs_res.is_mem);
|
||||
// FIXME Fill in lhs_res.res.bcx.sp
|
||||
|
@ -5757,7 +5758,7 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
|
|||
rhs_res.val, t);
|
||||
ret res(copy_res.bcx, C_nil());
|
||||
}
|
||||
case (ast::expr_swap(?dst, ?src, _)) {
|
||||
case (ast::expr_swap(?dst, ?src)) {
|
||||
auto lhs_res = trans_lval(cx, dst);
|
||||
assert (lhs_res.is_mem);
|
||||
// FIXME Fill in lhs_res.res.bcx.sp
|
||||
|
@ -5776,7 +5777,7 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
|
|||
memmove_ty(move2_res.bcx, rhs_res.res.val, tmp_res.val, t);
|
||||
ret res(move3_res.bcx, C_nil());
|
||||
}
|
||||
case (ast::expr_assign_op(?op, ?dst, ?src, _)) {
|
||||
case (ast::expr_assign_op(?op, ?dst, ?src)) {
|
||||
auto t = ty::expr_ty(cx.fcx.lcx.ccx.tcx, src);
|
||||
auto lhs_res = trans_lval(cx, dst);
|
||||
assert (lhs_res.is_mem);
|
||||
|
@ -5806,27 +5807,27 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
|
|||
copy_val(v.bcx, DROP_EXISTING, lhs_res.res.val, v.val, t);
|
||||
ret res(copy_res.bcx, C_nil());
|
||||
}
|
||||
case (ast::expr_bind(?f, ?args, ?id)) {
|
||||
ret trans_bind(cx, f, args, id);
|
||||
case (ast::expr_bind(?f, ?args)) {
|
||||
ret trans_bind(cx, f, args, e.id);
|
||||
}
|
||||
case (ast::expr_call(?f, ?args, ?id)) {
|
||||
ret trans_call(cx, f, none[ValueRef], args, id);
|
||||
case (ast::expr_call(?f, ?args)) {
|
||||
ret trans_call(cx, f, none[ValueRef], args, e.id);
|
||||
}
|
||||
case (ast::expr_cast(?e, _, ?id)) { ret trans_cast(cx, e, id); }
|
||||
case (ast::expr_vec(?args, _, ast::sk_rc, ?id)) {
|
||||
ret trans_vec(cx, args, id);
|
||||
case (ast::expr_cast(?val, _)) { ret trans_cast(cx, val, e.id); }
|
||||
case (ast::expr_vec(?args, _, ast::sk_rc)) {
|
||||
ret trans_vec(cx, args, e.id);
|
||||
}
|
||||
case (ast::expr_vec(?args, _, ast::sk_unique, ?id)) {
|
||||
ret trans_ivec(cx, args, id);
|
||||
case (ast::expr_vec(?args, _, ast::sk_unique)) {
|
||||
ret trans_ivec(cx, args, e.id);
|
||||
}
|
||||
case (ast::expr_tup(?args, ?id)) { ret trans_tup(cx, args, id); }
|
||||
case (ast::expr_rec(?args, ?base, ?id)) {
|
||||
ret trans_rec(cx, args, base, id);
|
||||
case (ast::expr_tup(?args)) { ret trans_tup(cx, args, e.id); }
|
||||
case (ast::expr_rec(?args, ?base)) {
|
||||
ret trans_rec(cx, args, base, e.id);
|
||||
}
|
||||
case (ast::expr_ext(_, _, _, ?expanded, _)) {
|
||||
case (ast::expr_ext(_, _, _, ?expanded)) {
|
||||
ret trans_expr(cx, expanded);
|
||||
}
|
||||
case (ast::expr_fail(_, ?str)) {
|
||||
case (ast::expr_fail(?str)) {
|
||||
auto failmsg;
|
||||
alt (str) {
|
||||
case (some(?msg)) { failmsg = msg; }
|
||||
|
@ -5834,31 +5835,31 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
|
|||
}
|
||||
ret trans_fail(cx, some(e.span), failmsg);
|
||||
}
|
||||
case (ast::expr_log(?lvl, ?a, _)) { ret trans_log(lvl, cx, a); }
|
||||
case (ast::expr_assert(?a, _)) {
|
||||
case (ast::expr_log(?lvl, ?a)) { ret trans_log(lvl, cx, a); }
|
||||
case (ast::expr_assert(?a)) {
|
||||
ret trans_check_expr(cx, a, "Assertion");
|
||||
}
|
||||
case (ast::expr_check(?a, _)) {
|
||||
case (ast::expr_check(?a)) {
|
||||
ret trans_check_expr(cx, a, "Predicate");
|
||||
}
|
||||
case (ast::expr_break(?a)) { ret trans_break(e.span, cx); }
|
||||
case (ast::expr_cont(?a)) { ret trans_cont(e.span, cx); }
|
||||
case (ast::expr_ret(?e, _)) { ret trans_ret(cx, e); }
|
||||
case (ast::expr_put(?e, _)) { ret trans_put(cx, e); }
|
||||
case (ast::expr_be(?e, _)) { ret trans_be(cx, e); }
|
||||
case (ast::expr_port(?id)) { ret trans_port(cx, id); }
|
||||
case (ast::expr_chan(?e, ?id)) { ret trans_chan(cx, e, id); }
|
||||
case (ast::expr_send(?lhs, ?rhs, ?id)) {
|
||||
ret trans_send(cx, lhs, rhs, id);
|
||||
case (ast::expr_break) { ret trans_break(e.span, cx); }
|
||||
case (ast::expr_cont) { ret trans_cont(e.span, cx); }
|
||||
case (ast::expr_ret(?ex)) { ret trans_ret(cx, ex); }
|
||||
case (ast::expr_put(?ex)) { ret trans_put(cx, ex); }
|
||||
case (ast::expr_be(?ex)) { ret trans_be(cx, ex); }
|
||||
case (ast::expr_port) { ret trans_port(cx, e.id); }
|
||||
case (ast::expr_chan(?ex)) { ret trans_chan(cx, ex, e.id); }
|
||||
case (ast::expr_send(?lhs, ?rhs)) {
|
||||
ret trans_send(cx, lhs, rhs, e.id);
|
||||
}
|
||||
case (ast::expr_recv(?lhs, ?rhs, ?id)) {
|
||||
ret trans_recv(cx, lhs, rhs, id);
|
||||
case (ast::expr_recv(?lhs, ?rhs)) {
|
||||
ret trans_recv(cx, lhs, rhs, e.id);
|
||||
}
|
||||
case (ast::expr_spawn(?dom, ?name, ?func, ?args, ?id)) {
|
||||
ret trans_spawn(cx, dom, name, func, args, id);
|
||||
case (ast::expr_spawn(?dom, ?name, ?func, ?args)) {
|
||||
ret trans_spawn(cx, dom, name, func, args, e.id);
|
||||
}
|
||||
case (ast::expr_anon_obj(?anon_obj, ?tps, ?odid, ?id)) {
|
||||
ret trans_anon_obj(cx, e.span, anon_obj, tps, odid.ctor, id);
|
||||
case (ast::expr_anon_obj(?anon_obj, ?tps, ?odid)) {
|
||||
ret trans_anon_obj(cx, e.span, anon_obj, tps, odid.ctor, e.id);
|
||||
}
|
||||
case (_) {
|
||||
// The expression is an lvalue. Fall through.
|
||||
|
@ -6600,8 +6601,7 @@ fn init_local(&@block_ctxt cx, &@ast::local local) -> result {
|
|||
// the value.
|
||||
|
||||
ty =
|
||||
node_id_type(cx.fcx.lcx.ccx,
|
||||
ty::expr_node_id(init.expr));
|
||||
node_id_type(cx.fcx.lcx.ccx, init.expr.id);
|
||||
auto sub = trans_expr(bcx, init.expr);
|
||||
bcx = copy_val(sub.bcx, INIT, llptr, sub.val, ty).bcx;
|
||||
}
|
||||
|
@ -6836,9 +6836,9 @@ fn trans_block(&@block_ctxt cx, &ast::block b, &out_method output) -> result {
|
|||
}
|
||||
fn accept_out_method(&@ast::expr expr) -> bool {
|
||||
ret alt (expr.node) {
|
||||
case (ast::expr_if(_, _, _, _)) { true }
|
||||
case (ast::expr_alt(_, _, _)) { true }
|
||||
case (ast::expr_block(_, _)) { true }
|
||||
case (ast::expr_if(_, _, _)) { true }
|
||||
case (ast::expr_alt(_, _)) { true }
|
||||
case (ast::expr_block(_)) { true }
|
||||
case (_) { false }
|
||||
};
|
||||
}
|
||||
|
@ -7506,7 +7506,7 @@ fn trans_tag_variant(@local_ctxt cx, ast::node_id tag_id,
|
|||
// that does so later on?
|
||||
fn trans_const_expr(&@crate_ctxt cx, @ast::expr e) -> ValueRef {
|
||||
alt (e.node) {
|
||||
case (ast::expr_lit(?lit, ?id)) { ret trans_lit(cx, *lit, id); }
|
||||
case (ast::expr_lit(?lit)) { ret trans_lit(cx, *lit, e.id); }
|
||||
case (_) {
|
||||
cx.sess.span_unimpl(e.span, "consts that's not a plain literal");
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import std::option;
|
|||
import std::option::some;
|
||||
import std::option::none;
|
||||
import front::ast::*;
|
||||
import middle::ty::expr_node_id;
|
||||
import util::common::istr;
|
||||
import util::common::uistr;
|
||||
import util::common::span;
|
||||
|
@ -25,7 +24,7 @@ import aux::add_node;
|
|||
import middle::tstate::ann::empty_ann;
|
||||
|
||||
fn collect_ids_expr(&@expr e, @mutable vec[node_id] res) {
|
||||
vec::push(*res, expr_node_id(e));
|
||||
vec::push(*res, e.id);
|
||||
}
|
||||
|
||||
fn collect_ids_block(&block b, @mutable vec[node_id] res) {
|
||||
|
|
|
@ -10,7 +10,6 @@ import std::option::some;
|
|||
import std::option::maybe;
|
||||
import front::ast;
|
||||
import front::ast::*;
|
||||
import middle::ty::expr_node_id;
|
||||
import util::common;
|
||||
import util::common::span;
|
||||
import util::common::respan;
|
||||
|
@ -284,14 +283,14 @@ fn stmt_to_ann(&crate_ctxt ccx, &stmt s) -> ts_ann {
|
|||
/* fails if e has no annotation */
|
||||
fn expr_states(&crate_ctxt ccx, @expr e) -> pre_and_post_state {
|
||||
log "expr_states";
|
||||
ret node_id_to_ts_ann(ccx, expr_node_id(e)).states;
|
||||
ret node_id_to_ts_ann(ccx, e.id).states;
|
||||
}
|
||||
|
||||
|
||||
/* fails if e has no annotation */
|
||||
fn expr_pp(&crate_ctxt ccx, @expr e) -> pre_and_post {
|
||||
log "expr_pp";
|
||||
ret node_id_to_ts_ann(ccx, expr_node_id(e)).conditions;
|
||||
ret node_id_to_ts_ann(ccx, e.id).conditions;
|
||||
}
|
||||
|
||||
fn stmt_pp(&crate_ctxt ccx, &stmt s) -> pre_and_post {
|
||||
|
@ -461,14 +460,14 @@ fn new_crate_ctxt(ty::ctxt cx) -> crate_ctxt {
|
|||
If it has a function type with a ! annotation,
|
||||
the answer is noreturn. */
|
||||
fn controlflow_expr(&crate_ctxt ccx, @expr e) -> controlflow {
|
||||
alt (ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, expr_node_id(e)))) {
|
||||
alt (ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, e.id))) {
|
||||
case (ty::ty_fn(_, _, _, ?cf, _)) { ret cf; }
|
||||
case (_) { ret return; }
|
||||
}
|
||||
}
|
||||
|
||||
fn constraints_expr(&ty::ctxt cx, @expr e) -> vec[@ty::constr_def] {
|
||||
alt (ty::struct(cx, ty::node_id_to_type(cx, expr_node_id(e)))) {
|
||||
alt (ty::struct(cx, ty::node_id_to_type(cx, e.id))) {
|
||||
case (ty::ty_fn(_, _, _, _, ?cs)) { ret cs; }
|
||||
case (_) { ret []; }
|
||||
}
|
||||
|
@ -547,7 +546,7 @@ fn node_id_for_constr(ty::ctxt tcx, node_id t) -> node_id {
|
|||
|
||||
fn expr_to_constr_arg(ty::ctxt tcx, &@expr e) -> @constr_arg_use {
|
||||
alt (e.node) {
|
||||
case (expr_path(?p, _)) {
|
||||
case (expr_path(?p)) {
|
||||
if (vec::len(p.node.idents) == 1u) {
|
||||
ret @respan(p.span, carg_ident[ident](p.node.idents.(0)));
|
||||
} else {
|
||||
|
@ -555,7 +554,7 @@ fn expr_to_constr_arg(ty::ctxt tcx, &@expr e) -> @constr_arg_use {
|
|||
"as pred arg");
|
||||
}
|
||||
}
|
||||
case (expr_lit(?l, _)) { ret @respan(e.span, carg_lit(l)); }
|
||||
case (expr_lit(?l)) { ret @respan(e.span, carg_lit(l)); }
|
||||
case (_) {
|
||||
tcx.sess.span_fatal(e.span,
|
||||
"Arguments to constrained functions must be "
|
||||
|
@ -575,11 +574,11 @@ fn expr_to_constr(ty::ctxt tcx, &@expr e) -> constr {
|
|||
case (
|
||||
// FIXME change the first pattern to expr_path to test a
|
||||
// typechecker bug
|
||||
expr_call(?operator, ?args, _)) {
|
||||
expr_call(?operator, ?args)) {
|
||||
alt (operator.node) {
|
||||
case (expr_path(?p, ?id)) {
|
||||
case (expr_path(?p)) {
|
||||
ret respan(e.span,
|
||||
rec(id=node_id_for_constr(tcx, id),
|
||||
rec(id=node_id_for_constr(tcx, operator.id),
|
||||
c=npred(p,
|
||||
exprs_to_constr_args(tcx, args))));
|
||||
}
|
||||
|
|
|
@ -35,15 +35,15 @@ fn collect_local(&ctxt cx, &@local loc) {
|
|||
|
||||
fn collect_pred(&ctxt cx, &@expr e) {
|
||||
alt (e.node) {
|
||||
case (expr_check(?e, _)) {
|
||||
vec::push(*cx.cs, expr_to_constr(cx.tcx, e));
|
||||
case (expr_check(?ch)) {
|
||||
vec::push(*cx.cs, expr_to_constr(cx.tcx, ch));
|
||||
}
|
||||
case (expr_if_check(?e, _, _, _)) {
|
||||
vec::push(*cx.cs, expr_to_constr(cx.tcx, e));
|
||||
case (expr_if_check(?ex, _, _)) {
|
||||
vec::push(*cx.cs, expr_to_constr(cx.tcx, ex));
|
||||
}
|
||||
// If it's a call, generate appropriate instances of the
|
||||
// call's constraints.
|
||||
case (expr_call(?operator, ?operands, _)) {
|
||||
case (expr_call(?operator, ?operands)) {
|
||||
for (@ty::constr_def c in constraints_expr(cx.tcx, operator)) {
|
||||
let aux::constr ct = respan(c.span,
|
||||
rec(id=c.node.id._1,
|
||||
|
|
|
@ -60,7 +60,6 @@ import bitvectors::bit_num;
|
|||
import bitvectors::gen;
|
||||
import bitvectors::relax_precond_block;
|
||||
import front::ast::*;
|
||||
import middle::ty::expr_node_id;
|
||||
import util::common::new_int_hash;
|
||||
import util::common::new_def_hash;
|
||||
import util::common::uistr;
|
||||
|
@ -189,7 +188,7 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq,
|
|||
alt (chck) {
|
||||
case (if_check) {
|
||||
let aux::constr c = expr_to_constr(fcx.ccx.tcx, antec);
|
||||
gen(fcx, expr_node_id(antec), c.node);
|
||||
gen(fcx, antec.id, c.node);
|
||||
}
|
||||
case (_) {}
|
||||
}
|
||||
|
@ -222,7 +221,7 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq,
|
|||
alt (chck) {
|
||||
case (if_check) {
|
||||
let aux::constr c = expr_to_constr(fcx.ccx.tcx, antec);
|
||||
gen(fcx, expr_node_id(antec), c.node);
|
||||
gen(fcx, antec.id, c.node);
|
||||
}
|
||||
case (_) {}
|
||||
}
|
||||
|
@ -278,10 +277,10 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
|
|||
"):";
|
||||
log_expr(*e);
|
||||
alt (e.node) {
|
||||
case (expr_call(?operator, ?operands, ?id)) {
|
||||
case (expr_call(?operator, ?operands)) {
|
||||
auto args = vec::clone[@expr](operands);
|
||||
vec::push[@expr](args, operator);
|
||||
find_pre_post_exprs(fcx, args, id);
|
||||
find_pre_post_exprs(fcx, args, e.id);
|
||||
/* see if the call has any constraints on its type */
|
||||
|
||||
log "a function: ";
|
||||
|
@ -299,25 +298,25 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
|
|||
|
||||
/* if this is a failing call, its postcondition sets everything */
|
||||
alt (controlflow_expr(fcx.ccx, operator)) {
|
||||
case (noreturn) { set_postcond_false(fcx.ccx, id); }
|
||||
case (noreturn) { set_postcond_false(fcx.ccx, e.id); }
|
||||
case (_) { }
|
||||
}
|
||||
}
|
||||
case (expr_spawn(_, _, ?operator, ?operands, ?id)) {
|
||||
case (expr_spawn(_, _, ?operator, ?operands)) {
|
||||
auto args = vec::clone[@expr](operands);
|
||||
vec::push[@expr](args, operator);
|
||||
find_pre_post_exprs(fcx, args, id);
|
||||
find_pre_post_exprs(fcx, args, e.id);
|
||||
}
|
||||
case (expr_vec(?args, _, _, ?id)) {
|
||||
find_pre_post_exprs(fcx, args, id);
|
||||
case (expr_vec(?args, _, _)) {
|
||||
find_pre_post_exprs(fcx, args, e.id);
|
||||
}
|
||||
case (expr_tup(?elts, ?id)) {
|
||||
find_pre_post_exprs(fcx, elt_exprs(elts), id);
|
||||
case (expr_tup(?elts)) {
|
||||
find_pre_post_exprs(fcx, elt_exprs(elts), e.id);
|
||||
}
|
||||
case (expr_path(?p, ?id)) {
|
||||
case (expr_path(?p)) {
|
||||
auto res = expr_pp(fcx.ccx, e);
|
||||
clear_pp(res);
|
||||
auto df = node_id_to_def_strict(fcx.ccx.tcx, id);
|
||||
auto df = node_id_to_def_strict(fcx.ccx.tcx, e.id);
|
||||
alt (df) {
|
||||
case (def_local(?d_id)) {
|
||||
auto i =
|
||||
|
@ -329,126 +328,121 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
|
|||
case (_) {/* nothing to check */ }
|
||||
}
|
||||
}
|
||||
case (expr_self_method(?v, ?id)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_log(_, ?arg, ?id)) {
|
||||
case (expr_self_method(?v)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_log(_, ?arg)) {
|
||||
find_pre_post_expr(fcx, arg);
|
||||
copy_pre_post(fcx.ccx, id, arg);
|
||||
copy_pre_post(fcx.ccx, e.id, arg);
|
||||
}
|
||||
case (expr_chan(?arg, ?id)) {
|
||||
case (expr_chan(?arg)) {
|
||||
find_pre_post_expr(fcx, arg);
|
||||
copy_pre_post(fcx.ccx, id, arg);
|
||||
copy_pre_post(fcx.ccx, e.id, arg);
|
||||
}
|
||||
case (expr_put(?opt, ?id)) {
|
||||
case (expr_put(?opt)) {
|
||||
alt (opt) {
|
||||
case (some(?arg)) {
|
||||
find_pre_post_expr(fcx, arg);
|
||||
copy_pre_post(fcx.ccx, id, arg);
|
||||
copy_pre_post(fcx.ccx, e.id, arg);
|
||||
}
|
||||
case (none) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
}
|
||||
}
|
||||
case (
|
||||
// FIXME this was just put in here as a placeholder
|
||||
expr_fn(?f, ?id)) {
|
||||
clear_pp(expr_pp(fcx.ccx, e));
|
||||
}
|
||||
case (expr_block(?b, ?id)) {
|
||||
case (expr_fn(?f)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_block(?b)) {
|
||||
find_pre_post_block(fcx, b);
|
||||
auto p = block_pp(fcx.ccx, b);
|
||||
set_pre_and_post(fcx.ccx, id, p.precondition, p.postcondition);
|
||||
set_pre_and_post(fcx.ccx, e.id, p.precondition, p.postcondition);
|
||||
}
|
||||
case (expr_rec(?fields, ?maybe_base, ?id)) {
|
||||
case (expr_rec(?fields, ?maybe_base)) {
|
||||
auto es = field_exprs(fields);
|
||||
vec::plus_option[@expr](es, maybe_base);
|
||||
find_pre_post_exprs(fcx, es, id);
|
||||
find_pre_post_exprs(fcx, es, e.id);
|
||||
}
|
||||
case (expr_move(?lhs, ?rhs, ?id)) {
|
||||
|
||||
case (expr_move(?lhs, ?rhs)) {
|
||||
// FIXME: this needs to deinitialize the rhs
|
||||
alt (lhs.node) {
|
||||
case (expr_path(?p, ?a_lhs)) {
|
||||
gen_if_local(fcx, lhs, rhs, id, a_lhs, p);
|
||||
case (expr_path(?p)) {
|
||||
gen_if_local(fcx, lhs, rhs, e.id, lhs.id, p);
|
||||
}
|
||||
case (_) { find_pre_post_exprs(fcx, [lhs, rhs], id); }
|
||||
case (_) { find_pre_post_exprs(fcx, [lhs, rhs], e.id); }
|
||||
}
|
||||
}
|
||||
case (expr_swap(?lhs, ?rhs, ?id)) {
|
||||
case (expr_swap(?lhs, ?rhs)) {
|
||||
// Both sides must already be initialized
|
||||
|
||||
find_pre_post_exprs(fcx, [lhs, rhs], id);
|
||||
find_pre_post_exprs(fcx, [lhs, rhs], e.id);
|
||||
}
|
||||
case (expr_assign(?lhs, ?rhs, ?id)) {
|
||||
case (expr_assign(?lhs, ?rhs)) {
|
||||
alt (lhs.node) {
|
||||
case (expr_path(?p, ?a_lhs)) {
|
||||
gen_if_local(fcx, lhs, rhs, id, a_lhs, p);
|
||||
case (expr_path(?p)) {
|
||||
gen_if_local(fcx, lhs, rhs, e.id, lhs.id, p);
|
||||
}
|
||||
case (_) { find_pre_post_exprs(fcx, [lhs, rhs], id); }
|
||||
case (_) { find_pre_post_exprs(fcx, [lhs, rhs], e.id); }
|
||||
}
|
||||
}
|
||||
case (expr_recv(?lhs, ?rhs, ?id)) {
|
||||
case (expr_recv(?lhs, ?rhs)) {
|
||||
alt (rhs.node) {
|
||||
case (expr_path(?p, ?id_rhs)) {
|
||||
gen_if_local(fcx, rhs, lhs, id, id_rhs, p);
|
||||
case (expr_path(?p)) {
|
||||
gen_if_local(fcx, rhs, lhs, e.id, rhs.id, p);
|
||||
}
|
||||
case (_) {
|
||||
// doesn't check that rhs is an lval, but
|
||||
// that's probably ok
|
||||
|
||||
find_pre_post_exprs(fcx, [lhs, rhs], id);
|
||||
find_pre_post_exprs(fcx, [lhs, rhs], e.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
case (expr_assign_op(_, ?lhs, ?rhs, ?id)) {
|
||||
case (expr_assign_op(_, ?lhs, ?rhs)) {
|
||||
/* Different from expr_assign in that the lhs *must*
|
||||
already be initialized */
|
||||
|
||||
find_pre_post_exprs(fcx, [lhs, rhs], id);
|
||||
find_pre_post_exprs(fcx, [lhs, rhs], e.id);
|
||||
}
|
||||
case (expr_lit(_, ?id)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_ret(?maybe_val, ?id)) {
|
||||
case (expr_lit(_)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_ret(?maybe_val)) {
|
||||
alt (maybe_val) {
|
||||
case (none) {
|
||||
clear_precond(fcx.ccx, id);
|
||||
set_postcond_false(fcx.ccx, id);
|
||||
clear_precond(fcx.ccx, e.id);
|
||||
set_postcond_false(fcx.ccx, e.id);
|
||||
}
|
||||
case (some(?ret_val)) {
|
||||
find_pre_post_expr(fcx, ret_val);
|
||||
set_precondition(node_id_to_ts_ann(fcx.ccx, id),
|
||||
set_precondition(node_id_to_ts_ann(fcx.ccx, e.id),
|
||||
expr_precond(fcx.ccx, ret_val));
|
||||
set_postcond_false(fcx.ccx, id);
|
||||
set_postcond_false(fcx.ccx, e.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
case (expr_be(?e, ?id)) {
|
||||
find_pre_post_expr(fcx, e);
|
||||
set_pre_and_post(fcx.ccx, id, expr_prestate(fcx.ccx, e),
|
||||
case (expr_be(?val)) {
|
||||
find_pre_post_expr(fcx, val);
|
||||
set_pre_and_post(fcx.ccx, e.id, expr_prestate(fcx.ccx, val),
|
||||
false_postcond(num_local_vars));
|
||||
}
|
||||
case (expr_if(?antec, ?conseq, ?maybe_alt, ?id)) {
|
||||
join_then_else(fcx, antec, conseq, maybe_alt, id, plain_if);
|
||||
case (expr_if(?antec, ?conseq, ?maybe_alt)) {
|
||||
join_then_else(fcx, antec, conseq, maybe_alt, e.id, plain_if);
|
||||
}
|
||||
case (expr_binary(?bop, ?l, ?r, ?id)) {
|
||||
case (expr_binary(?bop, ?l, ?r)) {
|
||||
/* *unless* bop is lazy (e.g. and, or)?
|
||||
FIXME */
|
||||
|
||||
find_pre_post_exprs(fcx, [l, r], id);
|
||||
find_pre_post_exprs(fcx, [l, r], e.id);
|
||||
}
|
||||
case (expr_send(?l, ?r, ?id)) {
|
||||
find_pre_post_exprs(fcx, [l, r], id);
|
||||
case (expr_send(?l, ?r)) {
|
||||
find_pre_post_exprs(fcx, [l, r], e.id);
|
||||
}
|
||||
case (expr_unary(_, ?operand, ?id)) {
|
||||
case (expr_unary(_, ?operand)) {
|
||||
find_pre_post_expr(fcx, operand);
|
||||
copy_pre_post(fcx.ccx, id, operand);
|
||||
copy_pre_post(fcx.ccx, e.id, operand);
|
||||
}
|
||||
case (expr_cast(?operand, _, ?id)) {
|
||||
case (expr_cast(?operand, _)) {
|
||||
find_pre_post_expr(fcx, operand);
|
||||
copy_pre_post(fcx.ccx, id, operand);
|
||||
copy_pre_post(fcx.ccx, e.id, operand);
|
||||
}
|
||||
case (expr_while(?test, ?body, ?id)) {
|
||||
case (expr_while(?test, ?body)) {
|
||||
find_pre_post_expr(fcx, test);
|
||||
find_pre_post_block(fcx, body);
|
||||
log "666";
|
||||
set_pre_and_post(fcx.ccx, id,
|
||||
set_pre_and_post(fcx.ccx, e.id,
|
||||
seq_preconds(fcx,
|
||||
[expr_pp(fcx.ccx, test),
|
||||
block_pp(fcx.ccx, body)]),
|
||||
|
@ -457,7 +451,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
|
|||
block_postcond(fcx.ccx,
|
||||
body)]));
|
||||
}
|
||||
case (expr_do_while(?body, ?test, ?id)) {
|
||||
case (expr_do_while(?body, ?test)) {
|
||||
find_pre_post_block(fcx, body);
|
||||
find_pre_post_expr(fcx, test);
|
||||
auto loop_postcond =
|
||||
|
@ -470,22 +464,22 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
|
|||
if (has_nonlocal_exits(body)) {
|
||||
loop_postcond = empty_poststate(num_local_vars);
|
||||
}
|
||||
set_pre_and_post(fcx.ccx, id,
|
||||
set_pre_and_post(fcx.ccx, e.id,
|
||||
seq_preconds(fcx,
|
||||
[block_pp(fcx.ccx, body),
|
||||
expr_pp(fcx.ccx, test)]),
|
||||
loop_postcond);
|
||||
}
|
||||
case (expr_for(?d, ?index, ?body, ?id)) {
|
||||
find_pre_post_loop(fcx, d, index, body, id);
|
||||
case (expr_for(?d, ?index, ?body)) {
|
||||
find_pre_post_loop(fcx, d, index, body, e.id);
|
||||
}
|
||||
case (expr_for_each(?d, ?index, ?body, ?id)) {
|
||||
find_pre_post_loop(fcx, d, index, body, id);
|
||||
case (expr_for_each(?d, ?index, ?body)) {
|
||||
find_pre_post_loop(fcx, d, index, body, e.id);
|
||||
}
|
||||
case (expr_index(?e, ?sub, ?id)) {
|
||||
find_pre_post_exprs(fcx, [e, sub], id);
|
||||
case (expr_index(?val, ?sub)) {
|
||||
find_pre_post_exprs(fcx, [val, sub], e.id);
|
||||
}
|
||||
case (expr_alt(?ex, ?alts, ?id)) {
|
||||
case (expr_alt(?ex, ?alts)) {
|
||||
find_pre_post_expr(fcx, ex);
|
||||
fn do_an_alt(&fn_ctxt fcx, &arm an_alt) -> pre_and_post {
|
||||
find_pre_post_block(fcx, an_alt.block);
|
||||
|
@ -495,7 +489,6 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
|
|||
auto alt_pps = vec::map[arm, pre_and_post](f, alts);
|
||||
fn combine_pp(pre_and_post antec, fn_ctxt fcx, &pre_and_post pp,
|
||||
&pre_and_post next) -> pre_and_post {
|
||||
log "777";
|
||||
union(pp.precondition, seq_preconds(fcx, [antec, next]));
|
||||
intersect(pp.postcondition, next.postcondition);
|
||||
ret pp;
|
||||
|
@ -507,54 +500,54 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
|
|||
auto g = bind combine_pp(antec_pp, fcx, _, _);
|
||||
auto alts_overall_pp =
|
||||
vec::foldl[pre_and_post, pre_and_post](g, e_pp, alt_pps);
|
||||
set_pre_and_post(fcx.ccx, id, alts_overall_pp.precondition,
|
||||
set_pre_and_post(fcx.ccx, e.id, alts_overall_pp.precondition,
|
||||
alts_overall_pp.postcondition);
|
||||
}
|
||||
case (expr_field(?operator, _, ?id)) {
|
||||
case (expr_field(?operator, _)) {
|
||||
find_pre_post_expr(fcx, operator);
|
||||
copy_pre_post(fcx.ccx, id, operator);
|
||||
copy_pre_post(fcx.ccx, e.id, operator);
|
||||
}
|
||||
case (expr_fail(?id, _)) {
|
||||
set_pre_and_post(fcx.ccx, id,
|
||||
case (expr_fail(_)) {
|
||||
set_pre_and_post(fcx.ccx, e.id,
|
||||
/* if execution continues after fail,
|
||||
then everything is true! */
|
||||
empty_prestate(num_local_vars),
|
||||
false_postcond(num_local_vars));
|
||||
}
|
||||
case (expr_assert(?p, ?id)) {
|
||||
case (expr_assert(?p)) {
|
||||
find_pre_post_expr(fcx, p);
|
||||
copy_pre_post(fcx.ccx, id, p);
|
||||
copy_pre_post(fcx.ccx, e.id, p);
|
||||
}
|
||||
case (expr_check(?p, ?id)) {
|
||||
case (expr_check(?p)) {
|
||||
find_pre_post_expr(fcx, p);
|
||||
copy_pre_post(fcx.ccx, id, p);
|
||||
copy_pre_post(fcx.ccx, e.id, p);
|
||||
/* predicate p holds after this expression executes */
|
||||
|
||||
let aux::constr c = expr_to_constr(fcx.ccx.tcx, p);
|
||||
gen(fcx, id, c.node);
|
||||
gen(fcx, e.id, c.node);
|
||||
}
|
||||
case (expr_if_check(?p, ?conseq, ?maybe_alt, ?id)) {
|
||||
join_then_else(fcx, p, conseq, maybe_alt, id, if_check);
|
||||
case (expr_if_check(?p, ?conseq, ?maybe_alt)) {
|
||||
join_then_else(fcx, p, conseq, maybe_alt, e.id, if_check);
|
||||
}
|
||||
|
||||
case (expr_bind(?operator, ?maybe_args, ?id)) {
|
||||
case (expr_bind(?operator, ?maybe_args)) {
|
||||
auto args = vec::cat_options[@expr](maybe_args);
|
||||
vec::push[@expr](args, operator); /* ??? order of eval? */
|
||||
|
||||
find_pre_post_exprs(fcx, args, id);
|
||||
find_pre_post_exprs(fcx, args, e.id);
|
||||
}
|
||||
case (expr_break(?id)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_cont(?id)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_port(?id)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_ext(_, _, _, ?expanded, ?id)) {
|
||||
case (expr_break) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_cont) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_port) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_ext(_, _, _, ?expanded)) {
|
||||
find_pre_post_expr(fcx, expanded);
|
||||
copy_pre_post(fcx.ccx, id, expanded);
|
||||
copy_pre_post(fcx.ccx, e.id, expanded);
|
||||
}
|
||||
case (expr_anon_obj(?anon_obj, _, _, ?id)) {
|
||||
case (expr_anon_obj(?anon_obj, _, _)) {
|
||||
alt (anon_obj.with_obj) {
|
||||
case (some(?ex)) {
|
||||
find_pre_post_expr(fcx, ex);
|
||||
copy_pre_post(fcx.ccx, id, ex);
|
||||
copy_pre_post(fcx.ccx, e.id, ex);
|
||||
}
|
||||
case (none) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
}
|
||||
|
@ -672,8 +665,7 @@ fn find_pre_post_fn(&fn_ctxt fcx, &_fn f) {
|
|||
// Treat the tail expression as a return statement
|
||||
alt (f.body.node.expr) {
|
||||
case (some(?tailexpr)) {
|
||||
auto tailann = expr_node_id(tailexpr);
|
||||
set_postcond_false(fcx.ccx, tailann);
|
||||
set_postcond_false(fcx.ccx, tailexpr.id);
|
||||
}
|
||||
case (none) {/* fallthrough */ }
|
||||
}
|
||||
|
|
|
@ -73,7 +73,6 @@ import bitvectors::gen_poststate;
|
|||
import bitvectors::kill_poststate;
|
||||
import front::ast;
|
||||
import front::ast::*;
|
||||
import middle::ty::expr_node_id;
|
||||
import middle::ty::expr_ty;
|
||||
import middle::ty::type_is_nil;
|
||||
import middle::ty::type_is_bot;
|
||||
|
@ -238,13 +237,13 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
|
||||
/* FIXME could get rid of some of the copy/paste */
|
||||
alt (e.node) {
|
||||
case (expr_vec(?elts, _, _, ?id)) {
|
||||
ret find_pre_post_state_exprs(fcx, pres, id, elts);
|
||||
case (expr_vec(?elts, _, _)) {
|
||||
ret find_pre_post_state_exprs(fcx, pres, e.id, elts);
|
||||
}
|
||||
case (expr_tup(?elts, ?id)) {
|
||||
ret find_pre_post_state_exprs(fcx, pres, id, elt_exprs(elts));
|
||||
case (expr_tup(?elts)) {
|
||||
ret find_pre_post_state_exprs(fcx, pres, e.id, elt_exprs(elts));
|
||||
}
|
||||
case (expr_call(?operator, ?operands, ?id)) {
|
||||
case (expr_call(?operator, ?operands)) {
|
||||
/* do the prestate for the rator */
|
||||
|
||||
/* fcx.ccx.tcx.sess.span_note(operator.span,
|
||||
|
@ -258,13 +257,13 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
changed =
|
||||
find_pre_post_state_exprs(fcx,
|
||||
expr_poststate(fcx.ccx, operator),
|
||||
id, operands) || changed;
|
||||
e.id, operands) || changed;
|
||||
/* if this is a failing call, it sets everything as initialized */
|
||||
|
||||
alt (controlflow_expr(fcx.ccx, operator)) {
|
||||
case (noreturn) {
|
||||
changed =
|
||||
set_poststate_ann(fcx.ccx, id,
|
||||
set_poststate_ann(fcx.ccx, e.id,
|
||||
false_postcond(num_local_vars)) ||
|
||||
changed;
|
||||
}
|
||||
|
@ -276,219 +275,194 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
*/
|
||||
ret changed;
|
||||
}
|
||||
case (expr_spawn(_, _, ?operator, ?operands, ?id)) {
|
||||
case (expr_spawn(_, _, ?operator, ?operands)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, operator);
|
||||
ret find_pre_post_state_exprs(fcx,
|
||||
expr_poststate(fcx.ccx, operator),
|
||||
id, operands) || changed;
|
||||
e.id, operands) || changed;
|
||||
}
|
||||
case (expr_bind(?operator, ?maybe_args, ?id)) {
|
||||
case (expr_bind(?operator, ?maybe_args)) {
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, pres, operator) || changed;
|
||||
ret find_pre_post_state_exprs(fcx,
|
||||
expr_poststate(fcx.ccx, operator),
|
||||
id, cat_options[@expr](maybe_args))
|
||||
|| changed;
|
||||
ret find_pre_post_state_exprs
|
||||
(fcx, expr_poststate(fcx.ccx, operator), e.id,
|
||||
cat_options[@expr](maybe_args)) || changed;
|
||||
}
|
||||
case (expr_path(_, ?id)) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
case (expr_log(_, ?e, ?id)) {
|
||||
case (expr_path(_)) { ret pure_exp(fcx.ccx, e.id, pres); }
|
||||
case (expr_log(_, ?ex)) {
|
||||
/* factor out the "one exp" pattern */
|
||||
|
||||
changed = find_pre_post_state_expr(fcx, pres, e);
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, e))
|
||||
|| changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, ex);
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, ex)) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_chan(?e, ?id)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, e);
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, e))
|
||||
|| changed;
|
||||
case (expr_chan(?ex)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, ex);
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, ex)) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_ext(_, _, _, ?expanded, ?id)) {
|
||||
case (expr_ext(_, _, _, ?expanded)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, expanded);
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, expanded)) ||
|
||||
changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, expanded)) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_put(?maybe_e, ?id)) {
|
||||
case (expr_put(?maybe_e)) {
|
||||
alt (maybe_e) {
|
||||
case (some(?arg)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, arg);
|
||||
changed =
|
||||
extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, arg)) ||
|
||||
changed = extend_prestate_ann
|
||||
(fcx.ccx, e.id, pres) || changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, arg)) ||
|
||||
changed;
|
||||
ret changed;
|
||||
}
|
||||
case (none) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
case (none) { ret pure_exp(fcx.ccx, e.id, pres); }
|
||||
}
|
||||
}
|
||||
case (expr_lit(?l, ?id)) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
case (
|
||||
case (expr_lit(?l)) { ret pure_exp(fcx.ccx, e.id, pres); }
|
||||
// FIXME This was just put in here as a placeholder
|
||||
expr_fn(?f, ?id)) {
|
||||
ret pure_exp(fcx.ccx, id, pres);
|
||||
}
|
||||
case (expr_block(?b, ?id)) {
|
||||
case (expr_fn(?f)) { ret pure_exp(fcx.ccx, e.id, pres); }
|
||||
case (expr_block(?b)) {
|
||||
changed = find_pre_post_state_block(fcx, pres, b) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id, block_poststate(fcx.ccx, b))
|
||||
|| changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, block_poststate(fcx.ccx, b)) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_rec(?fields, ?maybe_base, ?id)) {
|
||||
changed =
|
||||
find_pre_post_state_exprs(fcx, pres, id, field_exprs(fields))
|
||||
|| changed;
|
||||
case (expr_rec(?fields, ?maybe_base)) {
|
||||
changed = find_pre_post_state_exprs
|
||||
(fcx, pres, e.id, field_exprs(fields)) || changed;
|
||||
alt (maybe_base) {
|
||||
case (none) {/* do nothing */ }
|
||||
case (some(?base)) {
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, pres, base) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, base)) ||
|
||||
changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, base))
|
||||
|| changed;
|
||||
}
|
||||
}
|
||||
ret changed;
|
||||
}
|
||||
case (expr_move(?lhs, ?rhs, ?id)) {
|
||||
case (expr_move(?lhs, ?rhs)) {
|
||||
// FIXME: this needs to deinitialize the rhs
|
||||
|
||||
extend_prestate_ann(fcx.ccx, id, pres);
|
||||
extend_prestate_ann(fcx.ccx, e.id, pres);
|
||||
alt (lhs.node) {
|
||||
case (expr_path(?p, ?id_lhs)) {
|
||||
case (expr_path(?p)) {
|
||||
// assignment to local var
|
||||
|
||||
changed = pure_exp(fcx.ccx, id_lhs, pres) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, pres, rhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, rhs)) ||
|
||||
changed = pure_exp(fcx.ccx, lhs.id, pres) || changed;
|
||||
changed = find_pre_post_state_expr
|
||||
(fcx, pres, rhs) || changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, rhs)) ||
|
||||
changed;
|
||||
changed = gen_if_local(fcx, id_lhs, id, p) || changed;
|
||||
changed = gen_if_local(fcx, lhs.id, e.id, p) || changed;
|
||||
}
|
||||
case (_) {
|
||||
// assignment to something that must already have been
|
||||
// init'd
|
||||
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, pres, lhs) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx,
|
||||
expr_poststate(fcx.ccx, lhs),
|
||||
rhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, rhs)) ||
|
||||
changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, lhs)
|
||||
|| changed;
|
||||
changed = find_pre_post_state_expr
|
||||
(fcx, expr_poststate(fcx.ccx, lhs), rhs)
|
||||
|| changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, rhs))
|
||||
|| changed;
|
||||
}
|
||||
}
|
||||
ret changed;
|
||||
}
|
||||
case (expr_assign(?lhs, ?rhs, ?id)) {
|
||||
extend_prestate_ann(fcx.ccx, id, pres);
|
||||
case (expr_assign(?lhs, ?rhs)) {
|
||||
extend_prestate_ann(fcx.ccx, e.id, pres);
|
||||
alt (lhs.node) {
|
||||
case (expr_path(?p, ?a_lhs)) {
|
||||
case (expr_path(?p)) {
|
||||
// assignment to local var
|
||||
|
||||
changed = pure_exp(fcx.ccx, a_lhs, pres) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, pres, rhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, rhs)) ||
|
||||
changed;
|
||||
changed = gen_if_local(fcx, a_lhs, id, p) || changed;
|
||||
changed = pure_exp(fcx.ccx, lhs.id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, rhs)
|
||||
|| changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, rhs))
|
||||
|| changed;
|
||||
changed = gen_if_local(fcx, lhs.id, e.id, p) || changed;
|
||||
}
|
||||
case (_) {
|
||||
// assignment to something that must already have been
|
||||
// init'd
|
||||
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, pres, lhs) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx,
|
||||
expr_poststate(fcx.ccx, lhs),
|
||||
rhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, rhs)) ||
|
||||
changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, lhs)
|
||||
|| changed;
|
||||
changed = find_pre_post_state_expr
|
||||
(fcx, expr_poststate(fcx.ccx, lhs), rhs) || changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, rhs))
|
||||
|| changed;
|
||||
}
|
||||
}
|
||||
ret changed;
|
||||
}
|
||||
case (expr_swap(?lhs, ?rhs, ?id)) {
|
||||
case (expr_swap(?lhs, ?rhs)) {
|
||||
/* quite similar to binary -- should abstract this */
|
||||
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, lhs) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, lhs),
|
||||
rhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, rhs)) || changed;
|
||||
changed = find_pre_post_state_expr
|
||||
(fcx, expr_poststate(fcx.ccx, lhs), rhs) || changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, rhs)) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_recv(?lhs, ?rhs, ?id)) {
|
||||
extend_prestate_ann(fcx.ccx, id, pres);
|
||||
case (expr_recv(?lhs, ?rhs)) {
|
||||
extend_prestate_ann(fcx.ccx, e.id, pres);
|
||||
alt (rhs.node) {
|
||||
case (expr_path(?p, ?id_rhs)) {
|
||||
case (expr_path(?p)) {
|
||||
// receive to local var
|
||||
|
||||
changed = pure_exp(fcx.ccx, id_rhs, pres) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, pres, lhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, lhs)) ||
|
||||
changed;
|
||||
changed = gen_if_local(fcx, id_rhs, id, p) || changed;
|
||||
changed = pure_exp(fcx.ccx, rhs.id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, lhs)
|
||||
|| changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, lhs))
|
||||
|| changed;
|
||||
changed = gen_if_local(fcx, rhs.id, e.id, p) || changed;
|
||||
}
|
||||
case (_) {
|
||||
// receive to something that must already have been init'd
|
||||
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, pres, rhs) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx,
|
||||
expr_poststate(fcx.ccx, rhs),
|
||||
lhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, lhs)) ||
|
||||
changed;
|
||||
changed = find_pre_post_state_expr
|
||||
(fcx, pres, rhs) || changed;
|
||||
changed = find_pre_post_state_expr
|
||||
(fcx, expr_poststate(fcx.ccx, rhs), lhs) || changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, lhs))
|
||||
|| changed;
|
||||
}
|
||||
}
|
||||
ret changed;
|
||||
}
|
||||
case (expr_ret(?maybe_ret_val, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
case (expr_ret(?maybe_ret_val)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
/* normally, everything is true if execution continues after
|
||||
a ret expression (since execution never continues locally
|
||||
after a ret expression */
|
||||
|
||||
set_poststate_ann(fcx.ccx, id, false_postcond(num_local_vars));
|
||||
set_poststate_ann(fcx.ccx, e.id, false_postcond(num_local_vars));
|
||||
/* return from an always-failing function clears the return bit */
|
||||
|
||||
alt (fcx.enclosing.cf) {
|
||||
case (noreturn) {
|
||||
kill_poststate(fcx, id, rec(id=fcx.id,
|
||||
kill_poststate(fcx, e.id, rec(id=fcx.id,
|
||||
c=ninit(fcx.name)));
|
||||
}
|
||||
case (_) { }
|
||||
|
@ -496,66 +470,58 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
alt (maybe_ret_val) {
|
||||
case (none) {/* do nothing */ }
|
||||
case (some(?ret_val)) {
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, pres, ret_val) ||
|
||||
changed;
|
||||
changed = find_pre_post_state_expr
|
||||
(fcx, pres, ret_val) || changed;
|
||||
}
|
||||
}
|
||||
ret changed;
|
||||
}
|
||||
case (expr_be(?e, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
set_poststate_ann(fcx.ccx, id, false_postcond(num_local_vars));
|
||||
changed = find_pre_post_state_expr(fcx, pres, e) || changed;
|
||||
case (expr_be(?val)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
set_poststate_ann(fcx.ccx, e.id, false_postcond(num_local_vars));
|
||||
changed = find_pre_post_state_expr(fcx, pres, val) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_if(?antec, ?conseq, ?maybe_alt, ?id)) {
|
||||
changed = join_then_else(fcx, antec, conseq, maybe_alt, id,
|
||||
plain_if, pres)
|
||||
case (expr_if(?antec, ?conseq, ?maybe_alt)) {
|
||||
changed = join_then_else
|
||||
(fcx, antec, conseq, maybe_alt, e.id, plain_if, pres)
|
||||
|| changed;
|
||||
|
||||
ret changed;
|
||||
}
|
||||
case (expr_binary(?bop, ?l, ?r, ?id)) {
|
||||
case (expr_binary(?bop, ?l, ?r)) {
|
||||
/* FIXME: what if bop is lazy? */
|
||||
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, l) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, l), r)
|
||||
|| changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, r))
|
||||
|| changed;
|
||||
changed = find_pre_post_state_expr
|
||||
(fcx, expr_poststate(fcx.ccx, l), r) || changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, r)) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_send(?l, ?r, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
case (expr_send(?l, ?r)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, l) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, l), r)
|
||||
|| changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, r))
|
||||
|| changed;
|
||||
changed = find_pre_post_state_expr
|
||||
(fcx, expr_poststate(fcx.ccx, l), r) || changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, r)) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_assign_op(?op, ?lhs, ?rhs, ?id)) {
|
||||
case (expr_assign_op(?op, ?lhs, ?rhs)) {
|
||||
/* quite similar to binary -- should abstract this */
|
||||
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, lhs) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, lhs),
|
||||
rhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, rhs))
|
||||
|| changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, rhs)) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_while(?test, ?body, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
case (expr_while(?test, ?body)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
/* to handle general predicates, we need to pass in
|
||||
pres `intersect` (poststate(a))
|
||||
like: auto test_pres = intersect_postconds(pres,
|
||||
|
@ -572,22 +538,17 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
/* conservative approximation: if a loop contains a break
|
||||
or cont, we assume nothing about the poststate */
|
||||
if (has_nonlocal_exits(body)) {
|
||||
changed = set_poststate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = set_poststate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
}
|
||||
|
||||
changed =
|
||||
{
|
||||
auto e_post = expr_poststate(fcx.ccx, test);
|
||||
auto b_post = block_poststate(fcx.ccx, body);
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
intersect_postconds([e_post,
|
||||
b_post])) ||
|
||||
ret extend_poststate_ann
|
||||
(fcx.ccx, e.id, intersect_postconds([e_post, b_post])) ||
|
||||
changed
|
||||
};
|
||||
ret changed;
|
||||
}
|
||||
case (expr_do_while(?body, ?test, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
case (expr_do_while(?body, ?test)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
auto changed0 = changed;
|
||||
changed = find_pre_post_state_block(fcx, pres, body) || changed;
|
||||
/* conservative approximination: if the body of the loop
|
||||
|
@ -611,36 +572,36 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
test) || changed;
|
||||
|
||||
if (breaks) {
|
||||
set_poststate_ann(fcx.ccx, id, pres);
|
||||
set_poststate_ann(fcx.ccx, e.id, pres);
|
||||
}
|
||||
else {
|
||||
changed = extend_poststate_ann(fcx.ccx, id,
|
||||
changed = extend_poststate_ann(fcx.ccx, e.id,
|
||||
expr_poststate(fcx.ccx, test)) ||
|
||||
changed;
|
||||
}
|
||||
ret changed;
|
||||
}
|
||||
case (expr_for(?d, ?index, ?body, ?id)) {
|
||||
ret find_pre_post_state_loop(fcx, pres, d, index, body, id);
|
||||
case (expr_for(?d, ?index, ?body)) {
|
||||
ret find_pre_post_state_loop(fcx, pres, d, index, body, e.id);
|
||||
}
|
||||
case (expr_for_each(?d, ?index, ?body, ?id)) {
|
||||
ret find_pre_post_state_loop(fcx, pres, d, index, body, id);
|
||||
case (expr_for_each(?d, ?index, ?body)) {
|
||||
ret find_pre_post_state_loop(fcx, pres, d, index, body, e.id);
|
||||
}
|
||||
case (expr_index(?e, ?sub, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, e) || changed;
|
||||
case (expr_index(?val, ?sub)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, val) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, e), sub)
|
||||
|| changed;
|
||||
find_pre_post_state_expr
|
||||
(fcx, expr_poststate(fcx.ccx, val), sub) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
extend_poststate_ann(fcx.ccx, e.id,
|
||||
expr_poststate(fcx.ccx, sub));
|
||||
ret changed;
|
||||
}
|
||||
case (expr_alt(?e, ?alts, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, e) || changed;
|
||||
auto e_post = expr_poststate(fcx.ccx, e);
|
||||
case (expr_alt(?val, ?alts)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, val) || changed;
|
||||
auto e_post = expr_poststate(fcx.ccx, val);
|
||||
auto a_post;
|
||||
if (vec::len[arm](alts) > 0u) {
|
||||
a_post = false_postcond(num_local_vars);
|
||||
|
@ -659,85 +620,78 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
|
||||
a_post = e_post;
|
||||
}
|
||||
changed = extend_poststate_ann(fcx.ccx, id, a_post) || changed;
|
||||
changed = extend_poststate_ann(fcx.ccx, e.id, a_post) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_field(?e, _, ?id)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, e);
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, e))
|
||||
case (expr_field(?val, _)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, val);
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
changed = extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, val)) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_unary(_, ?operand)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, operand) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
ret extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, operand))
|
||||
|| changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_unary(_, ?operand, ?id)) {
|
||||
case (expr_cast(?operand, _)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, operand) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, operand)) ||
|
||||
changed;
|
||||
ret changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
ret extend_poststate_ann
|
||||
(fcx.ccx, e.id, expr_poststate(fcx.ccx, operand))
|
||||
|| changed;
|
||||
}
|
||||
case (expr_cast(?operand, _, ?id)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, operand) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, operand)) ||
|
||||
changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_fail(?id, _)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
case (expr_fail(_)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
/* if execution continues after fail, then everything is true!
|
||||
woo! */
|
||||
|
||||
changed =
|
||||
set_poststate_ann(fcx.ccx, id, false_postcond(num_local_vars))
|
||||
|| changed;
|
||||
changed = set_poststate_ann
|
||||
(fcx.ccx, e.id, false_postcond(num_local_vars)) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_assert(?p, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
case (expr_assert(?p)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, p) || changed;
|
||||
changed = extend_poststate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = extend_poststate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_check(?p, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
case (expr_check(?p)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, p) || changed;
|
||||
changed = extend_poststate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = extend_poststate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
/* predicate p holds after this expression executes */
|
||||
|
||||
let aux::constr c = expr_to_constr(fcx.ccx.tcx, p);
|
||||
changed = gen_poststate(fcx, id, c.node) || changed;
|
||||
changed = gen_poststate(fcx, e.id, c.node) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_if_check(?p, ?conseq, ?maybe_alt, ?id)) {
|
||||
changed = join_then_else(fcx, p, conseq, maybe_alt, id, if_check,
|
||||
pres)
|
||||
|| changed;
|
||||
case (expr_if_check(?p, ?conseq, ?maybe_alt)) {
|
||||
changed = join_then_else
|
||||
(fcx, p, conseq, maybe_alt, e.id, if_check, pres) || changed;
|
||||
|
||||
ret changed;
|
||||
}
|
||||
case (expr_break(?id)) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
case (expr_cont(?id)) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
case (expr_port(?id)) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
case (expr_self_method(_, ?id)) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
case (expr_anon_obj(?anon_obj, _, _, ?id)) {
|
||||
case (expr_break) { ret pure_exp(fcx.ccx, e.id, pres); }
|
||||
case (expr_cont) { ret pure_exp(fcx.ccx, e.id, pres); }
|
||||
case (expr_port) { ret pure_exp(fcx.ccx, e.id, pres); }
|
||||
case (expr_self_method(_)) { ret pure_exp(fcx.ccx, e.id, pres); }
|
||||
case (expr_anon_obj(?anon_obj, _, _)) {
|
||||
alt (anon_obj.with_obj) {
|
||||
case (some(?e)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, e);
|
||||
case (some(?wt)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, wt);
|
||||
changed =
|
||||
extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
extend_prestate_ann(fcx.ccx, e.id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, e)) ||
|
||||
extend_poststate_ann(fcx.ccx, e.id,
|
||||
expr_poststate(fcx.ccx, wt)) ||
|
||||
changed;
|
||||
ret changed;
|
||||
}
|
||||
case (none) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
case (none) { ret pure_exp(fcx.ccx, e.id, pres); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -816,14 +770,14 @@ fn find_pre_post_state_stmt(&fn_ctxt fcx, &prestate pres, @stmt s) -> bool {
|
|||
}
|
||||
}
|
||||
}
|
||||
case (stmt_expr(?e, _)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, e) || changed;
|
||||
case (stmt_expr(?ex, _)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, ex) || changed;
|
||||
changed =
|
||||
extend_prestate(stmt_ann.states.prestate,
|
||||
expr_prestate(fcx.ccx, e)) || changed;
|
||||
expr_prestate(fcx.ccx, ex)) || changed;
|
||||
changed =
|
||||
extend_poststate(stmt_ann.states.poststate,
|
||||
expr_poststate(fcx.ccx, e)) || changed;
|
||||
expr_poststate(fcx.ccx, ex)) || changed;
|
||||
/*
|
||||
log("Summary: stmt = ");
|
||||
log_stmt(*s);
|
||||
|
@ -896,7 +850,6 @@ fn find_pre_post_state_fn(&fn_ctxt fcx, &_fn f) -> bool {
|
|||
|
||||
alt (f.body.node.expr) {
|
||||
case (some(?tailexpr)) {
|
||||
auto tailann = expr_node_id(tailexpr);
|
||||
auto tailty = expr_ty(fcx.ccx.tcx, tailexpr);
|
||||
|
||||
// Since blocks and alts and ifs that don't have results
|
||||
|
@ -906,12 +859,12 @@ fn find_pre_post_state_fn(&fn_ctxt fcx, &_fn f) -> bool {
|
|||
if (!type_is_nil(fcx.ccx.tcx, tailty) &&
|
||||
!type_is_bot(fcx.ccx.tcx, tailty)) {
|
||||
auto p = false_postcond(num_local_vars);
|
||||
set_poststate_ann(fcx.ccx, tailann, p);
|
||||
set_poststate_ann(fcx.ccx, tailexpr.id, p);
|
||||
// be sure to set the block poststate to the same thing
|
||||
set_poststate_ann(fcx.ccx, f.body.node.id, p);
|
||||
alt (fcx.enclosing.cf) {
|
||||
case (noreturn) {
|
||||
kill_poststate(fcx, tailann,
|
||||
kill_poststate(fcx, tailexpr.id,
|
||||
rec(id=fcx.id, c=ninit(fcx.name)));
|
||||
}
|
||||
case (_) { }
|
||||
|
|
|
@ -42,7 +42,6 @@ export ctxt;
|
|||
export decl_local_ty;
|
||||
export def_has_ty_params;
|
||||
export eq_ty;
|
||||
export expr_node_id;
|
||||
export expr_has_ty_params;
|
||||
export expr_ty;
|
||||
export fold_ty;
|
||||
|
@ -1730,53 +1729,6 @@ fn pat_ty(&ctxt cx, &@ast::pat pat) -> t {
|
|||
ret node_id_to_monotype(cx, pat_node_id(pat));
|
||||
}
|
||||
|
||||
fn expr_node_id(&@ast::expr e) -> ast::node_id {
|
||||
ret alt (e.node) {
|
||||
case (ast::expr_vec(_, _, _, ?id)) { id }
|
||||
case (ast::expr_tup(_, ?id)) { id }
|
||||
case (ast::expr_rec(_, _, ?id)) { id }
|
||||
case (ast::expr_call(_, _, ?id)) { id }
|
||||
case (ast::expr_bind(_, _, ?id)) { id }
|
||||
case (ast::expr_binary(_, _, _, ?id)) { id }
|
||||
case (ast::expr_unary(_, _, ?id)) { id }
|
||||
case (ast::expr_lit(_, ?id)) { id }
|
||||
case (ast::expr_cast(_, _, ?id)) { id }
|
||||
case (ast::expr_if(_, _, _, ?id)) { id }
|
||||
case (ast::expr_if_check(_, _, _, ?id)) { id }
|
||||
case (ast::expr_while(_, _, ?id)) { id }
|
||||
case (ast::expr_for(_, _, _, ?id)) { id }
|
||||
case (ast::expr_for_each(_, _, _, ?id)) { id }
|
||||
case (ast::expr_do_while(_, _, ?id)) { id }
|
||||
case (ast::expr_alt(_, _, ?id)) { id }
|
||||
case (ast::expr_fn(_, ?id)) { id }
|
||||
case (ast::expr_block(_, ?id)) { id }
|
||||
case (ast::expr_move(_, _, ?id)) { id }
|
||||
case (ast::expr_assign(_, _, ?id)) { id }
|
||||
case (ast::expr_swap(_, _, ?id)) { id }
|
||||
case (ast::expr_assign_op(_, _, _, ?id)) { id }
|
||||
case (ast::expr_send(_, _, ?id)) { id }
|
||||
case (ast::expr_recv(_, _, ?id)) { id }
|
||||
case (ast::expr_field(_, _, ?id)) { id }
|
||||
case (ast::expr_index(_, _, ?id)) { id }
|
||||
case (ast::expr_path(_, ?id)) { id }
|
||||
case (ast::expr_ext(_, _, _, _, ?id)) { id }
|
||||
case (ast::expr_fail(?id, _)) { id }
|
||||
case (ast::expr_ret(_, ?id)) { id }
|
||||
case (ast::expr_put(_, ?id)) { id }
|
||||
case (ast::expr_be(_, ?id)) { id }
|
||||
case (ast::expr_log(_, _, ?id)) { id }
|
||||
case (ast::expr_assert(_, ?id)) { id }
|
||||
case (ast::expr_check(_, ?id)) { id }
|
||||
case (ast::expr_port(?id)) { id }
|
||||
case (ast::expr_chan(_, ?id)) { id }
|
||||
case (ast::expr_anon_obj(_, _, _, ?id)) { id }
|
||||
case (ast::expr_break(?id)) { id }
|
||||
case (ast::expr_cont(?id)) { id }
|
||||
case (ast::expr_self_method(_, ?id)) { id }
|
||||
case (ast::expr_spawn(_, _, _, _, ?id)) { id }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Returns the type of an expression as a monotype.
|
||||
//
|
||||
|
@ -1785,16 +1737,16 @@ fn expr_node_id(&@ast::expr e) -> ast::node_id {
|
|||
// instead of "fn(&T) -> T with T = int". If this isn't what you want, see
|
||||
// expr_ty_params_and_ty() below.
|
||||
fn expr_ty(&ctxt cx, &@ast::expr expr) -> t {
|
||||
ret node_id_to_monotype(cx, expr_node_id(expr));
|
||||
ret node_id_to_monotype(cx, expr.id);
|
||||
}
|
||||
|
||||
fn expr_ty_params_and_ty(&ctxt cx, &@ast::expr expr) -> tup(vec[t], t) {
|
||||
auto a = expr_node_id(expr);
|
||||
ret tup(node_id_to_type_params(cx, a), node_id_to_type(cx, a));
|
||||
ret tup(node_id_to_type_params(cx, expr.id),
|
||||
node_id_to_type(cx, expr.id));
|
||||
}
|
||||
|
||||
fn expr_has_ty_params(&ctxt cx, &@ast::expr expr) -> bool {
|
||||
ret node_id_has_type_params(cx, expr_node_id(expr));
|
||||
ret node_id_has_type_params(cx, expr.id);
|
||||
}
|
||||
|
||||
fn decl_local_ty(&ctxt cx, &@ast::local l) -> t {
|
||||
|
@ -1873,10 +1825,10 @@ fn sort_methods(&vec[method] meths) -> vec[method] {
|
|||
|
||||
fn is_lval(&@ast::expr expr) -> bool {
|
||||
alt (expr.node) {
|
||||
case (ast::expr_field(_, _, _)) { ret true; }
|
||||
case (ast::expr_index(_, _, _)) { ret true; }
|
||||
case (ast::expr_path(_, _)) { ret true; }
|
||||
case (ast::expr_unary(ast::deref, _, _)) { ret true; }
|
||||
case (ast::expr_field(_, _)) { ret true; }
|
||||
case (ast::expr_index(_, _)) { ret true; }
|
||||
case (ast::expr_path(_)) { ret true; }
|
||||
case (ast::expr_unary(ast::deref, _)) { ret true; }
|
||||
case (_) { ret false; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -976,7 +976,7 @@ mod writeback {
|
|||
resolve_type_vars_for_node(fcx, s.span, ty::stmt_node_id(s));
|
||||
}
|
||||
fn visit_expr_pre(@fn_ctxt fcx, &@ast::expr e) {
|
||||
resolve_type_vars_for_node(fcx, e.span, ty::expr_node_id(e));
|
||||
resolve_type_vars_for_node(fcx, e.span, e.id);
|
||||
}
|
||||
fn visit_block_pre(@fn_ctxt fcx, &ast::block b) {
|
||||
resolve_type_vars_for_node(fcx, b.span, b.node.id);
|
||||
|
@ -1139,7 +1139,7 @@ fn replace_expr_type(&@fn_ctxt fcx, &@ast::expr expr,
|
|||
if (ty::expr_has_ty_params(fcx.ccx.tcx, expr)) {
|
||||
new_tps = some[vec[ty::t]](new_tyt._0);
|
||||
} else { new_tps = none[vec[ty::t]]; }
|
||||
write::ty_fixup(fcx, ty::expr_node_id(expr), tup(new_tps, new_tyt._1));
|
||||
write::ty_fixup(fcx, expr.id, tup(new_tps, new_tyt._1));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1282,9 +1282,9 @@ fn require_pure_call(@crate_ctxt ccx, &ast::purity caller_purity,
|
|||
case (ast::impure_fn) { ret; }
|
||||
case (ast::pure_fn) {
|
||||
alt (callee.node) {
|
||||
case (ast::expr_path(_, ?id)) {
|
||||
case (ast::expr_path(_)) {
|
||||
auto d_id;
|
||||
alt (ccx.tcx.def_map.get(id)) {
|
||||
alt (ccx.tcx.def_map.get(callee.id)) {
|
||||
case (ast::def_fn(?_d_id)) { d_id = _d_id; }
|
||||
}
|
||||
alt (get_function_purity(ccx, d_id)) {
|
||||
|
@ -1425,11 +1425,11 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
/* e must be a call expr where all arguments are either
|
||||
literals or slots */
|
||||
alt (e.node) {
|
||||
case (ast::expr_call(?operator, ?operands, _)) {
|
||||
case (ast::expr_call(?operator, ?operands)) {
|
||||
alt (operator.node) {
|
||||
case (ast::expr_path(?oper_name, ?id)) {
|
||||
case (ast::expr_path(?oper_name)) {
|
||||
auto d_id;
|
||||
alt (fcx.ccx.tcx.def_map.get(id)) {
|
||||
alt (fcx.ccx.tcx.def_map.get(operator.id)) {
|
||||
case (ast::def_fn(?_d_id)) { d_id = _d_id; }
|
||||
}
|
||||
for (@ast::expr operand in operands) {
|
||||
|
@ -1477,12 +1477,13 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
write::ty_only_fixup(fcx, id, if_t);
|
||||
}
|
||||
|
||||
auto id = expr.id;
|
||||
alt (expr.node) {
|
||||
case (ast::expr_lit(?lit, ?id)) {
|
||||
case (ast::expr_lit(?lit)) {
|
||||
auto typ = check_lit(fcx.ccx, lit);
|
||||
write::ty_only_fixup(fcx, id, typ);
|
||||
}
|
||||
case (ast::expr_binary(?binop, ?lhs, ?rhs, ?id)) {
|
||||
case (ast::expr_binary(?binop, ?lhs, ?rhs)) {
|
||||
check_expr(fcx, lhs);
|
||||
check_expr(fcx, rhs);
|
||||
|
||||
|
@ -1505,7 +1506,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
write::ty_only_fixup(fcx, id, t);
|
||||
}
|
||||
case (ast::expr_unary(?unop, ?oper, ?id)) {
|
||||
case (ast::expr_unary(?unop, ?oper)) {
|
||||
check_expr(fcx, oper);
|
||||
auto oper_t = expr_ty(fcx.ccx.tcx, oper);
|
||||
alt (unop) {
|
||||
|
@ -1538,13 +1539,13 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
write::ty_only_fixup(fcx, id, oper_t);
|
||||
}
|
||||
case (ast::expr_path(?pth, ?old_id)) {
|
||||
case (ast::expr_path(?pth)) {
|
||||
auto t = ty::mk_nil(fcx.ccx.tcx);
|
||||
auto defn = fcx.ccx.tcx.def_map.get(old_id);
|
||||
auto defn = fcx.ccx.tcx.def_map.get(id);
|
||||
auto tpt = ty_param_count_and_ty_for_def(fcx, expr.span, defn);
|
||||
if (ty::def_has_ty_params(defn)) {
|
||||
auto path_tpot = instantiate_path(fcx, pth, tpt, expr.span);
|
||||
write::ty_fixup(fcx, old_id, path_tpot);
|
||||
write::ty_fixup(fcx, id, path_tpot);
|
||||
ret;
|
||||
}
|
||||
// The definition doesn't take type parameters. If the programmer
|
||||
|
@ -1555,17 +1556,17 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
"this kind of value does not \
|
||||
take type parameters");
|
||||
}
|
||||
write::ty_only_fixup(fcx, old_id, tpt._1);
|
||||
write::ty_only_fixup(fcx, id, tpt._1);
|
||||
}
|
||||
case (ast::expr_ext(?p, ?args, ?body, ?expanded, ?id)) {
|
||||
case (ast::expr_ext(?p, ?args, ?body, ?expanded)) {
|
||||
check_expr(fcx, expanded);
|
||||
auto t = expr_ty(fcx.ccx.tcx, expanded);
|
||||
write::ty_only_fixup(fcx, id, t);
|
||||
}
|
||||
case (ast::expr_fail(?id, _)) { write::bot_ty(fcx.ccx.tcx, id); }
|
||||
case (ast::expr_break(?id)) { write::bot_ty(fcx.ccx.tcx, id); }
|
||||
case (ast::expr_cont(?id)) { write::bot_ty(fcx.ccx.tcx, id); }
|
||||
case (ast::expr_ret(?expr_opt, ?id)) {
|
||||
case (ast::expr_fail(_)) { write::bot_ty(fcx.ccx.tcx, id); }
|
||||
case (ast::expr_break) { write::bot_ty(fcx.ccx.tcx, id); }
|
||||
case (ast::expr_cont) { write::bot_ty(fcx.ccx.tcx, id); }
|
||||
case (ast::expr_ret(?expr_opt)) {
|
||||
alt (expr_opt) {
|
||||
case (none) {
|
||||
auto nil = ty::mk_nil(fcx.ccx.tcx);
|
||||
|
@ -1584,7 +1585,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
}
|
||||
}
|
||||
case (ast::expr_put(?expr_opt, ?id)) {
|
||||
case (ast::expr_put(?expr_opt)) {
|
||||
require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
|
||||
alt (expr_opt) {
|
||||
case (none) {
|
||||
|
@ -1602,7 +1603,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
}
|
||||
}
|
||||
case (ast::expr_be(?e, ?id)) {
|
||||
case (ast::expr_be(?e)) {
|
||||
// FIXME: prove instead of assert
|
||||
|
||||
assert (ast::is_call_expr(e));
|
||||
|
@ -1610,41 +1611,41 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
demand::simple(fcx, e.span, fcx.ret_ty, expr_ty(fcx.ccx.tcx, e));
|
||||
write::nil_ty(fcx.ccx.tcx, id);
|
||||
}
|
||||
case (ast::expr_log(?l, ?e, ?id)) {
|
||||
case (ast::expr_log(?l, ?e)) {
|
||||
auto expr_t = check_expr(fcx, e);
|
||||
write::nil_ty(fcx.ccx.tcx, id);
|
||||
}
|
||||
case (ast::expr_check(?e, ?id)) {
|
||||
case (ast::expr_check(?e)) {
|
||||
check_pred_expr(fcx, e);
|
||||
write::nil_ty(fcx.ccx.tcx, id);
|
||||
}
|
||||
case (ast::expr_if_check(?cond, ?thn, ?elsopt, ?id)) {
|
||||
case (ast::expr_if_check(?cond, ?thn, ?elsopt)) {
|
||||
check_pred_expr(fcx, cond);
|
||||
check_then_else(fcx, thn, elsopt, id, expr.span);
|
||||
}
|
||||
case (ast::expr_assert(?e, ?id)) {
|
||||
case (ast::expr_assert(?e)) {
|
||||
check_expr(fcx, e);
|
||||
auto ety = expr_ty(fcx.ccx.tcx, e);
|
||||
demand::simple(fcx, expr.span, ty::mk_bool(fcx.ccx.tcx), ety);
|
||||
write::nil_ty(fcx.ccx.tcx, id);
|
||||
}
|
||||
case (ast::expr_move(?lhs, ?rhs, ?id)) {
|
||||
case (ast::expr_move(?lhs, ?rhs)) {
|
||||
require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
|
||||
check_assignment(fcx, expr.span, lhs, rhs, id);
|
||||
}
|
||||
case (ast::expr_assign(?lhs, ?rhs, ?id)) {
|
||||
case (ast::expr_assign(?lhs, ?rhs)) {
|
||||
require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
|
||||
check_assignment(fcx, expr.span, lhs, rhs, id);
|
||||
}
|
||||
case (ast::expr_swap(?lhs, ?rhs, ?id)) {
|
||||
case (ast::expr_swap(?lhs, ?rhs)) {
|
||||
require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
|
||||
check_assignment(fcx, expr.span, lhs, rhs, id);
|
||||
}
|
||||
case (ast::expr_assign_op(?op, ?lhs, ?rhs, ?id)) {
|
||||
case (ast::expr_assign_op(?op, ?lhs, ?rhs)) {
|
||||
require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
|
||||
check_assignment(fcx, expr.span, lhs, rhs, id);
|
||||
}
|
||||
case (ast::expr_send(?lhs, ?rhs, ?id)) {
|
||||
case (ast::expr_send(?lhs, ?rhs)) {
|
||||
require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
|
||||
check_expr(fcx, lhs);
|
||||
check_expr(fcx, rhs);
|
||||
|
@ -1664,7 +1665,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
write::ty_only_fixup(fcx, id, chan_t);
|
||||
}
|
||||
case (ast::expr_recv(?lhs, ?rhs, ?id)) {
|
||||
case (ast::expr_recv(?lhs, ?rhs)) {
|
||||
require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
|
||||
check_expr(fcx, lhs);
|
||||
check_expr(fcx, rhs);
|
||||
|
@ -1673,14 +1674,14 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
demand::simple(fcx, expr.span, port_t, expr_ty(fcx.ccx.tcx, lhs));
|
||||
write::ty_only_fixup(fcx, id, item_t);
|
||||
}
|
||||
case (ast::expr_if(?cond, ?thn, ?elsopt, ?id)) {
|
||||
case (ast::expr_if(?cond, ?thn, ?elsopt)) {
|
||||
check_expr(fcx, cond);
|
||||
demand::simple(fcx, cond.span,
|
||||
ty::mk_bool(fcx.ccx.tcx),
|
||||
expr_ty(fcx.ccx.tcx, cond));
|
||||
check_then_else(fcx, thn, elsopt, id, expr.span);
|
||||
}
|
||||
case (ast::expr_for(?decl, ?seq, ?body, ?id)) {
|
||||
case (ast::expr_for(?decl, ?seq, ?body)) {
|
||||
check_expr(fcx, seq);
|
||||
auto elt_ty;
|
||||
auto ety = expr_ty(fcx.ccx.tcx, seq);
|
||||
|
@ -1701,12 +1702,12 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
check_for_or_for_each(fcx, decl, elt_ty, body, id);
|
||||
}
|
||||
case (ast::expr_for_each(?decl, ?seq, ?body, ?id)) {
|
||||
case (ast::expr_for_each(?decl, ?seq, ?body)) {
|
||||
check_expr(fcx, seq);
|
||||
check_for_or_for_each(fcx, decl, expr_ty(fcx.ccx.tcx, seq), body,
|
||||
id);
|
||||
}
|
||||
case (ast::expr_while(?cond, ?body, ?id)) {
|
||||
case (ast::expr_while(?cond, ?body)) {
|
||||
check_expr(fcx, cond);
|
||||
check_block(fcx, body);
|
||||
demand::simple(fcx, cond.span, ty::mk_bool(fcx.ccx.tcx),
|
||||
|
@ -1714,13 +1715,13 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
auto typ = ty::mk_nil(fcx.ccx.tcx);
|
||||
write::ty_only_fixup(fcx, id, typ);
|
||||
}
|
||||
case (ast::expr_do_while(?body, ?cond, ?id)) {
|
||||
case (ast::expr_do_while(?body, ?cond)) {
|
||||
check_expr(fcx, cond);
|
||||
check_block(fcx, body);
|
||||
auto typ = block_ty(fcx.ccx.tcx, body);
|
||||
write::ty_only_fixup(fcx, id, typ);
|
||||
}
|
||||
case (ast::expr_alt(?expr, ?arms, ?id)) {
|
||||
case (ast::expr_alt(?expr, ?arms)) {
|
||||
check_expr(fcx, expr);
|
||||
// Typecheck the patterns first, so that we get types for all the
|
||||
// bindings.
|
||||
|
@ -1747,7 +1748,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
write::ty_only_fixup(fcx, id, result_ty);
|
||||
}
|
||||
case (ast::expr_fn(?f, ?id)) {
|
||||
case (ast::expr_fn(?f)) {
|
||||
auto cx = @rec(tcx=fcx.ccx.tcx);
|
||||
auto convert =
|
||||
bind ast_ty_to_ty(cx.tcx, bind collect::getter(cx, _), _);
|
||||
|
@ -1758,7 +1759,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
write::ty_only_fixup(fcx, id, fty);
|
||||
check_fn(fcx.ccx, f.decl, f.proto, f.body, id);
|
||||
}
|
||||
case (ast::expr_block(?b, ?id)) {
|
||||
case (ast::expr_block(?b)) {
|
||||
check_block(fcx, b);
|
||||
alt (b.node.expr) {
|
||||
case (some(?expr)) {
|
||||
|
@ -1771,7 +1772,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
}
|
||||
}
|
||||
case (ast::expr_bind(?f, ?args, ?id)) {
|
||||
case (ast::expr_bind(?f, ?args)) {
|
||||
// Call the generic checker.
|
||||
|
||||
check_call_or_bind(fcx, expr.span, f, args);
|
||||
|
@ -1812,7 +1813,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
write::ty_only_fixup(fcx, id, t_1);
|
||||
}
|
||||
case (ast::expr_call(?f, ?args, ?id)) {
|
||||
case (ast::expr_call(?f, ?args)) {
|
||||
/* here we're kind of hosed, as f can be any expr
|
||||
need to restrict it to being an explicit expr_path if we're
|
||||
inside a pure function, and need an environment mapping from
|
||||
|
@ -1834,7 +1835,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
write::ty_only_fixup(fcx, id, rt_1);
|
||||
}
|
||||
case (ast::expr_self_method(?ident, ?id)) {
|
||||
case (ast::expr_self_method(?ident)) {
|
||||
auto t = ty::mk_nil(fcx.ccx.tcx);
|
||||
let ty::t this_obj_ty;
|
||||
let option::t[obj_info] this_obj_info = get_obj_info(fcx.ccx);
|
||||
|
@ -1867,7 +1868,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
write::ty_only_fixup(fcx, id, t);
|
||||
require_impure(fcx.ccx.tcx.sess, fcx.purity, expr.span);
|
||||
}
|
||||
case (ast::expr_spawn(_, _, ?f, ?args, ?id)) {
|
||||
case (ast::expr_spawn(_, _, ?f, ?args)) {
|
||||
check_call(fcx, expr.span, f, args);
|
||||
auto fty = expr_ty(fcx.ccx.tcx, f);
|
||||
auto ret_ty = ty::ret_ty_of_fn_ty(fcx.ccx.tcx, fty);
|
||||
|
@ -1877,7 +1878,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
auto typ = ty::mk_task(fcx.ccx.tcx);
|
||||
write::ty_only_fixup(fcx, id, typ);
|
||||
}
|
||||
case (ast::expr_cast(?e, ?t, ?id)) {
|
||||
case (ast::expr_cast(?e, ?t)) {
|
||||
check_expr(fcx, e);
|
||||
auto t_1 = ast_ty_to_ty_crate(fcx.ccx, t);
|
||||
// FIXME: there are more forms of cast to support, eventually.
|
||||
|
@ -1893,7 +1894,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
write::ty_only_fixup(fcx, id, t_1);
|
||||
}
|
||||
case (ast::expr_vec(?args, ?mut, ?kind, ?id)) {
|
||||
case (ast::expr_vec(?args, ?mut, ?kind)) {
|
||||
let ty::t t;
|
||||
if (vec::len[@ast::expr](args) == 0u) {
|
||||
t = next_ty_var(fcx);
|
||||
|
@ -1917,7 +1918,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
write::ty_only_fixup(fcx, id, typ);
|
||||
}
|
||||
case (ast::expr_tup(?elts, ?id)) {
|
||||
case (ast::expr_tup(?elts)) {
|
||||
let vec[ty::mt] elts_mt = [];
|
||||
for (ast::elt e in elts) {
|
||||
check_expr(fcx, e.expr);
|
||||
|
@ -1927,7 +1928,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
auto typ = ty::mk_tup(fcx.ccx.tcx, elts_mt);
|
||||
write::ty_only_fixup(fcx, id, typ);
|
||||
}
|
||||
case (ast::expr_rec(?fields, ?base, ?id)) {
|
||||
case (ast::expr_rec(?fields, ?base)) {
|
||||
alt (base) {
|
||||
case (none) {/* no-op */ }
|
||||
case (some(?b_0)) { check_expr(fcx, b_0); }
|
||||
|
@ -1977,7 +1978,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
}
|
||||
}
|
||||
case (ast::expr_field(?base, ?field, ?id)) {
|
||||
case (ast::expr_field(?base, ?field)) {
|
||||
check_expr(fcx, base);
|
||||
auto base_t = expr_ty(fcx.ccx.tcx, base);
|
||||
base_t = strip_boxes(fcx, expr.span, base_t);
|
||||
|
@ -2024,7 +2025,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
}
|
||||
}
|
||||
case (ast::expr_index(?base, ?idx, ?id)) {
|
||||
case (ast::expr_index(?base, ?idx)) {
|
||||
check_expr(fcx, base);
|
||||
auto base_t = expr_ty(fcx.ccx.tcx, base);
|
||||
base_t = strip_boxes(fcx, expr.span, base_t);
|
||||
|
@ -2059,12 +2060,12 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
}
|
||||
}
|
||||
case (ast::expr_port(?id)) {
|
||||
case (ast::expr_port) {
|
||||
auto t = next_ty_var(fcx);
|
||||
auto pt = ty::mk_port(fcx.ccx.tcx, t);
|
||||
write::ty_only_fixup(fcx, id, pt);
|
||||
}
|
||||
case (ast::expr_chan(?x, ?id)) {
|
||||
case (ast::expr_chan(?x)) {
|
||||
check_expr(fcx, x);
|
||||
auto port_t = expr_ty(fcx.ccx.tcx, x);
|
||||
alt (structure_of(fcx, expr.span, port_t)) {
|
||||
|
@ -2080,7 +2081,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
|
|||
}
|
||||
}
|
||||
}
|
||||
case (ast::expr_anon_obj(?anon_obj, ?tps, ?obj_def_ids, ?id)) {
|
||||
case (ast::expr_anon_obj(?anon_obj, ?tps, ?obj_def_ids)) {
|
||||
// TODO: We probably need to do more work here to be able to
|
||||
// handle additional methods that use 'self'
|
||||
|
||||
|
|
|
@ -254,121 +254,121 @@ fn visit_exprs[E](vec[@expr] exprs, &E e, &vt[E] v) {
|
|||
|
||||
fn visit_expr[E](&@expr ex, &E e, &vt[E] v) {
|
||||
alt (ex.node) {
|
||||
case (expr_vec(?es, _, _, _)) { visit_exprs(es, e, v); }
|
||||
case (expr_tup(?elts, _)) {
|
||||
case (expr_vec(?es, _, _)) { visit_exprs(es, e, v); }
|
||||
case (expr_tup(?elts)) {
|
||||
for (elt el in elts) { vt(v).visit_expr(el.expr, e, v); }
|
||||
}
|
||||
case (expr_rec(?flds, ?base, _)) {
|
||||
case (expr_rec(?flds, ?base)) {
|
||||
for (field f in flds) { vt(v).visit_expr(f.node.expr, e, v); }
|
||||
visit_expr_opt(base, e, v);
|
||||
}
|
||||
case (expr_call(?callee, ?args, _)) {
|
||||
case (expr_call(?callee, ?args)) {
|
||||
vt(v).visit_expr(callee, e, v);
|
||||
visit_exprs(args, e, v);
|
||||
}
|
||||
case (expr_self_method(_, _)) { }
|
||||
case (expr_bind(?callee, ?args, _)) {
|
||||
case (expr_self_method(_)) { }
|
||||
case (expr_bind(?callee, ?args)) {
|
||||
vt(v).visit_expr(callee, e, v);
|
||||
for (option::t[@expr] eo in args) { visit_expr_opt(eo, e, v); }
|
||||
}
|
||||
case (expr_spawn(_, _, ?callee, ?args, _)) {
|
||||
case (expr_spawn(_, _, ?callee, ?args)) {
|
||||
vt(v).visit_expr(callee, e, v);
|
||||
visit_exprs(args, e, v);
|
||||
}
|
||||
case (expr_binary(_, ?a, ?b, _)) {
|
||||
case (expr_binary(_, ?a, ?b)) {
|
||||
vt(v).visit_expr(a, e, v);
|
||||
vt(v).visit_expr(b, e, v);
|
||||
}
|
||||
case (expr_unary(_, ?a, _)) { vt(v).visit_expr(a, e, v); }
|
||||
case (expr_lit(_, _)) { }
|
||||
case (expr_cast(?x, ?t, _)) {
|
||||
case (expr_unary(_, ?a)) { vt(v).visit_expr(a, e, v); }
|
||||
case (expr_lit(_)) { }
|
||||
case (expr_cast(?x, ?t)) {
|
||||
vt(v).visit_expr(x, e, v);
|
||||
vt(v).visit_ty(t, e, v);
|
||||
}
|
||||
case (expr_if(?x, ?b, ?eo, _)) {
|
||||
case (expr_if(?x, ?b, ?eo)) {
|
||||
vt(v).visit_expr(x, e, v);
|
||||
vt(v).visit_block(b, e, v);
|
||||
visit_expr_opt(eo, e, v);
|
||||
}
|
||||
case (expr_if_check(?x, ?b, ?eo, _)) {
|
||||
case (expr_if_check(?x, ?b, ?eo)) {
|
||||
vt(v).visit_expr(x, e, v);
|
||||
vt(v).visit_block(b, e, v);
|
||||
visit_expr_opt(eo, e, v);
|
||||
}
|
||||
case (expr_while(?x, ?b, _)) {
|
||||
case (expr_while(?x, ?b)) {
|
||||
vt(v).visit_expr(x, e, v);
|
||||
vt(v).visit_block(b, e, v);
|
||||
}
|
||||
case (expr_for(?dcl, ?x, ?b, _)) {
|
||||
case (expr_for(?dcl, ?x, ?b)) {
|
||||
vt(v).visit_local(dcl, e, v);
|
||||
vt(v).visit_expr(x, e, v);
|
||||
vt(v).visit_block(b, e, v);
|
||||
}
|
||||
case (expr_for_each(?dcl, ?x, ?b, _)) {
|
||||
case (expr_for_each(?dcl, ?x, ?b)) {
|
||||
vt(v).visit_local(dcl, e, v);
|
||||
vt(v).visit_expr(x, e, v);
|
||||
vt(v).visit_block(b, e, v);
|
||||
}
|
||||
case (expr_do_while(?b, ?x, _)) {
|
||||
case (expr_do_while(?b, ?x)) {
|
||||
vt(v).visit_block(b, e, v);
|
||||
vt(v).visit_expr(x, e, v);
|
||||
}
|
||||
case (expr_alt(?x, ?arms, _)) {
|
||||
case (expr_alt(?x, ?arms)) {
|
||||
vt(v).visit_expr(x, e, v);
|
||||
for (arm a in arms) { vt(v).visit_arm(a, e, v); }
|
||||
}
|
||||
case (expr_fn(?f, _)) {
|
||||
case (expr_fn(?f)) {
|
||||
visit_fn_decl(f.decl, e, v);
|
||||
vt(v).visit_block(f.body, e, v);
|
||||
}
|
||||
case (expr_block(?b, _)) { vt(v).visit_block(b, e, v); }
|
||||
case (expr_assign(?a, ?b, _)) {
|
||||
case (expr_block(?b)) { vt(v).visit_block(b, e, v); }
|
||||
case (expr_assign(?a, ?b)) {
|
||||
vt(v).visit_expr(b, e, v);
|
||||
vt(v).visit_expr(a, e, v);
|
||||
}
|
||||
case (expr_move(?a, ?b, _)) {
|
||||
case (expr_move(?a, ?b)) {
|
||||
vt(v).visit_expr(b, e, v);
|
||||
vt(v).visit_expr(a, e, v);
|
||||
}
|
||||
case (expr_swap(?a, ?b, _)) {
|
||||
case (expr_swap(?a, ?b)) {
|
||||
vt(v).visit_expr(a, e, v);
|
||||
vt(v).visit_expr(b, e, v);
|
||||
}
|
||||
case (expr_assign_op(_, ?a, ?b, _)) {
|
||||
case (expr_assign_op(_, ?a, ?b)) {
|
||||
vt(v).visit_expr(b, e, v);
|
||||
vt(v).visit_expr(a, e, v);
|
||||
}
|
||||
case (expr_send(?a, ?b, _)) {
|
||||
case (expr_send(?a, ?b)) {
|
||||
vt(v).visit_expr(a, e, v);
|
||||
vt(v).visit_expr(b, e, v);
|
||||
}
|
||||
case (expr_recv(?a, ?b, _)) {
|
||||
case (expr_recv(?a, ?b)) {
|
||||
vt(v).visit_expr(a, e, v);
|
||||
vt(v).visit_expr(b, e, v);
|
||||
}
|
||||
case (expr_field(?x, _, _)) { vt(v).visit_expr(x, e, v); }
|
||||
case (expr_index(?a, ?b, _)) {
|
||||
case (expr_field(?x, _)) { vt(v).visit_expr(x, e, v); }
|
||||
case (expr_index(?a, ?b)) {
|
||||
vt(v).visit_expr(a, e, v);
|
||||
vt(v).visit_expr(b, e, v);
|
||||
}
|
||||
case (expr_path(?p, _)) {
|
||||
case (expr_path(?p)) {
|
||||
for (@ty tp in p.node.types) { vt(v).visit_ty(tp, e, v); }
|
||||
}
|
||||
case (expr_ext(_, _, _, ?expansion, _)) {
|
||||
case (expr_ext(_, _, _, ?expansion)) {
|
||||
vt(v).visit_expr(expansion, e, v);
|
||||
}
|
||||
case (expr_fail(_, _)) { }
|
||||
case (expr_break(_)) { }
|
||||
case (expr_cont(_)) { }
|
||||
case (expr_ret(?eo, _)) { visit_expr_opt(eo, e, v); }
|
||||
case (expr_put(?eo, _)) { visit_expr_opt(eo, e, v); }
|
||||
case (expr_be(?x, _)) { vt(v).visit_expr(x, e, v); }
|
||||
case (expr_log(_, ?x, _)) { vt(v).visit_expr(x, e, v); }
|
||||
case (expr_check(?x, _)) { vt(v).visit_expr(x, e, v); }
|
||||
case (expr_assert(?x, _)) { vt(v).visit_expr(x, e, v); }
|
||||
case (expr_port(_)) { }
|
||||
case (expr_chan(?x, _)) { vt(v).visit_expr(x, e, v); }
|
||||
case (expr_anon_obj(?anon_obj, _, _, _)) {
|
||||
case (expr_fail(_)) { }
|
||||
case (expr_break) { }
|
||||
case (expr_cont) { }
|
||||
case (expr_ret(?eo)) { visit_expr_opt(eo, e, v); }
|
||||
case (expr_put(?eo)) { visit_expr_opt(eo, e, v); }
|
||||
case (expr_be(?x)) { vt(v).visit_expr(x, e, v); }
|
||||
case (expr_log(_, ?x)) { vt(v).visit_expr(x, e, v); }
|
||||
case (expr_check(?x)) { vt(v).visit_expr(x, e, v); }
|
||||
case (expr_assert(?x)) { vt(v).visit_expr(x, e, v); }
|
||||
case (expr_port) { }
|
||||
case (expr_chan(?x)) { vt(v).visit_expr(x, e, v); }
|
||||
case (expr_anon_obj(?anon_obj, _, _)) {
|
||||
alt (anon_obj.fields) {
|
||||
case (none) { }
|
||||
case (some(?fields)) {
|
||||
|
|
|
@ -269,64 +269,64 @@ fn walk_expr(&ast_visitor v, @ast::expr e) {
|
|||
if (!v.keep_going()) { ret; }
|
||||
v.visit_expr_pre(e);
|
||||
alt (e.node) {
|
||||
case (ast::expr_vec(?es, _, _, _)) { walk_exprs(v, es); }
|
||||
case (ast::expr_tup(?elts, _)) {
|
||||
case (ast::expr_vec(?es, _, _)) { walk_exprs(v, es); }
|
||||
case (ast::expr_tup(?elts)) {
|
||||
for (ast::elt e in elts) { walk_expr(v, e.expr); }
|
||||
}
|
||||
case (ast::expr_rec(?flds, ?base, _)) {
|
||||
case (ast::expr_rec(?flds, ?base)) {
|
||||
for (ast::field f in flds) { walk_expr(v, f.node.expr); }
|
||||
walk_expr_opt(v, base);
|
||||
}
|
||||
case (ast::expr_call(?callee, ?args, _)) {
|
||||
case (ast::expr_call(?callee, ?args)) {
|
||||
walk_expr(v, callee);
|
||||
walk_exprs(v, args);
|
||||
}
|
||||
case (ast::expr_self_method(_, _)) { }
|
||||
case (ast::expr_bind(?callee, ?args, _)) {
|
||||
case (ast::expr_self_method(_)) { }
|
||||
case (ast::expr_bind(?callee, ?args)) {
|
||||
walk_expr(v, callee);
|
||||
for (option::t[@ast::expr] eo in args) { walk_expr_opt(v, eo); }
|
||||
}
|
||||
case (ast::expr_spawn(_, _, ?callee, ?args, _)) {
|
||||
case (ast::expr_spawn(_, _, ?callee, ?args)) {
|
||||
walk_expr(v, callee);
|
||||
walk_exprs(v, args);
|
||||
}
|
||||
case (ast::expr_binary(_, ?a, ?b, _)) {
|
||||
case (ast::expr_binary(_, ?a, ?b)) {
|
||||
walk_expr(v, a);
|
||||
walk_expr(v, b);
|
||||
}
|
||||
case (ast::expr_unary(_, ?a, _)) { walk_expr(v, a); }
|
||||
case (ast::expr_lit(_, _)) { }
|
||||
case (ast::expr_cast(?x, ?t, _)) { walk_expr(v, x); walk_ty(v, t); }
|
||||
case (ast::expr_if(?x, ?b, ?eo, _)) {
|
||||
case (ast::expr_unary(_, ?a)) { walk_expr(v, a); }
|
||||
case (ast::expr_lit(_)) { }
|
||||
case (ast::expr_cast(?x, ?t)) { walk_expr(v, x); walk_ty(v, t); }
|
||||
case (ast::expr_if(?x, ?b, ?eo)) {
|
||||
walk_expr(v, x);
|
||||
walk_block(v, b);
|
||||
walk_expr_opt(v, eo);
|
||||
}
|
||||
case (ast::expr_if_check(?x, ?b, ?eo, _)) {
|
||||
case (ast::expr_if_check(?x, ?b, ?eo)) {
|
||||
walk_expr(v, x);
|
||||
walk_block(v, b);
|
||||
walk_expr_opt(v, eo);
|
||||
}
|
||||
|
||||
case (ast::expr_while(?x, ?b, _)) {
|
||||
case (ast::expr_while(?x, ?b)) {
|
||||
walk_expr(v, x);
|
||||
walk_block(v, b);
|
||||
}
|
||||
case (ast::expr_for(?dcl, ?x, ?b, _)) {
|
||||
case (ast::expr_for(?dcl, ?x, ?b)) {
|
||||
walk_local(v, dcl);
|
||||
walk_expr(v, x);
|
||||
walk_block(v, b);
|
||||
}
|
||||
case (ast::expr_for_each(?dcl, ?x, ?b, _)) {
|
||||
case (ast::expr_for_each(?dcl, ?x, ?b)) {
|
||||
walk_local(v, dcl);
|
||||
walk_expr(v, x);
|
||||
walk_block(v, b);
|
||||
}
|
||||
case (ast::expr_do_while(?b, ?x, _)) {
|
||||
case (ast::expr_do_while(?b, ?x)) {
|
||||
walk_block(v, b);
|
||||
walk_expr(v, x);
|
||||
}
|
||||
case (ast::expr_alt(?x, ?arms, _)) {
|
||||
case (ast::expr_alt(?x, ?arms)) {
|
||||
walk_expr(v, x);
|
||||
for (ast::arm a in arms) {
|
||||
walk_pat(v, a.pat);
|
||||
|
@ -335,48 +335,48 @@ fn walk_expr(&ast_visitor v, @ast::expr e) {
|
|||
v.visit_arm_post(a);
|
||||
}
|
||||
}
|
||||
case (ast::expr_fn(?f, ?a)) {
|
||||
case (ast::expr_fn(?f)) {
|
||||
walk_fn_decl(v, f.decl);
|
||||
walk_block(v, f.body);
|
||||
}
|
||||
case (ast::expr_block(?b, _)) { walk_block(v, b); }
|
||||
case (ast::expr_assign(?a, ?b, _)) {
|
||||
case (ast::expr_block(?b)) { walk_block(v, b); }
|
||||
case (ast::expr_assign(?a, ?b)) {
|
||||
walk_expr(v, a);
|
||||
walk_expr(v, b);
|
||||
}
|
||||
case (ast::expr_move(?a, ?b, _)) { walk_expr(v, a); walk_expr(v, b); }
|
||||
case (ast::expr_swap(?a, ?b, _)) { walk_expr(v, a); walk_expr(v, b); }
|
||||
case (ast::expr_assign_op(_, ?a, ?b, _)) {
|
||||
case (ast::expr_move(?a, ?b)) { walk_expr(v, a); walk_expr(v, b); }
|
||||
case (ast::expr_swap(?a, ?b)) { walk_expr(v, a); walk_expr(v, b); }
|
||||
case (ast::expr_assign_op(_, ?a, ?b)) {
|
||||
walk_expr(v, a);
|
||||
walk_expr(v, b);
|
||||
}
|
||||
case (ast::expr_send(?a, ?b, _)) { walk_expr(v, a); walk_expr(v, b); }
|
||||
case (ast::expr_recv(?a, ?b, _)) { walk_expr(v, a); walk_expr(v, b); }
|
||||
case (ast::expr_field(?x, _, _)) { walk_expr(v, x); }
|
||||
case (ast::expr_index(?a, ?b, _)) {
|
||||
case (ast::expr_send(?a, ?b)) { walk_expr(v, a); walk_expr(v, b); }
|
||||
case (ast::expr_recv(?a, ?b)) { walk_expr(v, a); walk_expr(v, b); }
|
||||
case (ast::expr_field(?x, _)) { walk_expr(v, x); }
|
||||
case (ast::expr_index(?a, ?b)) {
|
||||
walk_expr(v, a);
|
||||
walk_expr(v, b);
|
||||
}
|
||||
case (ast::expr_path(?p, _)) {
|
||||
case (ast::expr_path(?p)) {
|
||||
for (@ast::ty tp in p.node.types) { walk_ty(v, tp); }
|
||||
}
|
||||
case (ast::expr_ext(_, ?args, ?body, ?expansion, _)) {
|
||||
case (ast::expr_ext(_, ?args, ?body, ?expansion)) {
|
||||
// Only walk expansion, not args/body.
|
||||
|
||||
walk_expr(v, expansion);
|
||||
}
|
||||
case (ast::expr_fail(_, _)) { }
|
||||
case (ast::expr_break(_)) { }
|
||||
case (ast::expr_cont(_)) { }
|
||||
case (ast::expr_ret(?eo, _)) { walk_expr_opt(v, eo); }
|
||||
case (ast::expr_put(?eo, _)) { walk_expr_opt(v, eo); }
|
||||
case (ast::expr_be(?x, _)) { walk_expr(v, x); }
|
||||
case (ast::expr_log(_, ?x, _)) { walk_expr(v, x); }
|
||||
case (ast::expr_check(?x, _)) { walk_expr(v, x); }
|
||||
case (ast::expr_assert(?x, _)) { walk_expr(v, x); }
|
||||
case (ast::expr_port(_)) { }
|
||||
case (ast::expr_chan(?x, _)) { walk_expr(v, x); }
|
||||
case (ast::expr_anon_obj(?anon_obj, _, _, _)) {
|
||||
case (ast::expr_fail(_)) { }
|
||||
case (ast::expr_break) { }
|
||||
case (ast::expr_cont) { }
|
||||
case (ast::expr_ret(?eo)) { walk_expr_opt(v, eo); }
|
||||
case (ast::expr_put(?eo)) { walk_expr_opt(v, eo); }
|
||||
case (ast::expr_be(?x)) { walk_expr(v, x); }
|
||||
case (ast::expr_log(_, ?x)) { walk_expr(v, x); }
|
||||
case (ast::expr_check(?x)) { walk_expr(v, x); }
|
||||
case (ast::expr_assert(?x)) { walk_expr(v, x); }
|
||||
case (ast::expr_port) { }
|
||||
case (ast::expr_chan(?x)) { walk_expr(v, x); }
|
||||
case (ast::expr_anon_obj(?anon_obj, _, _)) {
|
||||
// Fields
|
||||
|
||||
let option::t[vec[ast::obj_field]] fields =
|
||||
|
|
|
@ -519,9 +519,8 @@ fn print_if(&ps s, &@ast::expr test, &ast::block block,
|
|||
alt (els) {
|
||||
case (some(?_else)) {
|
||||
alt (_else.node) {
|
||||
case (
|
||||
// "another else-if"
|
||||
ast::expr_if(?i, ?t, ?e, _)) {
|
||||
case (ast::expr_if(?i, ?t, ?e)) {
|
||||
cbox(s, indent_unit - 1u);
|
||||
ibox(s, 0u);
|
||||
word(s.s, " else if ");
|
||||
|
@ -532,9 +531,8 @@ fn print_if(&ps s, &@ast::expr test, &ast::block block,
|
|||
print_block(s, t);
|
||||
do_else(s, e);
|
||||
}
|
||||
case (
|
||||
// "final else"
|
||||
ast::expr_block(?b, _)) {
|
||||
case (ast::expr_block(?b)) {
|
||||
cbox(s, indent_unit - 1u);
|
||||
ibox(s, 0u);
|
||||
word(s.s, " else ");
|
||||
|
@ -557,7 +555,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
|||
case (mo_identified) { popen(s); }
|
||||
}
|
||||
alt (expr.node) {
|
||||
case (ast::expr_vec(?exprs, ?mut, ?kind, _)) {
|
||||
case (ast::expr_vec(?exprs, ?mut, ?kind)) {
|
||||
ibox(s, indent_unit);
|
||||
alt (kind) {
|
||||
case (ast::sk_rc) { word(s.s, "["); }
|
||||
|
@ -568,7 +566,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
|||
word(s.s, "]");
|
||||
end(s);
|
||||
}
|
||||
case (ast::expr_tup(?exprs, _)) {
|
||||
case (ast::expr_tup(?exprs)) {
|
||||
fn printElt(&ps s, &ast::elt elt) {
|
||||
ibox(s, indent_unit);
|
||||
if (elt.mut == ast::mut) { word_nbsp(s, "mutable"); }
|
||||
|
@ -581,7 +579,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
|||
commasep_cmnt(s, inconsistent, exprs, printElt, get_span);
|
||||
pclose(s);
|
||||
}
|
||||
case (ast::expr_rec(?fields, ?wth, _)) {
|
||||
case (ast::expr_rec(?fields, ?wth)) {
|
||||
fn print_field(&ps s, &ast::field field) {
|
||||
ibox(s, indent_unit);
|
||||
if (field.node.mut == ast::mut) { word_nbsp(s, "mutable"); }
|
||||
|
@ -606,17 +604,17 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
|||
}
|
||||
pclose(s);
|
||||
}
|
||||
case (ast::expr_call(?func, ?args, _)) {
|
||||
case (ast::expr_call(?func, ?args)) {
|
||||
print_expr(s, func);
|
||||
popen(s);
|
||||
commasep_exprs(s, inconsistent, args);
|
||||
pclose(s);
|
||||
}
|
||||
case (ast::expr_self_method(?ident, _)) {
|
||||
case (ast::expr_self_method(?ident)) {
|
||||
word(s.s, "self.");
|
||||
print_ident(s, ident);
|
||||
}
|
||||
case (ast::expr_bind(?func, ?args, _)) {
|
||||
case (ast::expr_bind(?func, ?args)) {
|
||||
fn print_opt(&ps s, &option::t[@ast::expr] expr) {
|
||||
alt (expr) {
|
||||
case (some(?expr)) { print_expr(s, expr); }
|
||||
|
@ -629,38 +627,38 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
|||
commasep(s, inconsistent, args, print_opt);
|
||||
pclose(s);
|
||||
}
|
||||
case (ast::expr_spawn(_, _, ?e, ?es, _)) {
|
||||
case (ast::expr_spawn(_, _, ?e, ?es)) {
|
||||
word_nbsp(s, "spawn");
|
||||
print_expr(s, e);
|
||||
popen(s);
|
||||
commasep_exprs(s, inconsistent, es);
|
||||
pclose(s);
|
||||
}
|
||||
case (ast::expr_binary(?op, ?lhs, ?rhs, _)) {
|
||||
case (ast::expr_binary(?op, ?lhs, ?rhs)) {
|
||||
auto prec = operator_prec(op);
|
||||
print_maybe_parens(s, lhs, prec);
|
||||
space(s.s);
|
||||
word_space(s, ast::binop_to_str(op));
|
||||
print_maybe_parens(s, rhs, prec + 1);
|
||||
}
|
||||
case (ast::expr_unary(?op, ?expr, _)) {
|
||||
case (ast::expr_unary(?op, ?expr)) {
|
||||
word(s.s, ast::unop_to_str(op));
|
||||
print_maybe_parens(s, expr, front::parser::unop_prec);
|
||||
}
|
||||
case (ast::expr_lit(?lit, _)) { print_literal(s, lit); }
|
||||
case (ast::expr_cast(?expr, ?ty, _)) {
|
||||
case (ast::expr_lit(?lit)) { print_literal(s, lit); }
|
||||
case (ast::expr_cast(?expr, ?ty)) {
|
||||
print_maybe_parens(s, expr, front::parser::as_prec);
|
||||
space(s.s);
|
||||
word_space(s, "as");
|
||||
print_type(s, *ty);
|
||||
}
|
||||
case (ast::expr_if(?test, ?block, ?elseopt, _)) {
|
||||
case (ast::expr_if(?test, ?block, ?elseopt)) {
|
||||
print_if(s, test, block, elseopt, false);
|
||||
}
|
||||
case (ast::expr_if_check(?test, ?block, ?elseopt, _)) {
|
||||
case (ast::expr_if_check(?test, ?block, ?elseopt)) {
|
||||
print_if(s, test, block, elseopt, true);
|
||||
}
|
||||
case (ast::expr_while(?test, ?block, _)) {
|
||||
case (ast::expr_while(?test, ?block)) {
|
||||
head(s, "while");
|
||||
popen(s);
|
||||
print_expr(s, test);
|
||||
|
@ -668,7 +666,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
|||
space(s.s);
|
||||
print_block(s, block);
|
||||
}
|
||||
case (ast::expr_for(?decl, ?expr, ?block, _)) {
|
||||
case (ast::expr_for(?decl, ?expr, ?block)) {
|
||||
head(s, "for");
|
||||
popen(s);
|
||||
print_for_decl(s, decl);
|
||||
|
@ -679,7 +677,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
|||
space(s.s);
|
||||
print_block(s, block);
|
||||
}
|
||||
case (ast::expr_for_each(?decl, ?expr, ?block, _)) {
|
||||
case (ast::expr_for_each(?decl, ?expr, ?block)) {
|
||||
head(s, "for each");
|
||||
popen(s);
|
||||
print_for_decl(s, decl);
|
||||
|
@ -690,7 +688,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
|||
space(s.s);
|
||||
print_block(s, block);
|
||||
}
|
||||
case (ast::expr_do_while(?block, ?expr, _)) {
|
||||
case (ast::expr_do_while(?block, ?expr)) {
|
||||
head(s, "do");
|
||||
space(s.s);
|
||||
print_block(s, block);
|
||||
|
@ -700,7 +698,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
|||
print_expr(s, expr);
|
||||
pclose(s);
|
||||
}
|
||||
case (ast::expr_alt(?expr, ?arms, _)) {
|
||||
case (ast::expr_alt(?expr, ?arms)) {
|
||||
head(s, "alt");
|
||||
popen(s);
|
||||
print_expr(s, expr);
|
||||
|
@ -718,13 +716,13 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
|||
}
|
||||
bclose(s, expr.span);
|
||||
}
|
||||
case (ast::expr_fn(?f, _)) {
|
||||
case (ast::expr_fn(?f)) {
|
||||
head(s, "fn");
|
||||
print_fn_args_and_ret(s, f.decl);
|
||||
space(s.s);
|
||||
print_block(s, f.body);
|
||||
}
|
||||
case (ast::expr_block(?block, _)) {
|
||||
case (ast::expr_block(?block)) {
|
||||
// containing cbox, will be closed by print-block at }
|
||||
|
||||
cbox(s, indent_unit);
|
||||
|
@ -733,103 +731,103 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
|||
ibox(s, 0u);
|
||||
print_block(s, block);
|
||||
}
|
||||
case (ast::expr_move(?lhs, ?rhs, _)) {
|
||||
case (ast::expr_move(?lhs, ?rhs)) {
|
||||
print_expr(s, lhs);
|
||||
space(s.s);
|
||||
word_space(s, "<-");
|
||||
print_expr(s, rhs);
|
||||
}
|
||||
case (ast::expr_assign(?lhs, ?rhs, _)) {
|
||||
case (ast::expr_assign(?lhs, ?rhs)) {
|
||||
print_expr(s, lhs);
|
||||
space(s.s);
|
||||
word_space(s, "=");
|
||||
print_expr(s, rhs);
|
||||
}
|
||||
case (ast::expr_swap(?lhs, ?rhs, _)) {
|
||||
case (ast::expr_swap(?lhs, ?rhs)) {
|
||||
print_expr(s, lhs);
|
||||
space(s.s);
|
||||
word_space(s, "<->");
|
||||
print_expr(s, rhs);
|
||||
}
|
||||
case (ast::expr_assign_op(?op, ?lhs, ?rhs, _)) {
|
||||
case (ast::expr_assign_op(?op, ?lhs, ?rhs)) {
|
||||
print_expr(s, lhs);
|
||||
space(s.s);
|
||||
word(s.s, ast::binop_to_str(op));
|
||||
word_space(s, "=");
|
||||
print_expr(s, rhs);
|
||||
}
|
||||
case (ast::expr_send(?lhs, ?rhs, _)) {
|
||||
case (ast::expr_send(?lhs, ?rhs)) {
|
||||
print_expr(s, lhs);
|
||||
space(s.s);
|
||||
word_space(s, "<|");
|
||||
print_expr(s, rhs);
|
||||
}
|
||||
case (ast::expr_recv(?lhs, ?rhs, _)) {
|
||||
case (ast::expr_recv(?lhs, ?rhs)) {
|
||||
print_expr(s, lhs);
|
||||
space(s.s);
|
||||
word_space(s, "|>");
|
||||
print_expr(s, rhs);
|
||||
}
|
||||
case (ast::expr_field(?expr, ?id, _)) {
|
||||
case (ast::expr_field(?expr, ?id)) {
|
||||
print_expr(s, expr);
|
||||
word(s.s, ".");
|
||||
word(s.s, id);
|
||||
}
|
||||
case (ast::expr_index(?expr, ?index, _)) {
|
||||
case (ast::expr_index(?expr, ?index)) {
|
||||
print_expr(s, expr);
|
||||
word(s.s, ".");
|
||||
popen(s);
|
||||
print_expr(s, index);
|
||||
pclose(s);
|
||||
}
|
||||
case (ast::expr_path(?path, _)) { print_path(s, path); }
|
||||
case (ast::expr_fail(_, ?str)) {
|
||||
case (ast::expr_path(?path)) { print_path(s, path); }
|
||||
case (ast::expr_fail(?str)) {
|
||||
word(s.s, "fail");
|
||||
alt (str) {
|
||||
case (some(?msg)) { word(s.s, #fmt("\"%s\"", msg)); }
|
||||
case (_) { }
|
||||
}
|
||||
}
|
||||
case (ast::expr_break(_)) { word(s.s, "break"); }
|
||||
case (ast::expr_cont(_)) { word(s.s, "cont"); }
|
||||
case (ast::expr_ret(?result, _)) {
|
||||
case (ast::expr_break) { word(s.s, "break"); }
|
||||
case (ast::expr_cont) { word(s.s, "cont"); }
|
||||
case (ast::expr_ret(?result)) {
|
||||
word(s.s, "ret");
|
||||
alt (result) {
|
||||
case (some(?expr)) { word(s.s, " "); print_expr(s, expr); }
|
||||
case (_) { }
|
||||
}
|
||||
}
|
||||
case (ast::expr_put(?result, _)) {
|
||||
case (ast::expr_put(?result)) {
|
||||
word(s.s, "put");
|
||||
alt (result) {
|
||||
case (some(?expr)) { word(s.s, " "); print_expr(s, expr); }
|
||||
case (_) { }
|
||||
}
|
||||
}
|
||||
case (ast::expr_be(?result, _)) {
|
||||
case (ast::expr_be(?result)) {
|
||||
word_nbsp(s, "be");
|
||||
print_expr(s, result);
|
||||
}
|
||||
case (ast::expr_log(?lvl, ?expr, _)) {
|
||||
case (ast::expr_log(?lvl, ?expr)) {
|
||||
alt (lvl) {
|
||||
case (1) { word_nbsp(s, "log"); }
|
||||
case (0) { word_nbsp(s, "log_err"); }
|
||||
}
|
||||
print_expr(s, expr);
|
||||
}
|
||||
case (ast::expr_check(?expr, _)) {
|
||||
case (ast::expr_check(?expr)) {
|
||||
word_nbsp(s, "check");
|
||||
popen(s);
|
||||
print_expr(s, expr);
|
||||
pclose(s);
|
||||
}
|
||||
case (ast::expr_assert(?expr, _)) {
|
||||
case (ast::expr_assert(?expr)) {
|
||||
word_nbsp(s, "assert");
|
||||
popen(s);
|
||||
print_expr(s, expr);
|
||||
pclose(s);
|
||||
}
|
||||
case (ast::expr_ext(?path, ?args, ?body, _, _)) {
|
||||
case (ast::expr_ext(?path, ?args, ?body, _)) {
|
||||
word(s.s, "#");
|
||||
print_path(s, path);
|
||||
if (vec::len(args) > 0u) {
|
||||
|
@ -840,14 +838,14 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
|||
// FIXME: extension 'body'
|
||||
|
||||
}
|
||||
case (ast::expr_port(_)) { word(s.s, "port"); popen(s); pclose(s); }
|
||||
case (ast::expr_chan(?expr, _)) {
|
||||
case (ast::expr_port) { word(s.s, "port"); popen(s); pclose(s); }
|
||||
case (ast::expr_chan(?expr)) {
|
||||
word(s.s, "chan");
|
||||
popen(s);
|
||||
print_expr(s, expr);
|
||||
pclose(s);
|
||||
}
|
||||
case (ast::expr_anon_obj(_, _, _, _)) {
|
||||
case (ast::expr_anon_obj(_, _, _)) {
|
||||
word(s.s, "anon obj");
|
||||
// FIXME (issue #499): nicer pretty-printing of anon objs
|
||||
|
||||
|
@ -866,7 +864,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
|||
}
|
||||
case (mo_identified) {
|
||||
space(s.s);
|
||||
synth_comment(s, int::to_str(ty::expr_node_id(expr), 10u));
|
||||
synth_comment(s, int::to_str(expr.id, 10u));
|
||||
pclose(s);
|
||||
}
|
||||
}
|
||||
|
@ -1085,10 +1083,10 @@ fn operator_prec(ast::binop op) -> int {
|
|||
fn print_maybe_parens(&ps s, &@ast::expr expr, int outer_prec) {
|
||||
auto add_them;
|
||||
alt (expr.node) {
|
||||
case (ast::expr_binary(?op, _, _, _)) {
|
||||
case (ast::expr_binary(?op, _, _)) {
|
||||
add_them = operator_prec(op) < outer_prec;
|
||||
}
|
||||
case (ast::expr_cast(_, _, _)) {
|
||||
case (ast::expr_cast(_, _)) {
|
||||
add_them = front::parser::as_prec < outer_prec;
|
||||
}
|
||||
case (_) { add_them = false; }
|
||||
|
|
|
@ -152,8 +152,8 @@ fn has_nonlocal_exits(&ast::block b) -> bool {
|
|||
auto has_exits = @mutable false;
|
||||
fn visit_expr(@mutable bool flag, &@ast::expr e) {
|
||||
alt (e.node) {
|
||||
case (ast::expr_break(_)) { *flag = true; }
|
||||
case (ast::expr_cont(_)) { *flag = true; }
|
||||
case (ast::expr_break) { *flag = true; }
|
||||
case (ast::expr_cont) { *flag = true; }
|
||||
case (_) { }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue