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

@ -294,7 +294,8 @@ fn load_link(mis: ~[@ast::meta_item]) -> (Option<~str>,
let mut uuid = None;
for mis.each |a| {
match a.node {
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => {
ast::meta_name_value(v, ast::spanned { node: ast::lit_str(s),
_ }) => {
match v {
~"name" => name = Some(*s),
~"vers" => vers = Some(*s),
@ -321,7 +322,8 @@ fn load_crate(filename: &Path) -> Option<Crate> {
for c.node.attrs.each |a| {
match a.node.value.node {
ast::meta_name_value(v, {node: ast::lit_str(_), span: _}) => {
ast::meta_name_value(v, ast::spanned { node: ast::lit_str(_),
_ }) => {
match v {
~"desc" => desc = Some(v),
~"sigs" => sigs = Some(v),

View file

@ -81,7 +81,7 @@ fn common_exprs() -> ~[ast::expr] {
}
fn dsl(l: ast::lit_) -> ast::lit {
{ node: l, span: ast_util::dummy_sp() }
ast::spanned { node: l, span: ast_util::dummy_sp() }
}
~[dse(ast::expr_break(option::None)),

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 });

View file

@ -23,8 +23,7 @@ use std::serialize::{Encodable, Decodable, Encoder, Decoder};
#[auto_encode]
#[auto_decode]
type spanned<T> = {node: T, span: span};
struct spanned<T> { node: T, span: span }
/* can't import macros yet, so this is copied from token.rs. See its comment
* there. */

View file

@ -176,12 +176,15 @@ fn map_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
cx.local_id += 1u;
}
match fk {
visit::fk_dtor(tps, ref attrs, self_id, parent_id) => {
let dt = @{node: {id: id, attrs: (*attrs), self_id: self_id,
body: /* FIXME (#2543) */ copy body}, span: sp};
cx.map.insert(id, node_dtor(/* FIXME (#2543) */ copy tps, dt,
parent_id,
@/* FIXME (#2543) */ copy cx.path));
visit::fk_dtor(tps, ref attrs, self_id, parent_id) => {
let dt = @spanned {
node: {id: id, attrs: (*attrs), self_id: self_id,
body: /* FIXME (#2543) */ copy body},
span: sp,
};
cx.map.insert(id, node_dtor(/* FIXME (#2543) */ copy tps, dt,
parent_id,
@/* FIXME (#2543) */ copy cx.path));
}
_ => ()
}

View file

@ -29,7 +29,7 @@ pure fn spanned<T>(+lo: BytePos, +hi: BytePos, +t: T) -> spanned<T> {
}
pure fn respan<T>(sp: span, +t: T) -> spanned<T> {
{node: move t, span: sp}
spanned {node: t, span: sp}
}
pure fn dummy_spanned<T>(+t: T) -> spanned<T> {
@ -284,7 +284,7 @@ impl def_id : to_bytes::IterBytes {
fn block_from_expr(e: @expr) -> blk {
let blk_ = default_block(~[], option::Some::<@expr>(e), e.id);
return {node: blk_, span: e.span};
return spanned {node: blk_, span: e.span};
}
fn default_block(+stmts1: ~[@stmt], expr1: Option<@expr>, id1: node_id) ->

View file

@ -299,8 +299,8 @@ priv impl ext_ctxt {
}
fn stmt(expr: @ast::expr) -> @ast::stmt {
@{node: ast::stmt_semi(expr, self.next_id()),
span: expr.span}
@ast::spanned { node: ast::stmt_semi(expr, self.next_id()),
span: expr.span }
}
fn lit_str(span: span, s: @~str) -> @ast::expr {
@ -310,8 +310,8 @@ priv impl ext_ctxt {
self.expr(
span,
ast::expr_lit(
@{node: ast::lit_str(s),
span: span})),
@ast::spanned { node: ast::lit_str(s),
span: span})),
ast::expr_vstore_uniq))
}
@ -319,8 +319,8 @@ priv impl ext_ctxt {
self.expr(
span,
ast::expr_lit(
@{node: ast::lit_uint(i as u64, ast::ty_u),
span: span}))
@ast::spanned { node: ast::lit_uint(i as u64, ast::ty_u),
span: span}))
}
fn lambda(blk: ast::blk) -> @ast::expr {
@ -330,21 +330,21 @@ priv impl ext_ctxt {
}
fn blk(span: span, stmts: ~[@ast::stmt]) -> ast::blk {
{node: {view_items: ~[],
stmts: stmts,
expr: None,
id: self.next_id(),
rules: ast::default_blk},
span: span}
ast::spanned { node: { view_items: ~[],
stmts: stmts,
expr: None,
id: self.next_id(),
rules: ast::default_blk},
span: span }
}
fn expr_blk(expr: @ast::expr) -> ast::blk {
{node: {view_items: ~[],
stmts: ~[],
expr: Some(expr),
id: self.next_id(),
rules: ast::default_blk},
span: expr.span}
ast::spanned { node: { view_items: ~[],
stmts: ~[],
expr: Some(expr),
id: self.next_id(),
rules: ast::default_blk},
span: expr.span }
}
fn expr_path(span: span, strs: ~[ast::ident]) -> @ast::expr {
@ -570,7 +570,8 @@ fn mk_ser_method(
ident: cx.ident_of(~"encode"),
attrs: ~[],
tps: ~[],
self_ty: { node: ast::sty_region(ast::m_imm), span: span },
self_ty: ast::spanned { node: ast::sty_region(ast::m_imm),
span: span },
purity: ast::impure_fn,
decl: ser_decl,
body: ser_body,
@ -624,7 +625,8 @@ fn mk_deser_method(
ident: cx.ident_of(~"decode"),
attrs: ~[],
tps: ~[],
self_ty: { node: ast::sty_static, span: span },
self_ty: ast::spanned { node: ast::sty_static,
span: span },
purity: ast::impure_fn,
decl: deser_decl,
body: deser_body,
@ -862,7 +864,7 @@ fn mk_deser_fields(
]
);
{
ast::spanned {
node: { mutbl: field.mutbl, ident: field.ident, expr: expr },
span: span,
}

View file

@ -26,7 +26,7 @@ fn mk_expr(cx: ext_ctxt, sp: codemap::span, expr: ast::expr_) ->
}
fn mk_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr {
let sp_lit = @{node: lit, span: sp};
let sp_lit = @ast::spanned { node: lit, span: sp };
mk_expr(cx, sp, ast::expr_lit(sp_lit))
}
fn mk_int(cx: ext_ctxt, sp: span, i: int) -> @ast::expr {
@ -136,7 +136,8 @@ fn mk_uniq_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr {
}
fn mk_field(sp: span, f: &{ident: ast::ident, ex: @ast::expr})
-> ast::field {
{node: {mutbl: ast::m_imm, ident: f.ident, expr: f.ex}, span: sp}
ast::spanned { node: {mutbl: ast::m_imm, ident: f.ident, expr: f.ex},
span: sp }
}
fn mk_fields(sp: span, fields: ~[{ident: ast::ident, ex: @ast::expr}]) ->
~[ast::field] {
@ -159,9 +160,10 @@ fn mk_struct_e(cx: ext_ctxt, sp: span,
}
fn mk_glob_use(cx: ext_ctxt, sp: span,
path: ~[ast::ident]) -> @ast::view_item {
let glob = @{node: ast::view_path_glob(mk_raw_path(sp, path),
cx.next_id()),
span: sp};
let glob = @ast::spanned {
node: ast::view_path_glob(mk_raw_path(sp, path), cx.next_id()),
span: sp,
};
@{node: ast::view_item_import(~[glob]),
attrs: ~[],
vis: ast::private,
@ -176,29 +178,29 @@ fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool,
None),
span: sp};
let ty : @ast::Ty = @{ id: cx.next_id(), node: ast::ty_infer, span: sp };
let local : @ast::local = @{node: {is_mutbl: mutbl,
ty: ty,
pat: pat,
init: Some(ex),
id: cx.next_id()},
span: sp};
let decl = {node: ast::decl_local(~[local]), span: sp};
@{ node: ast::stmt_decl(@decl, cx.next_id()), span: sp }
let local : @ast::local = @ast::spanned { node: { is_mutbl: mutbl,
ty: ty,
pat: pat,
init: Some(ex),
id: cx.next_id()},
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 }
}
fn mk_block(cx: ext_ctxt, sp: span,
view_items: ~[@ast::view_item],
stmts: ~[@ast::stmt],
expr: Option<@ast::expr>) -> @ast::expr {
let blk = {node: {view_items: view_items,
stmts: stmts,
expr: expr,
id: cx.next_id(),
rules: ast::default_blk },
span: sp };
let blk = ast::spanned { node: { view_items: view_items,
stmts: stmts,
expr: expr,
id: cx.next_id(),
rules: ast::default_blk },
span: sp };
mk_expr(cx, sp, ast::expr_block(blk))
}
fn mk_block_(cx: ext_ctxt, sp: span, +stmts: ~[@ast::stmt]) -> ast::blk {
{
ast::spanned {
node: {
view_items: ~[],
stmts: move stmts,
@ -217,7 +219,7 @@ fn mk_simple_block(cx: ext_ctxt, span: span, expr: @ast::expr) -> ast::blk {
id: cx.next_id(),
rules: ast::default_blk
};
{ node: move block, span: span }
ast::spanned { node: block, span: span }
}
fn mk_copy(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr {
mk_expr(cx, sp, ast::expr_copy(e))
@ -250,12 +252,13 @@ fn mk_pat_struct(cx: ext_ctxt,
mk_pat(cx, span, move pat)
}
fn mk_bool(cx: ext_ctxt, span: span, value: bool) -> @ast::expr {
let lit_expr = ast::expr_lit(@{ node: ast::lit_bool(value), span: span });
let lit_expr = ast::expr_lit(@ast::spanned { node: ast::lit_bool(value),
span: span });
build::mk_expr(cx, span, move lit_expr)
}
fn mk_stmt(cx: ext_ctxt, span: span, expr: @ast::expr) -> @ast::stmt {
let stmt_ = ast::stmt_semi(expr, cx.next_id());
@{ node: move stmt_, span: span }
@ast::spanned { node: move stmt_, span: span }
}
fn mk_ty_path(cx: ext_ctxt,
span: span,

View file

@ -16,10 +16,10 @@ use core::prelude::*;
use ast::{Ty, and, bind_by_ref, binop, deref, enum_def, enum_variant_kind};
use ast::{expr, expr_match, ident, item, item_, item_struct, item_enum};
use ast::{item_impl, m_imm, meta_item, method, named_field, or, pat};
use ast::{pat_ident, pat_wild, public, pure_fn, re_anon, stmt, struct_def};
use ast::{struct_variant_kind, sty_by_ref, sty_region, tuple_variant_kind};
use ast::{ty_nil, ty_param, ty_param_bound, ty_path, ty_rptr, unnamed_field};
use ast::{variant};
use ast::{pat_ident, pat_wild, public, pure_fn, re_anon, spanned, stmt};
use ast::{struct_def, struct_variant_kind, sty_by_ref, sty_region};
use ast::{tuple_variant_kind, ty_nil, ty_param, ty_param_bound, ty_path};
use ast::{ty_rptr, unnamed_field, variant};
use ext::base::ext_ctxt;
use ext::build;
use codemap::span;
@ -159,7 +159,7 @@ fn create_eq_method(cx: ext_ctxt,
let body_block = build::mk_simple_block(cx, span, body);
// Create the method.
let self_ty = { node: sty_region(m_imm), span: span };
let self_ty = spanned { node: sty_region(m_imm), span: span };
return @{
ident: method_ident,
attrs: ~[],
@ -309,7 +309,7 @@ fn create_iter_bytes_method(cx: ext_ctxt,
let body_block = build::mk_block_(cx, span, move statements);
// Create the method.
let self_ty = { node: sty_region(m_imm), span: span };
let self_ty = spanned { node: sty_region(m_imm), span: span };
let method_ident = cx.ident_of(~"iter_bytes");
return @{
ident: method_ident,

View file

@ -156,7 +156,9 @@ fn expand_item_mac(exts: HashMap<~str, syntax_extension>,
fld: ast_fold) -> Option<@ast::item> {
let (pth, tts) = match it.node {
item_mac({node: mac_invoc_tt(pth, ref tts), _}) => (pth, (*tts)),
item_mac(ast::spanned { node: mac_invoc_tt(pth, ref tts), _}) => {
(pth, (*tts))
}
_ => cx.span_bug(it.span, ~"invalid item macro invocation")
};
@ -234,7 +236,8 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
{call_site: sp, callie: {name: *extname, span: exp_sp}}));
let expanded = match exp(cx, mac.span, tts) {
mr_expr(e) =>
@{node: stmt_expr(e, cx.next_id()), span: e.span},
@ast::spanned { node: stmt_expr(e, cx.next_id()),
span: e.span},
mr_any(_,_,stmt_mkr) => stmt_mkr(),
_ => cx.span_fatal(
pth.span,

View file

@ -136,8 +136,8 @@ impl ext_ctxt: ext_ctxt_ast_builder {
}
fn stmt_expr(e: @ast::expr) -> @ast::stmt {
@{node: ast::stmt_expr(e, self.next_id()),
span: dummy_sp()}
@spanned { node: ast::stmt_expr(e, self.next_id()),
span: dummy_sp()}
}
fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt {
@ -146,8 +146,8 @@ impl ext_ctxt: ext_ctxt_ast_builder {
}
fn field_imm(name: ident, e: @ast::expr) -> ast::field {
{node: {mutbl: ast::m_imm, ident: name, expr: e},
span: dummy_sp()}
spanned { node: { mutbl: ast::m_imm, ident: name, expr: e },
span: dummy_sp()}
}
fn rec(+fields: ~[ast::field]) -> @ast::expr {
@ -158,8 +158,8 @@ impl ext_ctxt: ext_ctxt_ast_builder {
}
fn ty_field_imm(name: ident, ty: @ast::Ty) -> ast::ty_field {
{node: {ident: name, mt: { ty: ty, mutbl: ast::m_imm } },
span: dummy_sp()}
spanned { node: { ident: name, mt: { ty: ty, mutbl: ast::m_imm } },
span: dummy_sp() }
}
fn ty_rec(+fields: ~[ast::ty_field]) -> @ast::Ty {
@ -199,8 +199,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
id: self.next_id(),
rules: ast::default_blk};
{node: blk,
span: dummy_sp()}
spanned { node: blk, span: dummy_sp() }
}
fn expr_block(e: @ast::expr) -> ast::blk {
@ -275,13 +274,13 @@ impl ext_ctxt: ext_ctxt_ast_builder {
+tys: ~[@ast::Ty]) -> ast::variant {
let args = tys.map(|ty| {ty: *ty, id: self.next_id()});
{node: {name: name,
attrs: ~[],
kind: ast::tuple_variant_kind(args),
id: self.next_id(),
disr_expr: None,
vis: ast::public},
span: span}
spanned { node: { name: name,
attrs: ~[],
kind: ast::tuple_variant_kind(args),
id: self.next_id(),
disr_expr: None,
vis: ast::public},
span: span}
}
fn item_mod(name: ident,
@ -290,7 +289,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
// XXX: Total hack: import `core::kinds::Owned` to work around a
// parser bug whereby `fn f<T: ::kinds::Owned>` doesn't parse.
let vi = ast::view_item_import(~[
@{
@ast::spanned {
node: ast::view_path_simple(
self.ident_of(~"Owned"),
path(

View file

@ -189,13 +189,13 @@ fn nameize(p_s: parse_sess, ms: ~[matcher], res: ~[@named_match])
fn n_rec(p_s: parse_sess, m: matcher, res: ~[@named_match],
ret_val: HashMap<ident, @named_match>) {
match m {
{node: match_tok(_), span: _} => (),
{node: match_seq(ref more_ms, _, _, _, _), span: _} => {
spanned {node: match_tok(_), _} => (),
spanned {node: match_seq(ref more_ms, _, _, _, _), _} => {
for (*more_ms).each() |next_m| {
n_rec(p_s, *next_m, res, ret_val)
};
}
{node: match_nonterminal(bind_name, _, idx), span: sp} => {
spanned {node: match_nonterminal(bind_name, _, idx), span: sp} => {
if ret_val.contains_key(bind_name) {
p_s.span_diagnostic.span_fatal(sp, ~"Duplicated bind name: "+
*p_s.interner.get(bind_name))

View file

@ -33,7 +33,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
arg: ~[ast::token_tree]) -> base::mac_result {
// these spans won't matter, anyways
fn ms(m: matcher_) -> matcher {
{node: m, span: dummy_sp()}
ast::spanned { node: m, span: dummy_sp() }
}
let lhs_nm = cx.parse_sess().interner.gensym(@~"lhs");

View file

@ -93,27 +93,27 @@ type ast_fold_precursor = @{
//used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive
fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item {
return @{node:
match mi.node {
@spanned {
node:
match mi.node {
meta_word(ref id) => meta_word((*id)),
meta_list(ref id, mis) => {
let fold_meta_item = |x|fold_meta_item_(x, fld);
meta_list(/* FIXME: (#2543) */ copy (*id),
vec::map(mis, |e| fold_meta_item(*e)))
let fold_meta_item = |x|fold_meta_item_(x, fld);
meta_list(/* FIXME: (#2543) */ copy (*id),
vec::map(mis, |e| fold_meta_item(*e)))
}
meta_name_value(ref id, s) => {
meta_name_value((*id), /* FIXME (#2543) */ copy s)
meta_name_value((*id), /* FIXME (#2543) */ copy s)
}
},
span: fld.new_span(mi.span)};
},
span: fld.new_span(mi.span) }
}
//used in noop_fold_item and noop_fold_crate
fn fold_attribute_(at: attribute, fld: ast_fold) ->
attribute {
return {node: {style: at.node.style,
value: *fold_meta_item_(@at.node.value, fld),
is_sugared_doc: at.node.is_sugared_doc },
span: fld.new_span(at.span)};
fn fold_attribute_(at: attribute, fld: ast_fold) -> attribute {
spanned { node: { style: at.node.style,
value: *fold_meta_item_(@at.node.value, fld),
is_sugared_doc: at.node.is_sugared_doc },
span: fld.new_span(at.span) }
}
//used in noop_fold_foreign_item and noop_fold_fn_decl
fn fold_arg_(a: arg, fld: ast_fold) -> arg {
@ -124,11 +124,10 @@ fn fold_arg_(a: arg, fld: ast_fold) -> arg {
}
//used in noop_fold_expr, and possibly elsewhere in the future
fn fold_mac_(m: mac, fld: ast_fold) -> mac {
return {node:
match m.node {
mac_invoc_tt(*) => m.node,
},
span: fld.new_span(m.span)};
spanned { node: match m.node {
mac_invoc_tt(*) => m.node,
},
span: fld.new_span(m.span) }
}
fn fold_fn_decl(decl: ast::fn_decl, fld: ast_fold) -> ast::fn_decl {
@ -206,10 +205,10 @@ fn noop_fold_item(&&i: @item, fld: ast_fold) -> Option<@item> {
fn noop_fold_struct_field(&&sf: @struct_field, fld: ast_fold)
-> @struct_field {
@{node: {kind: copy sf.node.kind,
id: sf.node.id,
ty: fld.fold_ty(sf.node.ty)},
span: sf.span}
@spanned { node: { kind: copy sf.node.kind,
id: sf.node.id,
ty: fld.fold_ty(sf.node.ty) },
span: sf.span }
}
fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
@ -266,9 +265,10 @@ fn fold_struct_def(struct_def: @ast::struct_def, fld: ast_fold)
let dtor = do option::map(&struct_def.dtor) |dtor| {
let dtor_body = fld.fold_block(dtor.node.body);
let dtor_id = fld.new_id(dtor.node.id);
{node: {body: dtor_body,
id: dtor_id,.. dtor.node},
.. *dtor}};
spanned { node: { body: dtor_body,
id: dtor_id, .. dtor.node},
span: dtor.span }
};
return @{
fields: vec::map(struct_def.fields, |f| fold_struct_field(*f, fld)),
dtor: dtor,
@ -281,10 +281,10 @@ fn fold_trait_ref(&&p: @trait_ref, fld: ast_fold) -> @trait_ref {
}
fn fold_struct_field(&&f: @struct_field, fld: ast_fold) -> @struct_field {
@{node: {kind: copy f.node.kind,
id: fld.new_id(f.node.id),
ty: fld.fold_ty(f.node.ty)},
span: fld.new_span(f.span)}
@spanned { node: { kind: copy f.node.kind,
id: fld.new_id(f.node.id),
ty: fld.fold_ty(f.node.ty) },
span: fld.new_span(f.span) }
}
fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method {
@ -390,11 +390,10 @@ fn wrap<T>(f: fn@(T, ast_fold) -> T)
fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
fn fold_field_(field: field, fld: ast_fold) -> field {
return {node:
{mutbl: field.node.mutbl,
ident: fld.fold_ident(field.node.ident),
expr: fld.fold_expr(field.node.expr)},
span: fld.new_span(field.span)};
spanned { node: { mutbl: field.node.mutbl,
ident: fld.fold_ident(field.node.ident),
expr: fld.fold_expr(field.node.expr)},
span: fld.new_span(field.span) }
}
let fold_field = |x| fold_field_(x, fld);
@ -508,9 +507,9 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
{ty: fld.fold_ty(mt.ty), mutbl: mt.mutbl}
}
fn fold_field(f: ty_field, fld: ast_fold) -> ty_field {
{node: {ident: fld.fold_ident(f.node.ident),
mt: fold_mt(f.node.mt, fld)},
span: fld.new_span(f.span)}
spanned { node: { ident: fld.fold_ident(f.node.ident),
mt: fold_mt(f.node.mt, fld) },
span: fld.new_span(f.span) }
}
match t {
ty_nil | ty_bot | ty_infer => copy t,
@ -566,9 +565,10 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
let dtor = do option::map(&struct_def.dtor) |dtor| {
let dtor_body = fld.fold_block(dtor.node.body);
let dtor_id = fld.new_id(dtor.node.id);
{node: {body: dtor_body,
id: dtor_id,.. dtor.node},
.. *dtor}};
spanned { node: { body: dtor_body,
id: dtor_id, .. dtor.node},
.. *dtor }
};
kind = struct_variant_kind(@{
fields: vec::map(struct_def.fields,
|f| fld.fold_struct_field(*f)),
@ -661,7 +661,7 @@ impl ast_fold_precursor: ast_fold {
/* naturally, a macro to write these would be nice */
fn fold_crate(c: crate) -> crate {
let (n, s) = (self.fold_crate)(c.node, c.span, self as ast_fold);
return {node: n, span: (self.new_span)(s)};
spanned { node: n, span: (self.new_span)(s) }
}
fn fold_view_item(&&x: @view_item) ->
@view_item {
@ -679,10 +679,10 @@ impl ast_fold_precursor: ast_fold {
return (self.fold_item)(i, self as ast_fold);
}
fn fold_struct_field(&&sf: @struct_field) -> @struct_field {
@{node: {kind: copy sf.node.kind,
id: sf.node.id,
ty: (self as ast_fold).fold_ty(sf.node.ty)},
span: (self.new_span)(sf.span)}
@spanned { node: { kind: copy sf.node.kind,
id: sf.node.id,
ty: (self as ast_fold).fold_ty(sf.node.ty) },
span: (self.new_span)(sf.span) }
}
fn fold_item_underscore(i: item_) ->
item_ {
@ -694,11 +694,11 @@ impl ast_fold_precursor: ast_fold {
}
fn fold_block(x: blk) -> blk {
let (n, s) = (self.fold_block)(x.node, x.span, self as ast_fold);
return {node: n, span: (self.new_span)(s)};
spanned { node: n, span: (self.new_span)(s) }
}
fn fold_stmt(&&x: @stmt) -> @stmt {
let (n, s) = (self.fold_stmt)(x.node, x.span, self as ast_fold);
return @{node: n, span: (self.new_span)(s)};
@spanned { node: n, span: (self.new_span)(s) }
}
fn fold_arm(x: arm) -> arm {
return (self.fold_arm)(x, self as ast_fold);
@ -711,7 +711,7 @@ impl ast_fold_precursor: ast_fold {
}
fn fold_decl(&&x: @decl) -> @decl {
let (n, s) = (self.fold_decl)(x.node, x.span, self as ast_fold);
return @{node: n, span: (self.new_span)(s)};
@spanned { node: n, span: (self.new_span)(s) }
}
fn fold_expr(&&x: @expr) -> @expr {
let (n, s) = (self.fold_expr)(x.node, x.span, self as ast_fold);
@ -734,7 +734,7 @@ impl ast_fold_precursor: ast_fold {
fn fold_variant(x: variant) ->
variant {
let (n, s) = (self.fold_variant)(x.node, x.span, self as ast_fold);
return {node: n, span: (self.new_span)(s)};
spanned { node: n, span: (self.new_span)(s) }
}
fn fold_ident(&&x: ident) -> ident {
return (self.fold_ident)(x, self as ast_fold);
@ -744,7 +744,7 @@ impl ast_fold_precursor: ast_fold {
}
fn fold_local(&&x: @local) -> @local {
let (n, s) = (self.fold_local)(x.node, x.span, self as ast_fold);
return @{node: n, span: (self.new_span)(s)};
@spanned { node: n, span: (self.new_span)(s) }
}
fn map_exprs(f: fn@(&&v: @expr) -> @expr, e: ~[@expr]) -> ~[@expr] {
(self.map_exprs)(f, e)

View file

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

View file

@ -772,7 +772,7 @@ impl Parser {
self.bump();
self.lit_from_token(tok)
};
return {node: lit, span: mk_sp(lo, self.last_span.hi)};
spanned { node: lit, span: mk_sp(lo, self.last_span.hi) }
}
fn parse_path_without_tps() -> @path {
@ -844,7 +844,7 @@ impl Parser {
self.parse_seq_lt_gt(Some(token::COMMA),
|p| p.parse_ty(false))
} else {
{node: ~[], span: path.span}
spanned {node: ~[], span: path.span}
}
};
@ -880,14 +880,14 @@ impl Parser {
fn mk_mac_expr(+lo: BytePos, +hi: BytePos, m: mac_) -> @expr {
return @{id: self.get_id(),
callee_id: self.get_id(),
node: expr_mac({node: m, span: mk_sp(lo, hi)}),
node: expr_mac(spanned {node: m, span: mk_sp(lo, hi)}),
span: mk_sp(lo, hi)};
}
fn mk_lit_u32(i: u32) -> @expr {
let span = self.span;
let lv_lit = @{node: lit_uint(i as u64, ty_u32),
span: span};
let lv_lit = @spanned { node: lit_uint(i as u64, ty_u32),
span: span };
return @{id: self.get_id(), callee_id: self.get_id(),
node: expr_lit(lv_lit), span: span};
@ -1363,7 +1363,7 @@ impl Parser {
hi = e.span.hi;
// HACK: turn &[...] into a &-evec
ex = match e.node {
expr_vec(*) | expr_lit(@{node: lit_str(_), span: _})
expr_vec(*) | expr_lit(@spanned {node: lit_str(_), span: _})
if m == m_imm => {
expr_vstore(e, expr_vstore_slice)
}
@ -1386,7 +1386,7 @@ impl Parser {
expr_vec(*) if m == m_mutbl =>
expr_vstore(e, expr_vstore_mut_box),
expr_vec(*) if m == m_imm => expr_vstore(e, expr_vstore_box),
expr_lit(@{node: lit_str(_), span: _}) if m == m_imm =>
expr_lit(@spanned {node: lit_str(_), span: _}) if m == m_imm =>
expr_vstore(e, expr_vstore_box),
_ => expr_unary(box(m), e)
};
@ -1398,7 +1398,7 @@ impl Parser {
hi = e.span.hi;
// HACK: turn ~[...] into a ~-evec
ex = match e.node {
expr_vec(*) | expr_lit(@{node: lit_str(_), span: _})
expr_vec(*) | expr_lit(@spanned {node: lit_str(_), span: _})
if m == m_imm => expr_vstore(e, expr_vstore_uniq),
_ => expr_unary(uniq(m), e)
};
@ -1748,12 +1748,12 @@ impl Parser {
self.eat(token::COMMA);
}
let blk = {node: {view_items: ~[],
stmts: ~[],
expr: Some(expr),
id: self.get_id(),
rules: default_blk},
span: expr.span};
let blk = spanned { node: { view_items: ~[],
stmts: ~[],
expr: Some(expr),
id: self.get_id(),
rules: default_blk},
span: expr.span };
arms.push({pats: pats, guard: guard, body: blk});
}
@ -1893,7 +1893,7 @@ impl Parser {
// HACK: parse @"..." as a literal of a vstore @str
pat = match sub.node {
pat_lit(e@@{
node: expr_lit(@{node: lit_str(_), span: _}), _
node: expr_lit(@spanned {node: lit_str(_), span: _}), _
}) => {
let vst = @{id: self.get_id(), callee_id: self.get_id(),
node: expr_vstore(e, expr_vstore_box),
@ -1910,7 +1910,7 @@ impl Parser {
// HACK: parse ~"..." as a literal of a vstore ~str
pat = match sub.node {
pat_lit(e@@{
node: expr_lit(@{node: lit_str(_), span: _}), _
node: expr_lit(@spanned {node: lit_str(_), span: _}), _
}) => {
let vst = @{id: self.get_id(), callee_id: self.get_id(),
node: expr_vstore(e, expr_vstore_uniq),
@ -1929,7 +1929,7 @@ impl Parser {
// HACK: parse &"..." as a literal of a borrowed str
pat = match sub.node {
pat_lit(e@@{
node: expr_lit(@{node: lit_str(_), span: _}), _
node: expr_lit(@spanned {node: lit_str(_), span: _}), _
}) => {
let vst = @{
id: self.get_id(),
@ -1954,7 +1954,7 @@ impl Parser {
if self.token == token::RPAREN {
hi = self.span.hi;
self.bump();
let lit = @{node: lit_nil, span: mk_sp(lo, hi)};
let lit = @spanned {node: lit_nil, span: mk_sp(lo, hi)};
let expr = self.mk_expr(lo, hi, expr_lit(lit));
pat = pat_lit(expr);
} else {
@ -2319,8 +2319,9 @@ impl Parser {
match self.token {
token::SEMI => {
self.bump();
stmts.push(@{node: stmt_semi(e, stmt_id),
..*stmt});
stmts.push(@spanned {
node: stmt_semi(e, stmt_id),
.. *stmt});
}
token::RBRACE => {
expr = Some(e);
@ -2343,8 +2344,9 @@ impl Parser {
match self.token {
token::SEMI => {
self.bump();
stmts.push(@{node: stmt_mac((*m), true),
..*stmt});
stmts.push(@spanned {
node: stmt_mac((*m), true),
.. *stmt});
}
token::RBRACE => {
// if a block ends in `m!(arg)` without
@ -2811,11 +2813,11 @@ impl Parser {
let actual_dtor = do the_dtor.map |dtor| {
let (d_body, d_attrs, d_s) = *dtor;
{node: {id: self.get_id(),
attrs: d_attrs,
self_id: self.get_id(),
body: d_body},
span: d_s}};
spanned { node: { id: self.get_id(),
attrs: d_attrs,
self_id: self.get_id(),
body: d_body},
span: d_s}};
let _ = self.get_id(); // XXX: Workaround for crazy bug.
let new_id = self.get_id();
(class_name,
@ -3308,11 +3310,11 @@ impl Parser {
self.bump();
let mut actual_dtor = do the_dtor.map |dtor| {
let (d_body, d_attrs, d_s) = *dtor;
{node: {id: self.get_id(),
attrs: d_attrs,
self_id: self.get_id(),
body: d_body},
span: d_s}
spanned { node: { id: self.get_id(),
attrs: d_attrs,
self_id: self.get_id(),
body: d_body },
span: d_s }
};
return @{
@ -3592,9 +3594,9 @@ impl Parser {
_ => self.fatal(~"expected open delimiter")
};
let m = ast::mac_invoc_tt(pth, tts);
let m: ast::mac = {node: m,
span: mk_sp(self.span.lo,
self.span.hi)};
let m: ast::mac = spanned { node: m,
span: mk_sp(self.span.lo,
self.span.hi) };
let item_ = item_mac(m);
return iovi_item(self.mk_item(lo, self.last_span.hi, id, item_,
visibility, attrs));

View file

@ -599,7 +599,8 @@ fn print_item(s: ps, &&item: @ast::item) {
}
bclose(s, item.span);
}
ast::item_mac({node: ast::mac_invoc_tt(pth, ref tts), _}) => {
ast::item_mac(ast::spanned { node: ast::mac_invoc_tt(pth, ref tts),
_}) => {
print_visibility(s, item.vis);
print_path(s, pth, false);
word(s.s, ~"! ");