diff options
| author | bors <bors@rust-lang.org> | 2013-03-02 08:30:41 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-03-02 08:30:41 -0800 |
| commit | afdd0b868a4b94e828ccf7e1f68a2b0017943e2c (patch) | |
| tree | 4e3d85a43f684fd9d3b2e80a6a9178f90e63d7ce /src/libsyntax/ext | |
| parent | 2304fe6208404ce952aaa37e7634db570ff71f6c (diff) | |
| parent | 5515fd5c8cf65a8eebd43ddb0de6ff920a509ece (diff) | |
| download | rust-afdd0b868a4b94e828ccf7e1f68a2b0017943e2c.tar.gz rust-afdd0b868a4b94e828ccf7e1f68a2b0017943e2c.zip | |
auto merge of #5143 : erickt/rust/incoming, r=pcwalton
Good morning,
It's taken a long time, but I finally am almost done freeing libsyntax of `vecs_implicitly_copyable` in this pull request, but I'm running into some issues. I've confirmed that all but the last commit (which only disables `vecs_implicitly_copyable` pass the `check` tests. The last commit errors with this message, which makes no sense to me:
```
/Users/erickt/rust/rust/src/libcore/num/f32.rs:35:37: 35:43 error: expected `,` but found `=`
/Users/erickt/rust/rust/src/libcore/num/f32.rs:35 pub pure fn $name($( $arg : $arg_ty ),*) -> $rv {
^~~~~~
```
and this stack trace:
```
#1 0x00000001000b059b in sys::begin_unwind_::_a923ca4ae164c::_06 ()
#2 0x00000001000b0542 in sys::begin_unwind::anon::anon::expr_fn_13876 ()
#3 0x00000001000048a1 in sys::begin_unwind::_8ec273289fc0adc0::_06 ()
#4 0x00000001005df999 in diagnostic::__extensions__::meth_7941::span_fatal::_efdf2d14612d79ec::_06 ()
#5 0x0000000100682d48 in parse::parser::__extensions__::meth_16938::fatal::_8aa3239426747a3::_06 ()
#6 0x00000001006850b8 in parse::common::__extensions__::meth_17005::expect::_d3604ec6c7698d5f::_06 ()
#7 0x00000001006b59f1 in parse::common::__extensions__::parse_seq_to_before_end_17860::_48c79835f9eb1011::_06 ()
#8 0x00000001006a50f7 in parse::parser::__extensions__::meth_17606::parse_fn_decl::_14f3785fe78967d::_06 ()
#9 0x00000001006b6f59 in parse::parser::__extensions__::meth_17987::parse_item_fn::_8a6be529cf7b2ca5::_06 ()
#10 0x00000001006ac839 in parse::parser::__extensions__::meth_17761::parse_item_or_view_item::_bfead947d6dd7d25::_06 ()
#11 0x00000001006c8b8f in parse::parser::__extensions__::meth_18364::parse_item::_96b54e33f65abe76::_06 ()
#12 0x000000010076179f in ext::tt::macro_rules::add_new_extension::generic_extension::anon::anon::expr_fn_23365 ()
#13 0x000000010072e793 in ext::expand::expand_item_mac::_a4f486c4465cfb1b::_06 ()
#14 0x00000001007b5ad3 in __morestack ()
```
There also a bunch of new warnings that I haven't cleaned up yet: https://gist.github.com/erickt/5048251.
@nikomatsakis thought there might be some scary bug in the parser caused by moving a vector in the parser instead of copying it, which is why I'm filing this pull request before it's ready. Thanks for any help!
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/auto_encode.rs | 83 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 25 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 68 | ||||
| -rw-r--r-- | src/libsyntax/ext/concat_idents.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/ext/env.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 201 | ||||
| -rw-r--r-- | src/libsyntax/ext/fmt.rs | 17 | ||||
| -rw-r--r-- | src/libsyntax/ext/log_syntax.rs | 13 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/ast_builder.rs | 118 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/liveness.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/mod.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/parse_proto.rs | 70 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/pipec.rs | 13 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/proto.rs | 14 | ||||
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 30 | ||||
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 50 | ||||
| -rw-r--r-- | src/libsyntax/ext/trace_macros.rs | 24 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_parser.rs | 38 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 19 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/transcribe.rs | 39 |
21 files changed, 495 insertions, 356 deletions
diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index b00fa9d0a19..0e2f3c2c856 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -114,7 +114,7 @@ mod syntax { pub fn expand_auto_encode( cx: ext_ctxt, span: span, - _mitem: ast::meta_item, + _mitem: @ast::meta_item, in_items: ~[@ast::item] ) -> ~[@ast::item] { fn is_auto_encode(a: &ast::attribute) -> bool { @@ -124,7 +124,7 @@ pub fn expand_auto_encode( fn filter_attrs(item: @ast::item) -> @ast::item { @ast::item { attrs: item.attrs.filtered(|a| !is_auto_encode(a)), - .. *item + .. copy *item } } @@ -147,7 +147,7 @@ pub fn expand_auto_encode( cx, item.span, item.ident, - *enum_def, + copy *enum_def, generics ); @@ -169,7 +169,7 @@ pub fn expand_auto_encode( pub fn expand_auto_decode( cx: ext_ctxt, span: span, - _mitem: ast::meta_item, + _mitem: @ast::meta_item, in_items: ~[@ast::item] ) -> ~[@ast::item] { fn is_auto_decode(a: &ast::attribute) -> bool { @@ -179,7 +179,7 @@ pub fn expand_auto_decode( fn filter_attrs(item: @ast::item) -> @ast::item { @ast::item { attrs: item.attrs.filtered(|a| !is_auto_decode(a)), - .. *item + .. copy *item } } @@ -202,7 +202,7 @@ pub fn expand_auto_decode( cx, item.span, item.ident, - *enum_def, + copy *enum_def, generics ); @@ -241,7 +241,7 @@ priv impl ext_ctxt { } } - fn expr(span: span, node: ast::expr_) -> @ast::expr { + fn expr(span: span, +node: ast::expr_) -> @ast::expr { @ast::expr { id: self.next_id(), callee_id: self.next_id(), @@ -250,7 +250,7 @@ priv impl ext_ctxt { } } - fn path(span: span, strs: ~[ast::ident]) -> @ast::path { + fn path(span: span, +strs: ~[ast::ident]) -> @ast::path { @ast::path { span: span, global: false, @@ -260,7 +260,7 @@ priv impl ext_ctxt { } } - fn path_global(span: span, strs: ~[ast::ident]) -> @ast::path { + fn path_global(span: span, +strs: ~[ast::ident]) -> @ast::path { @ast::path { span: span, global: true, @@ -270,8 +270,11 @@ priv impl ext_ctxt { } } - fn path_tps(span: span, strs: ~[ast::ident], - tps: ~[@ast::Ty]) -> @ast::path { + fn path_tps( + span: span, + +strs: ~[ast::ident], + +tps: ~[@ast::Ty] + ) -> @ast::path { @ast::path { span: span, global: false, @@ -281,8 +284,11 @@ priv impl ext_ctxt { } } - fn path_tps_global(span: span, strs: ~[ast::ident], - tps: ~[@ast::Ty]) -> @ast::path { + fn path_tps_global( + span: span, + +strs: ~[ast::ident], + +tps: ~[@ast::Ty] + ) -> @ast::path { @ast::path { span: span, global: true, @@ -292,8 +298,11 @@ priv impl ext_ctxt { } } - fn ty_path(span: span, strs: ~[ast::ident], - tps: ~[@ast::Ty]) -> @ast::Ty { + fn ty_path( + span: span, + +strs: ~[ast::ident], + +tps: ~[@ast::Ty] + ) -> @ast::Ty { @ast::Ty { id: self.next_id(), node: ast::ty_path( @@ -339,13 +348,13 @@ priv impl ext_ctxt { span: span})) } - fn lambda(blk: ast::blk) -> @ast::expr { + fn lambda(+blk: ast::blk) -> @ast::expr { let ext_cx = self; - let blk_e = self.expr(blk.span, ast::expr_block(blk)); + let blk_e = self.expr(copy blk.span, ast::expr_block(copy blk)); quote_expr!( || $blk_e ) } - fn blk(span: span, stmts: ~[@ast::stmt]) -> ast::blk { + fn blk(span: span, +stmts: ~[@ast::stmt]) -> ast::blk { codemap::spanned { node: ast::blk_ { view_items: ~[], @@ -371,15 +380,15 @@ priv impl ext_ctxt { } } - fn expr_path(span: span, strs: ~[ast::ident]) -> @ast::expr { + fn expr_path(span: span, +strs: ~[ast::ident]) -> @ast::expr { self.expr(span, ast::expr_path(self.path(span, strs))) } - fn expr_path_global(span: span, strs: ~[ast::ident]) -> @ast::expr { + fn expr_path_global(span: span, +strs: ~[ast::ident]) -> @ast::expr { self.expr(span, ast::expr_path(self.path_global(span, strs))) } - fn expr_var(span: span, var: ~str) -> @ast::expr { + fn expr_var(span: span, +var: ~str) -> @ast::expr { self.expr_path(span, ~[self.ident_of(var)]) } @@ -394,7 +403,7 @@ priv impl ext_ctxt { fn expr_call( span: span, expr: @ast::expr, - args: ~[@ast::expr] + +args: ~[@ast::expr] ) -> @ast::expr { self.expr(span, ast::expr_call(expr, args, ast::NoSugar)) } @@ -403,7 +412,7 @@ priv impl ext_ctxt { self.lambda(self.expr_blk(expr)) } - fn lambda_stmts(span: span, stmts: ~[@ast::stmt]) -> @ast::expr { + fn lambda_stmts(span: span, +stmts: ~[@ast::stmt]) -> @ast::expr { self.lambda(self.blk(span, stmts)) } } @@ -572,7 +581,7 @@ fn mk_deser_impl( fn mk_ser_method( cx: ext_ctxt, span: span, - ser_body: ast::blk + +ser_body: ast::blk ) -> @ast::method { let ty_s = @ast::Ty { id: cx.next_id(), @@ -636,7 +645,7 @@ fn mk_deser_method( cx: ext_ctxt, span: span, ty: @ast::Ty, - deser_body: ast::blk + +deser_body: ast::blk ) -> @ast::method { let ty_d = @ast::Ty { id: cx.next_id(), @@ -858,14 +867,14 @@ fn mk_enum_ser_impl( cx: ext_ctxt, span: span, ident: ast::ident, - enum_def: ast::enum_def, + +enum_def: ast::enum_def, generics: &ast::Generics ) -> @ast::item { let body = mk_enum_ser_body( cx, span, ident, - enum_def.variants + copy enum_def.variants ); mk_ser_impl(cx, span, ident, generics, body) @@ -875,7 +884,7 @@ fn mk_enum_deser_impl( cx: ext_ctxt, span: span, ident: ast::ident, - enum_def: ast::enum_def, + +enum_def: ast::enum_def, generics: &ast::Generics ) -> @ast::item { let body = mk_enum_deser_body( @@ -974,12 +983,18 @@ fn mk_enum_ser_body( cx: ext_ctxt, span: span, name: ast::ident, - variants: ~[ast::variant] + +variants: ~[ast::variant] ) -> @ast::expr { let arms = do variants.mapi |v_idx, variant| { match variant.node.kind { - ast::tuple_variant_kind(args) => - ser_variant(cx, span, variant.node.name, v_idx, args), + ast::tuple_variant_kind(ref args) => + ser_variant( + cx, + span, + variant.node.name, + v_idx, + /*bad*/ copy *args + ), ast::struct_variant_kind(*) => fail!(~"struct variants unimplemented"), ast::enum_variant_kind(*) => @@ -1059,7 +1074,7 @@ fn mk_enum_deser_body( ) -> @ast::expr { let mut arms = do variants.mapi |v_idx, variant| { let body = match variant.node.kind { - ast::tuple_variant_kind(args) => { + ast::tuple_variant_kind(ref args) => { if args.is_empty() { // for a nullary variant v, do "v" ext_cx.expr_path(span, ~[variant.node.name]) @@ -1069,7 +1084,7 @@ fn mk_enum_deser_body( ext_cx, span, variant.node.name, - args + copy *args ) } }, @@ -1092,7 +1107,7 @@ fn mk_enum_deser_body( } }; - let quoted_expr = quote_expr!( + let quoted_expr = copy quote_expr!( ::core::sys::begin_unwind(~"explicit failure", ~"empty", 1); ).node; diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 9525369d334..7d3c7cafa95 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -38,7 +38,7 @@ pub struct MacroDef { } pub type ItemDecorator = - fn@(ext_ctxt, span, ast::meta_item, ~[@ast::item]) -> ~[@ast::item]; + fn@(ext_ctxt, span, @ast::meta_item, ~[@ast::item]) -> ~[@ast::item]; pub struct SyntaxExpanderTT { expander: SyntaxExpanderTTFun, @@ -46,7 +46,7 @@ pub struct SyntaxExpanderTT { } pub type SyntaxExpanderTTFun - = fn@(ext_ctxt, span, ~[ast::token_tree]) -> MacResult; + = fn@(ext_ctxt, span, &[ast::token_tree]) -> MacResult; pub struct SyntaxExpanderTTItem { expander: SyntaxExpanderTTItemFun, @@ -222,7 +222,7 @@ pub trait ext_ctxt { } pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, - cfg: ast::crate_cfg) -> ext_ctxt { + +cfg: ast::crate_cfg) -> ext_ctxt { struct CtxtRepr { parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg, @@ -233,7 +233,7 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, impl ext_ctxt for CtxtRepr { fn codemap(@mut self) -> @CodeMap { self.parse_sess.cm } fn parse_sess(@mut self) -> @mut parse::ParseSess { self.parse_sess } - fn cfg(@mut self) -> ast::crate_cfg { self.cfg } + fn cfg(@mut self) -> ast::crate_cfg { copy self.cfg } fn call_site(@mut self) -> span { match *self.backtrace { Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs, @@ -244,7 +244,7 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, fn backtrace(@mut self) -> Option<@ExpnInfo> { *self.backtrace } fn mod_push(@mut self, i: ast::ident) { self.mod_path.push(i); } fn mod_pop(@mut self) { self.mod_path.pop(); } - fn mod_path(@mut self) -> ~[ast::ident] { return self.mod_path; } + fn mod_path(@mut self) -> ~[ast::ident] { copy self.mod_path } fn bt_push(@mut self, ei: codemap::ExpnInfo) { match ei { ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => { @@ -252,7 +252,7 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, Some(@ExpandedFrom(CallInfo { call_site: span {lo: cs.lo, hi: cs.hi, expn_info: *self.backtrace}, - callee: (*callee)})); + callee: copy *callee})); } } } @@ -299,12 +299,11 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, fn set_trace_macros(@mut self, x: bool) { self.trace_mac = x } - fn str_of(@mut self, id: ast::ident) -> ~str { - *self.parse_sess.interner.get(id) + copy *self.parse_sess.interner.get(id) } fn ident_of(@mut self, st: ~str) -> ast::ident { - self.parse_sess.interner.intern(@st) + self.parse_sess.interner.intern(@/*bad*/ copy st) } } let imp: @mut CtxtRepr = @mut CtxtRepr { @@ -320,7 +319,7 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, pub fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, err_msg: ~str) -> ~str { match expr.node { ast::expr_lit(l) => match l.node { - ast::lit_str(s) => return *s, + ast::lit_str(s) => copy *s, _ => cx.span_fatal(l.span, err_msg) }, _ => cx.span_fatal(expr.span, err_msg) @@ -363,15 +362,15 @@ pub fn get_single_str_from_tts(cx: ext_ctxt, } } -pub fn get_exprs_from_tts(cx: ext_ctxt, tts: ~[ast::token_tree]) +pub fn get_exprs_from_tts(cx: ext_ctxt, tts: &[ast::token_tree]) -> ~[@ast::expr] { let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), - tts); + vec::from_slice(tts)); let mut es = ~[]; while *p.token != token::EOF { if es.len() != 0 { - p.eat(token::COMMA); + p.eat(&token::COMMA); } es.push(p.parse_expr()); } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index fa21243df03..c6e6e677348 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -29,7 +29,7 @@ pub struct Field { pub fn mk_expr(cx: ext_ctxt, sp: codemap::span, - expr: ast::expr_) + +expr: ast::expr_) -> @ast::expr { @ast::expr { id: cx.next_id(), @@ -65,7 +65,7 @@ pub fn mk_unary(cx: ext_ctxt, sp: span, op: ast::unop, e: @ast::expr) cx.next_id(); // see ast_util::op_expr_callee_id mk_expr(cx, sp, ast::expr_unary(op, e)) } -pub fn mk_raw_path(sp: span, idents: ~[ast::ident]) -> @ast::path { +pub fn mk_raw_path(sp: span, +idents: ~[ast::ident]) -> @ast::path { let p = @ast::path { span: sp, global: false, idents: idents, @@ -74,7 +74,7 @@ pub fn mk_raw_path(sp: span, idents: ~[ast::ident]) -> @ast::path { return p; } pub fn mk_raw_path_(sp: span, - idents: ~[ast::ident], + +idents: ~[ast::ident], +types: ~[@ast::Ty]) -> @ast::path { @ast::path { span: sp, @@ -83,17 +83,17 @@ pub fn mk_raw_path_(sp: span, rp: None, types: types } } -pub fn mk_raw_path_global(sp: span, idents: ~[ast::ident]) -> @ast::path { +pub fn mk_raw_path_global(sp: span, +idents: ~[ast::ident]) -> @ast::path { @ast::path { span: sp, global: true, idents: idents, rp: None, types: ~[] } } -pub fn mk_path(cx: ext_ctxt, sp: span, idents: ~[ast::ident]) -> @ast::expr { +pub fn mk_path(cx: ext_ctxt, sp: span, +idents: ~[ast::ident]) -> @ast::expr { mk_expr(cx, sp, ast::expr_path(mk_raw_path(sp, idents))) } -pub fn mk_path_global(cx: ext_ctxt, sp: span, idents: ~[ast::ident]) +pub fn mk_path_global(cx: ext_ctxt, sp: span, +idents: ~[ast::ident]) -> @ast::expr { mk_expr(cx, sp, ast::expr_path(mk_raw_path_global(sp, idents))) } @@ -101,7 +101,7 @@ pub fn mk_access_(cx: ext_ctxt, sp: span, p: @ast::expr, m: ast::ident) -> @ast::expr { mk_expr(cx, sp, ast::expr_field(p, m, ~[])) } -pub fn mk_access(cx: ext_ctxt, sp: span, p: ~[ast::ident], m: ast::ident) +pub fn mk_access(cx: ext_ctxt, sp: span, +p: ~[ast::ident], m: ast::ident) -> @ast::expr { let pathexpr = mk_path(cx, sp, p); return mk_access_(cx, sp, pathexpr, m); @@ -110,21 +110,21 @@ pub fn mk_addr_of(cx: ext_ctxt, sp: span, e: @ast::expr) -> @ast::expr { return mk_expr(cx, sp, ast::expr_addr_of(ast::m_imm, e)); } pub fn mk_call_(cx: ext_ctxt, sp: span, fn_expr: @ast::expr, - args: ~[@ast::expr]) -> @ast::expr { + +args: ~[@ast::expr]) -> @ast::expr { mk_expr(cx, sp, ast::expr_call(fn_expr, args, ast::NoSugar)) } -pub fn mk_call(cx: ext_ctxt, sp: span, fn_path: ~[ast::ident], - args: ~[@ast::expr]) -> @ast::expr { +pub fn mk_call(cx: ext_ctxt, sp: span, +fn_path: ~[ast::ident], + +args: ~[@ast::expr]) -> @ast::expr { let pathexpr = mk_path(cx, sp, fn_path); return mk_call_(cx, sp, pathexpr, args); } -pub fn mk_call_global(cx: ext_ctxt, sp: span, fn_path: ~[ast::ident], - args: ~[@ast::expr]) -> @ast::expr { +pub fn mk_call_global(cx: ext_ctxt, sp: span, +fn_path: ~[ast::ident], + +args: ~[@ast::expr]) -> @ast::expr { let pathexpr = mk_path_global(cx, sp, fn_path); return mk_call_(cx, sp, pathexpr, args); } // e = expr, t = type -pub fn mk_base_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) +pub fn mk_base_vec_e(cx: ext_ctxt, sp: span, +exprs: ~[@ast::expr]) -> @ast::expr { let vecexpr = ast::expr_vec(exprs, ast::m_imm); mk_expr(cx, sp, vecexpr) @@ -134,25 +134,25 @@ pub fn mk_vstore_e(cx: ext_ctxt, sp: span, expr: @ast::expr, @ast::expr { mk_expr(cx, sp, ast::expr_vstore(expr, vst)) } -pub fn mk_uniq_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) +pub fn mk_uniq_vec_e(cx: ext_ctxt, sp: span, +exprs: ~[@ast::expr]) -> @ast::expr { mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::expr_vstore_uniq) } -pub fn mk_slice_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) +pub fn mk_slice_vec_e(cx: ext_ctxt, sp: span, +exprs: ~[@ast::expr]) -> @ast::expr { mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::expr_vstore_slice) } -pub fn mk_fixed_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) +pub fn mk_fixed_vec_e(cx: ext_ctxt, sp: span, +exprs: ~[@ast::expr]) -> @ast::expr { mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::expr_vstore_fixed(None)) } -pub fn mk_base_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr { +pub fn mk_base_str(cx: ext_ctxt, sp: span, +s: ~str) -> @ast::expr { let lit = ast::lit_str(@s); return mk_lit(cx, sp, lit); } -pub fn mk_uniq_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr { +pub fn mk_uniq_str(cx: ext_ctxt, sp: span, +s: ~str) -> @ast::expr { mk_vstore_e(cx, sp, mk_base_str(cx, sp, s), ast::expr_vstore_uniq) } pub fn mk_field(sp: span, f: &Field) -> ast::field { @@ -164,28 +164,36 @@ pub fn mk_field(sp: span, f: &Field) -> ast::field { pub fn mk_fields(sp: span, fields: ~[Field]) -> ~[ast::field] { fields.map(|f| mk_field(sp, f)) } -pub fn mk_rec_e(cx: ext_ctxt, sp: span, fields: ~[Field]) -> @ast::expr { +pub fn mk_rec_e(cx: ext_ctxt, + sp: span, + +fields: ~[Field]) + -> @ast::expr { mk_expr(cx, sp, ast::expr_rec(mk_fields(sp, fields), option::None::<@ast::expr>)) } -pub fn mk_struct_e(cx: ext_ctxt, sp: span, ctor_path: ~[ast::ident], - fields: ~[Field]) -> @ast::expr { +pub fn mk_struct_e(cx: ext_ctxt, + sp: span, + +ctor_path: ~[ast::ident], + +fields: ~[Field]) + -> @ast::expr { mk_expr(cx, sp, ast::expr_struct(mk_raw_path(sp, ctor_path), mk_fields(sp, fields), option::None::<@ast::expr>)) } -pub fn mk_global_struct_e(cx: ext_ctxt, sp: span, - ctor_path: ~[ast::ident], - fields: ~[Field]) +pub fn mk_global_struct_e(cx: ext_ctxt, + sp: span, + +ctor_path: ~[ast::ident], + +fields: ~[Field]) -> @ast::expr { mk_expr(cx, sp, ast::expr_struct(mk_raw_path_global(sp, ctor_path), mk_fields(sp, fields), option::None::<@ast::expr>)) } -pub fn mk_glob_use(cx: ext_ctxt, sp: span, path: ~[ast::ident]) - -> @ast::view_item { +pub fn mk_glob_use(cx: ext_ctxt, + sp: span, + +path: ~[ast::ident]) -> @ast::view_item { let glob = @codemap::spanned { node: ast::view_path_glob(mk_raw_path(sp, path), cx.next_id()), span: sp, @@ -221,8 +229,8 @@ pub fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool, @codemap::spanned { node: ast::stmt_decl(@decl, cx.next_id()), span: sp } } pub fn mk_block(cx: ext_ctxt, span: span, - view_items: ~[@ast::view_item], - stmts: ~[@ast::stmt], + +view_items: ~[@ast::view_item], + +stmts: ~[@ast::stmt], expr: Option<@ast::expr>) -> @ast::expr { let blk = codemap::spanned { node: ast::blk_ { @@ -316,7 +324,7 @@ pub fn mk_stmt(cx: ext_ctxt, span: span, expr: @ast::expr) -> @ast::stmt { } pub fn mk_ty_path(cx: ext_ctxt, span: span, - idents: ~[ ast::ident ]) + +idents: ~[ ast::ident ]) -> @ast::Ty { let ty = build::mk_raw_path(span, idents); let ty = ast::ty_path(ty, cx.next_id()); @@ -325,7 +333,7 @@ pub fn mk_ty_path(cx: ext_ctxt, } pub fn mk_ty_path_global(cx: ext_ctxt, span: span, - idents: ~[ ast::ident ]) + +idents: ~[ ast::ident ]) -> @ast::Ty { let ty = build::mk_raw_path_global(span, idents); let ty = ast::ty_path(ty, cx.next_id()); diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index 1dc5350c452..4f53bf62efb 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -16,7 +16,7 @@ use ext::base::*; use ext::base; use parse::token; -pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) +pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let mut res_str = ~""; for tts.eachi |i, e| { diff --git a/src/libsyntax/ext/deriving.rs b/src/libsyntax/ext/deriving.rs index 7820bb5e964..50047d2ce41 100644 --- a/src/libsyntax/ext/deriving.rs +++ b/src/libsyntax/ext/deriving.rs @@ -62,7 +62,7 @@ type ExpandDerivingEnumDefFn = &fn(ext_ctxt, pub fn expand_deriving_eq(cx: ext_ctxt, span: span, - _mitem: meta_item, + _mitem: @meta_item, in_items: ~[@item]) -> ~[@item] { expand_deriving(cx, @@ -74,7 +74,7 @@ pub fn expand_deriving_eq(cx: ext_ctxt, pub fn expand_deriving_iter_bytes(cx: ext_ctxt, span: span, - _mitem: meta_item, + _mitem: @meta_item, in_items: ~[@item]) -> ~[@item] { expand_deriving(cx, @@ -490,8 +490,8 @@ fn call_substructure_iter_bytes_method(cx: ext_ctxt, fn variant_arg_count(cx: ext_ctxt, span: span, variant: &variant) -> uint { match variant.node.kind { - tuple_variant_kind(args) => args.len(), - struct_variant_kind(struct_def) => struct_def.fields.len(), + tuple_variant_kind(ref args) => args.len(), + struct_variant_kind(ref struct_def) => struct_def.fields.len(), enum_variant_kind(*) => { cx.span_bug(span, ~"variant_arg_count: enum variants deprecated") } @@ -856,7 +856,7 @@ fn expand_deriving_eq_struct_tuple_method(cx: ext_ctxt, let self_str = ~"self"; let other_str = ~"__other"; let type_path = build::mk_raw_path(span, ~[type_ident]); - let fields = struct_def.fields; + let fields = copy struct_def.fields; // Create comparison expression, comparing each of the fields let mut match_body = None; diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index ce87c2f1363..91a9de9c051 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -15,16 +15,15 @@ * interface. */ +use prelude::*; + use ast; use codemap::span; use ext::base::*; use ext::base; use ext::build::mk_uniq_str; -use core::option; -use core::os; - -pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) +pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let var = get_single_str_from_tts(cx, sp, tts, "env!"); @@ -33,8 +32,8 @@ pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) // Option<str> rather than just an maybe-empty string. let e = match os::getenv(var) { - option::None => mk_uniq_str(cx, sp, ~""), - option::Some(ref s) => mk_uniq_str(cx, sp, (*s)) + None => mk_uniq_str(cx, sp, ~""), + Some(ref s) => mk_uniq_str(cx, sp, copy *s) }; MRExpr(e) } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 1a67a569845..e3408a47c9a 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -27,64 +27,73 @@ use core::vec; use core::hashmap::LinearMap; pub fn expand_expr(extsbox: @mut SyntaxEnv, cx: ext_ctxt, - e: expr_, s: span, fld: ast_fold, - orig: fn@(expr_, span, ast_fold) -> (expr_, span)) + e: &expr_, s: span, fld: ast_fold, + orig: fn@(&expr_, span, ast_fold) -> (expr_, span)) -> (expr_, span) { - return match e { - // expr_mac should really be expr_ext or something; it's the - // entry-point for all syntax extensions. - expr_mac(ref mac) => { - + match *e { + // expr_mac should really be expr_ext or something; it's the + // entry-point for all syntax extensions. + expr_mac(ref mac) => { match (*mac).node { - - // Token-tree macros, these will be the only case when we're - // finished transitioning. - mac_invoc_tt(pth, ref tts) => { - assert (vec::len(pth.idents) == 1u); - /* using idents and token::special_idents would make the - the macro names be hygienic */ - let extname = cx.parse_sess().interner.get(pth.idents[0]); - // leaving explicit deref here to highlight unbox op: - match (*extsbox).find(&extname) { - None => { - cx.span_fatal(pth.span, - fmt!("macro undefined: '%s'", *extname)) - } - Some(@SE(NormalTT(SyntaxExpanderTT{expander: exp, - span: exp_sp}))) => { - cx.bt_push(ExpandedFrom(CallInfo{ - call_site: s, - callee: NameAndSpan { - name: *extname, span: exp_sp + // Token-tree macros, these will be the only case when we're + // finished transitioning. + mac_invoc_tt(pth, ref tts) => { + assert (vec::len(pth.idents) == 1u); + /* using idents and token::special_idents would make the + the macro names be hygienic */ + let extname = cx.parse_sess().interner.get(pth.idents[0]); + // leaving explicit deref here to highlight unbox op: + match (*extsbox).find(&extname) { + None => { + cx.span_fatal( + pth.span, + fmt!("macro undefined: '%s'", *extname)) } - })); - - let expanded = match exp(cx, (*mac).span, (*tts)) { - MRExpr(e) => e, - MRAny(expr_maker,_,_) => expr_maker(), - _ => cx.span_fatal( - pth.span, fmt!("non-expr macro in expr pos: %s", - *extname)) - }; - - //keep going, outside-in - let fully_expanded = fld.fold_expr(expanded).node; - cx.bt_pop(); - - (fully_expanded, s) - } - _ => { - cx.span_fatal(pth.span, - fmt!("'%s' is not a tt-style macro", - *extname)) - } - + Some(@SE(NormalTT(SyntaxExpanderTT{ + expander: exp, + span: exp_sp + }))) => { + cx.bt_push(ExpandedFrom(CallInfo { + call_site: s, + callee: NameAndSpan { + name: copy *extname, + span: exp_sp, + }, + })); + + let expanded = match exp(cx, mac.span, *tts) { + MRExpr(e) => e, + MRAny(expr_maker,_,_) => expr_maker(), + _ => { + cx.span_fatal( + pth.span, + fmt!( + "non-expr macro in expr pos: %s", + *extname + ) + ) + } + }; + + //keep going, outside-in + let fully_expanded = + copy fld.fold_expr(expanded).node; + cx.bt_pop(); + + (fully_expanded, s) + } + _ => { + cx.span_fatal( + pth.span, + fmt!("'%s' is not a tt-style macro", *extname) + ) + } + } } - } } - } - _ => orig(e, s, fld) - }; + } + _ => orig(e, s, fld) + } } // This is a secondary mechanism for invoking syntax extensions on items: @@ -97,8 +106,8 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv, cx: ext_ctxt, // NB: there is some redundancy between this and expand_item, below, and // they might benefit from some amount of semantic and language-UI merger. pub fn expand_mod_items(extsbox: @mut SyntaxEnv, cx: ext_ctxt, - module_: ast::_mod, fld: ast_fold, - orig: fn@(ast::_mod, ast_fold) -> ast::_mod) + module_: &ast::_mod, fld: ast_fold, + orig: fn@(&ast::_mod, ast_fold) -> ast::_mod) -> ast::_mod { // Fold the contents first: let module_ = orig(module_, fld); @@ -146,8 +155,8 @@ macro_rules! with_exts_frame ( // When we enter a module, record it, for the sake of `module!` pub fn expand_item(extsbox: @mut SyntaxEnv, - cx: ext_ctxt, &&it: @ast::item, fld: ast_fold, - orig: fn@(&&v: @ast::item, ast_fold) -> Option<@ast::item>) + cx: ext_ctxt, it: @ast::item, fld: ast_fold, + orig: fn@(@ast::item, ast_fold) -> Option<@ast::item>) -> Option<@ast::item> { // need to do expansion first... it might turn out to be a module. let maybe_it = match it.node { @@ -225,7 +234,7 @@ pub fn expand_item_mac(+extsbox: @mut SyntaxEnv, let (pth, tts) = match it.node { item_mac(codemap::spanned { node: mac_invoc_tt(pth, ref tts), _}) => { - (pth, (*tts)) + (pth, copy *tts) } _ => cx.span_bug(it.span, ~"invalid item macro invocation") }; @@ -245,8 +254,8 @@ pub fn expand_item_mac(+extsbox: @mut SyntaxEnv, cx.bt_push(ExpandedFrom(CallInfo { call_site: it.span, callee: NameAndSpan { - name: *extname, - span: (*expand).span + name: copy *extname, + span: expand.span } })); ((*expand).expander)(cx, it.span, tts) @@ -260,8 +269,8 @@ pub fn expand_item_mac(+extsbox: @mut SyntaxEnv, cx.bt_push(ExpandedFrom(CallInfo { call_site: it.span, callee: NameAndSpan { - name: *extname, - span: (*expand).span + name: copy *extname, + span: expand.span } })); ((*expand).expander)(cx, it.span, it.ident, tts) @@ -288,14 +297,16 @@ pub fn expand_item_mac(+extsbox: @mut SyntaxEnv, // expand a stmt pub fn expand_stmt(extsbox: @mut SyntaxEnv, cx: ext_ctxt, - && s: stmt_, sp: span, fld: ast_fold, - orig: fn@(&&s: stmt_, span, ast_fold) -> (stmt_, span)) + s: &stmt_, sp: span, fld: ast_fold, + orig: fn@(s: &stmt_, span, ast_fold) -> (stmt_, span)) -> (stmt_, span) { - let (mac, pth, tts, semi) = match s { + let (mac, pth, tts, semi) = match *s { stmt_mac(ref mac, semi) => { - match (*mac).node { - mac_invoc_tt(pth, ref tts) => ((*mac), pth, (*tts), semi) + match mac.node { + mac_invoc_tt(pth, ref tts) => { + (copy *mac, pth, copy *tts, semi) + } } } _ => return orig(s, sp, fld) @@ -311,7 +322,7 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, cx: ext_ctxt, SyntaxExpanderTT{expander: exp, span: exp_sp}))) => { cx.bt_push(ExpandedFrom(CallInfo { call_site: sp, - callee: NameAndSpan { name: *extname, span: exp_sp } + callee: NameAndSpan { name: copy *extname, span: exp_sp } })); let expanded = match exp(cx, mac.span, tts) { MRExpr(e) => @@ -324,7 +335,7 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, cx: ext_ctxt, }; //keep going, outside-in - let fully_expanded = fld.fold_stmt(expanded).node; + let fully_expanded = copy fld.fold_stmt(expanded).node; cx.bt_pop(); (fully_expanded, sp) @@ -346,8 +357,8 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, cx: ext_ctxt, pub fn expand_block(extsbox: @mut SyntaxEnv, cx: ext_ctxt, - && blk: blk_, sp: span, fld: ast_fold, - orig: fn@(&&s: blk_, span, ast_fold) -> (blk_, span)) + blk: &blk_, sp: span, fld: ast_fold, + orig: fn@(&blk_, span, ast_fold) -> (blk_, span)) -> (blk_, span) { match (*extsbox).find(&@~" block") { // no scope limit on macros in this block, no need @@ -433,7 +444,7 @@ pub fn expand_crate(parse_sess: @mut parse::ParseSess, // every method/element of AstFoldFns in fold.rs. let extsbox = @mut syntax_expander_table(); let afp = default_ast_fold(); - let cx: ext_ctxt = mk_ctxt(parse_sess, cfg); + let cx: ext_ctxt = mk_ctxt(parse_sess, copy cfg); let f_pre = @AstFoldFns { fold_expr: |expr,span,recur| expand_expr(extsbox, cx, expr, span, recur, afp.fold_expr), @@ -444,23 +455,30 @@ pub fn expand_crate(parse_sess: @mut parse::ParseSess, fold_stmt: |stmt,span,recur| expand_stmt(extsbox, cx, stmt, span, recur, afp.fold_stmt), fold_block: |blk,span,recur| - expand_block (extsbox, cx, blk, span, recur, afp.fold_block), + expand_block(extsbox, cx, blk, span, recur, afp.fold_block), new_span: |a| new_span(cx, a), .. *afp}; let f = make_fold(f_pre); // add a bunch of macros as though they were placed at the // head of the program (ick). - let attrs = ~[spanned {span:codemap::dummy_sp(), - node: attribute_ - {style:attr_outer, - value:spanned - {node:meta_word(@~"macro_escape"), - span:codemap::dummy_sp()}, - is_sugared_doc:false}}]; + let attrs = ~[ + spanned { + span: codemap::dummy_sp(), + node: attribute_ { + style: attr_outer, + value: @spanned { + node: meta_word(@~"macro_escape"), + span: codemap::dummy_sp(), + }, + is_sugared_doc: false, + } + } + ]; let cm = match parse_item_from_source_str(~"<core-macros>", @core_macros(), - cfg,attrs, + copy cfg, + attrs, parse_sess) { Some(item) => item, None => cx.bug(~"expected core macros to parse correctly") @@ -469,8 +487,7 @@ pub fn expand_crate(parse_sess: @mut parse::ParseSess, // as it registers all the core macros as expanders. f.fold_item(cm); - let res = @f.fold_crate(*c); - return res; + @f.fold_crate(&*c) } #[cfg(test)] @@ -575,13 +592,17 @@ mod test { // make a "meta_word" outer attribute with the given name fn make_dummy_attr(s: @~str) -> ast::attribute { - spanned {span:codemap::dummy_sp(), - node: attribute_ - {style:attr_outer, - value:spanned - {node:meta_word(s), - span:codemap::dummy_sp()}, - is_sugared_doc:false}} + spanned { + span:codemap::dummy_sp(), + node: attribute_ { + style: attr_outer, + value: @spanned { + node: meta_word(s), + span: codemap::dummy_sp(), + }, + is_sugared_doc: false, + } + } } } diff --git a/src/libsyntax/ext/fmt.rs b/src/libsyntax/ext/fmt.rs index 3861db28e1d..e06e43f6287 100644 --- a/src/libsyntax/ext/fmt.rs +++ b/src/libsyntax/ext/fmt.rs @@ -26,9 +26,9 @@ use ext::build; use ext::build::*; use unstable::extfmt::ct::*; -pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) +pub fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { - let args = get_exprs_from_tts(cx, copy tts); + let args = get_exprs_from_tts(cx, tts); if args.len() == 0 { cx.span_fatal(sp, "fmt! takes at least 1 argument."); } @@ -277,9 +277,9 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, for pieces.each |pc| { match *pc { PieceString(ref s) => { - piece_exprs.push(mk_uniq_str(cx, fmt_sp, (*s))) + piece_exprs.push(mk_uniq_str(cx, fmt_sp, copy *s)) } - PieceConv(conv) => { + PieceConv(ref conv) => { n += 1u; if n >= nargs { cx.span_fatal(sp, @@ -287,9 +287,14 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, ~"for the given format string"); } debug!("Building conversion:"); - log_conv(conv); + log_conv(/*bad*/ copy *conv); let arg_expr = args[n]; - let c_expr = make_new_conv(cx, fmt_sp, conv, arg_expr); + let c_expr = make_new_conv( + cx, + fmt_sp, + /*bad*/ copy *conv, + arg_expr + ); piece_exprs.push(c_expr); } } diff --git a/src/libsyntax/ext/log_syntax.rs b/src/libsyntax/ext/log_syntax.rs index 15ddc44e85d..368520acd2d 100644 --- a/src/libsyntax/ext/log_syntax.rs +++ b/src/libsyntax/ext/log_syntax.rs @@ -8,24 +8,25 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use prelude::*; +use core::io::WriterUtil; + use ast; use codemap; use ext::base::*; use ext::base; use print; -use core::io; -use core::io::WriterUtil; -use core::option; - pub fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, - tt: ~[ast::token_tree]) + tt: &[ast::token_tree]) -> base::MacResult { cx.print_backtrace(); io::stdout().write_line( - print::pprust::tt_to_str(ast::tt_delim(tt),cx.parse_sess().interner)); + print::pprust::tt_to_str( + ast::tt_delim(vec::from_slice(tt)), + cx.parse_sess().interner)); //trivial expression MRExpr(@ast::expr { diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index 6e1406e3647..3b885b7a7b9 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -35,7 +35,7 @@ mod syntax { pub use parse; } -pub fn path(ids: ~[ident], span: span) -> @ast::path { +pub fn path(+ids: ~[ident], span: span) -> @ast::path { @ast::path { span: span, global: false, idents: ids, @@ -43,7 +43,7 @@ pub fn path(ids: ~[ident], span: span) -> @ast::path { types: ~[] } } -pub fn path_global(ids: ~[ident], span: span) -> @ast::path { +pub fn path_global(+ids: ~[ident], span: span) -> @ast::path { @ast::path { span: span, global: true, idents: ids, @@ -52,19 +52,23 @@ pub fn path_global(ids: ~[ident], span: span) -> @ast::path { } pub trait append_types { - fn add_ty(ty: @ast::Ty) -> @ast::path; - fn add_tys(+tys: ~[@ast::Ty]) -> @ast::path; + fn add_ty(&self, ty: @ast::Ty) -> @ast::path; + fn add_tys(&self, +tys: ~[@ast::Ty]) -> @ast::path; } impl append_types for @ast::path { - fn add_ty(ty: @ast::Ty) -> @ast::path { - @ast::path { types: vec::append_one(self.types, ty), - .. *self} + fn add_ty(&self, ty: @ast::Ty) -> @ast::path { + @ast::path { + types: vec::append_one(copy self.types, ty), + .. copy **self + } } - fn add_tys(+tys: ~[@ast::Ty]) -> @ast::path { - @ast::path { types: vec::append(self.types, tys), - .. *self} + fn add_tys(&self, +tys: ~[@ast::Ty]) -> @ast::path { + @ast::path { + types: vec::append(copy self.types, tys), + .. copy **self + } } } @@ -75,34 +79,49 @@ pub trait ext_ctxt_ast_builder { fn expr_block(&self, e: @ast::expr) -> ast::blk; fn fn_decl(&self, +inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl; fn item(&self, name: ident, span: span, +node: ast::item_) -> @ast::item; - fn item_fn_poly(&self, name: ident, + fn item_fn_poly(&self, + ame: ident, +inputs: ~[ast::arg], output: @ast::Ty, +generics: Generics, +body: ast::blk) -> @ast::item; - fn item_fn(&self, name: ident, + fn item_fn(&self, + name: ident, +inputs: ~[ast::arg], output: @ast::Ty, +body: ast::blk) -> @ast::item; - fn item_enum_poly(&self, name: ident, + fn item_enum_poly(&self, + name: ident, span: span, +enum_definition: ast::enum_def, +generics: Generics) -> @ast::item; - fn item_enum(&self, name: ident, span: span, + fn item_enum(&self, + name: ident, + span: span, +enum_definition: ast::enum_def) -> @ast::item; - fn item_struct_poly(&self, name: ident, span: span, - struct_def: ast::struct_def, + fn item_struct_poly(&self, + name: ident, + span: span, + +struct_def: ast::struct_def, +generics: Generics) -> @ast::item; - fn item_struct(&self, name: ident, span: span, - struct_def: ast::struct_def) -> @ast::item; - fn struct_expr(&self, path: @ast::path, - fields: ~[ast::field]) -> @ast::expr; - fn variant(&self, name: ident, span: span, + fn item_struct(&self, + name: ident, + span: span, + +struct_def: ast::struct_def) -> @ast::item; + fn struct_expr(&self, + path: @ast::path, + +fields: ~[ast::field]) -> @ast::expr; + fn variant(&self, + name: ident, + span: span, +tys: ~[@ast::Ty]) -> ast::variant; - fn item_mod(&self, name: ident, span: span, + fn item_mod(&self, + name: ident, + span: span, +items: ~[@ast::item]) -> @ast::item; fn ty_path_ast_builder(&self, path: @ast::path) -> @ast::Ty; - fn item_ty_poly(&self, name: ident, + fn item_ty_poly(&self, + name: ident, span: span, ty: @ast::Ty, +generics: Generics) -> @ast::item; @@ -114,7 +133,7 @@ pub trait ext_ctxt_ast_builder { fn block(&self, +stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk; fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt; fn stmt_expr(&self, e: @ast::expr) -> @ast::stmt; - fn block_expr(&self, b: ast::blk) -> @ast::expr; + fn block_expr(&self, +b: ast::blk) -> @ast::expr; fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty; fn ty_infer(&self) -> @ast::Ty; fn ty_nil_ast_builder(&self) -> @ast::Ty; @@ -130,7 +149,7 @@ impl ext_ctxt_ast_builder for ext_ctxt { ], dummy_sp()).add_ty(ty)) } - fn block_expr(&self, b: ast::blk) -> @ast::expr { + fn block_expr(&self, +b: ast::blk) -> @ast::expr { @expr { id: self.next_id(), callee_id: self.next_id(), @@ -229,7 +248,7 @@ impl ext_ctxt_ast_builder for ext_ctxt { // Rust coding conventions let non_camel_case_attribute = respan(dummy_sp(), ast::attribute_ { style: ast::attr_outer, - value: respan(dummy_sp(), + value: @respan(dummy_sp(), ast::meta_list(@~"allow", ~[ @respan(dummy_sp(), ast::meta_word( @@ -259,12 +278,19 @@ impl ext_ctxt_ast_builder for ext_ctxt { body)) } - fn item_fn(&self, name: ident, + fn item_fn(&self, + name: ident, +inputs: ~[ast::arg], output: @ast::Ty, - +body: ast::blk) -> @ast::item { - self.item_fn_poly(name, inputs, output, - ast_util::empty_generics(), body) + +body: ast::blk + ) -> @ast::item { + self.item_fn_poly( + name, + inputs, + output, + ast_util::empty_generics(), + body + ) } fn item_enum_poly(&self, name: ident, span: span, @@ -279,20 +305,31 @@ impl ext_ctxt_ast_builder for ext_ctxt { ast_util::empty_generics()) } - fn item_struct(&self, name: ident, span: span, - struct_def: ast::struct_def) -> @ast::item { - self.item_struct_poly(name, span, struct_def, - ast_util::empty_generics()) + fn item_struct( + &self, name: ident, + span: span, + +struct_def: ast::struct_def + ) -> @ast::item { + self.item_struct_poly( + name, + span, + struct_def, + ast_util::empty_generics() + ) } - fn item_struct_poly(&self, name: ident, span: span, - struct_def: ast::struct_def, - +generics: Generics) -> @ast::item { + fn item_struct_poly( + &self, + name: ident, + span: span, + +struct_def: ast::struct_def, + +generics: Generics + ) -> @ast::item { self.item(name, span, ast::item_struct(@struct_def, generics)) } fn struct_expr(&self, path: @ast::path, - fields: ~[ast::field]) -> @ast::expr { + +fields: ~[ast::field]) -> @ast::expr { @ast::expr { id: self.next_id(), callee_id: self.next_id(), @@ -381,7 +418,10 @@ impl ext_ctxt_ast_builder for ext_ctxt { let new_params = do generics.ty_params.map |ty_param| { ast::TyParam { bounds: no_bounds, ..copy *ty_param } }; - Generics { ty_params: new_params, ..*generics } + Generics { + ty_params: new_params, + .. copy *generics + } } fn item_ty_poly(&self, name: ident, span: span, ty: @ast::Ty, diff --git a/src/libsyntax/ext/pipes/liveness.rs b/src/libsyntax/ext/pipes/liveness.rs index a7f01d75648..c5bed32a24f 100644 --- a/src/libsyntax/ext/pipes/liveness.rs +++ b/src/libsyntax/ext/pipes/liveness.rs @@ -88,7 +88,7 @@ pub fn analyze(proto: protocol, _cx: ext_ctxt) { } if self_live.len() > 0 { - let states = str::connect(self_live.map(|s| s.name), ~" "); + let states = str::connect(self_live.map(|s| copy s.name), ~" "); debug!("protocol %s is unbounded due to loops involving: %s", proto.name, states); diff --git a/src/libsyntax/ext/pipes/mod.rs b/src/libsyntax/ext/pipes/mod.rs index 8b8e48bd522..c26bfd178b0 100644 --- a/src/libsyntax/ext/pipes/mod.rs +++ b/src/libsyntax/ext/pipes/mod.rs @@ -65,11 +65,11 @@ pub mod liveness; pub fn expand_proto(cx: ext_ctxt, _sp: span, id: ast::ident, - tt: ~[ast::token_tree]) -> base::MacResult { + tt: ~[ast::token_tree]) -> base::MacResult { let sess = cx.parse_sess(); let cfg = cx.cfg(); let tt_rdr = new_tt_reader(copy cx.parse_sess().span_diagnostic, - cx.parse_sess().interner, None, tt); + cx.parse_sess().interner, None, copy tt); let rdr = tt_rdr as reader; let rust_parser = Parser(sess, cfg, rdr.dup()); diff --git a/src/libsyntax/ext/pipes/parse_proto.rs b/src/libsyntax/ext/pipes/parse_proto.rs index a6b820cf3f9..a5ca24c6737 100644 --- a/src/libsyntax/ext/pipes/parse_proto.rs +++ b/src/libsyntax/ext/pipes/parse_proto.rs @@ -20,31 +20,35 @@ use parse::token; use core::prelude::*; pub trait proto_parser { - fn parse_proto(&self, id: ~str) -> protocol; + fn parse_proto(&self, +id: ~str) -> protocol; fn parse_state(&self, proto: protocol); fn parse_message(&self, state: state); } impl proto_parser for parser::Parser { - fn parse_proto(&self, id: ~str) -> protocol { + fn parse_proto(&self, +id: ~str) -> protocol { let proto = protocol(id, *self.span); - self.parse_seq_to_before_end(token::EOF, SeqSep { - sep: None, - trailing_sep_allowed: false - }, |self| self.parse_state(proto)); + self.parse_seq_to_before_end( + &token::EOF, + SeqSep { + sep: None, + trailing_sep_allowed: false, + }, + |self| self.parse_state(proto) + ); return proto; } fn parse_state(&self, proto: protocol) { let id = self.parse_ident(); - let name = *self.interner.get(id); + let name = copy *self.interner.get(id); - self.expect(token::COLON); - let dir = match *self.token { - token::IDENT(n, _) => self.interner.get(n), - _ => fail!() + self.expect(&token::COLON); + let dir = match copy *self.token { + token::IDENT(n, _) => self.interner.get(n), + _ => fail!() }; self.bump(); let dir = match dir { @@ -63,35 +67,47 @@ impl proto_parser for parser::Parser { // parse the messages self.parse_unspanned_seq( - token::LBRACE, token::RBRACE, SeqSep { + &token::LBRACE, + &token::RBRACE, + SeqSep { sep: Some(token::COMMA), - trailing_sep_allowed: true - }, |self| self.parse_message(state)); + trailing_sep_allowed: true, + }, + |self| self.parse_message(state) + ); } fn parse_message(&self, state: state) { - let mname = *self.interner.get(self.parse_ident()); + let mname = copy *self.interner.get(self.parse_ident()); let args = if *self.token == token::LPAREN { - self.parse_unspanned_seq(token::LPAREN, - token::RPAREN, SeqSep { - sep: Some(token::COMMA), - trailing_sep_allowed: true - }, |p| p.parse_ty(false)) + self.parse_unspanned_seq( + &token::LPAREN, + &token::RPAREN, + SeqSep { + sep: Some(token::COMMA), + trailing_sep_allowed: true, + }, + |p| p.parse_ty(false) + ) } else { ~[] }; - self.expect(token::RARROW); + self.expect(&token::RARROW); let next = match *self.token { token::IDENT(_, _) => { - let name = *self.interner.get(self.parse_ident()); + let name = copy *self.interner.get(self.parse_ident()); let ntys = if *self.token == token::LT { - self.parse_unspanned_seq(token::LT, - token::GT, SeqSep { - sep: Some(token::COMMA), - trailing_sep_allowed: true - }, |p| p.parse_ty(false)) + self.parse_unspanned_seq( + &token::LT, + &token::GT, + SeqSep { + sep: Some(token::COMMA), + trailing_sep_allowed: true, + }, + |p| p.parse_ty(false) + ) } else { ~[] }; Some(next_state {state: name, tys: ntys}) diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 46f10cd52bb..968a0e5f77e 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -60,8 +60,7 @@ impl gen_send for message { let next = this.proto.get_state(next_state.state); assert next_state.tys.len() == next.generics.ty_params.len(); let arg_names = tys.mapi(|i, _ty| cx.ident_of(~"x_"+i.to_str())); - - let args_ast = (arg_names, *tys).map(|n, t| cx.arg(*n, *t)); + let args_ast = vec::map2(arg_names, *tys, |n, t| cx.arg(*n, *t)); let pipe_ty = cx.ty_path_ast_builder( path(~[this.data_name()], span) @@ -121,7 +120,7 @@ impl gen_send for message { let mut rty = cx.ty_path_ast_builder(path(~[next.data_name()], span) - .add_tys(next_state.tys)); + .add_tys(copy next_state.tys)); if try { rty = cx.ty_option(rty); } @@ -139,7 +138,7 @@ impl gen_send for message { debug!("pipec: no next state"); let arg_names = tys.mapi(|i, _ty| (~"x_" + i.to_str())); - let args_ast = do (arg_names, *tys).map |n, t| { + let args_ast = do vec::map2(arg_names, *tys) |n, t| { cx.arg(cx.ident_of(*n), *t) }; @@ -155,7 +154,7 @@ impl gen_send for message { ~"" } else { - ~"(" + str::connect(arg_names.map(|x| *x), + ~"(" + str::connect(arg_names.map(|x| copy *x), ~", ") + ~")" }; @@ -212,7 +211,7 @@ impl to_type_decls for state { let mut items_msg = ~[]; for self.messages.each |m| { - let message(name, span, tys, this, next) = *m; + let message(name, span, tys, this, next) = copy *m; let tys = match next { Some(ref next_state) => { @@ -228,7 +227,7 @@ impl to_type_decls for state { cx.ty_path_ast_builder( path(~[cx.ident_of(dir), cx.ident_of(next_name)], span) - .add_tys(next_state.tys))) + .add_tys(copy next_state.tys))) } None => tys }; diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 6873baf731f..db5c6541e26 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -50,7 +50,7 @@ pub struct message(~str, span, ~[@ast::Ty], state, Option<next_state>); pub impl message { fn name(&mut self) -> ~str { match *self { - message(ref id, _, _, _, _) => (*id) + message(ref id, _, _, _, _) => copy *id } } @@ -63,7 +63,7 @@ pub impl message { /// Return the type parameters actually used by this message fn get_generics(&self) -> ast::Generics { match *self { - message(_, _, _, this, _) => this.generics + message(_, _, _, this, _) => copy this.generics } } } @@ -82,8 +82,8 @@ pub struct state_ { } pub impl state_ { - fn add_message(@self, name: ~str, span: span, - +data: ~[@ast::Ty], next: Option<next_state>) { + fn add_message(@self, +name: ~str, span: span, + +data: ~[@ast::Ty], +next: Option<next_state>) { self.messages.push(message(name, span, data, self, next)); } @@ -120,11 +120,11 @@ pub impl state_ { pub type protocol = @mut protocol_; -pub fn protocol(name: ~str, +span: span) -> protocol { +pub fn protocol(+name: ~str, +span: span) -> protocol { @mut protocol_(name, span) } -pub fn protocol_(name: ~str, span: span) -> protocol_ { +pub fn protocol_(+name: ~str, span: span) -> protocol_ { protocol_ { name: name, span: span, @@ -174,7 +174,7 @@ pub impl protocol_ { } pub impl protocol { - fn add_state_poly(&self, name: ~str, ident: ast::ident, dir: direction, + fn add_state_poly(&self, +name: ~str, ident: ast::ident, dir: direction, +generics: ast::Generics) -> state { let messages = @mut ~[]; diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 757302c78fc..4349ffaea43 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -221,19 +221,19 @@ pub mod rt { pub fn expand_quote_tokens(cx: ext_ctxt, sp: span, - tts: ~[ast::token_tree]) -> base::MacResult { + tts: &[ast::token_tree]) -> base::MacResult { base::MRExpr(expand_tts(cx, sp, tts)) } pub fn expand_quote_expr(cx: ext_ctxt, sp: span, - tts: ~[ast::token_tree]) -> base::MacResult { + tts: &[ast::token_tree]) -> base::MacResult { base::MRExpr(expand_parse_call(cx, sp, ~"parse_expr", ~[], tts)) } pub fn expand_quote_item(cx: ext_ctxt, sp: span, - tts: ~[ast::token_tree]) -> base::MacResult { + tts: &[ast::token_tree]) -> base::MacResult { let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]); base::MRExpr(expand_parse_call(cx, sp, ~"parse_item", ~[e_attrs], tts)) @@ -241,7 +241,7 @@ pub fn expand_quote_item(cx: ext_ctxt, pub fn expand_quote_pat(cx: ext_ctxt, sp: span, - tts: ~[ast::token_tree]) -> base::MacResult { + tts: &[ast::token_tree]) -> base::MacResult { let e_refutable = build::mk_lit(cx, sp, ast::lit_bool(true)); base::MRExpr(expand_parse_call(cx, sp, ~"parse_pat", ~[e_refutable], tts)) @@ -249,7 +249,7 @@ pub fn expand_quote_pat(cx: ext_ctxt, pub fn expand_quote_ty(cx: ext_ctxt, sp: span, - tts: ~[ast::token_tree]) -> base::MacResult { + tts: &[ast::token_tree]) -> base::MacResult { let e_param_colons = build::mk_lit(cx, sp, ast::lit_bool(false)); base::MRExpr(expand_parse_call(cx, sp, ~"parse_ty", ~[e_param_colons], tts)) @@ -257,17 +257,17 @@ pub fn expand_quote_ty(cx: ext_ctxt, pub fn expand_quote_stmt(cx: ext_ctxt, sp: span, - tts: ~[ast::token_tree]) -> base::MacResult { + tts: &[ast::token_tree]) -> base::MacResult { let e_attrs = build::mk_uniq_vec_e(cx, sp, ~[]); base::MRExpr(expand_parse_call(cx, sp, ~"parse_stmt", ~[e_attrs], tts)) } fn ids_ext(cx: ext_ctxt, strs: ~[~str]) -> ~[ast::ident] { - strs.map(|str| cx.parse_sess().interner.intern(@*str)) + strs.map(|str| cx.parse_sess().interner.intern(@copy *str)) } -fn id_ext(cx: ext_ctxt, str: ~str) -> ast::ident { +fn id_ext(cx: ext_ctxt, +str: ~str) -> ast::ident { cx.parse_sess().interner.intern(@str) } @@ -508,7 +508,7 @@ fn mk_tts(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) fn expand_tts(cx: ext_ctxt, sp: span, - tts: ~[ast::token_tree]) -> @ast::expr { + tts: &[ast::token_tree]) -> @ast::expr { // NB: It appears that the main parser loses its mind if we consider // $foo as a tt_nonterminal during the main parse, so we have to re-parse @@ -516,7 +516,11 @@ fn expand_tts(cx: ext_ctxt, // it has to do with transition away from supporting old-style macros, so // try removing it when enough of them are gone. - let p = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), tts); + let p = parse::new_parser_from_tts( + cx.parse_sess(), + cx.cfg(), + vec::from_slice(tts) + ); *p.quote_depth += 1u; let tts = p.parse_all_token_trees(); p.abort_if_errors(); @@ -578,9 +582,9 @@ fn expand_tts(cx: ext_ctxt, fn expand_parse_call(cx: ext_ctxt, sp: span, - parse_method: ~str, - arg_exprs: ~[@ast::expr], - tts: ~[ast::token_tree]) -> @ast::expr { + +parse_method: ~str, + +arg_exprs: ~[@ast::expr], + tts: &[ast::token_tree]) -> @ast::expr { let tts_expr = expand_tts(cx, sp, tts); let cfg_call = || build::mk_call_( diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 5b870f07b60..296305bb62e 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -29,7 +29,7 @@ use core::vec; // a given file into the current one. /* line!(): expands to the current line number */ -pub fn expand_line(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) +pub fn expand_line(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "line!"); @@ -40,7 +40,7 @@ pub fn expand_line(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) } /* col!(): expands to the current column number */ -pub fn expand_col(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) +pub fn expand_col(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "col!"); @@ -52,7 +52,7 @@ pub fn expand_col(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) /* file!(): expands to the current filename */ /* The filemap (`loc.file`) contains a bunch more information we could spit * out if we wanted. */ -pub fn expand_file(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) +pub fn expand_file(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "file!"); @@ -62,13 +62,13 @@ pub fn expand_file(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) base::MRExpr(mk_base_str(cx, topmost.call_site, filename)) } -pub fn expand_stringify(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) +pub fn expand_stringify(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let s = pprust::tts_to_str(tts, cx.parse_sess().interner); base::MRExpr(mk_base_str(cx, sp, s)) } -pub fn expand_mod(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) +pub fn expand_mod(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { base::check_zero_tts(cx, sp, tts, "module_path!"); base::MRExpr(mk_base_str(cx, sp, @@ -79,7 +79,7 @@ pub fn expand_mod(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) // include! : parse the given file as an expr // This is generally a bad idea because it's going to behave // unhygienically. -pub fn expand_include(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) +pub fn expand_include(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include!"); let p = parse::new_sub_parser_from_file( @@ -89,7 +89,7 @@ pub fn expand_include(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) } // include_str! : read the given file, insert it as a literal string expr -pub fn expand_include_str(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) +pub fn expand_include_str(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include_str!"); let res = io::read_whole_file_str(&res_rel_file(cx, sp, &Path(file))); @@ -103,7 +103,7 @@ pub fn expand_include_str(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) base::MRExpr(mk_base_str(cx, sp, result::unwrap(res))) } -pub fn expand_include_bin(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) +pub fn expand_include_bin(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include_bin!"); match io::read_whole_file(&res_rel_file(cx, sp, &Path(file))) { @@ -121,19 +121,27 @@ pub fn expand_include_bin(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree]) // recur along an ExpnInfo chain to find the original expression fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo { - let ExpandedFrom(CallInfo { call_site, _ }) = *expn_info; - match call_site.expn_info { - Some(next_expn_info) => { - let ExpandedFrom(CallInfo { - callee: NameAndSpan {name, _}, - _ - }) = *next_expn_info; - // Don't recurse into file using "include!" - if name == ~"include" { return expn_info; } - - topmost_expn_info(next_expn_info) - }, - None => expn_info + match *expn_info { + ExpandedFrom(CallInfo { call_site: ref call_site, _ }) => { + match call_site.expn_info { + Some(next_expn_info) => { + match *next_expn_info { + ExpandedFrom(CallInfo { + callee: NameAndSpan { name: ref name, _ }, + _ + }) => { + // Don't recurse into file using "include!" + if *name == ~"include" { + expn_info + } else { + topmost_expn_info(next_expn_info) + } + } + } + }, + None => expn_info + } + } } } diff --git a/src/libsyntax/ext/trace_macros.rs b/src/libsyntax/ext/trace_macros.rs index f662f0337bf..bb6d656d5cc 100644 --- a/src/libsyntax/ext/trace_macros.rs +++ b/src/libsyntax/ext/trace_macros.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use prelude::*; + use ast::tt_delim; use ast; use codemap::span; @@ -16,20 +18,26 @@ use ext::base; use parse::lexer::{new_tt_reader, reader}; use parse::parser::Parser; -use core::option::None; - pub fn expand_trace_macros(cx: ext_ctxt, sp: span, - tt: ~[ast::token_tree]) -> base::MacResult { + tt: &[ast::token_tree]) -> base::MacResult { let sess = cx.parse_sess(); let cfg = cx.cfg(); - let tt_rdr = new_tt_reader(copy cx.parse_sess().span_diagnostic, - cx.parse_sess().interner, None, tt); + let tt_rdr = new_tt_reader( + copy cx.parse_sess().span_diagnostic, + cx.parse_sess().interner, + None, + vec::from_slice(tt) + ); let rdr = tt_rdr as reader; - let rust_parser = Parser(sess, cfg, rdr.dup()); + let rust_parser = Parser( + sess, + copy cfg, + rdr.dup() + ); - if rust_parser.is_keyword(~"true") { + if rust_parser.is_keyword(&~"true") { cx.set_trace_macros(true); - } else if rust_parser.is_keyword(~"false") { + } else if rust_parser.is_keyword(&~"false") { cx.set_trace_macros(false); } else { cx.span_fatal(sp, ~"trace_macros! only accepts `true` or `false`") diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 3fc580827e9..fae9e1651d3 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -140,10 +140,10 @@ pub fn count_names(ms: &[matcher]) -> uint { } #[allow(non_implicitly_copyable_typarams)] -pub fn initial_matcher_pos(ms: ~[matcher], sep: Option<Token>, lo: BytePos) +pub fn initial_matcher_pos(+ms: ~[matcher], sep: Option<Token>, lo: BytePos) -> ~MatcherPos { let mut match_idx_hi = 0u; - for ms.each() |elt| { + for ms.each |elt| { match elt.node { match_tok(_) => (), match_seq(_,_,_,_,hi) => { @@ -154,12 +154,13 @@ pub fn initial_matcher_pos(ms: ~[matcher], sep: Option<Token>, lo: BytePos) } } } + let matches = vec::from_fn(count_names(ms), |_i| dvec::DVec()); ~MatcherPos { elts: ms, sep: sep, idx: 0u, up: matcher_pos_up(None), - matches: copy vec::from_fn(count_names(ms), |_i| dvec::DVec()), + matches: matches, match_lo: 0u, match_hi: match_idx_hi, sp_lo: lo @@ -225,8 +226,12 @@ pub enum parse_result { error(codemap::span, ~str) } -pub fn parse_or_else(sess: @mut ParseSess, cfg: ast::crate_cfg, rdr: reader, - ms: ~[matcher]) -> HashMap<ident, @named_match> { +pub fn parse_or_else( + sess: @mut ParseSess, + +cfg: ast::crate_cfg, + rdr: reader, + ms: ~[matcher] +) -> HashMap<ident, @named_match> { match parse(sess, cfg, rdr, ms) { success(m) => m, failure(sp, ref str) => sess.span_diagnostic.span_fatal(sp, (*str)), @@ -234,13 +239,14 @@ pub fn parse_or_else(sess: @mut ParseSess, cfg: ast::crate_cfg, rdr: reader, } } -pub fn parse(sess: @mut ParseSess, - cfg: ast::crate_cfg, - rdr: reader, - ms: ~[matcher]) - -> parse_result { +pub fn parse( + sess: @mut ParseSess, + cfg: ast::crate_cfg, + rdr: reader, + ms: ~[matcher] +) -> parse_result { let mut cur_eis = ~[]; - cur_eis.push(initial_matcher_pos(ms, None, rdr.peek().sp.lo)); + cur_eis.push(initial_matcher_pos(copy ms, None, rdr.peek().sp.lo)); loop { let mut bb_eis = ~[]; // black-box parsed by parser.rs @@ -331,8 +337,8 @@ pub fn parse(sess: @mut ParseSess, |_m| DVec::<@named_match>()); let ei_t = ei; cur_eis.push(~MatcherPos { - elts: (*matchers), - sep: (*sep), + elts: copy *matchers, + sep: copy *sep, idx: 0u, up: matcher_pos_up(Some(ei_t)), matches: matches, @@ -380,7 +386,7 @@ pub fn parse(sess: @mut ParseSess, nts, next_eis.len())); } else if (bb_eis.len() == 0u && next_eis.len() == 0u) { return failure(sp, ~"No rules expected the token: " - + to_str(rdr.interner(), tok)); + + to_str(rdr.interner(), &tok)); } else if (next_eis.len() > 0u) { /* Now process the next token */ while(next_eis.len() > 0u) { @@ -388,7 +394,7 @@ pub fn parse(sess: @mut ParseSess, } rdr.next_token(); } else /* bb_eis.len() == 1 */ { - let rust_parser = Parser(sess, cfg, rdr.dup()); + let rust_parser = Parser(sess, copy cfg, rdr.dup()); let mut ei = bb_eis.pop(); match ei.elts[ei.idx].node { @@ -426,7 +432,7 @@ pub fn parse_nt(p: Parser, name: ~str) -> nonterminal { ~"ident" => match *p.token { token::IDENT(sn,b) => { p.bump(); token::nt_ident(sn,b) } _ => p.fatal(~"expected ident, found " - + token::to_str(p.reader.interner(), *p.token)) + + token::to_str(p.reader.interner(), © *p.token)) }, ~"path" => token::nt_path(p.parse_path_with_tps(false)), ~"tt" => { diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index f42bb01f7c2..5c20abc385d 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -54,7 +54,7 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, // Parse the macro_rules! invocation (`none` is for no interpolations): let arg_reader = new_tt_reader(copy cx.parse_sess().span_diagnostic, - cx.parse_sess().interner, None, arg); + cx.parse_sess().interner, None, copy arg); let argument_map = parse_or_else(cx.parse_sess(), cx.cfg(), arg_reader as reader, argument_gram); @@ -71,7 +71,7 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, // Given `lhses` and `rhses`, this is the new macro we create fn generic_extension(cx: ext_ctxt, sp: span, name: ident, - arg: ~[ast::token_tree], + arg: &[ast::token_tree], lhses: ~[@named_match], rhses: ~[@named_match]) -> MacResult { @@ -79,7 +79,7 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, io::println(fmt!("%s! { %s }", cx.str_of(name), print::pprust::tt_to_str( - ast::tt_delim(arg), + ast::tt_delim(vec::from_slice(arg)), cx.parse_sess().interner))); } @@ -94,7 +94,12 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, match *lhs { @matched_nonterminal(nt_matchers(ref mtcs)) => { // `none` is because we're not interpolating - let arg_rdr = new_tt_reader(s_d, itr, None, arg) as reader; + let arg_rdr = new_tt_reader( + s_d, + itr, + None, + vec::from_slice(arg) + ) as reader; match parse(cx.parse_sess(), cx.cfg(), arg_rdr, (*mtcs)) { success(named_matches) => { let rhs = match rhses[i] { @@ -125,7 +130,7 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, } failure(sp, ref msg) => if sp.lo >= best_fail_spot.lo { best_fail_spot = sp; - best_fail_msg = (*msg); + best_fail_msg = copy *msg; }, error(sp, ref msg) => cx.span_fatal(sp, (*msg)) } @@ -136,11 +141,11 @@ pub fn add_new_extension(cx: ext_ctxt, sp: span, name: ident, cx.span_fatal(best_fail_spot, best_fail_msg); } - let exp: @fn(ext_ctxt, span, ~[ast::token_tree]) -> MacResult = + let exp: @fn(ext_ctxt, span, &[ast::token_tree]) -> MacResult = |cx, sp, arg| generic_extension(cx, sp, name, arg, lhses, rhses); return MRDef(MacroDef{ - name: *cx.parse_sess().interner.get(name), + name: copy *cx.parse_sess().interner.get(name), ext: NormalTT(base::SyntaxExpanderTT{expander: exp, span: Some(sp)}) }); } diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index a9502ff2902..99afd7958e9 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -54,7 +54,7 @@ pub struct TtReader { pub fn new_tt_reader(sp_diag: span_handler, itr: @ident_interner, interp: Option<std::oldmap::HashMap<ident,@named_match>>, - src: ~[ast::token_tree]) + +src: ~[ast::token_tree]) -> @mut TtReader { let r = @mut TtReader { sp_diag: sp_diag, @@ -101,7 +101,7 @@ pub pure fn dup_tt_reader(r: @mut TtReader) -> @mut TtReader { interpolations: r.interpolations, repeat_idx: copy r.repeat_idx, repeat_len: copy r.repeat_len, - cur_tok: r.cur_tok, + cur_tok: copy r.cur_tok, cur_span: r.cur_span } } @@ -115,7 +115,7 @@ pure fn lookup_cur_matched_by_matched(r: @mut TtReader, // end of the line; duplicate henceforth ad } - matched_seq(ads, _) => ads[*idx] + matched_seq(ref ads, _) => ads[*idx] } } vec::foldl(start, r.repeat_idx, red) @@ -131,15 +131,15 @@ enum lis { fn lockstep_iter_size(t: token_tree, r: @mut TtReader) -> lis { fn lis_merge(lhs: lis, rhs: lis, r: @mut TtReader) -> lis { match lhs { - lis_unconstrained => rhs, - lis_contradiction(_) => lhs, + lis_unconstrained => copy rhs, + lis_contradiction(_) => copy lhs, lis_constraint(l_len, l_id) => match rhs { - lis_unconstrained => lhs, - lis_contradiction(_) => rhs, - lis_constraint(r_len, _) if l_len == r_len => lhs, + lis_unconstrained => copy lhs, + lis_contradiction(_) => copy rhs, + lis_constraint(r_len, _) if l_len == r_len => copy lhs, lis_constraint(r_len, r_id) => { - let l_n = *r.interner.get(l_id); - let r_n = *r.interner.get(r_id); + let l_n = copy *r.interner.get(l_id); + let r_n = copy *r.interner.get(r_id); lis_contradiction(fmt!("Inconsistent lockstep iteration: \ '%s' has %u items, but '%s' has %u", l_n, l_len, r_n, r_len)) @@ -155,14 +155,17 @@ fn lockstep_iter_size(t: token_tree, r: @mut TtReader) -> lis { tt_tok(*) => lis_unconstrained, tt_nonterminal(_, name) => match *lookup_cur_matched(r, name) { matched_nonterminal(_) => lis_unconstrained, - matched_seq(ads, _) => lis_constraint(ads.len(), name) + matched_seq(ref ads, _) => lis_constraint(ads.len(), name) } } } pub fn tt_next_token(r: @mut TtReader) -> TokenAndSpan { - let ret_val = TokenAndSpan { tok: r.cur_tok, sp: r.cur_span }; + let ret_val = TokenAndSpan { + tok: copy r.cur_tok, + sp: r.cur_span, + }; while r.cur.idx >= r.cur.readme.len() { /* done with this set; pop or repeat? */ if ! r.cur.dotdotdoted @@ -199,9 +202,9 @@ pub fn tt_next_token(r: @mut TtReader) -> TokenAndSpan { loop { /* because it's easiest, this handles `tt_delim` not starting with a `tt_tok`, even though it won't happen */ match r.cur.readme[r.cur.idx] { - tt_delim(tts) => { + tt_delim(copy tts) => { r.cur = @mut TtFrame { - readme: @mut copy tts, + readme: @mut tts, idx: 0u, dotdotdoted: false, sep: None, @@ -210,12 +213,13 @@ pub fn tt_next_token(r: @mut TtReader) -> TokenAndSpan { // if this could be 0-length, we'd need to potentially recur here } tt_tok(sp, copy tok) => { - r.cur_span = sp; r.cur_tok = tok; + r.cur_span = sp; + r.cur_tok = tok; r.cur.idx += 1u; return ret_val; } tt_seq(sp, copy tts, copy sep, zerok) => { - match lockstep_iter_size(tt_seq(sp, tts, sep, zerok), r) { + match lockstep_iter_size(tt_seq(sp, copy tts, sep, zerok), r) { lis_unconstrained => { r.sp_diag.span_fatal( sp, /* blame macro writer */ @@ -264,7 +268,8 @@ pub fn tt_next_token(r: @mut TtReader) -> TokenAndSpan { return ret_val; } matched_nonterminal(ref other_whole_nt) => { - r.cur_span = sp; r.cur_tok = INTERPOLATED((*other_whole_nt)); + r.cur_span = sp; + r.cur_tok = INTERPOLATED(copy *other_whole_nt); r.cur.idx += 1u; return ret_val; } |
