Skip to content

Commit 1cda74d

Browse files
committed
Add representation for by-ref let bindings
Issue #918
1 parent 197f360 commit 1cda74d

File tree

12 files changed

+31
-19
lines changed

12 files changed

+31
-19
lines changed

src/comp/middle/alias.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ fn visit_decl(cx: @ctx, d: @ast::decl, sc: scope, v: vt<scope>) {
144144
visit::visit_decl(d, sc, v);
145145
alt d.node {
146146
ast::decl_local(locs) {
147-
for loc: @ast::local in locs {
147+
// FIXME check that init is lvalue
148+
for (style, loc) in locs {
148149
alt loc.node.init {
149150
some(init) {
150151
if init.op == ast::init_move {

src/comp/middle/mut.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ fn visit_decl(cx: @ctx, d: @decl, e: (), v: visit::vt<()>) {
142142
visit::visit_decl(d, e, v);
143143
alt d.node {
144144
decl_local(locs) {
145-
for loc: @local in locs {
145+
for (_, loc) in locs {
146146
alt loc.node.init {
147147
some(init) {
148148
if init.op == init_move { check_move_rhs(cx, init.expr); }

src/comp/middle/resolve.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ fn visit_decl_with_scope(d: @decl, sc: scopes, v: vt<scopes>) {
371371
};
372372
alt d.node {
373373
decl_local(locs) {
374-
for loc in locs { v.visit_local(loc, sc, v);; *loc_pos += 1u; }
374+
for (_, loc) in locs { v.visit_local(loc, sc, v);; *loc_pos += 1u; }
375375
}
376376
decl_item(it) { v.visit_item(it, sc, v); }
377377
}
@@ -797,7 +797,7 @@ fn lookup_in_block(name: ident, b: ast::blk_, pos: uint, loc_pos: uint,
797797
let j = vec::len(locs);
798798
while j > 0u {
799799
j -= 1u;
800-
let loc = locs[j];
800+
let (_, loc) = locs[j];
801801
if ns == ns_value && (i < pos || j < loc_pos) {
802802
alt lookup_in_pat(name, loc.node.pat) {
803803
some(did) { ret some(ast::def_local(did)); }
@@ -1315,7 +1315,7 @@ fn check_block(e: @env, b: ast::blk, x: (), v: vt<()>) {
13151315
alt d.node {
13161316
ast::decl_local(locs) {
13171317
let local_values = checker(*e, "value");
1318-
for loc in locs {
1318+
for (_, loc) in locs {
13191319
for each p in ast_util::pat_bindings(loc.node.pat) {
13201320
let ident = alt p.node { pat_bind(n) { n } };
13211321
add_name(local_values, p.span, ident);

src/comp/middle/trans.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4538,7 +4538,7 @@ fn trans_stmt(cx: @block_ctxt, s: ast::stmt) -> result {
45384538
ast::stmt_decl(d, _) {
45394539
alt d.node {
45404540
ast::decl_local(locals) {
4541-
for local: @ast::local in locals {
4541+
for (_, local) in locals {
45424542
bcx = init_local(bcx, local).bcx;
45434543
}
45444544
}
@@ -4654,7 +4654,7 @@ iter block_locals(b: ast::blk) -> @ast::local {
46544654
ast::stmt_decl(d, _) {
46554655
alt d.node {
46564656
ast::decl_local(locals) {
4657-
for local: @ast::local in locals { put local; }
4657+
for (_, local) in locals { put local; }
46584658
}
46594659
_ {/* fall through */ }
46604660
}

src/comp/middle/tstate/auxiliary.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1063,8 +1063,10 @@ fn local_to_bindings(loc: @local) -> binding {
10631063
{lhs: lhs, rhs: loc.node.init}
10641064
}
10651065

1066-
fn locals_to_bindings(locals: [@local]) -> [binding] {
1067-
vec::map(local_to_bindings, locals)
1066+
fn locals_to_bindings(locals: [(let_style, @local)]) -> [binding] {
1067+
let rslt = [];
1068+
for (_, loc) in locals { rslt += [local_to_bindings(loc)]; }
1069+
ret rslt;
10681070
}
10691071

10701072
fn callee_modes(fcx: fn_ctxt, callee: node_id) -> [ty::mode] {

src/comp/middle/tstate/pre_post_conditions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ fn find_pre_post_stmt(fcx: fn_ctxt, s: stmt) {
572572
decl_local(alocals) {
573573
let e_pp;
574574
let prev_pp = empty_pre_post(num_constraints(fcx.enclosing));
575-
for alocal: @local in alocals {
575+
for (_, alocal) in alocals {
576576
alt alocal.node.init {
577577
some(an_init) {
578578
/* LHS always becomes initialized,

src/comp/middle/typeck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2418,7 +2418,7 @@ fn check_stmt(fcx: @fn_ctxt, stmt: @ast::stmt) -> bool {
24182418
node_id = id;
24192419
alt decl.node {
24202420
ast::decl_local(ls) {
2421-
for l: @ast::local in ls { bot |= check_decl_local(fcx, l); }
2421+
for (_, l) in ls { bot |= check_decl_local(fcx, l); }
24222422
}
24232423
ast::decl_item(_) {/* ignore for now */ }
24242424
}

src/comp/syntax/ast.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ type local = spanned<local_>;
149149

150150
type decl = spanned<decl_>;
151151

152-
tag decl_ { decl_local([@local]); decl_item(@item); }
152+
tag let_style { let_copy; let_ref; }
153+
154+
tag decl_ { decl_local([(let_style, @local)]); decl_item(@item); }
153155

154156
type arm = {pats: [@pat], guard: option::t<@expr>, body: blk};
155157

src/comp/syntax/fold.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,10 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
296296

297297
fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ {
298298
ret alt d {
299-
decl_local(ls) { decl_local(vec::map(fld.fold_local, ls)) }
299+
decl_local(ls) {
300+
decl_local(vec::map({|l| let (st, lc) = l;
301+
(st, fld.fold_local(lc))}, ls))
302+
}
300303
decl_item(it) { decl_item(fld.fold_item(it)) }
301304
}
302305
}

src/comp/syntax/parse/parser.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1505,11 +1505,13 @@ fn parse_local(p: parser, allow_init: bool) -> @ast::local {
15051505
}
15061506

15071507
fn parse_let(p: parser) -> @ast::decl {
1508+
fn parse_let_style(p: parser) -> ast::let_style {
1509+
eat(p, token::BINOP(token::AND)) ? ast::let_ref : ast::let_copy
1510+
}
15081511
let lo = p.get_lo_pos();
1509-
let locals = [parse_local(p, true)];
1510-
while p.peek() == token::COMMA {
1511-
p.bump();
1512-
locals += [parse_local(p, true)];
1512+
let locals = [(parse_let_style(p), parse_local(p, true))];
1513+
while eat(p, token::COMMA) {
1514+
locals += [(parse_let_style(p), parse_local(p, true))];
15131515
}
15141516
ret @spanned(lo, p.get_last_hi_pos(), ast::decl_local(locals));
15151517
}

src/comp/syntax/print/pprust.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1024,8 +1024,10 @@ fn print_decl(s: ps, decl: @ast::decl) {
10241024
space_if_not_bol(s);
10251025
ibox(s, indent_unit);
10261026
word_nbsp(s, "let");
1027-
fn print_local(s: ps, loc: @ast::local) {
1027+
fn print_local(s: ps, loc_st: (ast::let_style, @ast::local)) {
1028+
let (st, loc) = loc_st;
10281029
ibox(s, indent_unit);
1030+
if st == ast::let_ref { word(s.s, "&"); }
10291031
print_local_decl(s, loc);
10301032
end(s);
10311033
alt loc.node.init {

src/comp/syntax/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
212212
fn visit_decl<E>(d: @decl, e: E, v: vt<E>) {
213213
alt d.node {
214214
decl_local(locs) {
215-
for loc: @ast::local in locs { v.visit_local(loc, e, v); }
215+
for (_, loc) in locs { v.visit_local(loc, e, v); }
216216
}
217217
decl_item(it) { v.visit_item(it, e, v); }
218218
}

0 commit comments

Comments
 (0)