diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 4aa71743e92..acf64c1b183 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -259,14 +259,15 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] { // FIXME: can only remove this sort of thing when both typestate and // alt-exhaustive-match checking are co-operating. - let ast.expr_ ex = ast.expr_lit(@spanned(lo, lo, ast.lit_nil)); + auto lit = @spanned(lo, lo, ast.lit_nil); + let ast.expr_ ex = ast.expr_lit(lit, none[@ast.ty]); alt (p.peek()) { case (token.IDENT(?i)) { auto n = parse_name(p, i); hi = n.span; - ex = ast.expr_name(n, none[ast.def]); + ex = ast.expr_name(n, none[ast.def], none[@ast.ty]); } case (token.LPAREN) { @@ -285,7 +286,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] { some(token.COMMA), pf, p); hi = es.span; - ex = ast.expr_tup(es.node); + ex = ast.expr_tup(es.node, none[@ast.ty]); } case (token.VEC) { @@ -296,7 +297,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] { some(token.COMMA), pf, p); hi = es.span; - ex = ast.expr_vec(es.node); + ex = ast.expr_vec(es.node, none[@ast.ty]); } case (token.REC) { @@ -315,14 +316,14 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] { some(token.COMMA), pf, p); hi = es.span; - ex = ast.expr_rec(es.node); + ex = ast.expr_rec(es.node, none[@ast.ty]); } case (_) { alt (parse_lit(p)) { case (some[ast.lit](?lit)) { hi = lit.span; - ex = ast.expr_lit(@lit); + ex = ast.expr_lit(@lit, none[@ast.ty]); } case (none[ast.lit]) { p.err("expecting expression"); @@ -347,13 +348,15 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] { case (token.IDENT(?i)) { hi = p.get_span(); p.bump(); - e = @spanned(lo, hi, ast.expr_field(e, i)); + auto e_ = ast.expr_field(e, i, none[@ast.ty]); + e = @spanned(lo, hi, e_); } case (token.LPAREN) { auto ix = parse_bottom_expr(p); hi = ix.span; - e = @spanned(lo, hi, ast.expr_index(e, ix)); + auto e_ = ast.expr_index(e, ix, none[@ast.ty]); + e = @spanned(lo, hi, e_); } } } @@ -372,7 +375,8 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] { // FIXME: can only remove this sort of thing when both typestate and // alt-exhaustive-match checking are co-operating. - let ast.expr_ ex = ast.expr_lit(@spanned(lo, lo, ast.lit_nil)); + auto lit = @spanned(lo, lo, ast.lit_nil); + let ast.expr_ ex = ast.expr_lit(lit, none[@ast.ty]); alt (p.peek()) { @@ -380,14 +384,14 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] { p.bump(); auto e = parse_prefix_expr(p); hi = e.span; - ex = ast.expr_unary(ast.not, e); + ex = ast.expr_unary(ast.not, e, none[@ast.ty]); } case (token.TILDE) { p.bump(); auto e = parse_prefix_expr(p); hi = e.span; - ex = ast.expr_unary(ast.bitnot, e); + ex = ast.expr_unary(ast.bitnot, e, none[@ast.ty]); } case (token.BINOP(?b)) { @@ -396,14 +400,14 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] { p.bump(); auto e = parse_prefix_expr(p); hi = e.span; - ex = ast.expr_unary(ast.neg, e); + ex = ast.expr_unary(ast.neg, e, none[@ast.ty]); } case (token.STAR) { p.bump(); auto e = parse_prefix_expr(p); hi = e.span; - ex = ast.expr_unary(ast.deref, e); + ex = ast.expr_unary(ast.deref, e, none[@ast.ty]); } case (_) { @@ -416,7 +420,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] { p.bump(); auto e = parse_prefix_expr(p); hi = e.span; - ex = ast.expr_unary(ast.box, e); + ex = ast.expr_unary(ast.box, e, none[@ast.ty]); } case (_) { @@ -443,7 +447,8 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] { p.bump(); auto rhs = sub(p); hi = rhs.span; - auto exp = ast.expr_binary(pair._1, e, rhs); + auto exp = ast.expr_binary(pair._1, e, rhs, + none[@ast.ty]); e = @spanned(lo, hi, exp); more = true; } @@ -469,7 +474,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] { p.bump(); auto rhs = sub(p); hi = rhs.span; - auto exp = ast.expr_binary(pair._1, e, rhs); + auto exp = ast.expr_binary(pair._1, e, rhs, none[@ast.ty]); e = @spanned(lo, hi, exp); more = true; } @@ -578,7 +583,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] { hi = eblk.span; } } - ret @spanned(lo, hi, ast.expr_if(cond, thn, els)); + ret @spanned(lo, hi, ast.expr_if(cond, thn, els, none[@ast.ty])); } io fn parse_expr(parser p) -> @ast.expr { @@ -586,7 +591,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] { case (token.LBRACE) { auto blk = parse_block(p); ret @spanned(blk.span, blk.span, - ast.expr_block(blk)); + ast.expr_block(blk, none[@ast.ty])); } case (token.IF) { ret parse_if_expr(p); diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index a3a356912a9..81bbffeb3ee 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -106,7 +106,7 @@ &ast.local local) -> @decl) fold_decl_local, (fn(&ENV e, &span sp, - @item item, option[@ty] ty) -> @decl) fold_decl_item, + @item item) -> @decl) fold_decl_item, // Stmt folds. @@ -278,49 +278,49 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr { } alt (e.node) { - case (ast.expr_vec(?es)) { + case (ast.expr_vec(?es, ?t)) { auto ees = fold_exprs(env_, fld, es); - ret fld.fold_expr_vec(env_, e.span, ees); + ret fld.fold_expr_vec(env_, e.span, ees, t); } - case (ast.expr_tup(?es)) { + case (ast.expr_tup(?es, ?t)) { let vec[tup(bool,@expr)] entries = vec(); for (tup(bool,@expr) entry in es) { entries += fold_tup_entry[ENV](env, fld, entry); } - ret fld.fold_expr_tup(env_, e.span, entries); + ret fld.fold_expr_tup(env_, e.span, entries, t); } - case (ast.expr_rec(?es)) { + case (ast.expr_rec(?es, ?t)) { let vec[tup(ident,@expr)] entries = vec(); for (tup(ident,@expr) entry in es) { entries += fold_rec_entry(env, fld, entry); } - ret fld.fold_expr_rec(env_, e.span, entries); + ret fld.fold_expr_rec(env_, e.span, entries, t); } - case (ast.expr_call(?f, ?args)) { + case (ast.expr_call(?f, ?args, ?t)) { auto ff = fold_expr(env_, fld, f); auto aargs = fold_exprs(env_, fld, args); - ret fld.fold_expr_call(env_, e.span, ff, aargs); + ret fld.fold_expr_call(env_, e.span, ff, aargs, t); } - case (ast.expr_binary(?op, ?a, ?b)) { + case (ast.expr_binary(?op, ?a, ?b, ?t)) { auto aa = fold_expr(env_, fld, a); auto bb = fold_expr(env_, fld, b); - ret fld.fold_expr_binary(env_, e.span, op, aa, bb); + ret fld.fold_expr_binary(env_, e.span, op, aa, bb, t); } - case (ast.expr_unary(?op, ?a)) { + case (ast.expr_unary(?op, ?a, ?t)) { auto aa = fold_expr(env_, fld, a); - ret fld.fold_expr_unary(env_, e.span, op, a); + ret fld.fold_expr_unary(env_, e.span, op, a, t); } - case (ast.expr_lit(?lit)) { - ret fld.fold_expr_lit(env_, e.span, lit); + case (ast.expr_lit(?lit, ?t)) { + ret fld.fold_expr_lit(env_, e.span, lit, t); } - case (ast.expr_if(?cnd, ?thn, ?els)) { + case (ast.expr_if(?cnd, ?thn, ?els, ?t)) { auto ccnd = fold_expr(env_, fld, cnd); auto tthn = fold_block(env_, fld, thn); auto eels = none[block]; @@ -329,34 +329,34 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr { eels = some(fold_block(env_, fld, b)); } } - ret fld.fold_expr_if(env_, e.span, ccnd, tthn, eels); + ret fld.fold_expr_if(env_, e.span, ccnd, tthn, eels, t); } - case (ast.expr_block(?b)) { + case (ast.expr_block(?b, ?t)) { auto bb = fold_block(env_, fld, b); - ret fld.fold_expr_block(env_, e.span, bb); + ret fld.fold_expr_block(env_, e.span, bb, t); } - case (ast.expr_assign(?lhs, ?rhs)) { + case (ast.expr_assign(?lhs, ?rhs, ?t)) { auto llhs = fold_expr(env_, fld, lhs); auto rrhs = fold_expr(env_, fld, rhs); - ret fld.fold_expr_assign(env_, e.span, llhs, rrhs); + ret fld.fold_expr_assign(env_, e.span, llhs, rrhs, t); } - case (ast.expr_field(?e, ?i)) { + case (ast.expr_field(?e, ?i, ?t)) { auto ee = fold_expr(env_, fld, e); - ret fld.fold_expr_field(env_, e.span, ee, i); + ret fld.fold_expr_field(env_, e.span, ee, i, t); } - case (ast.expr_index(?e, ?ix)) { + case (ast.expr_index(?e, ?ix, ?t)) { auto ee = fold_expr(env_, fld, e); auto iix = fold_expr(env_, fld, ix); - ret fld.fold_expr_index(env_, e.span, ee, iix); + ret fld.fold_expr_index(env_, e.span, ee, iix, t); } - case (ast.expr_name(?n, ?r)) { + case (ast.expr_name(?n, ?r, ?t)) { auto n_ = fold_name(env_, fld, n); - ret fld.fold_expr_name(env_, e.span, n, r); + ret fld.fold_expr_name(env_, e.span, n, r, t); } } @@ -547,74 +547,74 @@ fn identity_fold_ty_path[ENV](&ENV env, &span sp, ast.path p, // Expr identities. fn identity_fold_expr_vec[ENV](&ENV env, &span sp, vec[@expr] es, - option[@ty] ty) -> @expr { - ret @respan(sp, ast.expr_vec(es, ty)); + option[@ty] t) -> @expr { + ret @respan(sp, ast.expr_vec(es, t)); } fn identity_fold_expr_tup[ENV](&ENV env, &span sp, vec[tup(bool, @expr)] es, - option[@ty] ty) -> @expr { - ret @respan(sp, ast.expr_tup(es, ty)); + option[@ty] t) -> @expr { + ret @respan(sp, ast.expr_tup(es, t)); } fn identity_fold_expr_rec[ENV](&ENV env, &span sp, - vec[tup(ident,@expr)] fields, option[@ty] ty) + vec[tup(ident,@expr)] fields, option[@ty] t) -> @expr { - ret @respan(sp, ast.expr_rec(fields, ty)); + ret @respan(sp, ast.expr_rec(fields, t)); } fn identity_fold_expr_call[ENV](&ENV env, &span sp, @expr f, - vec[@expr] args, option[@ty] ty) -> @expr { - ret @respan(sp, ast.expr_call(f, args, ty)); + vec[@expr] args, option[@ty] t) -> @expr { + ret @respan(sp, ast.expr_call(f, args, t)); } fn identity_fold_expr_binary[ENV](&ENV env, &span sp, ast.binop b, @expr lhs, @expr rhs, - option[@ty] ty) -> @expr { - ret @respan(sp, ast.expr_binary(b, lhs, rhs, ty)); + option[@ty] t) -> @expr { + ret @respan(sp, ast.expr_binary(b, lhs, rhs, t)); } fn identity_fold_expr_unary[ENV](&ENV env, &span sp, - ast.unop u, @expr e, option[@ty] ty) + ast.unop u, @expr e, option[@ty] t) -> @expr { - ret @respan(sp, ast.expr_unary(u, e, ty)); + ret @respan(sp, ast.expr_unary(u, e, t)); } fn identity_fold_expr_lit[ENV](&ENV env, &span sp, @ast.lit lit, - option[@ty] ty) -> @expr { - ret @respan(sp, ast.expr_lit(lit, ty)); + option[@ty] t) -> @expr { + ret @respan(sp, ast.expr_lit(lit, t)); } fn identity_fold_expr_if[ENV](&ENV env, &span sp, @expr cond, &block thn, - &option[block] els, option[@ty] ty) -> @expr { - ret @respan(sp, ast.expr_if(cond, thn, els, ty)); + &option[block] els, option[@ty] t) -> @expr { + ret @respan(sp, ast.expr_if(cond, thn, els, t)); } fn identity_fold_expr_block[ENV](&ENV env, &span sp, &block blk, - option[@ty] ty) -> @expr { - ret @respan(sp, ast.expr_block(blk, ty)); + option[@ty] t) -> @expr { + ret @respan(sp, ast.expr_block(blk, t)); } fn identity_fold_expr_assign[ENV](&ENV env, &span sp, - @expr lhs, @expr rhs, option[@ty] ty) + @expr lhs, @expr rhs, option[@ty] t) -> @expr { - ret @respan(sp, ast.expr_assign(lhs, rhs, ty)); + ret @respan(sp, ast.expr_assign(lhs, rhs, t)); } fn identity_fold_expr_field[ENV](&ENV env, &span sp, - @expr e, ident i, option[@ty] ty) -> @expr { - ret @respan(sp, ast.expr_field(e, i, ty)); + @expr e, ident i, option[@ty] t) -> @expr { + ret @respan(sp, ast.expr_field(e, i, t)); } fn identity_fold_expr_index[ENV](&ENV env, &span sp, - @expr e, @expr ix, option[@ty] ty) -> @expr { - ret @respan(sp, ast.expr_index(e, ix, ty)); + @expr e, @expr ix, option[@ty] t) -> @expr { + ret @respan(sp, ast.expr_index(e, ix, t)); } fn identity_fold_expr_name[ENV](&ENV env, &span sp, &name n, &option[def] d, - option[@ty] ty) -> @expr { - ret @respan(sp, ast.expr_name(n, d, ty)); + option[@ty] t) -> @expr { + ret @respan(sp, ast.expr_name(n, d, t)); } @@ -745,19 +745,19 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_ty_tup = bind identity_fold_ty_tup[ENV](_,_,_), fold_ty_path = bind identity_fold_ty_path[ENV](_,_,_,_), - fold_expr_vec = bind identity_fold_expr_vec[ENV](_,_,_), - fold_expr_tup = bind identity_fold_expr_tup[ENV](_,_,_), - fold_expr_rec = bind identity_fold_expr_rec[ENV](_,_,_), - fold_expr_call = bind identity_fold_expr_call[ENV](_,_,_,_), - fold_expr_binary = bind identity_fold_expr_binary[ENV](_,_,_,_,_), - fold_expr_unary = bind identity_fold_expr_unary[ENV](_,_,_,_), - fold_expr_lit = bind identity_fold_expr_lit[ENV](_,_,_), - fold_expr_if = bind identity_fold_expr_if[ENV](_,_,_,_,_), - fold_expr_block = bind identity_fold_expr_block[ENV](_,_,_), - fold_expr_assign = bind identity_fold_expr_assign[ENV](_,_,_,_), - fold_expr_field = bind identity_fold_expr_field[ENV](_,_,_,_), - fold_expr_index = bind identity_fold_expr_index[ENV](_,_,_,_), - fold_expr_name = bind identity_fold_expr_name[ENV](_,_,_,_), + fold_expr_vec = bind identity_fold_expr_vec[ENV](_,_,_,_), + fold_expr_tup = bind identity_fold_expr_tup[ENV](_,_,_,_), + fold_expr_rec = bind identity_fold_expr_rec[ENV](_,_,_,_), + fold_expr_call = bind identity_fold_expr_call[ENV](_,_,_,_,_), + fold_expr_binary = bind identity_fold_expr_binary[ENV](_,_,_,_,_,_), + fold_expr_unary = bind identity_fold_expr_unary[ENV](_,_,_,_,_), + fold_expr_lit = bind identity_fold_expr_lit[ENV](_,_,_,_), + fold_expr_if = bind identity_fold_expr_if[ENV](_,_,_,_,_,_), + fold_expr_block = bind identity_fold_expr_block[ENV](_,_,_,_), + fold_expr_assign = bind identity_fold_expr_assign[ENV](_,_,_,_,_), + fold_expr_field = bind identity_fold_expr_field[ENV](_,_,_,_,_), + fold_expr_index = bind identity_fold_expr_index[ENV](_,_,_,_,_), + fold_expr_name = bind identity_fold_expr_name[ENV](_,_,_,_,_), fold_decl_local = bind identity_fold_decl_local[ENV](_,_,_), fold_decl_item = bind identity_fold_decl_item[ENV](_,_,_), diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs index 82cdf3fa3c3..08b2e588596 100644 --- a/src/comp/middle/resolve.rs +++ b/src/comp/middle/resolve.rs @@ -101,7 +101,7 @@ fn in_scope(ast.ident i, &scope s) -> option[def] { } fn fold_expr_name(&env e, &span sp, &ast.name n, - &option[def] d) -> @ast.expr { + &option[def] d, option[@ast.ty] t) -> @ast.expr { auto d_ = lookup_name(e, n.node.ident); @@ -114,7 +114,7 @@ fn fold_expr_name(&env e, &span sp, &ast.name n, } } - ret @fold.respan[ast.expr_](sp, ast.expr_name(n, d_)); + ret @fold.respan[ast.expr_](sp, ast.expr_name(n, d_, t)); } fn update_env_for_crate(&env e, @ast.crate c) -> env { @@ -131,7 +131,7 @@ fn update_env_for_block(&env e, &ast.block b) -> env { fn resolve_crate(session.session sess, @ast.crate crate) -> @ast.crate { let fold.ast_fold[env] fld = fold.new_identity_fold[env](); - fld = @rec( fold_expr_name = bind fold_expr_name(_,_,_,_), + fld = @rec( fold_expr_name = bind fold_expr_name(_,_,_,_,_), update_env_for_crate = bind update_env_for_crate(_,_), update_env_for_item = bind update_env_for_item(_,_), update_env_for_block = bind update_env_for_block(_,_) diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 095990fa50c..dd7ac62e968 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -546,23 +546,23 @@ fn trans_if(@block_ctxt cx, &ast.expr cond, fn trans_expr(@block_ctxt cx, &ast.expr e) -> result { alt (e.node) { - case (ast.expr_lit(?lit)) { + case (ast.expr_lit(?lit, _)) { ret trans_lit(cx, *lit); } - case (ast.expr_unary(?op, ?x)) { + case (ast.expr_unary(?op, ?x, _)) { ret trans_unary(cx, op, *x); } - 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)) { + case (ast.expr_if(?cond, ?thn, ?els, _)) { ret trans_if(cx, *cond, thn, els); } - case (ast.expr_block(?blk)) { + case (ast.expr_block(?blk, _)) { auto sub_cx = new_empty_block_ctxt(cx.fcx); auto next_cx = new_extension_block_ctxt(cx); auto sub = trans_block(sub_cx, blk); @@ -579,7 +579,7 @@ fn trans_expr(@block_ctxt cx, &ast.expr e) -> result { fn trans_log(@block_ctxt cx, &ast.expr e) -> result { alt (e.node) { - case (ast.expr_lit(?lit)) { + case (ast.expr_lit(?lit, _)) { alt (lit.node) { case (ast.lit_str(_)) { auto sub = trans_expr(cx, e);