auto merge of #7826 : michaelwoerister/rust/end_of_spanned, r=cmr

This is the first of a series of refactorings to get rid of the `codemap::spanned<T>` struct (see this thread for more information: https://mail.mozilla.org/pipermail/rust-dev/2013-July/004798.html).

The changes in this PR should not change any semantics, just rename `ast::blk_` to `ast::blk` and add a span field to it. 95% of the changes were of the form `block.node.id` -> `block.id`. Only some transformations in `libsyntax::fold` where not entirely trivial.
This commit is contained in:
bors 2013-07-17 09:49:43 -07:00
commit 9c1e530bde
37 changed files with 190 additions and 191 deletions

View File

@ -422,7 +422,7 @@ pub fn pretty_print_input(sess: Session, cfg: ast::crate_cfg, input: &input,
pprust::node_block(s, ref blk) => { pprust::node_block(s, ref blk) => {
pp::space(s.s); pp::space(s.s);
pprust::synth_comment( pprust::synth_comment(
s, ~"block " + int::to_str(blk.node.id)); s, ~"block " + int::to_str(blk.id));
} }
pprust::node_expr(s, expr) => { pprust::node_expr(s, expr) => {
pp::space(s.s); pp::space(s.s);

View File

@ -33,7 +33,7 @@ pub fn strip_items(crate: &ast::crate, in_cfg: in_cfg_pred)
let precursor = @fold::AstFoldFns { let precursor = @fold::AstFoldFns {
fold_mod: |a,b| fold_mod(ctxt, a, b), fold_mod: |a,b| fold_mod(ctxt, a, b),
fold_block: fold::wrap(|a,b| fold_block(ctxt, a, b) ), fold_block: |a,b| fold_block(ctxt, a, b),
fold_foreign_mod: |a,b| fold_foreign_mod(ctxt, a, b), fold_foreign_mod: |a,b| fold_foreign_mod(ctxt, a, b),
fold_item_underscore: |a,b| { fold_item_underscore: |a,b| {
// Bad copy. // Bad copy.
@ -133,21 +133,22 @@ fn filter_stmt(cx: @Context, stmt: @ast::stmt) ->
fn fold_block( fn fold_block(
cx: @Context, cx: @Context,
b: &ast::blk_, b: &ast::blk,
fld: @fold::ast_fold fld: @fold::ast_fold
) -> ast::blk_ { ) -> ast::blk {
let resulting_stmts = do b.stmts.iter().filter_map |a| { let resulting_stmts = do b.stmts.iter().filter_map |a| {
filter_stmt(cx, *a).chain(|stmt| fld.fold_stmt(stmt)) filter_stmt(cx, *a).chain(|stmt| fld.fold_stmt(stmt))
}.collect(); }.collect();
let filtered_view_items = do b.view_items.iter().filter_map |a| { let filtered_view_items = do b.view_items.iter().filter_map |a| {
filter_view_item(cx, a).map(|&x| fld.fold_view_item(x)) filter_view_item(cx, a).map(|&x| fld.fold_view_item(x))
}.collect(); }.collect();
ast::blk_ { ast::blk {
view_items: filtered_view_items, view_items: filtered_view_items,
stmts: resulting_stmts, stmts: resulting_stmts,
expr: b.expr.map(|x| fld.fold_expr(*x)), expr: b.expr.map(|x| fld.fold_expr(*x)),
id: b.id, id: b.id,
rules: b.rules, rules: b.rules,
span: b.span,
} }
} }

View File

@ -289,7 +289,7 @@ fn encode_ast(ebml_w: &mut writer::Encoder, item: ast::inlined_item) {
// nested items, as otherwise it would get confused when translating // nested items, as otherwise it would get confused when translating
// inlined items. // inlined items.
fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item { fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item {
fn drop_nested_items(blk: &ast::blk_, fld: @fold::ast_fold) -> ast::blk_ { fn drop_nested_items(blk: &ast::blk, fld: @fold::ast_fold) -> ast::blk {
let stmts_sans_items = do blk.stmts.iter().filter_map |stmt| { let stmts_sans_items = do blk.stmts.iter().filter_map |stmt| {
match stmt.node { match stmt.node {
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) | ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
@ -300,19 +300,20 @@ fn simplify_ast(ii: &ast::inlined_item) -> ast::inlined_item {
ast::stmt_mac(*) => fail!("unexpanded macro in astencode") ast::stmt_mac(*) => fail!("unexpanded macro in astencode")
} }
}.collect(); }.collect();
let blk_sans_items = ast::blk_ { let blk_sans_items = ast::blk {
view_items: ~[], // I don't know if we need the view_items here, view_items: ~[], // I don't know if we need the view_items here,
// but it doesn't break tests! // but it doesn't break tests!
stmts: stmts_sans_items, stmts: stmts_sans_items,
expr: blk.expr, expr: blk.expr,
id: blk.id, id: blk.id,
rules: blk.rules rules: blk.rules,
span: blk.span,
}; };
fold::noop_fold_block(&blk_sans_items, fld) fold::noop_fold_block(&blk_sans_items, fld)
} }
let fld = fold::make_fold(@fold::AstFoldFns { let fld = fold::make_fold(@fold::AstFoldFns {
fold_block: fold::wrap(drop_nested_items), fold_block: drop_nested_items,
.. *fold::default_ast_fold() .. *fold::default_ast_fold()
}); });

View File

@ -44,7 +44,7 @@ pub fn check_loans(bccx: @BorrowckCtxt,
move_data: move_data::FlowedMoveData, move_data: move_data::FlowedMoveData,
all_loans: &[Loan], all_loans: &[Loan],
body: &ast::blk) { body: &ast::blk) {
debug!("check_loans(body id=%?)", body.node.id); debug!("check_loans(body id=%?)", body.id);
let clcx = @mut CheckLoanCtxt { let clcx = @mut CheckLoanCtxt {
bccx: bccx, bccx: bccx,
@ -751,5 +751,5 @@ fn check_loans_in_block<'a>(blk: &ast::blk,
visit::vt<@mut CheckLoanCtxt<'a>>)) visit::vt<@mut CheckLoanCtxt<'a>>))
{ {
visit::visit_block(blk, (this, vt)); visit::visit_block(blk, (this, vt));
this.check_for_conflicting_loans(blk.node.id); this.check_for_conflicting_loans(blk.id);
} }

View File

@ -80,8 +80,8 @@ pub fn gather_loans(bccx: @BorrowckCtxt,
bccx: bccx, bccx: bccx,
id_range: id_range::max(), id_range: id_range::max(),
all_loans: @mut ~[], all_loans: @mut ~[],
item_ub: body.node.id, item_ub: body.id,
repeating_ids: ~[body.node.id], repeating_ids: ~[body.id],
move_data: @mut MoveData::new() move_data: @mut MoveData::new()
}; };
glcx.gather_fn_arg_patterns(decl, body); glcx.gather_fn_arg_patterns(decl, body);
@ -123,9 +123,9 @@ fn gather_loans_in_fn(fk: &visit::fn_kind,
// Visit closures as part of the containing item. // Visit closures as part of the containing item.
&visit::fk_anon(*) | &visit::fk_fn_block(*) => { &visit::fk_anon(*) | &visit::fk_fn_block(*) => {
this.push_repeating_id(body.node.id); this.push_repeating_id(body.id);
visit::visit_fn(fk, decl, body, sp, id, (this, v)); visit::visit_fn(fk, decl, body, sp, id, (this, v));
this.pop_repeating_id(body.node.id); this.pop_repeating_id(body.id);
this.gather_fn_arg_patterns(decl, body); this.gather_fn_arg_patterns(decl, body);
} }
} }
@ -134,7 +134,7 @@ fn gather_loans_in_fn(fk: &visit::fn_kind,
fn gather_loans_in_block(blk: &ast::blk, fn gather_loans_in_block(blk: &ast::blk,
(this, vt): (@mut GatherLoanCtxt, (this, vt): (@mut GatherLoanCtxt,
visit::vt<@mut GatherLoanCtxt>)) { visit::vt<@mut GatherLoanCtxt>)) {
this.id_range.add(blk.node.id); this.id_range.add(blk.id);
visit::visit_block(blk, (this, vt)); visit::visit_block(blk, (this, vt));
} }
@ -240,7 +240,7 @@ fn gather_loans_in_expr(ex: @ast::expr,
let cmt = this.bccx.cat_expr(ex_v); let cmt = this.bccx.cat_expr(ex_v);
for arms.iter().advance |arm| { for arms.iter().advance |arm| {
for arm.pats.iter().advance |pat| { for arm.pats.iter().advance |pat| {
this.gather_pat(cmt, *pat, Some((arm.body.node.id, ex.id))); this.gather_pat(cmt, *pat, Some((arm.body.id, ex.id)));
} }
} }
visit::visit_expr(ex, (this, vt)); visit::visit_expr(ex, (this, vt));
@ -268,16 +268,16 @@ fn gather_loans_in_expr(ex: @ast::expr,
this.pop_repeating_id(cond.id); this.pop_repeating_id(cond.id);
// during body, can only root for the body // during body, can only root for the body
this.push_repeating_id(body.node.id); this.push_repeating_id(body.id);
(vt.visit_block)(body, (this, vt)); (vt.visit_block)(body, (this, vt));
this.pop_repeating_id(body.node.id); this.pop_repeating_id(body.id);
} }
// see explanation attached to the `root_ub` field: // see explanation attached to the `root_ub` field:
ast::expr_loop(ref body, _) => { ast::expr_loop(ref body, _) => {
this.push_repeating_id(body.node.id); this.push_repeating_id(body.id);
visit::visit_expr(ex, (this, vt)); visit::visit_expr(ex, (this, vt));
this.pop_repeating_id(body.node.id); this.pop_repeating_id(body.id);
} }
ast::expr_fn_block(*) => { ast::expr_fn_block(*) => {
@ -623,7 +623,7 @@ impl GatherLoanCtxt {
let arg_cmt = mc_ctxt.cat_rvalue( let arg_cmt = mc_ctxt.cat_rvalue(
arg.id, arg.id,
arg.pat.span, arg.pat.span,
body.node.id, // Arguments live only as long as the fn body. body.id, // Arguments live only as long as the fn body.
arg_ty); arg_ty);
self.gather_pat(arg_cmt, arg.pat, None); self.gather_pat(arg_cmt, arg.pat, None);

View File

@ -53,13 +53,13 @@ pub fn construct(tcx: ty::ctxt,
impl CFGBuilder { impl CFGBuilder {
fn block(&mut self, blk: &ast::blk, pred: CFGIndex) -> CFGIndex { fn block(&mut self, blk: &ast::blk, pred: CFGIndex) -> CFGIndex {
let mut stmts_exit = pred; let mut stmts_exit = pred;
for blk.node.stmts.iter().advance |&stmt| { for blk.stmts.iter().advance |&stmt| {
stmts_exit = self.stmt(stmt, stmts_exit); stmts_exit = self.stmt(stmt, stmts_exit);
} }
let expr_exit = self.opt_expr(blk.node.expr, stmts_exit); let expr_exit = self.opt_expr(blk.expr, stmts_exit);
self.add_node(blk.node.id, [expr_exit]) self.add_node(blk.id, [expr_exit])
} }
fn stmt(&mut self, stmt: @ast::stmt, pred: CFGIndex) -> CFGIndex { fn stmt(&mut self, stmt: @ast::stmt, pred: CFGIndex) -> CFGIndex {

View File

@ -330,7 +330,7 @@ impl<O:DataFlowOperator+Copy+'static> DataFlowContext<O> {
let pre: @fn(pprust::ann_node) = |node| { let pre: @fn(pprust::ann_node) = |node| {
let (ps, id) = match node { let (ps, id) = match node {
pprust::node_expr(ps, expr) => (ps, expr.id), pprust::node_expr(ps, expr) => (ps, expr.id),
pprust::node_block(ps, blk) => (ps, blk.node.id), pprust::node_block(ps, blk) => (ps, blk.id),
pprust::node_item(ps, _) => (ps, 0), pprust::node_item(ps, _) => (ps, 0),
pprust::node_pat(ps, pat) => (ps, pat.id) pprust::node_pat(ps, pat) => (ps, pat.id)
}; };
@ -383,18 +383,18 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> {
blk: &ast::blk, blk: &ast::blk,
in_out: &mut [uint], in_out: &mut [uint],
loop_scopes: &mut ~[LoopScope]) { loop_scopes: &mut ~[LoopScope]) {
debug!("DataFlowContext::walk_block(blk.node.id=%?, in_out=%s)", debug!("DataFlowContext::walk_block(blk.id=%?, in_out=%s)",
blk.node.id, bits_to_str(reslice(in_out))); blk.id, bits_to_str(reslice(in_out)));
self.merge_with_entry_set(blk.node.id, in_out); self.merge_with_entry_set(blk.id, in_out);
for blk.node.stmts.iter().advance |&stmt| { for blk.stmts.iter().advance |&stmt| {
self.walk_stmt(stmt, in_out, loop_scopes); self.walk_stmt(stmt, in_out, loop_scopes);
} }
self.walk_opt_expr(blk.node.expr, in_out, loop_scopes); self.walk_opt_expr(blk.expr, in_out, loop_scopes);
self.dfcx.apply_gen_kill(blk.node.id, in_out); self.dfcx.apply_gen_kill(blk.id, in_out);
} }
fn walk_stmt(&mut self, fn walk_stmt(&mut self,

View File

@ -99,9 +99,9 @@ pub fn check_crate(tcx: ty::ctxt,
visit_block: |block, (_, visitor)| { visit_block: |block, (_, visitor)| {
let old_unsafe_context = context.unsafe_context; let old_unsafe_context = context.unsafe_context;
if block.node.rules == unsafe_blk && if block.rules == unsafe_blk &&
context.unsafe_context == SafeContext { context.unsafe_context == SafeContext {
context.unsafe_context = UnsafeBlock(block.node.id) context.unsafe_context = UnsafeBlock(block.id)
} }
visit::visit_block(block, ((), visitor)); visit::visit_block(block, ((), visitor));

View File

@ -921,8 +921,8 @@ fn lint_unused_unsafe() -> visit::vt<@mut Context> {
visit::mk_vt(@visit::Visitor { visit::mk_vt(@visit::Visitor {
visit_expr: |e, (cx, vt): (@mut Context, visit::vt<@mut Context>)| { visit_expr: |e, (cx, vt): (@mut Context, visit::vt<@mut Context>)| {
match e.node { match e.node {
ast::expr_block(ref blk) if blk.node.rules == ast::unsafe_blk => { ast::expr_block(ref blk) if blk.rules == ast::unsafe_blk => {
if !cx.tcx.used_unsafe.contains(&blk.node.id) { if !cx.tcx.used_unsafe.contains(&blk.id) {
cx.span_lint(unused_unsafe, blk.span, cx.span_lint(unused_unsafe, blk.span,
"unnecessary `unsafe` block"); "unnecessary `unsafe` block");
} }

View File

@ -886,7 +886,7 @@ impl Liveness {
self.tcx.sess.intr())); self.tcx.sess.intr()));
let entry_ln: LiveNode = let entry_ln: LiveNode =
self.with_loop_nodes(body.node.id, self.s.exit_ln, self.s.exit_ln, self.with_loop_nodes(body.id, self.s.exit_ln, self.s.exit_ln,
|| { self.propagate_through_fn_block(decl, body) }); || { self.propagate_through_fn_block(decl, body) });
// hack to skip the loop unless debug! is enabled: // hack to skip the loop unless debug! is enabled:
@ -895,7 +895,7 @@ impl Liveness {
for uint::range(0u, self.ir.num_live_nodes) |ln_idx| { for uint::range(0u, self.ir.num_live_nodes) |ln_idx| {
debug!("%s", self.ln_str(LiveNode(ln_idx))); debug!("%s", self.ln_str(LiveNode(ln_idx)));
} }
body.node.id body.id
}, },
entry_ln.to_str()); entry_ln.to_str());
@ -907,7 +907,7 @@ impl Liveness {
// the fallthrough exit is only for those cases where we do not // the fallthrough exit is only for those cases where we do not
// explicitly return: // explicitly return:
self.init_from_succ(self.s.fallthrough_ln, self.s.exit_ln); self.init_from_succ(self.s.fallthrough_ln, self.s.exit_ln);
if blk.node.expr.is_none() { if blk.expr.is_none() {
self.acc(self.s.fallthrough_ln, self.s.no_ret_var, ACC_READ) self.acc(self.s.fallthrough_ln, self.s.no_ret_var, ACC_READ)
} }
@ -916,8 +916,8 @@ impl Liveness {
pub fn propagate_through_block(&self, blk: &blk, succ: LiveNode) pub fn propagate_through_block(&self, blk: &blk, succ: LiveNode)
-> LiveNode { -> LiveNode {
let succ = self.propagate_through_opt_expr(blk.node.expr, succ); let succ = self.propagate_through_opt_expr(blk.expr, succ);
do blk.node.stmts.rev_iter().fold(succ) |succ, stmt| { do blk.stmts.rev_iter().fold(succ) |succ, stmt| {
self.propagate_through_stmt(*stmt, succ) self.propagate_through_stmt(*stmt, succ)
} }
} }
@ -1009,7 +1009,7 @@ impl Liveness {
The next-node for a break is the successor of the entire The next-node for a break is the successor of the entire
loop. The next-node for a continue is the top of this loop. loop. The next-node for a continue is the top of this loop.
*/ */
self.with_loop_nodes(blk.node.id, succ, self.with_loop_nodes(blk.id, succ,
self.live_node(expr.id, expr.span), || { self.live_node(expr.id, expr.span), || {
// the construction of a closure itself is not important, // the construction of a closure itself is not important,

View File

@ -285,13 +285,13 @@ impl VisitContext {
* meaning either copied or moved depending on its type. * meaning either copied or moved depending on its type.
*/ */
debug!("consume_block(blk.id=%?)", blk.node.id); debug!("consume_block(blk.id=%?)", blk.id);
for blk.node.stmts.iter().advance |stmt| { for blk.stmts.iter().advance |stmt| {
(visitor.visit_stmt)(*stmt, (*self, visitor)); (visitor.visit_stmt)(*stmt, (*self, visitor));
} }
for blk.node.expr.iter().advance |tail_expr| { for blk.expr.iter().advance |tail_expr| {
self.consume_expr(*tail_expr, visitor); self.consume_expr(*tail_expr, visitor);
} }
} }

View File

@ -384,7 +384,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
visit_block: |block, (method_map, visitor)| { visit_block: |block, (method_map, visitor)| {
// Gather up all the privileged items. // Gather up all the privileged items.
let mut n_added = 0; let mut n_added = 0;
for block.node.stmts.iter().advance |stmt| { for block.stmts.iter().advance |stmt| {
match stmt.node { match stmt.node {
stmt_decl(decl, _) => { stmt_decl(decl, _) => {
match decl.node { match decl.node {

View File

@ -324,11 +324,11 @@ fn parent_to_expr(cx: Context, child_id: ast::node_id, sp: span) {
fn resolve_block(blk: &ast::blk, (cx, visitor): (Context, visit::vt<Context>)) { fn resolve_block(blk: &ast::blk, (cx, visitor): (Context, visit::vt<Context>)) {
// Record the parent of this block. // Record the parent of this block.
parent_to_expr(cx, blk.node.id, blk.span); parent_to_expr(cx, blk.id, blk.span);
// Descend. // Descend.
let new_cx = Context {var_parent: Some(blk.node.id), let new_cx = Context {var_parent: Some(blk.id),
parent: Some(blk.node.id), parent: Some(blk.id),
..cx}; ..cx};
visit::visit_block(blk, (new_cx, visitor)); visit::visit_block(blk, (new_cx, visitor));
} }
@ -420,20 +420,20 @@ fn resolve_fn(fk: &visit::fn_kind,
visit::vt<Context>)) { visit::vt<Context>)) {
debug!("region::resolve_fn(id=%?, \ debug!("region::resolve_fn(id=%?, \
span=%?, \ span=%?, \
body.node.id=%?, \ body.id=%?, \
cx.parent=%?)", cx.parent=%?)",
id, id,
cx.sess.codemap.span_to_str(sp), cx.sess.codemap.span_to_str(sp),
body.node.id, body.id,
cx.parent); cx.parent);
// The arguments and `self` are parented to the body of the fn. // The arguments and `self` are parented to the body of the fn.
let decl_cx = Context {parent: Some(body.node.id), let decl_cx = Context {parent: Some(body.id),
var_parent: Some(body.node.id), var_parent: Some(body.id),
..cx}; ..cx};
match *fk { match *fk {
visit::fk_method(_, _, method) => { visit::fk_method(_, _, method) => {
cx.region_maps.record_parent(method.self_id, body.node.id); cx.region_maps.record_parent(method.self_id, body.id);
} }
_ => {} _ => {}
} }

View File

@ -1069,12 +1069,12 @@ impl Resolver {
pub fn block_needs_anonymous_module(@mut self, block: &blk) -> bool { pub fn block_needs_anonymous_module(@mut self, block: &blk) -> bool {
// If the block has view items, we need an anonymous module. // If the block has view items, we need an anonymous module.
if block.node.view_items.len() > 0 { if block.view_items.len() > 0 {
return true; return true;
} }
// Check each statement. // Check each statement.
for block.node.stmts.iter().advance |statement| { for block.stmts.iter().advance |statement| {
match statement.node { match statement.node {
stmt_decl(declaration, _) => { stmt_decl(declaration, _) => {
match declaration.node { match declaration.node {
@ -1566,7 +1566,7 @@ impl Resolver {
vt<ReducedGraphParent>)) { vt<ReducedGraphParent>)) {
let new_parent; let new_parent;
if self.block_needs_anonymous_module(block) { if self.block_needs_anonymous_module(block) {
let block_id = block.node.id; let block_id = block.id;
debug!("(building reduced graph for block) creating a new \ debug!("(building reduced graph for block) creating a new \
anonymous module for block %d", anonymous module for block %d",
@ -4096,7 +4096,7 @@ impl Resolver {
// Move down in the graph, if there's an anonymous module rooted here. // Move down in the graph, if there's an anonymous module rooted here.
let orig_module = self.current_module; let orig_module = self.current_module;
match self.current_module.anonymous_children.find(&block.node.id) { match self.current_module.anonymous_children.find(&block.id) {
None => { /* Nothing to do. */ } None => { /* Nothing to do. */ }
Some(&anonymous_module) => { Some(&anonymous_module) => {
debug!("(resolving block) found anonymous module, moving \ debug!("(resolving block) found anonymous module, moving \
@ -4989,7 +4989,7 @@ impl Resolver {
} }
expr_fn_block(ref fn_decl, ref block) => { expr_fn_block(ref fn_decl, ref block) => {
self.resolve_function(FunctionRibKind(expr.id, block.node.id), self.resolve_function(FunctionRibKind(expr.id, block.id),
Some(fn_decl), Some(fn_decl),
NoTypeParameters, NoTypeParameters,
block, block,

View File

@ -1446,7 +1446,7 @@ pub fn with_scope_datumblock(bcx: block, opt_node_info: Option<NodeInfo>,
} }
pub fn block_locals(b: &ast::blk, it: &fn(@ast::local)) { pub fn block_locals(b: &ast::blk, it: &fn(@ast::local)) {
for b.node.stmts.iter().advance |s| { for b.stmts.iter().advance |s| {
match s.node { match s.node {
ast::stmt_decl(d, _) => { ast::stmt_decl(d, _) => {
match d.node { match d.node {
@ -1874,7 +1874,7 @@ pub fn trans_closure(ccx: @mut CrateContext,
let bcx_top = top_scope_block(fcx, body.info()); let bcx_top = top_scope_block(fcx, body.info());
let mut bcx = bcx_top; let mut bcx = bcx_top;
let lltop = bcx.llbb; let lltop = bcx.llbb;
let block_ty = node_id_type(bcx, body.node.id); let block_ty = node_id_type(bcx, body.id);
let arg_tys = ty::ty_fn_args(node_id_type(bcx, id)); let arg_tys = ty::ty_fn_args(node_id_type(bcx, id));
bcx = copy_args_to_allocas(fcx, bcx, decl.inputs, raw_llargs, arg_tys); bcx = copy_args_to_allocas(fcx, bcx, decl.inputs, raw_llargs, arg_tys);
@ -1885,7 +1885,7 @@ pub fn trans_closure(ccx: @mut CrateContext,
// translation calls that don't have a return value (trans_crate, // translation calls that don't have a return value (trans_crate,
// trans_mod, trans_item, et cetera) and those that do // trans_mod, trans_item, et cetera) and those that do
// (trans_block, trans_expr, et cetera). // (trans_block, trans_expr, et cetera).
if body.node.expr.is_none() || ty::type_is_bot(block_ty) || if body.expr.is_none() || ty::type_is_bot(block_ty) ||
ty::type_is_nil(block_ty) ty::type_is_nil(block_ty)
{ {
bcx = controlflow::trans_block(bcx, body, expr::Ignore); bcx = controlflow::trans_block(bcx, body, expr::Ignore);
@ -2148,7 +2148,7 @@ pub fn trans_item(ccx: @mut CrateContext, item: &ast::item) {
item.id, item.id,
item.attrs); item.attrs);
} else { } else {
for body.node.stmts.iter().advance |stmt| { for body.stmts.iter().advance |stmt| {
match stmt.node { match stmt.node {
ast::stmt_decl(@codemap::spanned { node: ast::decl_item(i), ast::stmt_decl(@codemap::spanned { node: ast::decl_item(i),
_ }, _) => { _ }, _) => {

View File

@ -482,7 +482,7 @@ impl get_node_info for ast::expr {
impl get_node_info for ast::blk { impl get_node_info for ast::blk {
fn info(&self) -> Option<NodeInfo> { fn info(&self) -> Option<NodeInfo> {
Some(NodeInfo {id: self.node.id, Some(NodeInfo {id: self.id,
callee_id: None, callee_id: None,
span: self.span}) span: self.span})
} }

View File

@ -37,11 +37,11 @@ use syntax::codemap::span;
pub fn trans_block(bcx: block, b: &ast::blk, dest: expr::Dest) -> block { pub fn trans_block(bcx: block, b: &ast::blk, dest: expr::Dest) -> block {
let _icx = push_ctxt("trans_block"); let _icx = push_ctxt("trans_block");
let mut bcx = bcx; let mut bcx = bcx;
for b.node.stmts.iter().advance |s| { for b.stmts.iter().advance |s| {
debuginfo::update_source_pos(bcx, b.span); debuginfo::update_source_pos(bcx, b.span);
bcx = trans_stmt(bcx, *s); bcx = trans_stmt(bcx, *s);
} }
match b.node.expr { match b.expr {
Some(e) => { Some(e) => {
debuginfo::update_source_pos(bcx, e.span); debuginfo::update_source_pos(bcx, e.span);
bcx = expr::trans_into(bcx, e, dest); bcx = expr::trans_into(bcx, e, dest);
@ -60,7 +60,7 @@ pub fn trans_if(bcx: block,
dest: expr::Dest) dest: expr::Dest)
-> block { -> block {
debug!("trans_if(bcx=%s, cond=%s, thn=%?, dest=%s)", debug!("trans_if(bcx=%s, cond=%s, thn=%?, dest=%s)",
bcx.to_str(), bcx.expr_to_str(cond), thn.node.id, bcx.to_str(), bcx.expr_to_str(cond), thn.id,
dest.to_str(bcx.ccx())); dest.to_str(bcx.ccx()));
let _indenter = indenter(); let _indenter = indenter();

View File

@ -414,7 +414,7 @@ pub fn handle_body(cx: &Context, body: &blk) {
}, },
visit_block: |b, (cx, v)| { visit_block: |b, (cx, v)| {
visit::visit_block(b, (cx, v)); visit::visit_block(b, (cx, v));
for b.node.expr.iter().advance |e| { for b.expr.iter().advance |e| {
node_type_needs(cx, use_repr, e.id); node_type_needs(cx, use_repr, e.id);
} }
}, },

View File

@ -2842,7 +2842,7 @@ pub fn tys_in_fn_sig(sig: &FnSig) -> ~[t] {
// Type accessors for AST nodes // Type accessors for AST nodes
pub fn block_ty(cx: ctxt, b: &ast::blk) -> t { pub fn block_ty(cx: ctxt, b: &ast::blk) -> t {
return node_id_to_type(cx, b.node.id); return node_id_to_type(cx, b.id);
} }

View File

@ -72,14 +72,14 @@ pub fn check_match(fcx: @mut FnCtxt,
None => () None => ()
} }
check_block(fcx, &arm.body); check_block(fcx, &arm.body);
let bty = fcx.node_ty(arm.body.node.id); let bty = fcx.node_ty(arm.body.id);
saw_err = saw_err || ty::type_is_error(bty); saw_err = saw_err || ty::type_is_error(bty);
if guard_err { if guard_err {
fcx.write_error(arm.body.node.id); fcx.write_error(arm.body.id);
saw_err = true; saw_err = true;
} }
else if guard_bot { else if guard_bot {
fcx.write_bot(arm.body.node.id); fcx.write_bot(arm.body.id);
} }
result_ty = result_ty =

View File

@ -200,8 +200,8 @@ impl PurityState {
ast::unsafe_fn if self.from_fn => *self, ast::unsafe_fn if self.from_fn => *self,
purity => { purity => {
let (purity, def) = match blk.node.rules { let (purity, def) = match blk.rules {
ast::unsafe_blk => (ast::unsafe_fn, blk.node.id), ast::unsafe_blk => (ast::unsafe_fn, blk.id),
ast::default_blk => (purity, self.def), ast::default_blk => (purity, self.def),
}; };
PurityState{ def: def, PurityState{ def: def,
@ -365,7 +365,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
let (isr, opt_self_ty, fn_sig) = let (isr, opt_self_ty, fn_sig) =
replace_bound_regions_in_fn_sig( replace_bound_regions_in_fn_sig(
tcx, inherited_isr, opt_self_ty, fn_sig, tcx, inherited_isr, opt_self_ty, fn_sig,
|br| ty::re_free(ty::FreeRegion {scope_id: body.node.id, |br| ty::re_free(ty::FreeRegion {scope_id: body.id,
bound_region: br})); bound_region: br}));
let opt_self_info = let opt_self_info =
opt_self_info.map( opt_self_info.map(
@ -399,7 +399,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
ret_ty: ret_ty, ret_ty: ret_ty,
indirect_ret_ty: indirect_ret_ty, indirect_ret_ty: indirect_ret_ty,
ps: PurityState::function(purity, id), ps: PurityState::function(purity, id),
region_lb: body.node.id, region_lb: body.id,
in_scope_regions: isr, in_scope_regions: isr,
fn_kind: fn_kind, fn_kind: fn_kind,
inh: inherited, inh: inherited,
@ -412,7 +412,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
// We unify the tail expr's type with the // We unify the tail expr's type with the
// function result type, if there is a tail expr. // function result type, if there is a tail expr.
match body.node.expr { match body.expr {
Some(tail_expr) => { Some(tail_expr) => {
let tail_expr_ty = fcx.expr_ty(tail_expr); let tail_expr_ty = fcx.expr_ty(tail_expr);
// Special case: we print a special error if there appears // Special case: we print a special error if there appears
@ -515,7 +515,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
// non-obvious: the `blk` variable maps to region lb, so // non-obvious: the `blk` variable maps to region lb, so
// we have to keep this up-to-date. This // we have to keep this up-to-date. This
// is... unfortunate. It'd be nice to not need this. // is... unfortunate. It'd be nice to not need this.
do fcx.with_region_lb(b.node.id) { do fcx.with_region_lb(b.id) {
visit::visit_block(b, (e, v)); visit::visit_block(b, (e, v));
} }
}; };
@ -1456,7 +1456,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
let branches_ty = match opt_else_expr { let branches_ty = match opt_else_expr {
Some(else_expr) => { Some(else_expr) => {
check_block_with_expected(fcx, then_blk, expected); check_block_with_expected(fcx, then_blk, expected);
let then_ty = fcx.node_ty(then_blk.node.id); let then_ty = fcx.node_ty(then_blk.id);
check_expr_with_opt_hint(fcx, else_expr, expected); check_expr_with_opt_hint(fcx, else_expr, expected);
let else_ty = fcx.expr_ty(else_expr); let else_ty = fcx.expr_ty(else_expr);
infer::common_supertype(fcx.infcx(), infer::common_supertype(fcx.infcx(),
@ -2533,7 +2533,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
check_expr_has_type(fcx, cond, ty::mk_bool()); check_expr_has_type(fcx, cond, ty::mk_bool());
check_block_no_value(fcx, body); check_block_no_value(fcx, body);
let cond_ty = fcx.expr_ty(cond); let cond_ty = fcx.expr_ty(cond);
let body_ty = fcx.node_ty(body.node.id); let body_ty = fcx.node_ty(body.id);
if ty::type_is_error(cond_ty) || ty::type_is_error(body_ty) { if ty::type_is_error(cond_ty) || ty::type_is_error(body_ty) {
fcx.write_error(id); fcx.write_error(id);
} }
@ -2598,7 +2598,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
} }
ast::expr_block(ref b) => { ast::expr_block(ref b) => {
check_block_with_expected(fcx, b, expected); check_block_with_expected(fcx, b, expected);
fcx.write_ty(id, fcx.node_ty(b.node.id)); fcx.write_ty(id, fcx.node_ty(b.id));
} }
ast::expr_call(f, ref args, sugar) => { ast::expr_call(f, ref args, sugar) => {
check_call(fcx, expr.id, expr, f, *args, sugar); check_call(fcx, expr.id, expr, f, *args, sugar);
@ -2959,12 +2959,12 @@ pub fn check_stmt(fcx: @mut FnCtxt, stmt: @ast::stmt) {
pub fn check_block_no_value(fcx: @mut FnCtxt, blk: &ast::blk) { pub fn check_block_no_value(fcx: @mut FnCtxt, blk: &ast::blk) {
check_block_with_expected(fcx, blk, Some(ty::mk_nil())); check_block_with_expected(fcx, blk, Some(ty::mk_nil()));
let blkty = fcx.node_ty(blk.node.id); let blkty = fcx.node_ty(blk.id);
if ty::type_is_error(blkty) { if ty::type_is_error(blkty) {
fcx.write_error(blk.node.id); fcx.write_error(blk.id);
} }
else if ty::type_is_bot(blkty) { else if ty::type_is_bot(blkty) {
fcx.write_bot(blk.node.id); fcx.write_bot(blk.id);
} }
else { else {
let nilty = ty::mk_nil(); let nilty = ty::mk_nil();
@ -2982,12 +2982,12 @@ pub fn check_block_with_expected(fcx: @mut FnCtxt,
let purity_state = fcx.ps.recurse(blk); let purity_state = fcx.ps.recurse(blk);
let prev = replace(&mut fcx.ps, purity_state); let prev = replace(&mut fcx.ps, purity_state);
do fcx.with_region_lb(blk.node.id) { do fcx.with_region_lb(blk.id) {
let mut warned = false; let mut warned = false;
let mut last_was_bot = false; let mut last_was_bot = false;
let mut any_bot = false; let mut any_bot = false;
let mut any_err = false; let mut any_err = false;
for blk.node.stmts.iter().advance |s| { for blk.stmts.iter().advance |s| {
check_stmt(fcx, *s); check_stmt(fcx, *s);
let s_id = ast_util::stmt_id(*s); let s_id = ast_util::stmt_id(*s);
let s_ty = fcx.node_ty(s_id); let s_ty = fcx.node_ty(s_id);
@ -3009,15 +3009,15 @@ pub fn check_block_with_expected(fcx: @mut FnCtxt,
any_bot = any_bot || ty::type_is_bot(s_ty); any_bot = any_bot || ty::type_is_bot(s_ty);
any_err = any_err || ty::type_is_error(s_ty); any_err = any_err || ty::type_is_error(s_ty);
} }
match blk.node.expr { match blk.expr {
None => if any_err { None => if any_err {
fcx.write_error(blk.node.id); fcx.write_error(blk.id);
} }
else if any_bot { else if any_bot {
fcx.write_bot(blk.node.id); fcx.write_bot(blk.id);
} }
else { else {
fcx.write_nil(blk.node.id); fcx.write_nil(blk.id);
}, },
Some(e) => { Some(e) => {
if any_bot && !warned { if any_bot && !warned {
@ -3025,12 +3025,12 @@ pub fn check_block_with_expected(fcx: @mut FnCtxt,
} }
check_expr_with_opt_hint(fcx, e, expected); check_expr_with_opt_hint(fcx, e, expected);
let ety = fcx.expr_ty(e); let ety = fcx.expr_ty(e);
fcx.write_ty(blk.node.id, ety); fcx.write_ty(blk.id, ety);
if any_err { if any_err {
fcx.write_error(blk.node.id); fcx.write_error(blk.id);
} }
else if any_bot { else if any_bot {
fcx.write_bot(blk.node.id); fcx.write_bot(blk.id);
} }
} }
}; };

View File

@ -155,7 +155,7 @@ pub fn regionck_expr(fcx: @mut FnCtxt, e: @ast::expr) {
pub fn regionck_fn(fcx: @mut FnCtxt, blk: &ast::blk) { pub fn regionck_fn(fcx: @mut FnCtxt, blk: &ast::blk) {
let rcx = @mut Rcx { fcx: fcx, errors_reported: 0, let rcx = @mut Rcx { fcx: fcx, errors_reported: 0,
repeating_scope: blk.node.id }; repeating_scope: blk.id };
if fcx.err_count_since_creation() == 0 { if fcx.err_count_since_creation() == 0 {
// regionck assumes typeck succeeded // regionck assumes typeck succeeded
let v = regionck_visitor(); let v = regionck_visitor();
@ -188,7 +188,7 @@ fn visit_item(_item: @ast::item, (_rcx, _v): (@mut Rcx, rvt)) {
} }
fn visit_block(b: &ast::blk, (rcx, v): (@mut Rcx, rvt)) { fn visit_block(b: &ast::blk, (rcx, v): (@mut Rcx, rvt)) {
rcx.fcx.tcx().region_maps.record_cleanup_scope(b.node.id); rcx.fcx.tcx().region_maps.record_cleanup_scope(b.id);
visit::visit_block(b, (rcx, v)); visit::visit_block(b, (rcx, v));
} }
@ -287,11 +287,11 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
} }
} }
ast::expr_loop(ref body, _) => { ast::expr_loop(ref body, _) => {
tcx.region_maps.record_cleanup_scope(body.node.id); tcx.region_maps.record_cleanup_scope(body.id);
} }
ast::expr_while(cond, ref body) => { ast::expr_while(cond, ref body) => {
tcx.region_maps.record_cleanup_scope(cond.id); tcx.region_maps.record_cleanup_scope(cond.id);
tcx.region_maps.record_cleanup_scope(body.node.id); tcx.region_maps.record_cleanup_scope(body.id);
} }
_ => {} _ => {}
} }
@ -434,7 +434,7 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
} }
ast::expr_loop(ref body, _) => { ast::expr_loop(ref body, _) => {
let repeating_scope = rcx.set_repeating_scope(body.node.id); let repeating_scope = rcx.set_repeating_scope(body.id);
visit::visit_expr(expr, (rcx, v)); visit::visit_expr(expr, (rcx, v));
rcx.set_repeating_scope(repeating_scope); rcx.set_repeating_scope(repeating_scope);
} }
@ -443,7 +443,7 @@ fn visit_expr(expr: @ast::expr, (rcx, v): (@mut Rcx, rvt)) {
let repeating_scope = rcx.set_repeating_scope(cond.id); let repeating_scope = rcx.set_repeating_scope(cond.id);
(v.visit_expr)(cond, (rcx, v)); (v.visit_expr)(cond, (rcx, v));
rcx.set_repeating_scope(body.node.id); rcx.set_repeating_scope(body.id);
(v.visit_block)(body, (rcx, v)); (v.visit_block)(body, (rcx, v));
rcx.set_repeating_scope(repeating_scope); rcx.set_repeating_scope(repeating_scope);
@ -486,7 +486,7 @@ fn check_expr_fn_block(rcx: @mut Rcx,
_ => () _ => ()
} }
let repeating_scope = rcx.set_repeating_scope(body.node.id); let repeating_scope = rcx.set_repeating_scope(body.id);
visit::visit_expr(expr, (rcx, v)); visit::visit_expr(expr, (rcx, v));
rcx.set_repeating_scope(repeating_scope); rcx.set_repeating_scope(repeating_scope);
} }

View File

@ -276,7 +276,7 @@ fn visit_block(b: &ast::blk, (wbcx, v): (@mut WbCtxt, wb_vt)) {
return; return;
} }
resolve_type_vars_for_node(wbcx, b.span, b.node.id); resolve_type_vars_for_node(wbcx, b.span, b.id);
visit::visit_block(b, (wbcx, v)); visit::visit_block(b, (wbcx, v));
} }

View File

@ -749,7 +749,7 @@ pub fn convert_methods(ccx: &CrateCtxt,
write_ty_to_tcx(tcx, m.id, fty); write_ty_to_tcx(tcx, m.id, fty);
tcx.methods.insert(mty.def_id, mty); tcx.methods.insert(mty.def_id, mty);
ConvertedMethod {mty: mty, id: m.id, ConvertedMethod {mty: mty, id: m.id,
span: m.span, body_id: m.body.node.id} span: m.span, body_id: m.body.id}
}).collect(); }).collect();
fn ty_of_method(ccx: &CrateCtxt, fn ty_of_method(ccx: &CrateCtxt,

View File

@ -346,7 +346,7 @@ impl Program {
// helper functions to perform ast iteration // helper functions to perform ast iteration
fn each_user_local(blk: &ast::blk, f: &fn(@ast::local)) { fn each_user_local(blk: &ast::blk, f: &fn(@ast::local)) {
do find_user_block(blk) |blk| { do find_user_block(blk) |blk| {
for blk.node.stmts.iter().advance |stmt| { for blk.stmts.iter().advance |stmt| {
match stmt.node { match stmt.node {
ast::stmt_decl(d, _) => { ast::stmt_decl(d, _) => {
match d.node { match d.node {
@ -361,7 +361,7 @@ impl Program {
} }
fn find_user_block(blk: &ast::blk, f: &fn(&ast::blk)) { fn find_user_block(blk: &ast::blk, f: &fn(&ast::blk)) {
for blk.node.stmts.iter().advance |stmt| { for blk.stmts.iter().advance |stmt| {
match stmt.node { match stmt.node {
ast::stmt_semi(e, _) => { ast::stmt_semi(e, _) => {
match e.node { match e.node {

View File

@ -149,7 +149,7 @@ fn run(mut program: ~Program, binary: ~str, lib_search_paths: ~[~str],
do find_main(crate, sess) |blk| { do find_main(crate, sess) |blk| {
// Fish out all the view items, be sure to record 'extern mod' items // Fish out all the view items, be sure to record 'extern mod' items
// differently beause they must appear before all 'use' statements // differently beause they must appear before all 'use' statements
for blk.node.view_items.iter().advance |vi| { for blk.view_items.iter().advance |vi| {
let s = do with_pp(intr) |pp, _| { let s = do with_pp(intr) |pp, _| {
pprust::print_view_item(pp, vi); pprust::print_view_item(pp, vi);
}; };
@ -163,7 +163,7 @@ fn run(mut program: ~Program, binary: ~str, lib_search_paths: ~[~str],
// Iterate through all of the block's statements, inserting them into // Iterate through all of the block's statements, inserting them into
// the correct portions of the program // the correct portions of the program
for blk.node.stmts.iter().advance |stmt| { for blk.stmts.iter().advance |stmt| {
let s = do with_pp(intr) |pp, _| { pprust::print_stmt(pp, *stmt); }; let s = do with_pp(intr) |pp, _| { pprust::print_stmt(pp, *stmt); };
match stmt.node { match stmt.node {
ast::stmt_decl(d, _) => { ast::stmt_decl(d, _) => {
@ -203,7 +203,7 @@ fn run(mut program: ~Program, binary: ~str, lib_search_paths: ~[~str],
} }
} }
} }
result = do blk.node.expr.map_consume |e| { result = do blk.expr.map_consume |e| {
do with_pp(intr) |pp, _| { pprust::print_expr(pp, e); } do with_pp(intr) |pp, _| { pprust::print_expr(pp, e); }
}; };
} }

View File

@ -215,15 +215,16 @@ pub enum meta_item_ {
meta_name_value(@str, lit), meta_name_value(@str, lit),
} }
pub type blk = spanned<blk_>; //pub type blk = spanned<blk_>;
#[deriving(Eq, Encodable, Decodable,IterBytes)] #[deriving(Eq, Encodable, Decodable,IterBytes)]
pub struct blk_ { pub struct blk {
view_items: ~[view_item], view_items: ~[view_item],
stmts: ~[@stmt], stmts: ~[@stmt],
expr: Option<@expr>, expr: Option<@expr>,
id: node_id, id: node_id,
rules: blk_check_mode, rules: blk_check_mode,
span: span,
} }
#[deriving(Eq, Encodable, Decodable,IterBytes)] #[deriving(Eq, Encodable, Decodable,IterBytes)]

View File

@ -190,7 +190,7 @@ pub fn map_fn(
} }
pub fn map_block(b: &blk, (cx,v): (@mut Ctx, visit::vt<@mut Ctx>)) { pub fn map_block(b: &blk, (cx,v): (@mut Ctx, visit::vt<@mut Ctx>)) {
cx.map.insert(b.node.id, node_block(/* FIXME (#2543) */ copy *b)); cx.map.insert(b.id, node_block(/* FIXME (#2543) */ copy *b));
visit::visit_block(b, (cx, v)); visit::visit_block(b, (cx, v));
} }

View File

@ -11,7 +11,7 @@
use ast::*; use ast::*;
use ast; use ast;
use ast_util; use ast_util;
use codemap::{span, spanned}; use codemap::{span, dummy_sp};
use opt_vec; use opt_vec;
use parse::token; use parse::token;
use visit; use visit;
@ -194,21 +194,23 @@ pub fn is_call_expr(e: @expr) -> bool {
} }
pub fn block_from_expr(e: @expr) -> blk { pub fn block_from_expr(e: @expr) -> blk {
let blk_ = default_block(~[], option::Some::<@expr>(e), e.id); let mut blk = default_block(~[], option::Some::<@expr>(e), e.id);
return spanned {node: blk_, span: e.span}; blk.span = e.span;
return blk;
} }
pub fn default_block( pub fn default_block(
stmts1: ~[@stmt], stmts1: ~[@stmt],
expr1: Option<@expr>, expr1: Option<@expr>,
id1: node_id id1: node_id
) -> blk_ { ) -> blk {
ast::blk_ { ast::blk {
view_items: ~[], view_items: ~[],
stmts: stmts1, stmts: stmts1,
expr: expr1, expr: expr1,
id: id1, id: id1,
rules: default_blk, rules: default_blk,
span: dummy_sp(),
} }
} }
@ -437,7 +439,7 @@ pub fn id_visitor<T: Copy>(vfn: @fn(node_id, T)) -> visit::vt<T> {
visit::visit_local(l, (t, vt)); visit::visit_local(l, (t, vt));
}, },
visit_block: |b, (t, vt)| { visit_block: |b, (t, vt)| {
vfn(b.node.id, copy t); vfn(b.id, copy t);
visit::visit_block(b, (t, vt)); visit::visit_block(b, (t, vt));
}, },
visit_stmt: |s, (t, vt)| { visit_stmt: |s, (t, vt)| {

View File

@ -400,14 +400,14 @@ impl AstBuilder for @ExtCtxt {
view_items: ~[ast::view_item], view_items: ~[ast::view_item],
stmts: ~[@ast::stmt], stmts: ~[@ast::stmt],
expr: Option<@ast::expr>) -> ast::blk { expr: Option<@ast::expr>) -> ast::blk {
respan(span, ast::blk {
ast::blk_ { view_items: view_items,
view_items: view_items, stmts: stmts,
stmts: stmts, expr: expr,
expr: expr, id: self.next_id(),
id: self.next_id(), rules: ast::default_blk,
rules: ast::default_blk, span: span,
}) }
} }
fn expr(&self, span: span, node: ast::expr_) -> @ast::expr { fn expr(&self, span: span, node: ast::expr_) -> @ast::expr {

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use ast::{blk_, crate, expr_, expr_mac, mac_invoc_tt}; use ast::{blk, crate, expr_, expr_mac, mac_invoc_tt};
use ast::{item_mac, stmt_, stmt_mac, stmt_expr, stmt_semi}; use ast::{item_mac, stmt_, stmt_mac, stmt_expr, stmt_semi};
use ast::{illegal_ctxt}; use ast::{illegal_ctxt};
use ast; use ast;
@ -394,13 +394,12 @@ pub fn new_name_finder() -> @Visitor<@mut ~[ast::ident]> {
pub fn expand_block(extsbox: @mut SyntaxEnv, pub fn expand_block(extsbox: @mut SyntaxEnv,
_cx: @ExtCtxt, _cx: @ExtCtxt,
blk: &blk_, blk: &blk,
sp: span,
fld: @ast_fold, fld: @ast_fold,
orig: @fn(&blk_, span, @ast_fold) -> (blk_, span)) orig: @fn(&blk, @ast_fold) -> blk)
-> (blk_, span) { -> blk {
// see note below about treatment of exts table // see note below about treatment of exts table
with_exts_frame!(extsbox,false,orig(blk,sp,fld)) with_exts_frame!(extsbox,false,orig(blk,fld))
} }
@ -736,8 +735,8 @@ pub fn expand_crate(parse_sess: @mut parse::ParseSess,
expand_item(extsbox, cx, item, recur, afp.fold_item), expand_item(extsbox, cx, item, recur, afp.fold_item),
fold_stmt: |stmt,span,recur| fold_stmt: |stmt,span,recur|
expand_stmt(extsbox, cx, stmt, span, recur, afp.fold_stmt), expand_stmt(extsbox, cx, stmt, span, recur, afp.fold_stmt),
fold_block: |blk,span,recur| fold_block: |blk,recur|
expand_block(extsbox, cx, blk, span, recur, afp.fold_block), expand_block(extsbox, cx, blk, recur, afp.fold_block),
new_span: |a| new_span(cx, a), new_span: |a| new_span(cx, a),
.. *afp}; .. *afp};
let f = make_fold(f_pre); let f = make_fold(f_pre);

View File

@ -51,7 +51,7 @@ pub struct AstFoldFns {
fold_struct_field: @fn(@struct_field, @ast_fold) -> @struct_field, fold_struct_field: @fn(@struct_field, @ast_fold) -> @struct_field,
fold_item_underscore: @fn(&item_, @ast_fold) -> item_, fold_item_underscore: @fn(&item_, @ast_fold) -> item_,
fold_method: @fn(@method, @ast_fold) -> @method, fold_method: @fn(@method, @ast_fold) -> @method,
fold_block: @fn(&blk_, span, @ast_fold) -> (blk_, span), fold_block: @fn(&blk, @ast_fold) -> blk,
fold_stmt: @fn(&stmt_, span, @ast_fold) -> (Option<stmt_>, span), fold_stmt: @fn(&stmt_, span, @ast_fold) -> (Option<stmt_>, span),
fold_arm: @fn(&arm, @ast_fold) -> arm, fold_arm: @fn(&arm, @ast_fold) -> arm,
fold_pat: @fn(&pat_, span, @ast_fold) -> (pat_, span), fold_pat: @fn(&pat_, span, @ast_fold) -> (pat_, span),
@ -372,7 +372,7 @@ fn noop_fold_method(m: @method, fld: @ast_fold) -> @method {
} }
pub fn noop_fold_block(b: &blk_, fld: @ast_fold) -> blk_ { pub fn noop_fold_block(b: &blk, fld: @ast_fold) -> blk {
let view_items = b.view_items.map(|x| fld.fold_view_item(x)); let view_items = b.view_items.map(|x| fld.fold_view_item(x));
let mut stmts = ~[]; let mut stmts = ~[];
for b.stmts.iter().advance |stmt| { for b.stmts.iter().advance |stmt| {
@ -381,12 +381,13 @@ pub fn noop_fold_block(b: &blk_, fld: @ast_fold) -> blk_ {
Some(stmt) => stmts.push(stmt) Some(stmt) => stmts.push(stmt)
} }
} }
ast::blk_ { ast::blk {
view_items: view_items, view_items: view_items,
stmts: stmts, stmts: stmts,
expr: b.expr.map(|x| fld.fold_expr(*x)), expr: b.expr.map(|x| fld.fold_expr(*x)),
id: fld.new_id(b.id), id: fld.new_id(b.id),
rules: b.rules, rules: b.rules,
span: b.span,
} }
} }
@ -794,7 +795,7 @@ pub fn default_ast_fold() -> ast_fold_fns {
fold_struct_field: noop_fold_struct_field, fold_struct_field: noop_fold_struct_field,
fold_item_underscore: noop_fold_item_underscore, fold_item_underscore: noop_fold_item_underscore,
fold_method: noop_fold_method, fold_method: noop_fold_method,
fold_block: wrap(noop_fold_block), fold_block: noop_fold_block,
fold_stmt: |x, s, fld| (noop_fold_stmt(x, fld), s), fold_stmt: |x, s, fld| (noop_fold_stmt(x, fld), s),
fold_arm: noop_fold_arm, fold_arm: noop_fold_arm,
fold_pat: wrap(noop_fold_pat), fold_pat: wrap(noop_fold_pat),
@ -851,8 +852,7 @@ impl ast_fold for AstFoldFns {
(self.fold_method)(x, self as @ast_fold) (self.fold_method)(x, self as @ast_fold)
} }
fn fold_block(@self, x: &blk) -> blk { fn fold_block(@self, x: &blk) -> blk {
let (n, s) = (self.fold_block)(&x.node, x.span, self as @ast_fold); (self.fold_block)(x, self as @ast_fold)
spanned { node: n, span: (self.new_span)(s) }
} }
fn fold_stmt(@self, x: &stmt) -> Option<@stmt> { fn fold_stmt(@self, x: &stmt) -> Option<@stmt> {
let (n_opt, s) = (self.fold_stmt)(&x.node, x.span, self as @ast_fold); let (n_opt, s) = (self.fold_stmt)(&x.node, x.span, self as @ast_fold);

View File

@ -13,7 +13,6 @@
*/ */
use ast; use ast;
use codemap;
// does this expression require a semicolon to be treated // does this expression require a semicolon to be treated
// as a statement? The negation of this: 'can this expression // as a statement? The negation of this: 'can this expression
@ -40,8 +39,7 @@ pub fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool {
pub fn expr_is_simple_block(e: @ast::expr) -> bool { pub fn expr_is_simple_block(e: @ast::expr) -> bool {
match e.node { match e.node {
ast::expr_block( ast::expr_block(
codemap::spanned { ast::blk { rules: ast::default_blk, _ }
node: ast::blk_ { rules: ast::default_blk, _ }, _ }
) => true, ) => true,
_ => false _ => false
} }

View File

@ -557,27 +557,26 @@ mod test {
lifetimes: opt_vec::Empty, lifetimes: opt_vec::Empty,
ty_params: opt_vec::Empty, ty_params: opt_vec::Empty,
}, },
spanned{ ast::blk {
view_items: ~[],
stmts: ~[@spanned{
node: ast::stmt_semi(@ast::expr{
id: 6,
node: ast::expr_path(
ast::Path{
span:sp(17,18),
global:false,
idents:~[str_to_ident("b")],
rp:None,
types: ~[]}),
span: sp(17,18)},
7), // fixme
span: sp(17,18)}],
expr: None,
id: 8, // fixme
rules: ast::default_blk, // no idea
span: sp(15,21), span: sp(15,21),
node: ast::blk_{ }),
view_items: ~[],
stmts: ~[@spanned{
node: ast::stmt_semi(@ast::expr{
id: 6,
node: ast::expr_path(
ast::Path{
span:sp(17,18),
global:false,
idents:~[str_to_ident("b")],
rp:None,
types: ~[]}),
span: sp(17,18)},
7), // fixme
span: sp(17,18)}],
expr: None,
id: 8, // fixme
rules: ast::default_blk // no idea
}}),
vis: ast::inherited, vis: ast::inherited,
span: sp(0,21)})); span: sp(0,21)}));
} }

View File

@ -2245,15 +2245,15 @@ impl Parser {
let lo = self.last_span.lo; let lo = self.last_span.lo;
let decl = parse_decl(); let decl = parse_decl();
let body = parse_body(); let body = parse_body();
let fakeblock = ast::blk_ { let fakeblock = ast::blk {
view_items: ~[], view_items: ~[],
stmts: ~[], stmts: ~[],
expr: Some(body), expr: Some(body),
id: self.get_id(), id: self.get_id(),
rules: default_blk, rules: default_blk,
span: body.span,
}; };
let fakeblock = spanned(body.span.lo, body.span.hi,
fakeblock);
return self.mk_expr(lo, body.span.hi, return self.mk_expr(lo, body.span.hi,
expr_fn_block(decl, fakeblock)); expr_fn_block(decl, fakeblock));
} }
@ -2402,14 +2402,12 @@ impl Parser {
self.eat(&token::COMMA); self.eat(&token::COMMA);
} }
let blk = codemap::spanned { let blk = ast::blk {
node: ast::blk_ { view_items: ~[],
view_items: ~[], stmts: ~[],
stmts: ~[], expr: Some(expr),
expr: Some(expr), id: self.get_id(),
id: self.get_id(), rules: default_blk,
rules: default_blk,
},
span: expr.span, span: expr.span,
}; };
@ -3120,14 +3118,14 @@ impl Parser {
let hi = self.span.hi; let hi = self.span.hi;
self.bump(); self.bump();
let bloc = ast::blk_ { ast::blk {
view_items: view_items, view_items: view_items,
stmts: stmts, stmts: stmts,
expr: expr, expr: expr,
id: self.get_id(), id: self.get_id(),
rules: s, rules: s,
}; span: mk_sp(lo, hi),
spanned(lo, hi, bloc) }
} }
fn parse_optional_purity(&self) -> ast::purity { fn parse_optional_purity(&self) -> ast::purity {

View File

@ -932,7 +932,7 @@ pub fn print_possibly_embedded_block_(s: @ps,
indented: uint, indented: uint,
attrs: &[ast::attribute], attrs: &[ast::attribute],
close_box: bool) { close_box: bool) {
match blk.node.rules { match blk.rules {
ast::unsafe_blk => word_space(s, "unsafe"), ast::unsafe_blk => word_space(s, "unsafe"),
ast::default_blk => () ast::default_blk => ()
} }
@ -946,11 +946,11 @@ pub fn print_possibly_embedded_block_(s: @ps,
print_inner_attributes(s, attrs); print_inner_attributes(s, attrs);
for blk.node.view_items.iter().advance |vi| { print_view_item(s, vi); } for blk.view_items.iter().advance |vi| { print_view_item(s, vi); }
for blk.node.stmts.iter().advance |st| { for blk.stmts.iter().advance |st| {
print_stmt(s, *st); print_stmt(s, *st);
} }
match blk.node.expr { match blk.expr {
Some(expr) => { Some(expr) => {
space_if_not_bol(s); space_if_not_bol(s);
print_expr(s, expr); print_expr(s, expr);
@ -1255,12 +1255,12 @@ pub fn print_expr(s: @ps, expr: &ast::expr) {
// Extract the expression from the extra block the parser adds // Extract the expression from the extra block the parser adds
// in the case of foo => expr // in the case of foo => expr
if arm.body.node.view_items.is_empty() && if arm.body.view_items.is_empty() &&
arm.body.node.stmts.is_empty() && arm.body.stmts.is_empty() &&
arm.body.node.rules == ast::default_blk && arm.body.rules == ast::default_blk &&
arm.body.node.expr.is_some() arm.body.expr.is_some()
{ {
match arm.body.node.expr { match arm.body.expr {
Some(expr) => { Some(expr) => {
match expr.node { match expr.node {
ast::expr_block(ref blk) => { ast::expr_block(ref blk) => {
@ -1297,16 +1297,16 @@ pub fn print_expr(s: @ps, expr: &ast::expr) {
print_fn_block_args(s, decl); print_fn_block_args(s, decl);
space(s.s); space(s.s);
// } // }
assert!(body.node.stmts.is_empty()); assert!(body.stmts.is_empty());
assert!(body.node.expr.is_some()); assert!(body.expr.is_some());
// we extract the block, so as not to create another set of boxes // we extract the block, so as not to create another set of boxes
match body.node.expr.get().node { match body.expr.get().node {
ast::expr_block(ref blk) => { ast::expr_block(ref blk) => {
print_block_unclosed(s, blk); print_block_unclosed(s, blk);
} }
_ => { _ => {
// this is a bare expression // this is a bare expression
print_expr(s, body.node.expr.get()); print_expr(s, body.expr.get());
end(s); // need to close a box end(s); // need to close a box
} }
} }

View File

@ -413,13 +413,13 @@ pub fn visit_struct_field<E: Copy>(sf: &struct_field, (e, v): (E, vt<E>)) {
} }
pub fn visit_block<E: Copy>(b: &blk, (e, v): (E, vt<E>)) { pub fn visit_block<E: Copy>(b: &blk, (e, v): (E, vt<E>)) {
for b.node.view_items.iter().advance |vi| { for b.view_items.iter().advance |vi| {
(v.visit_view_item)(vi, (copy e, v)); (v.visit_view_item)(vi, (copy e, v));
} }
for b.node.stmts.iter().advance |s| { for b.stmts.iter().advance |s| {
(v.visit_stmt)(*s, (copy e, v)); (v.visit_stmt)(*s, (copy e, v));
} }
visit_expr_opt(b.node.expr, (e, v)); visit_expr_opt(b.expr, (e, v));
} }
pub fn visit_stmt<E>(s: &stmt, (e, v): (E, vt<E>)) { pub fn visit_stmt<E>(s: &stmt, (e, v): (E, vt<E>)) {