convert ast::blk_ into a struct

This commit is contained in:
Erick Tryzelaar 2013-01-14 19:35:08 -08:00
parent 0b9e23146b
commit 3ea3136e84
8 changed files with 108 additions and 65 deletions

View file

@ -313,11 +313,13 @@ type blk = spanned<blk_>;
#[auto_encode] #[auto_encode]
#[auto_decode] #[auto_decode]
type blk_ = {view_items: ~[@view_item], struct blk_ {
stmts: ~[@stmt], view_items: ~[@view_item],
expr: Option<@expr>, stmts: ~[@stmt],
id: node_id, expr: Option<@expr>,
rules: blk_check_mode}; id: node_id,
rules: blk_check_mode,
}
#[auto_encode] #[auto_encode]
#[auto_decode] #[auto_decode]

View file

@ -289,10 +289,18 @@ fn block_from_expr(e: @expr) -> blk {
return spanned {node: blk_, span: e.span}; return spanned {node: blk_, span: e.span};
} }
fn default_block(+stmts1: ~[@stmt], expr1: Option<@expr>, id1: node_id) -> fn default_block(
blk_ { +stmts1: ~[@stmt],
{view_items: ~[], stmts: stmts1, expr1: Option<@expr>,
expr: expr1, id: id1, rules: default_blk} id1: node_id
) -> blk_ {
ast::blk_ {
view_items: ~[],
stmts: stmts1,
expr: expr1,
id: id1,
rules: default_blk,
}
} }
fn ident_to_path(s: span, +i: ident) -> @path { fn ident_to_path(s: span, +i: ident) -> @path {

View file

@ -356,21 +356,29 @@ priv impl ext_ctxt {
} }
fn blk(span: span, stmts: ~[@ast::stmt]) -> ast::blk { fn blk(span: span, stmts: ~[@ast::stmt]) -> ast::blk {
ast::spanned { node: { view_items: ~[], ast::spanned {
stmts: stmts, node: ast::blk_ {
expr: None, view_items: ~[],
id: self.next_id(), stmts: stmts,
rules: ast::default_blk}, expr: None,
span: span } id: self.next_id(),
rules: ast::default_blk,
},
span: span,
}
} }
fn expr_blk(expr: @ast::expr) -> ast::blk { fn expr_blk(expr: @ast::expr) -> ast::blk {
ast::spanned { node: { view_items: ~[], ast::spanned {
stmts: ~[], node: ast::blk_ {
expr: Some(expr), view_items: ~[],
id: self.next_id(), stmts: ~[],
rules: ast::default_blk}, expr: Some(expr),
span: expr.span } id: self.next_id(),
rules: ast::default_blk,
},
span: expr.span,
}
} }
fn expr_path(span: span, strs: ~[ast::ident]) -> @ast::expr { fn expr_path(span: span, strs: ~[ast::ident]) -> @ast::expr {

View file

@ -196,39 +196,45 @@ fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool,
let decl = ast::spanned {node: ast::decl_local(~[local]), span: sp}; let decl = ast::spanned {node: ast::decl_local(~[local]), span: sp};
@ast::spanned { node: ast::stmt_decl(@decl, cx.next_id()), span: sp } @ast::spanned { node: ast::stmt_decl(@decl, cx.next_id()), span: sp }
} }
fn mk_block(cx: ext_ctxt, sp: span, fn mk_block(cx: ext_ctxt, span: span,
view_items: ~[@ast::view_item], view_items: ~[@ast::view_item],
stmts: ~[@ast::stmt], stmts: ~[@ast::stmt],
expr: Option<@ast::expr>) -> @ast::expr { expr: Option<@ast::expr>) -> @ast::expr {
let blk = ast::spanned { node: { view_items: view_items, let blk = ast::spanned {
stmts: stmts, node: ast::blk_ {
expr: expr, view_items: view_items,
id: cx.next_id(), stmts: stmts,
rules: ast::default_blk }, expr: expr,
span: sp }; id: cx.next_id(),
mk_expr(cx, sp, ast::expr_block(blk)) rules: ast::default_blk,
},
span: span,
};
mk_expr(cx, span, ast::expr_block(blk))
} }
fn mk_block_(cx: ext_ctxt, sp: span, +stmts: ~[@ast::stmt]) -> ast::blk { fn mk_block_(cx: ext_ctxt, span: span, +stmts: ~[@ast::stmt]) -> ast::blk {
ast::spanned { ast::spanned {
node: { node: ast::blk_ {
view_items: ~[], view_items: ~[],
stmts: move stmts, stmts: stmts,
expr: None, expr: None,
id: cx.next_id(), id: cx.next_id(),
rules: ast::default_blk rules: ast::default_blk,
}, },
span: sp span: span,
} }
} }
fn mk_simple_block(cx: ext_ctxt, span: span, expr: @ast::expr) -> ast::blk { fn mk_simple_block(cx: ext_ctxt, span: span, expr: @ast::expr) -> ast::blk {
let block = { ast::spanned {
view_items: ~[], node: ast::blk_ {
stmts: ~[], view_items: ~[],
expr: Some(expr), stmts: ~[],
id: cx.next_id(), expr: Some(expr),
rules: ast::default_blk id: cx.next_id(),
}; rules: ast::default_blk,
ast::spanned { node: block, span: span } },
span: span,
}
} }
fn mk_copy(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr { fn mk_copy(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
mk_expr(cx, sp, ast::expr_copy(e)) mk_expr(cx, sp, ast::expr_copy(e))

View file

@ -193,11 +193,13 @@ impl ext_ctxt: ext_ctxt_ast_builder {
} }
fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk { fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk {
let blk = {view_items: ~[], let blk = ast::blk_ {
stmts: stmts, view_items: ~[],
expr: Some(e), stmts: stmts,
id: self.next_id(), expr: Some(e),
rules: ast::default_blk}; id: self.next_id(),
rules: ast::default_blk,
};
spanned { node: blk, span: dummy_sp() } spanned { node: blk, span: dummy_sp() }
} }

View file

@ -319,11 +319,13 @@ fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method {
fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ { fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ {
return {view_items: vec::map(b.view_items, |x| fld.fold_view_item(*x)), ast::blk_ {
stmts: vec::map(b.stmts, |x| fld.fold_stmt(*x)), view_items: b.view_items.map(|x| fld.fold_view_item(*x)),
expr: option::map(&b.expr, |x| fld.fold_expr(*x)), stmts: b.stmts.map(|x| fld.fold_stmt(*x)),
id: fld.new_id(b.id), expr: b.expr.map(|x| fld.fold_expr(*x)),
rules: b.rules}; id: fld.new_id(b.id),
rules: b.rules,
}
} }
fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ { fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {

View file

@ -30,8 +30,9 @@ fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool {
fn expr_is_simple_block(e: @ast::expr) -> bool { fn expr_is_simple_block(e: @ast::expr) -> bool {
match e.node { match e.node {
ast::expr_block(ast::spanned {node: {rules: ast::default_blk, _}, _}) => ast::expr_block(
true, ast::spanned { node: ast::blk_ { rules: ast::default_blk, _ }, _ }
) => true,
_ => false _ => false
} }
} }

View file

@ -1574,8 +1574,13 @@ impl Parser {
let lo = self.last_span.lo; let lo = self.last_span.lo;
let (decl, captures) = parse_decl(); let (decl, captures) = parse_decl();
let body = parse_body(); let body = parse_body();
let fakeblock = {view_items: ~[], stmts: ~[], expr: Some(body), let fakeblock = ast::blk_ {
id: self.get_id(), rules: default_blk}; view_items: ~[],
stmts: ~[],
expr: Some(body),
id: self.get_id(),
rules: default_blk,
};
let fakeblock = spanned(body.span.lo, body.span.hi, let fakeblock = spanned(body.span.lo, body.span.hi,
fakeblock); fakeblock);
return self.mk_expr(lo, body.span.hi, return self.mk_expr(lo, body.span.hi,
@ -1753,12 +1758,16 @@ impl Parser {
self.eat(token::COMMA); self.eat(token::COMMA);
} }
let blk = spanned { node: { view_items: ~[], let blk = spanned {
stmts: ~[], node: ast::blk_ {
expr: Some(expr), view_items: ~[],
id: self.get_id(), stmts: ~[],
rules: default_blk}, expr: Some(expr),
span: expr.span }; id: self.get_id(),
rules: default_blk,
},
span: expr.span,
};
arms.push({pats: pats, guard: guard, body: blk}); arms.push({pats: pats, guard: guard, body: blk});
} }
@ -2378,9 +2387,14 @@ impl Parser {
} }
let mut hi = self.span.hi; let mut hi = self.span.hi;
self.bump(); self.bump();
let bloc = {view_items: view_items, stmts: stmts, expr: expr, let bloc = ast::blk_ {
id: self.get_id(), rules: s}; view_items: view_items,
return spanned(lo, hi, bloc); stmts: stmts,
expr: expr,
id: self.get_id(),
rules: s,
};
spanned(lo, hi, bloc)
} }
fn mk_ty_path(i: ident) -> @Ty { fn mk_ty_path(i: ident) -> @Ty {