rustc: Parse and typecheck unique pointers

This commit is contained in:
Patrick Walton 2011-08-15 14:36:52 -07:00
parent 5c6790519b
commit af61daf294
7 changed files with 14 additions and 1 deletions

View File

@ -620,6 +620,7 @@ fn find_pre_post_state_expr(fcx: &fn_ctxt, pres: &prestate, e: @expr) ->
none. { ret pure_exp(fcx.ccx, e.id, pres); }
}
}
expr_uniq(_) { ret pure_exp(fcx.ccx, e.id, pres); }
}
}

View File

@ -2467,6 +2467,11 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr,
// Now remove the info from the stack.
ivec::pop[obj_info](fcx.ccx.obj_infos);
}
ast::expr_uniq(x) {
let t = next_ty_var(fcx);
check_expr_with(fcx, x, ty::mk_uniq(tcx, t));
write::ty_only_fixup(fcx, id, ty::mk_uniq(tcx, t));
}
_ { tcx.sess.unimpl("expr type in typeck::check_expr"); }
}
if bot {

View File

@ -336,6 +336,7 @@ tag expr_ {
expr_chan(@expr);
expr_anon_obj(anon_obj);
expr_mac(mac);
expr_uniq(@expr);
}
type mac = spanned[mac_];

View File

@ -433,6 +433,7 @@ fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ {
expr_chan(e) { expr_chan(fld.fold_expr(e)) }
expr_anon_obj(ao) { expr_anon_obj(fold_anon_obj(ao)) }
expr_mac(mac) { expr_mac(fold_mac(mac)) }
expr_uniq(e) { expr_uniq(fld.fold_expr(e)) }
}
}

View File

@ -870,7 +870,7 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr {
span: p.get_span()};
ex = ast::expr_lit(lit);
}
_ { p.fatal("unimplemented: unique pointer creation"); }
_ { ex = ast::expr_uniq(parse_expr(p)); }
}
} else if (eat_word(p, "obj")) {
// Anonymous object

View File

@ -1037,6 +1037,10 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
}
bclose(s, expr.span);
}
ast::expr_uniq(expr) {
word(s.s, "~");
print_expr(s, expr);
}
}
s.ann.post(ann_node);
end(s);

View File

@ -341,6 +341,7 @@ fn visit_expr[E](ex: &@expr, e: &E, v: &vt[E]) {
}
}
expr_mac(mac) { visit_mac(mac, e, v); }
expr_uniq(x) { v.visit_expr(x, e, v); }
}
}