1
Fork 0

Convert ast::{pat,field_pat,local_,arm} into structs

This commit is contained in:
Erick Tryzelaar 2013-01-14 20:52:28 -08:00
parent 3ea3136e84
commit 4bcd19f6be
13 changed files with 185 additions and 130 deletions

View file

@ -133,14 +133,19 @@ fn filter_stmt(cx: ctxt, &&stmt: @ast::stmt) ->
} }
} }
fn fold_block(cx: ctxt, b: ast::blk_, fld: fold::ast_fold) -> fn fold_block(
ast::blk_ { cx: ctxt,
b: ast::blk_,
fld: fold::ast_fold
) -> ast::blk_ {
let filtered_stmts = vec::filter_map(b.stmts, |a| filter_stmt(cx, *a)); let filtered_stmts = vec::filter_map(b.stmts, |a| filter_stmt(cx, *a));
return {view_items: /*bad*/copy b.view_items, ast::blk_ {
view_items: /*bad*/copy b.view_items,
stmts: vec::map(filtered_stmts, |x| fld.fold_stmt(*x)), stmts: vec::map(filtered_stmts, |x| fld.fold_stmt(*x)),
expr: option::map(&b.expr, |x| fld.fold_expr(*x)), expr: option::map(&b.expr, |x| fld.fold_expr(*x)),
id: b.id, id: b.id,
rules: b.rules}; rules: b.rules,
}
} }
fn item_in_cfg(cx: ctxt, item: @ast::item) -> bool { fn item_in_cfg(cx: ctxt, item: @ast::item) -> bool {

View file

@ -469,7 +469,7 @@ fn mk_test_wrapper(cx: test_ctxt,
cf: ast::return_val cf: ast::return_val
}; };
let wrapper_body: ast::blk = nospan({ let wrapper_body = nospan(ast::blk_ {
view_items: ~[], view_items: ~[],
stmts: ~[@call_stmt], stmts: ~[@call_stmt],
expr: option::None, expr: option::None,

View file

@ -267,7 +267,10 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
} }
}; };
// XXX: Bad copy. // XXX: Bad copy.
let blk_sans_items = { stmts: stmts_sans_items,.. copy blk }; let blk_sans_items = ast::blk_ {
stmts: stmts_sans_items,
.. copy blk
};
fold::noop_fold_block(blk_sans_items, fld) fold::noop_fold_block(blk_sans_items, fld)
} }

View file

