Add representation for by-ref let bindings

Issue #918
This commit is contained in:
Marijn Haverbeke 2011-09-15 11:42:56 +02:00
parent 197f360e30
commit 1cda74deee
12 changed files with 31 additions and 19 deletions

View file

@ -149,7 +149,9 @@ type local = spanned<local_>;
type decl = spanned<decl_>;
tag decl_ { decl_local([@local]); decl_item(@item); }
tag let_style { let_copy; let_ref; }
tag decl_ { decl_local([(let_style, @local)]); decl_item(@item); }
type arm = {pats: [@pat], guard: option::t<@expr>, body: blk};

View file

@ -296,7 +296,10 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ {
ret alt d {
decl_local(ls) { decl_local(vec::map(fld.fold_local, ls)) }
decl_local(ls) {
decl_local(vec::map({|l| let (st, lc) = l;
(st, fld.fold_local(lc))}, ls))
}
decl_item(it) { decl_item(fld.fold_item(it)) }
}
}

View file

@ -1505,11 +1505,13 @@ fn parse_local(p: parser, allow_init: bool) -> @ast::local {
}
fn parse_let(p: parser) -> @ast::decl {
fn parse_let_style(p: parser) -> ast::let_style {
eat(p, token::BINOP(token::AND)) ? ast::let_ref : ast::let_copy
}
let lo = p.get_lo_pos();
let locals = [parse_local(p, true)];
while p.peek() == token::COMMA {
p.bump();
locals += [parse_local(p, true)];
let locals = [(parse_let_style(p), parse_local(p, true))];
while eat(p, token::COMMA) {
locals += [(parse_let_style(p), parse_local(p, true))];
}
ret @spanned(lo, p.get_last_hi_pos(), ast::decl_local(locals));
}

View file

@ -1024,8 +1024,10 @@ fn print_decl(s: ps, decl: @ast::decl) {
space_if_not_bol(s);
ibox(s, indent_unit);
word_nbsp(s, "let");
fn print_local(s: ps, loc: @ast::local) {
fn print_local(s: ps, loc_st: (ast::let_style, @ast::local)) {
let (st, loc) = loc_st;
ibox(s, indent_unit);
if st == ast::let_ref { word(s.s, "&"); }
print_local_decl(s, loc);
end(s);
alt loc.node.init {

View file

@ -212,7 +212,7 @@ fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
fn visit_decl<E>(d: @decl, e: E, v: vt<E>) {
alt d.node {
decl_local(locs) {
for loc: @ast::local in locs { v.visit_local(loc, e, v); }
for (_, loc) in locs { v.visit_local(loc, e, v); }
}
decl_item(it) { v.visit_item(it, e, v); }
}