syntax: convert ast::spanned into a struct

This commit is contained in:
Erick Tryzelaar 2012-12-27 14:36:00 -05:00
parent b75550af5c
commit 93c2ebf994
31 changed files with 245 additions and 210 deletions

View file

@ -39,7 +39,7 @@ fn use_core(crate: @ast::crate) -> bool {
fn inject_libcore_ref(sess: Session,
crate: @ast::crate) -> @ast::crate {
fn spanned<T: Copy>(x: T) -> ast::spanned<T> {
return {node: x, span: dummy_sp()};
ast::spanned { node: x, span: dummy_sp() }
}
let precursor = @{

View file

@ -36,6 +36,9 @@ fn inject_intrinsic(sess: Session, crate: @ast::crate) -> @ast::crate {
let items = vec::append(~[item], crate.node.module.items);
return @{node: {module: { items: items ,.. /*bad*/copy crate.node.module }
,.. /*bad*/copy crate.node} ,.. /*bad*/copy *crate }
@ast::spanned {
node: { module: { items: items ,.. /*bad*/copy crate.node.module },
.. /*bad*/copy crate.node},
.. /*bad*/copy *crate
}
}

View file

@ -242,7 +242,7 @@ fn mk_test_module(cx: test_ctxt) -> @ast::item {
}
fn nospan<T: Copy>(t: T) -> ast::spanned<T> {
return {node: t, span: dummy_sp()};
ast::spanned { node: t, span: dummy_sp() }
}
fn path_node(+ids: ~[ast::ident]) -> @ast::path {
@ -489,7 +489,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
let body_: ast::blk_ =
default_block(~[], option::Some(test_main_call_expr),
cx.sess.next_node_id());
let body = {node: body_, span: dummy_sp()};
let body = ast::spanned { node: body_, span: dummy_sp() };
let item_ = ast::item_fn(decl, ast::impure_fn, ~[], body);
let item: ast::item =

View file

@ -1031,9 +1031,10 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::attribute] {
assert (vec::len(meta_items) == 1u);
let meta_item = meta_items[0];
attrs.push(
{node: {style: ast::attr_outer, value: /*bad*/copy *meta_item,
is_sugared_doc: false},
span: ast_util::dummy_sp()});
ast::spanned { node: { style: ast::attr_outer,
value: /*bad*/copy *meta_item,
is_sugared_doc: false },
span: ast_util::dummy_sp()});
};
}
option::None => ()

View file

@ -259,8 +259,10 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
let stmts_sans_items = do vec::filter(blk.stmts) |stmt| {
match stmt.node {
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
ast::stmt_decl(@{node: ast::decl_local(_), span: _}, _) => true,
ast::stmt_decl(@{node: ast::decl_item(_), span: _}, _) => false,
ast::stmt_decl(@ast::spanned { node: ast::decl_local(_),
span: _}, _) => true,
ast::stmt_decl(@ast::spanned { node: ast::decl_item(_),
span: _}, _) => false,
ast::stmt_mac(*) => fail ~"unexpanded macro in astencode"
}
};
@ -286,9 +288,10 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
}
ast::ii_dtor(ref dtor, nm, ref tps, parent_id) => {
let dtor_body = fld.fold_block((*dtor).node.body);
ast::ii_dtor({node: {body: dtor_body,
.. /*bad*/copy (*dtor).node},
.. (/*bad*/copy *dtor)}, nm, /*bad*/copy *tps, parent_id)
ast::ii_dtor(ast::spanned { node: { body: dtor_body,
.. /*bad*/copy (*dtor).node },
.. (/*bad*/copy *dtor) },
nm, /*bad*/copy *tps, parent_id)
}
}
}
@ -324,9 +327,11 @@ fn renumber_ast(xcx: extended_decode_ctxt, ii: ast::inlined_item)
let dtor_id = fld.new_id((*dtor).node.id);
let new_parent = xcx.tr_def_id(parent_id);
let new_self = fld.new_id((*dtor).node.self_id);
ast::ii_dtor({node: {id: dtor_id, attrs: dtor_attrs,
self_id: new_self, body: dtor_body},
.. (/*bad*/copy *dtor)},
ast::ii_dtor(ast::spanned { node: { id: dtor_id,
attrs: dtor_attrs,
self_id: new_self,
body: dtor_body },
.. (/*bad*/copy *dtor)},
nm, new_params, new_parent)
}
}

