Consistify ast::local.

This commit is contained in:
Paul Stansifer 2011-06-16 15:58:25 -07:00 committed by Brian Anderson
parent d47101703e
commit 391348ec86
12 changed files with 75 additions and 70 deletions

View File

@ -205,11 +205,11 @@ type local_ =
def_id id,
ann ann);
type local = spanned[@local_];
type local = spanned[local_];
type decl = spanned[decl_];
tag decl_ { decl_local(@local_); decl_item(@item); }
tag decl_ { decl_local(@local); decl_item(@item); }
type arm = rec(@pat pat, block block);

View File

@ -1265,11 +1265,11 @@ fn parse_else_expr(&parser p) -> @ast::expr {
fn parse_head_local(&parser p) -> @ast::local {
auto lo = p.get_lo_pos();
let @ast::local_ l =
if (is_word(p, "auto")) {
parse_auto_local(p)
} else { parse_typed_local(p) };
ret @spanned(lo, p.get_hi_pos(), l);
if (is_word(p, "auto")) {
ret parse_auto_local(p);
} else {
ret parse_typed_local(p);
}
}
fn parse_for_expr(&parser p) -> @ast::expr {
@ -1444,23 +1444,27 @@ fn parse_pat(&parser p) -> @ast::pat {
ret @spanned(lo, hi, pat);
}
fn parse_local_full(&option::t[@ast::ty] tyopt, &parser p) -> @ast::local_ {
fn parse_local_full(&option::t[@ast::ty] tyopt, &parser p)
-> @ast::local {
auto lo = p.get_lo_pos();
auto ident = parse_value_ident(p);
auto init = parse_initializer(p);
ret @rec(ty=tyopt,
infer=false,
ident=ident,
init=init,
id=p.next_def_id(),
ann=p.get_ann());
ret @spanned(lo, p.get_hi_pos(),
rec(ty=tyopt,
infer=false,
ident=ident,
init=init,
id=p.next_def_id(),
ann=p.get_ann()));
}
fn parse_typed_local(&parser p) -> @ast::local_ {
fn parse_typed_local(&parser p) -> @ast::local {
auto ty = parse_ty(p);
ret parse_local_full(some(ty), p);
}
fn parse_auto_local(&parser p) -> @ast::local_ {
fn parse_auto_local(&parser p) -> @ast::local {
ret parse_local_full(none, p);
}

View File

@ -41,8 +41,7 @@ tag scope {
scope_item(@ast::item);
scope_fn(ast::fn_decl, vec[ast::ty_param]);
scope_native_item(@ast::native_item);
scope_loop(@ast::local_); // there's only 1 decl per loop.
scope_loop(@ast::local); // there's only 1 decl per loop.
scope_block(ast::block);
scope_arm(ast::arm);
}
@ -356,10 +355,10 @@ fn visit_expr_with_scope(&@ast::expr x, &scopes sc, &vt[scopes] v) {
auto new_sc =
alt (x.node) {
case (ast::expr_for(?d, _, _, _)) {
cons[scope](scope_loop(d.node), @sc)
cons[scope](scope_loop(d), @sc)
}
case (ast::expr_for_each(?d, _, _, _)) {
cons[scope](scope_loop(d.node), @sc)
cons[scope](scope_loop(d), @sc)
}
case (ast::expr_fn(?f, _)) { cons(scope_fn(f.decl, []), @sc) }
case (_) { sc }
@ -575,8 +574,8 @@ fn lookup_in_scope(&env e, scopes sc, &span sp, &ident id, namespace ns) ->
}
case (scope_loop(?local)) {
if (ns == ns_value) {
if (str::eq(local.ident, id)) {
ret some(ast::def_local(local.id));
if (str::eq(local.node.ident, id)) {
ret some(ast::def_local(local.node.id));
}
}
}
@ -680,8 +679,8 @@ fn lookup_in_block(&ident id, &ast::block_ b, namespace ns) ->
case (ast::stmt_decl(?d, _)) {
alt (d.node) {
case (ast::decl_local(?loc)) {
if (ns == ns_value && str::eq(id, loc.ident)) {
ret some(ast::def_local(loc.id));
if (ns == ns_value && str::eq(id, loc.node.ident)) {
ret some(ast::def_local(loc.node.id));
}
}
case (ast::decl_item(?it)) {
@ -1169,7 +1168,7 @@ fn check_block(@env e, &ast::block b, &() x, &vt[()] v) {
case (ast::stmt_decl(?d, _)) {
alt (d.node) {
case (ast::decl_local(?loc)) {
add_name(values, d.span, loc.ident);
add_name(values, d.span, loc.node.ident);
}
case (ast::decl_item(?it)) {
alt (it.node) {

View File

@ -4026,7 +4026,7 @@ fn trans_if(&@block_ctxt cx, &@ast::expr cond, &ast::block thn,
fn trans_for(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
&ast::block body) -> result {
fn inner(&@block_ctxt cx, @ast::local_ local, ValueRef curr, ty::t t,
fn inner(&@block_ctxt cx, @ast::local local, ValueRef curr, ty::t t,
ast::block body, @block_ctxt outer_next_cx) -> result {
auto next_cx = new_sub_block_ctxt(cx, "next");
auto scope_cx =
@ -4045,7 +4045,7 @@ fn trans_for(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
auto seq_res = trans_expr(cx, seq);
auto it =
iter_sequence(seq_res.bcx, seq_res.val, seq_ty,
bind inner(_, local.node, _, _, body, next_cx));
bind inner(_, local, _, _, body, next_cx));
it.bcx.build.Br(next_cx.llbb);
ret res(next_cx, it.val);
}
@ -6440,15 +6440,15 @@ fn trans_anon_obj(@block_ctxt bcx, &span sp, &ast::anon_obj anon_obj,
ret res(bcx, pair);
}
fn init_local(&@block_ctxt cx, &@ast::local_ local) -> result {
fn init_local(&@block_ctxt cx, &@ast::local local) -> result {
// Make a note to drop this slot on the way out.
assert (cx.fcx.lllocals.contains_key(local.id));
auto llptr = cx.fcx.lllocals.get(local.id);
auto ty = node_ann_type(cx.fcx.lcx.ccx, local.ann);
assert (cx.fcx.lllocals.contains_key(local.node.id));
auto llptr = cx.fcx.lllocals.get(local.node.id);
auto ty = node_ann_type(cx.fcx.lcx.ccx, local.node.ann);
auto bcx = cx;
find_scope_cx(cx).cleanups += [clean(bind drop_slot(_, llptr, ty))];
alt (local.init) {
alt (local.node.init) {
case (some(?init)) {
alt (init.op) {
case (ast::init_assign) {
@ -6595,8 +6595,7 @@ fn trans_block_cleanups(&@block_ctxt cx, &@block_ctxt cleanup_cx) ->
ret bcx;
}
iter block_locals(&ast::block b) -> @ast::local_ {
iter block_locals(&ast::block b) -> @ast::local {
// FIXME: putting from inside an iter block doesn't work, so we can't
// use the index here.
for (@ast::stmt s in b.node.stmts) {
@ -6645,18 +6644,17 @@ fn alloc_ty(&@block_ctxt cx, &ty::t t) -> result {
ret res(cx, val);
}
fn alloc_local(&@block_ctxt cx, &@ast::local_ local) -> result {
auto t = node_ann_type(cx.fcx.lcx.ccx, local.ann);
fn alloc_local(&@block_ctxt cx, &@ast::local local) -> result {
auto t = node_ann_type(cx.fcx.lcx.ccx, local.node.ann);
auto r = alloc_ty(cx, t);
r.bcx.fcx.lllocals.insert(local.id, r.val);
r.bcx.fcx.lllocals.insert(local.node.id, r.val);
ret r;
}
fn trans_block(&@block_ctxt cx, &ast::block b, &out_method output) -> result {
auto bcx = cx;
for each (@ast::local_ local in block_locals(b)) {
for each (@ast::local local in block_locals(b)) {
// FIXME Update bcx.sp
bcx = alloc_local(bcx, local).bcx;
}
auto r = res(bcx, C_nil());

View File

@ -550,20 +550,23 @@ fn find_pre_post_stmt(&fn_ctxt fcx, &stmt s) {
case (stmt_decl(?adecl, ?a)) {
alt (adecl.node) {
case (decl_local(?alocal)) {
alt (alocal.init) {
alt (alocal.node.init) {
case (some(?an_init)) {
find_pre_post_expr(fcx, an_init.expr);
copy_pre_post(fcx.ccx, alocal.ann, an_init.expr);
copy_pre_post(fcx.ccx, alocal.node.ann,
an_init.expr);
/* Inherit ann from initializer, and add var being
initialized to the postcondition */
copy_pre_post(fcx.ccx, a, an_init.expr);
gen(fcx, a,
rec(id=alocal.id, c=ninit(alocal.ident)));
rec(id=alocal.node.id,
c=ninit(alocal.node.ident)));
}
case (none) {
clear_pp(ann_to_ts_ann(fcx.ccx,
alocal.ann).conditions);
alocal.node.ann)
.conditions);
clear_pp(ann_to_ts_ann(fcx.ccx, a).conditions);
}
}

View File

@ -663,15 +663,15 @@ fn find_pre_post_state_stmt(&fn_ctxt fcx, &prestate pres, @stmt s) -> bool {
case (stmt_decl(?adecl, ?a)) {
alt (adecl.node) {
case (decl_local(?alocal)) {
alt (alocal.init) {
alt (alocal.node.init) {
case (some(?an_init)) {
changed =
extend_prestate(stmt_ann.states.prestate,
pres) || changed;
changed =
find_pre_post_state_expr(fcx, pres,
an_init.expr) ||
changed;
an_init.expr)
|| changed;
changed =
extend_poststate(stmt_ann.states.poststate,
expr_poststate(fcx.ccx,
@ -679,9 +679,9 @@ fn find_pre_post_state_stmt(&fn_ctxt fcx, &prestate pres, @stmt s) -> bool {
|| changed;
changed =
gen_poststate(fcx, a,
rec(id=alocal.id,
c=ninit(alocal.ident))) ||
changed;
rec(id=alocal.node.id,
c=ninit(alocal.node.ident)))
|| changed;
log "Summary: stmt = ";
log_stmt(*s);
log "prestate = ";

View File

@ -1577,8 +1577,8 @@ fn expr_has_ty_params(&ctxt cx, &@ast::expr expr) -> bool {
ret ann_has_type_params(cx, expr_ann(expr));
}
fn decl_local_ty(&ctxt cx, &@ast::local_ l) -> t {
ret ann_to_type(cx, l.ann);
fn decl_local_ty(&ctxt cx, &@ast::local l) -> t {
ret ann_to_type(cx, l.node.ann);
}
fn stmt_ann(&@ast::stmt s) -> ast::ann {

View File

@ -1443,12 +1443,11 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
fn check_for_or_for_each(&@fn_ctxt fcx, &@ast::local local,
&ty::t element_ty, &ast::block body,
uint node_id) {
check_decl_local(fcx, local.node);
check_decl_local(fcx, local);
check_block(fcx, body);
// Unify type of decl with element type of the seq
demand::simple(fcx, local.span,
ty::decl_local_ty(fcx.ccx.tcx, local.node),
ty::decl_local_ty(fcx.ccx.tcx, local),
element_ty);
auto typ = ty::mk_nil(fcx.ccx.tcx);
write::ty_only_fixup(fcx, node_id, typ);
@ -2239,24 +2238,26 @@ fn check_decl_initializer(&@fn_ctxt fcx, &ast::def_id lid,
}
}
fn check_decl_local(&@fn_ctxt fcx, &@ast::local_ local) -> @ast::local_ {
auto a_res = local.ann;
alt (fcx.locals.find(local.id)) {
fn check_decl_local(&@fn_ctxt fcx, &@ast::local local) -> @ast::local {
auto a_res = local.node.ann;
alt (fcx.locals.find(local.node.id)) {
case (none) {
fcx.ccx.tcx.sess.bug("check_decl_local: local id not found " +
local.ident);
local.node.ident);
}
case (some(?i)) {
auto t = ty::mk_var(fcx.ccx.tcx, i);
write::ty_only_fixup(fcx, a_res.id, t);
auto initopt = local.init;
alt (local.init) {
auto initopt = local.node.init;
alt (initopt) {
case (some(?init)) {
check_decl_initializer(fcx, local.id, init);
check_decl_initializer(fcx, local.node.id, init);
}
case (_) {/* fall through */ }
}
ret @rec(init=initopt, ann=a_res with *local);
auto newlocal = rec(init=initopt, ann=a_res with local.node);
ret @rec(node=newlocal, span=local.span);
}
}
}

View File

@ -236,7 +236,7 @@ fn visit_stmt[E](&@stmt s, &E e, &vt[E] v) {
fn visit_decl[E](&@decl d, &E e, &vt[E] v) {
alt (d.node) {
case (decl_local(?loc)) {
vt(v).visit_local(@respan(d.span, loc), e, v);
vt(v).visit_local(loc, e, v);
}
case (decl_item(?it)) { vt(v).visit_item(it, e, v); }
}

View File

@ -256,7 +256,7 @@ fn walk_decl(&ast_visitor v, @ast::decl d) {
if (!v.keep_going()) { ret; }
v.visit_decl_pre(d);
alt (d.node) {
case (ast::decl_local(?loc)) { walk_local(v, @respan(d.span, loc)); }
case (ast::decl_local(?loc)) { walk_local(v, loc); }
case (ast::decl_item(?it)) { walk_item(v, it); }
}
v.visit_decl_post(d);

View File

@ -864,7 +864,7 @@ fn print_decl(&ps s, &@ast::decl decl) {
case (ast::decl_local(?loc)) {
space(s.s);
ibox(s, indent_unit);
alt (loc.ty) {
alt (loc.node.ty) {
case (some(?ty)) {
word_nbsp(s, "let");
print_type(s, *ty);
@ -877,15 +877,15 @@ fn print_decl(&ps s, &@ast::decl decl) {
alt (s.mode) {
case (mo_untyped) {/* no-op */ }
case (mo_typed(?tcx)) {
auto lty = ty::ann_to_type(tcx, loc.ann);
auto lty = ty::ann_to_type(tcx, loc.node.ann);
word_space(s, ppaux::ty_to_str(tcx, lty));
}
case (mo_identified) {/* no-op */ }
}
}
}
word(s.s, loc.ident);
alt (loc.init) {
word(s.s, loc.node.ident);
alt (loc.node.init) {
case (some(?init)) {
space(s.s);
alt (init.op) {

View File

@ -164,8 +164,8 @@ fn has_nonlocal_exits(&ast::block b) -> bool {
ret *has_exits;
}
fn local_rhs_span(&@ast::local_ l, &span def) -> span {
alt (l.init) {
fn local_rhs_span(&@ast::local l, &span def) -> span {
alt (l.node.init) {
case (some(?i)) { ret i.expr.span; }
case (_) { ret def; }
}