@ -478,7 +478,7 @@ fn ctor_arity(cx: @MatchCheckCtxt, ctor: ctor, ty: ty::t) -> uint {
} }
fn wild() -> @pat { fn wild() -> @pat {
@{id: 0, node: pat_wild, span: ast_util::dummy_sp()} @pat {id: 0, node: pat_wild, span: ast_util::dummy_sp()}
} }
fn specialize(cx: @MatchCheckCtxt, r: ~[@pat], ctor_id: ctor, arity: uint, fn specialize(cx: @MatchCheckCtxt, r: ~[@pat], ctor_id: ctor, arity: uint,

View file

@ -499,7 +499,7 @@ fn enter_opt(bcx: block, m: &[@Match/&r], opt: &Opt, col: uint,
let _indenter = indenter(); let _indenter = indenter();
let tcx = bcx.tcx(); let tcx = bcx.tcx();
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, tcx.def_map, m, col, val) |p| { do enter_match(bcx, tcx.def_map, m, col, val) |p| {
match /*bad*/copy p.node { match /*bad*/copy p.node {
ast::pat_enum(_, subpats) => { ast::pat_enum(_, subpats) => {
@ -600,7 +600,7 @@ fn enter_rec_or_struct(bcx: block, dm: DefMap, m: &[@Match/&r], col: uint,
bcx.val_str(val)); bcx.val_str(val));
let _indenter = indenter(); let _indenter = indenter();
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| { do enter_match(bcx, dm, m, col, val) |p| {
match /*bad*/copy p.node { match /*bad*/copy p.node {
ast::pat_rec(fpats, _) | ast::pat_struct(_, fpats, _) => { ast::pat_rec(fpats, _) | ast::pat_struct(_, fpats, _) => {
@ -632,7 +632,7 @@ fn enter_tup(bcx: block, dm: DefMap, m: &[@Match/&r],
bcx.val_str(val)); bcx.val_str(val));
let _indenter = indenter(); let _indenter = indenter();
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| { do enter_match(bcx, dm, m, col, val) |p| {
match /*bad*/copy p.node { match /*bad*/copy p.node {
ast::pat_tup(elts) => { ast::pat_tup(elts) => {
@ -657,7 +657,7 @@ fn enter_tuple_struct(bcx: block, dm: DefMap, m: &[@Match/&r], col: uint,
bcx.val_str(val)); bcx.val_str(val));
let _indenter = indenter(); let _indenter = indenter();
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| { do enter_match(bcx, dm, m, col, val) |p| {
match /*bad*/copy p.node { match /*bad*/copy p.node {
ast::pat_enum(_, Some(elts)) => Some(elts), ast::pat_enum(_, Some(elts)) => Some(elts),
@ -680,7 +680,7 @@ fn enter_box(bcx: block, dm: DefMap, m: &[@Match/&r],
bcx.val_str(val)); bcx.val_str(val));
let _indenter = indenter(); let _indenter = indenter();
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| { do enter_match(bcx, dm, m, col, val) |p| {
match p.node { match p.node {
ast::pat_box(sub) => { ast::pat_box(sub) => {
@ -705,7 +705,7 @@ fn enter_uniq(bcx: block, dm: DefMap, m: &[@Match/&r],
bcx.val_str(val)); bcx.val_str(val));
let _indenter = indenter(); let _indenter = indenter();
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| { do enter_match(bcx, dm, m, col, val) |p| {
match p.node { match p.node {
ast::pat_uniq(sub) => { ast::pat_uniq(sub) => {
@ -730,7 +730,7 @@ fn enter_region(bcx: block, dm: DefMap, m: &[@Match/&r],
bcx.val_str(val)); bcx.val_str(val));
let _indenter = indenter(); let _indenter = indenter();
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; let dummy = @ast::pat { id: 0, node: ast::pat_wild, span: dummy_sp() };
do enter_match(bcx, dm, m, col, val) |p| { do enter_match(bcx, dm, m, col, val) |p| {
match p.node { match p.node {
ast::pat_region(sub) => { ast::pat_region(sub) => {

View file

@ -323,11 +323,18 @@ struct blk_ {
#[auto_encode] #[auto_encode]
#[auto_decode] #[auto_decode]
type pat = {id: node_id, node: pat_, span: span}; struct pat {
id: node_id,
node: pat_,
span: span,
}
#[auto_encode] #[auto_encode]
#[auto_decode] #[auto_decode]
type field_pat = {ident: ident, pat: @pat}; struct field_pat {
ident: ident,
pat: @pat,
}
#[auto_encode] #[auto_encode]
#[auto_decode] #[auto_decode]
@ -637,8 +644,13 @@ enum stmt_ {
// a refinement on pat. // a refinement on pat.
#[auto_encode] #[auto_encode]
#[auto_decode] #[auto_decode]
type local_ = {is_mutbl: bool, ty: @Ty, pat: @pat, struct local_ {
init: Option<@expr>, id: node_id}; is_mutbl: bool,
ty: @Ty,
pat: @pat,
init: Option<@expr>,
id: node_id,
}
type local = spanned<local_>; type local = spanned<local_>;
@ -650,7 +662,11 @@ enum decl_ { decl_local(~[@local]), decl_item(@item), }
#[auto_encode] #[auto_encode]
#[auto_decode] #[auto_decode]
type arm = {pats: ~[@pat], guard: Option<@expr>, body: blk}; struct arm {
pats: ~[@pat],
guard: Option<@expr>,
body: blk,
}
#[auto_encode] #[auto_encode]
#[auto_decode] #[auto_decode]

View file

@ -312,9 +312,9 @@ fn ident_to_path(s: span, +i: ident) -> @path {
} }
fn ident_to_pat(id: node_id, s: span, +i: ident) -> @pat { fn ident_to_pat(id: node_id, s: span, +i: ident) -> @pat {
@{id: id, @ast::pat { id: id,
node: pat_ident(bind_by_value, ident_to_path(s, i), None), node: pat_ident(bind_by_value, ident_to_path(s, i), None),
span: s} span: s }
} }
pure fn is_unguarded(a: &arm) -> bool { pure fn is_unguarded(a: &arm) -> bool {

View file

@ -317,11 +317,14 @@ priv impl ext_ctxt {
} }
fn binder_pat(span: span, nm: ast::ident) -> @ast::pat { fn binder_pat(span: span, nm: ast::ident) -> @ast::pat {
@{id: self.next_id(), @ast::pat {
node: ast::pat_ident(ast::bind_by_ref(ast::m_imm), id: self.next_id(),
node: ast::pat_ident(
ast::bind_by_ref(ast::m_imm),
self.path(span, ~[nm]), self.path(span, ~[nm]),
None), None),
span: span} span: span,
}
} }
fn stmt(expr: @ast::expr) -> @ast::stmt { fn stmt(expr: @ast::expr) -> @ast::stmt {
@ -579,12 +582,14 @@ fn mk_ser_method(
let ser_inputs = ~[{ let ser_inputs = ~[{
mode: ast::infer(cx.next_id()), mode: ast::infer(cx.next_id()),
ty: ty_s, ty: ty_s,
pat: @{id: cx.next_id(), pat: @ast::pat {
id: cx.next_id(),
node: ast::pat_ident( node: ast::pat_ident(
ast::bind_by_value, ast::bind_by_value,
ast_util::ident_to_path(span, cx.ident_of(~"__s")), ast_util::ident_to_path(span, cx.ident_of(~"__s")),
None), None),
span: span}, span: span,
},
id: cx.next_id(), id: cx.next_id(),
}]; }];
@ -640,12 +645,14 @@ fn mk_deser_method(
let deser_inputs = ~[{ let deser_inputs = ~[{
mode: ast::infer(cx.next_id()), mode: ast::infer(cx.next_id()),
ty: ty_d, ty: ty_d,
pat: @{id: cx.next_id(), pat: @ast::pat {
id: cx.next_id(),
node: ast::pat_ident( node: ast::pat_ident(
ast::bind_by_value, ast::bind_by_value,
ast_util::ident_to_path(span, cx.ident_of(~"__d")), ast_util::ident_to_path(span, cx.ident_of(~"__d")),
None), None),
span: span}, span: span,
},
id: cx.next_id(), id: cx.next_id(),
}]; }];
@ -967,7 +974,7 @@ fn ser_variant(
) )
}; };
let pat = @{ let pat = @ast::pat {
id: cx.next_id(), id: cx.next_id(),
node: pat_node, node: pat_node,
span: span, span: span,
@ -1020,7 +1027,7 @@ fn ser_variant(
] ]
); );
{ pats: ~[pat], guard: None, body: cx.expr_blk(body) } ast::arm { pats: ~[pat], guard: None, body: cx.expr_blk(body) }
} }
fn mk_enum_ser_body( fn mk_enum_ser_body(
@ -1132,21 +1139,25 @@ fn mk_enum_deser_body(
fail ~"enum variants unimplemented", fail ~"enum variants unimplemented",
}; };
let pat = @{ let pat = @ast::pat {
id: cx.next_id(), id: cx.next_id(),
node: ast::pat_lit(cx.lit_uint(span, v_idx)), node: ast::pat_lit(cx.lit_uint(span, v_idx)),
span: span, span: span,
}; };
{ ast::arm {
pats: ~[pat], pats: ~[pat],
guard: None, guard: None,
body: cx.expr_blk(body), body: cx.expr_blk(body),
} }
}; };
let impossible_case = { let impossible_case = ast::arm {
pats: ~[@{ id: cx.next_id(), node: ast::pat_wild, span: span}], pats: ~[@ast::pat {
id: cx.next_id(),
node: ast::pat_wild,
span: span,
}],
guard: None, guard: None,
// FIXME(#3198): proper error message // FIXME(#3198): proper error message
@ -1167,13 +1178,14 @@ fn mk_enum_deser_body(
node: ast::ty_infer, node: ast::ty_infer,
span: span span: span
}, },
pat: @{id: cx.next_id(), pat: @ast::pat {
id: cx.next_id(),
node: ast::pat_ident( node: ast::pat_ident(
ast::bind_by_value, ast::bind_by_value,
ast_util::ident_to_path(span, ast_util::ident_to_path(span, cx.ident_of(~"i")),
cx.ident_of(~"i")),
None), None),
span: span}, span: span,
},
id: cx.next_id(), id: cx.next_id(),
}], }],
output: @{ output: @{

View file

@ -181,18 +181,25 @@ fn mk_glob_use(cx: ext_ctxt, sp: span,
fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool, fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool,
ident: ast::ident, ex: @ast::expr) -> @ast::stmt { ident: ast::ident, ex: @ast::expr) -> @ast::stmt {
let pat : @ast::pat = @{id: cx.next_id(), let pat = @ast::pat {
node: ast::pat_ident(ast::bind_by_value, id: cx.next_id(),
node: ast::pat_ident(
ast::bind_by_value,
mk_raw_path(sp, ~[ident]), mk_raw_path(sp, ~[ident]),
None), None),
span: sp}; span: sp,
};
let ty : @ast::Ty = @{ id: cx.next_id(), node: ast::ty_infer, span: sp }; let ty : @ast::Ty = @{ id: cx.next_id(), node: ast::ty_infer, span: sp };
let local : @ast::local = @ast::spanned { node: { is_mutbl: mutbl, let local = @ast::spanned {
node: ast::local_ {
is_mutbl: mutbl,
ty: ty, ty: ty,
pat: pat, pat: pat,
init: Some(ex), init: Some(ex),
id: cx.next_id()}, id: cx.next_id(),
span: sp}; },
span: sp,
};
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 }
} }
@ -243,7 +250,7 @@ fn mk_managed(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
mk_expr(cx, sp, ast::expr_unary(ast::box(ast::m_imm), e)) mk_expr(cx, sp, ast::expr_unary(ast::box(ast::m_imm), e))
} }
fn mk_pat(cx: ext_ctxt, span: span, +pat: ast::pat_) -> @ast::pat { fn mk_pat(cx: ext_ctxt, span: span, +pat: ast::pat_) -> @ast::pat {
@{ id: cx.next_id(), node: move pat, span: span } @ast::pat { id: cx.next_id(), node: pat, span: span }
} }
fn mk_pat_ident(cx: ext_ctxt, span: span, ident: ast::ident) -> @ast::pat { fn mk_pat_ident(cx: ext_ctxt, span: span, ident: ast::ident) -> @ast::pat {
let path = mk_raw_path(span, ~[ ident ]); let path = mk_raw_path(span, ~[ ident ]);

View file

@ -374,22 +374,17 @@ fn create_enum_variant_pattern(cx: ext_ctxt,
prefix, prefix,
struct_def.fields.len()); struct_def.fields.len());
let field_pats = dvec::DVec(); let field_pats = do struct_def.fields.mapi |i, struct_field| {
for struct_def.fields.eachi |i, struct_field| {
let ident = match struct_field.node.kind { let ident = match struct_field.node.kind {
named_field(ident, _, _) => ident, named_field(ident, _, _) => ident,
unnamed_field => { unnamed_field => {
cx.span_bug(span, ~"unexpected unnamed field"); cx.span_bug(span, ~"unexpected unnamed field");
} }
}; };
field_pats.push({ ident: ident, pat: subpats[i] }); ast::field_pat { ident: ident, pat: subpats[i] }
} };
let field_pats = dvec::unwrap(move field_pats);
return build::mk_pat_struct(cx, build::mk_pat_struct(cx, span, matching_path, field_pats)
span,
matching_path,
move field_pats);
} }
enum_variant_kind(*) => { enum_variant_kind(*) => {
cx.span_unimpl(span, ~"enum variants for `deriving`"); cx.span_unimpl(span, ~"enum variants for `deriving`");
@ -732,7 +727,7 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt,
matching_body_expr); matching_body_expr);
// Create the matching arm. // Create the matching arm.
let matching_arm = { let matching_arm = ast::arm {
pats: ~[ matching_pat ], pats: ~[ matching_pat ],
guard: None, guard: None,
body: move matching_body_block body: move matching_body_block
@ -743,7 +738,7 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt,
// variant then there will always be a match. // variant then there will always be a match.
if enum_definition.variants.len() > 1 { if enum_definition.variants.len() > 1 {
// Create the nonmatching pattern. // Create the nonmatching pattern.
let nonmatching_pat = @{ let nonmatching_pat = @ast::pat {
id: cx.next_id(), id: cx.next_id(),
node: pat_wild, node: pat_wild,
span: span span: span
@ -757,12 +752,12 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt,
nonmatching_expr); nonmatching_expr);
// Create the nonmatching arm. // Create the nonmatching arm.
let nonmatching_arm = { let nonmatching_arm = ast::arm {
pats: ~[ nonmatching_pat ], pats: ~[ nonmatching_pat ],
guard: None, guard: None,
body: move nonmatching_body_block body: nonmatching_body_block,
}; };
other_arms.push(move nonmatching_arm); other_arms.push(nonmatching_arm);
} }
// Create the self pattern. // Create the self pattern.
@ -784,10 +779,10 @@ fn expand_deriving_eq_enum_method(cx: ext_ctxt,
other_match_expr); other_match_expr);
// Create the self arm. // Create the self arm.
let self_arm = { let self_arm = ast::arm {
pats: ~[ self_pat ], pats: ~[ self_pat ],
guard: None, guard: None,
body: move other_match_body_block body: other_match_body_block,
}; };
self_arms.push(move self_arm); self_arms.push(move self_arm);
} }
@ -813,8 +808,7 @@ fn expand_deriving_iter_bytes_enum_method(cx: ext_ctxt,
enum_definition: &enum_def) enum_definition: &enum_def)
-> @method { -> @method {
// Create the arms of the match in the method body. // Create the arms of the match in the method body.
let arms = dvec::DVec(); let arms = do enum_definition.variants.mapi |i, variant| {
for enum_definition.variants.eachi |i, variant| {
// Create the matching pattern. // Create the matching pattern.
let pat = create_enum_variant_pattern(cx, span, variant, ~"__self"); let pat = create_enum_variant_pattern(cx, span, variant, ~"__self");
@ -850,24 +844,22 @@ fn expand_deriving_iter_bytes_enum_method(cx: ext_ctxt,
let match_body_block = build::mk_block_(cx, span, move stmts); let match_body_block = build::mk_block_(cx, span, move stmts);
// Create the arm. // Create the arm.
let arm = { ast::arm {
pats: ~[ pat ], pats: ~[ pat ],
guard: None, guard: None,
body: move match_body_block body: match_body_block,
};
arms.push(move arm);
} }
};
// Create the method body. // Create the method body.
let self_ident = cx.ident_of(~"self"); let self_ident = cx.ident_of(~"self");
let self_expr = build::mk_path(cx, span, ~[ self_ident ]); let self_expr = build::mk_path(cx, span, ~[ self_ident ]);
let self_expr = build::mk_unary(cx, span, deref, self_expr); let self_expr = build::mk_unary(cx, span, deref, self_expr);
let arms = dvec::unwrap(move arms); let self_match_expr = expr_match(self_expr, arms);
let self_match_expr = expr_match(self_expr, move arms); let self_match_expr = build::mk_expr(cx, span, self_match_expr);
let self_match_expr = build::mk_expr(cx, span, move self_match_expr);
let self_match_stmt = build::mk_stmt(cx, span, self_match_expr); let self_match_stmt = build::mk_stmt(cx, span, self_match_expr);
// Create the method. // Create the method.
return create_iter_bytes_method(cx, span, ~[ self_match_stmt ]); create_iter_bytes_method(cx, span, ~[ self_match_stmt ])
} }

View file

@ -181,15 +181,19 @@ impl ext_ctxt: ext_ctxt_ast_builder {
} }
fn arg(name: ident, ty: @ast::Ty) -> ast::arg { fn arg(name: ident, ty: @ast::Ty) -> ast::arg {
{mode: ast::infer(self.next_id()), {
mode: ast::infer(self.next_id()),
ty: ty, ty: ty,
pat: @{id: self.next_id(), pat: @ast::pat {
id: self.next_id(),
node: ast::pat_ident( node: ast::pat_ident(
ast::bind_by_value, ast::bind_by_value,
ast_util::ident_to_path(dummy_sp(), name), ast_util::ident_to_path(dummy_sp(), name),
None), None),
span: dummy_sp()}, span: dummy_sp(),
id: self.next_id()} },
id: self.next_id(),
}
} }
fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk { fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk {

View file

@ -339,9 +339,11 @@ fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
} }
fn noop_fold_arm(a: arm, fld: ast_fold) -> arm { fn noop_fold_arm(a: arm, fld: ast_fold) -> arm {
return {pats: vec::map(a.pats, |x| fld.fold_pat(*x)), arm {
pats: vec::map(a.pats, |x| fld.fold_pat(*x)),
guard: option::map(&a.guard, |x| fld.fold_expr(*x)), guard: option::map(&a.guard, |x| fld.fold_expr(*x)),
body: fld.fold_block(a.body)}; body: fld.fold_block(a.body),
}
} }
fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
@ -358,20 +360,22 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
|pats| vec::map(*pats, |x| fld.fold_pat(*x)))) |pats| vec::map(*pats, |x| fld.fold_pat(*x))))
} }
pat_rec(fields, etc) => { pat_rec(fields, etc) => {
let mut fs = ~[]; let fs = do fields.map |f| {
for fields.each |f| { ast::field_pat {
fs.push({ident: /* FIXME (#2543) */ copy f.ident, ident: /* FIXME (#2543) */ copy f.ident,
pat: fld.fold_pat(f.pat)}); pat: fld.fold_pat(f.pat),
} }
};
pat_rec(fs, etc) pat_rec(fs, etc)
} }
pat_struct(pth, fields, etc) => { pat_struct(pth, fields, etc) => {
let pth_ = fld.fold_path(pth); let pth_ = fld.fold_path(pth);
let mut fs = ~[]; let fs = do fields.map |f| {
for fields.each |f| { ast::field_pat {
fs.push({ident: /* FIXME (#2543) */ copy f.ident, ident: /* FIXME (#2543) */ copy f.ident,
pat: fld.fold_pat(f.pat)}); pat: fld.fold_pat(f.pat)
} }
};
pat_struct(pth_, fs, etc) pat_struct(pth_, fs, etc)
} }
pat_tup(elts) => pat_tup(vec::map(elts, |x| fld.fold_pat(*x))), pat_tup(elts) => pat_tup(vec::map(elts, |x| fld.fold_pat(*x))),
@ -634,11 +638,13 @@ fn noop_fold_path(&&p: path, fld: ast_fold) -> path {
} }
fn noop_fold_local(l: local_, fld: ast_fold) -> local_ { fn noop_fold_local(l: local_, fld: ast_fold) -> local_ {
return {is_mutbl: l.is_mutbl, local_ {
is_mutbl: l.is_mutbl,
ty: fld.fold_ty(l.ty), ty: fld.fold_ty(l.ty),
pat: fld.fold_pat(l.pat), pat: fld.fold_pat(l.pat),
init: l.init.map(|e| fld.fold_expr(*e)), init: l.init.map(|e| fld.fold_expr(*e)),
id: fld.new_id(l.id)}; id: fld.new_id(l.id),
}
} }
/* temporarily eta-expand because of a compiler bug with using `fn<T>` as a /* temporarily eta-expand because of a compiler bug with using `fn<T>` as a
@ -731,9 +737,11 @@ impl ast_fold_fns: ast_fold {
} }
fn fold_pat(&&x: @pat) -> @pat { fn fold_pat(&&x: @pat) -> @pat {
let (n, s) = (self.fold_pat)(x.node, x.span, self as ast_fold); let (n, s) = (self.fold_pat)(x.node, x.span, self as ast_fold);
return @{id: (self.new_id)(x.id), @pat {
id: (self.new_id)(x.id),
node: n, node: n,
span: (self.new_span)(s)}; span: (self.new_span)(s),
}
} }
fn fold_decl(&&x: @decl) -> @decl { fn fold_decl(&&x: @decl) -> @decl {
let (n, s) = (self.fold_decl)(x.node, x.span, self as ast_fold); let (n, s) = (self.fold_decl)(x.node, x.span, self as ast_fold);

View file

@ -1769,7 +1769,7 @@ impl Parser {
span: expr.span, span: expr.span,
}; };
arms.push({pats: pats, guard: guard, body: blk}); arms.push(ast::arm { pats: pats, guard: guard, body: blk });
} }
let mut hi = self.span.hi; let mut hi = self.span.hi;
self.bump(); self.bump();
@ -1833,9 +1833,9 @@ impl Parser {
let subpat = self.parse_pat(refutable); let subpat = self.parse_pat(refutable);
if is_tail { if is_tail {
match subpat { match subpat {
@{ node: pat_wild, _ } => (), @ast::pat { node: pat_wild, _ } => (),
@{ node: pat_ident(_, _, _), _ } => (), @ast::pat { node: pat_ident(_, _, _), _ } => (),
@{ span, _ } => self.span_fatal( @ast::pat { span, _ } => self.span_fatal(
span, ~"expected an identifier or `_`" span, ~"expected an identifier or `_`"
) )
} }
@ -1881,13 +1881,13 @@ impl Parser {
self.bump(); self.bump();
subpat = self.parse_pat(refutable); subpat = self.parse_pat(refutable);
} else { } else {
subpat = @{ subpat = @ast::pat {
id: self.get_id(), id: self.get_id(),
node: pat_ident(bind_infer, fieldpath, None), node: pat_ident(bind_infer, fieldpath, None),
span: self.last_span span: self.last_span
}; };
} }
fields.push({ident: fieldname, pat: subpat}); fields.push(ast::field_pat { ident: fieldname, pat: subpat });
} }
return (fields, etc); return (fields, etc);
} }
@ -2092,7 +2092,7 @@ impl Parser {
hi = self.span.hi; hi = self.span.hi;
} }
} }
return @{id: self.get_id(), node: pat, span: mk_sp(lo, hi)}; @ast::pat { id: self.get_id(), node: pat, span: mk_sp(lo, hi) }
} }
fn parse_pat_ident(refutable: bool, fn parse_pat_ident(refutable: bool,
@ -2131,9 +2131,17 @@ impl Parser {
span: mk_sp(lo, lo)}; span: mk_sp(lo, lo)};
if self.eat(token::COLON) { ty = self.parse_ty(false); } if self.eat(token::COLON) { ty = self.parse_ty(false); }
let init = if allow_init { self.parse_initializer() } else { None }; let init = if allow_init { self.parse_initializer() } else { None };
return @spanned(lo, self.last_span.hi, @spanned(
{is_mutbl: is_mutbl, ty: ty, pat: pat, lo,
init: init, id: self.get_id()}); self.last_span.hi,
ast::local_ {
is_mutbl: is_mutbl,
ty: ty,
pat: pat,
init: init,
id: self.get_id(),
}
)
} }
fn parse_let() -> @decl { fn parse_let() -> @decl {