View file

@ -57,7 +57,8 @@ fn check_item(sess: Session, ast_map: ast_map::map,
fn check_pat(p: @pat, &&_is_const: bool, v: visit::vt<bool>) {
fn is_str(e: @expr) -> bool {
match e.node {
expr_vstore(@{node: expr_lit(@{node: lit_str(_), _}), _},
expr_vstore(@{node: expr_lit(@spanned { node: lit_str(_),
_}), _},
expr_vstore_uniq) => true,
_ => false
}
@ -84,7 +85,7 @@ fn check_expr(sess: Session, def_map: resolve::DefMap,
~"disallowed operator in constant expression");
return;
}
expr_lit(@{node: lit_str(_), _}) => { }
expr_lit(@spanned {node: lit_str(_), _}) => { }
expr_binary(_, _, _) | expr_unary(_, _) => {
if method_map.contains_key(e.id) {
sess.span_err(e.span, ~"user-defined operators are not \
@ -170,7 +171,7 @@ fn check_expr(sess: Session, def_map: resolve::DefMap,
}
}
match e.node {
expr_lit(@{node: lit_int(v, t), _}) => {
expr_lit(@spanned {node: lit_int(v, t), _}) => {
if t != ty_char {
if (v as u64) > ast_util::int_ty_max(
if t == ty_i { sess.targ_cfg.int_type } else { t }) {
@ -178,7 +179,7 @@ fn check_expr(sess: Session, def_map: resolve::DefMap,
}
}
}
expr_lit(@{node: lit_uint(v, t), _}) => {
expr_lit(@spanned {node: lit_uint(v, t), _}) => {
if v > ast_util::uint_ty_max(
if t == ty_u { sess.targ_cfg.uint_type } else { t }) {
sess.span_err(e.span, ~"literal out of range for its type");

View file

@ -692,7 +692,10 @@ fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
is_refutable(cx, sub)
}
pat_wild | pat_ident(_, _, None) => { false }
pat_lit(@{node: expr_lit(@{node: lit_nil, _}), _}) => { false } // "()"
pat_lit(@{node: expr_lit(@spanned { node: lit_nil, _}), _}) => {
// "()"
false
}
pat_lit(_) | pat_range(_, _) => { true }
pat_rec(fields, _) => {
fields.any(|f| is_refutable(cx, f.pat))

View file

@ -409,7 +409,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
fn check_stmt(stmt: @stmt, cx: ctx, v: visit::vt<ctx>) {
match stmt.node {
stmt_decl(@{node: decl_local(ref locals), _}, _) => {
stmt_decl(@spanned {node: decl_local(ref locals), _}, _) => {
for locals.each |local| {
match local.node.init {
Some(expr) =>

View file

@ -467,7 +467,8 @@ fn check_item_while_true(cx: ty::ctxt, it: @ast::item) {
match e.node {
ast::expr_while(cond, _) => {
match cond.node {
ast::expr_lit(@{node: ast::lit_bool(true),_}) => {
ast::expr_lit(@ast::spanned { node: ast::lit_bool(true),
_}) => {
cx.sess.span_lint(
while_true, e.id, it.id,
e.span,

View file

@ -1938,7 +1938,8 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
} else {
for vec::each((*body).node.stmts) |stmt| {
match stmt.node {
ast::stmt_decl(@{node: ast::decl_item(i), _}, _) => {
ast::stmt_decl(@ast::spanned { node: ast::decl_item(i),
_ }, _) => {
trans_item(ccx, *i);
}
_ => ()

View file

@ -545,7 +545,7 @@ fn trans_rvalue_dps_unadjusted(bcx: block, expr: @ast::expr,
ast::expr_tup(args) => {
return trans_tup(bcx, args, dest);
}
ast::expr_lit(@{node: ast::lit_str(s), _}) => {
ast::expr_lit(@ast::spanned {node: ast::lit_str(s), _}) => {
return tvec::trans_lit_str(bcx, expr, s, dest);
}
ast::expr_vstore(contents, ast::expr_vstore_slice) |

View file

@ -197,7 +197,7 @@ fn trans_slice_vstore(bcx: block,
// Handle the &"..." case:
match content_expr.node {
ast::expr_lit(@{node: ast::lit_str(s), span: _}) => {
ast::expr_lit(@ast::spanned {node: ast::lit_str(s), span: _}) => {
return trans_lit_str(bcx, content_expr, s, dest);
}
_ => {}
@ -316,7 +316,7 @@ fn write_content(bcx: block,
let _indenter = indenter();
match /*bad*/copy content_expr.node {
ast::expr_lit(@{node: ast::lit_str(s), span: _}) => {
ast::expr_lit(@ast::spanned { node: ast::lit_str(s), _ }) => {
match dest {
Ignore => {
return bcx;
@ -422,7 +422,9 @@ fn elements_required(bcx: block, content_expr: @ast::expr) -> uint {
//! Figure out the number of elements we need to store this content
match /*bad*/copy content_expr.node {
ast::expr_lit(@{node: ast::lit_str(s), span: _}) => s.len() + 1,
ast::expr_lit(@ast::spanned { node: ast::lit_str(s), _ }) => {
s.len() + 1
},
ast::expr_vec(es, _) => es.len(),
ast::expr_repeat(_, count_expr, _) => {
ty::eval_repeat_count(bcx.tcx(), count_expr, content_expr.span)

View file

@ -3157,7 +3157,7 @@ fn expr_kind(tcx: ctxt,
ast::expr_copy(*) |
ast::expr_unary_move(*) |
ast::expr_repeat(*) |
ast::expr_lit(@{node: lit_str(_), _}) |
ast::expr_lit(@ast::spanned {node: lit_str(_), _}) |
ast::expr_vstore(_, ast::expr_vstore_slice) |
ast::expr_vstore(_, ast::expr_vstore_mut_slice) |
ast::expr_vstore(_, ast::expr_vstore_fixed(_)) |

View file

@ -552,11 +552,12 @@ fn check_struct(ccx: @crate_ctxt, struct_def: @ast::struct_def,
let self_ty = ty::node_id_to_type(tcx, id);
do struct_def.dtor.iter() |dtor| {
let class_t = {self_ty: self_ty,
self_id: dtor.node.self_id,
def_id: local_def(id),
explicit_self: {node: ast::sty_by_ref,
span: ast_util::dummy_sp()}};
let class_t = { self_ty: self_ty,
self_id: dtor.node.self_id,
def_id: local_def(id),
explicit_self:
spanned { node: ast::sty_by_ref,
span: ast_util::dummy_sp() } };
// typecheck the dtor
check_bare_fn(ccx, ast_util::dtor_dec(),
dtor.node.body, dtor.node.id,
@ -1911,7 +1912,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
match /*bad*/copy expr.node {
ast::expr_vstore(ev, vst) => {
let typ = match /*bad*/copy ev.node {
ast::expr_lit(@{node: ast::lit_str(s), span:_}) => {
ast::expr_lit(@ast::spanned { node: ast::lit_str(s), _ }) => {
let tt = ast_expr_vstore_to_vstore(fcx, ev, str::len(*s), vst);
ty::mk_estr(tcx, tt)
}
@ -2600,7 +2601,8 @@ fn check_block(fcx0: @fn_ctxt, blk: ast::blk) -> bool {
for blk.node.stmts.each |s| {
if bot && !warned &&
match s.node {
ast::stmt_decl(@{node: ast::decl_local(_), _}, _) |
ast::stmt_decl(@ast::spanned { node: ast::decl_local(_),
_}, _) |
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) => {
true
}

View file

@ -43,7 +43,8 @@ fn replace_bound_regions_in_fn_ty(
let mut all_tys = ty::tys_in_fn_ty(fn_ty);
match self_info {
Some({explicit_self: {node: ast::sty_region(m), _}, _}) => {
Some({explicit_self: ast::spanned { node: ast::sty_region(m),
_}, _}) => {
let region = ty::re_bound(ty::br_self);
let ty = ty::mk_rptr(tcx, region,
{ ty: ty::mk_self(tcx), mutbl: m });