From 7cf4d8bc446177204e9e12b1efb199a5dbc956b5 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Thu, 27 Mar 2014 15:14:58 +0200 Subject: Used inherited mutability in lexer::Reader. --- src/libsyntax/ext/tt/macro_parser.rs | 22 +-- src/libsyntax/ext/tt/transcribe.rs | 314 ++++++++++++++++------------------- 2 files changed, 152 insertions(+), 184 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index aa4f192f779..d730f50c7bc 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -204,11 +204,11 @@ pub enum ParseResult { Error(codemap::Span, ~str) } -pub fn parse_or_else(sess: &ParseSess, - cfg: ast::CrateConfig, - rdr: R, - ms: Vec ) - -> HashMap { +pub fn parse_or_else(sess: &ParseSess, + cfg: ast::CrateConfig, + rdr: TtReader, + ms: Vec ) + -> HashMap { match parse(sess, cfg, rdr, ms.as_slice()) { Success(m) => m, Failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str), @@ -226,11 +226,11 @@ pub fn token_name_eq(t1 : &Token, t2 : &Token) -> bool { } } -pub fn parse(sess: &ParseSess, - cfg: ast::CrateConfig, - rdr: R, - ms: &[Matcher]) - -> ParseResult { +pub fn parse(sess: &ParseSess, + cfg: ast::CrateConfig, + mut rdr: TtReader, + ms: &[Matcher]) + -> ParseResult { let mut cur_eis = Vec::new(); cur_eis.push(initial_matcher_pos(ms.iter() .map(|x| (*x).clone()) @@ -395,7 +395,7 @@ pub fn parse(sess: &ParseSess, } rdr.next_token(); } else /* bb_eis.len() == 1 */ { - let mut rust_parser = Parser(sess, cfg.clone(), rdr.dup()); + let mut rust_parser = Parser(sess, cfg.clone(), ~rdr.clone()); let mut ei = bb_eis.pop().unwrap(); match ei.elts.get(ei.idx).node { diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 933fbe3d566..1a32332bee6 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -17,29 +17,29 @@ use parse::token::{EOF, INTERPOLATED, IDENT, Token, NtIdent}; use parse::token; use parse::lexer::TokenAndSpan; -use std::cell::{Cell, RefCell}; use collections::HashMap; ///an unzipping of `TokenTree`s +#[deriving(Clone)] struct TtFrame { - forest: @Vec , - idx: Cell, + forest: @Vec, + idx: uint, dotdotdoted: bool, sep: Option, - up: Option<@TtFrame>, } +#[deriving(Clone)] pub struct TtReader<'a> { sp_diag: &'a SpanHandler, // the unzipped tree: - priv stack: RefCell<@TtFrame>, + priv stack: Vec, /* for MBE-style macro transcription */ - priv interpolations: RefCell>, - priv repeat_idx: RefCell >, - priv repeat_len: RefCell >, + priv interpolations: HashMap, + priv repeat_idx: Vec, + priv repeat_len: Vec, /* cached: */ - cur_tok: RefCell, - cur_span: RefCell, + cur_tok: Token, + cur_span: Span, } /** This can do Macro-By-Example transcription. On the other hand, if @@ -49,58 +49,30 @@ pub fn new_tt_reader<'a>(sp_diag: &'a SpanHandler, interp: Option>, src: Vec ) -> TtReader<'a> { - let r = TtReader { + let mut r = TtReader { sp_diag: sp_diag, - stack: RefCell::new(@TtFrame { + stack: vec!(TtFrame { forest: @src, - idx: Cell::new(0u), + idx: 0, dotdotdoted: false, sep: None, - up: None }), interpolations: match interp { /* just a convienience */ - None => RefCell::new(HashMap::new()), - Some(x) => RefCell::new(x), + None => HashMap::new(), + Some(x) => x, }, - repeat_idx: RefCell::new(Vec::new()), - repeat_len: RefCell::new(Vec::new()), + repeat_idx: Vec::new(), + repeat_len: Vec::new(), /* dummy values, never read: */ - cur_tok: RefCell::new(EOF), - cur_span: RefCell::new(DUMMY_SP), + cur_tok: EOF, + cur_span: DUMMY_SP, }; - tt_next_token(&r); /* get cur_tok and cur_span set up */ + tt_next_token(&mut r); /* get cur_tok and cur_span set up */ r } -fn dup_tt_frame(f: @TtFrame) -> @TtFrame { - @TtFrame { - forest: @(*f.forest).clone(), - idx: f.idx.clone(), - dotdotdoted: f.dotdotdoted, - sep: f.sep.clone(), - up: match f.up { - Some(up_frame) => Some(dup_tt_frame(up_frame)), - None => None - } - } -} - -pub fn dup_tt_reader<'a>(r: &TtReader<'a>) -> TtReader<'a> { - TtReader { - sp_diag: r.sp_diag, - stack: RefCell::new(dup_tt_frame(r.stack.get())), - repeat_idx: r.repeat_idx.clone(), - repeat_len: r.repeat_len.clone(), - cur_tok: r.cur_tok.clone(), - cur_span: r.cur_span.clone(), - interpolations: r.interpolations.clone(), - } -} - - -fn lookup_cur_matched_by_matched(r: &TtReader, start: @NamedMatch) - -> @NamedMatch { - fn red(ad: @NamedMatch, idx: &uint) -> @NamedMatch { +fn lookup_cur_matched_by_matched(r: &TtReader, start: @NamedMatch) -> @NamedMatch { + r.repeat_idx.iter().fold(start, |ad, idx| { match *ad { MatchedNonterminal(_) => { // end of the line; duplicate henceforth @@ -108,16 +80,15 @@ fn lookup_cur_matched_by_matched(r: &TtReader, start: @NamedMatch) } MatchedSeq(ref ads, _) => *ads.get(*idx) } - } - r.repeat_idx.borrow().iter().fold(start, red) + }) } fn lookup_cur_matched(r: &TtReader, name: Ident) -> @NamedMatch { - let matched_opt = r.interpolations.borrow().find_copy(&name); + let matched_opt = r.interpolations.find_copy(&name); match matched_opt { Some(s) => lookup_cur_matched_by_matched(r, s), None => { - r.sp_diag.span_fatal(r.cur_span.get(), + r.sp_diag.span_fatal(r.cur_span, format!("unknown macro variable `{}`", token::get_ident(name))); } @@ -167,143 +138,140 @@ fn lockstep_iter_size(t: &TokenTree, r: &TtReader) -> LockstepIterSize { // return the next token from the TtReader. // EFFECT: advances the reader's token field -pub fn tt_next_token(r: &TtReader) -> TokenAndSpan { +pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { // FIXME(pcwalton): Bad copy? let ret_val = TokenAndSpan { - tok: r.cur_tok.get(), - sp: r.cur_span.get(), + tok: r.cur_tok.clone(), + sp: r.cur_span.clone(), }; loop { - if r.stack.borrow().idx.get() < r.stack.borrow().forest.len() { - break; - } - - /* done with this set; pop or repeat? */ - if !r.stack.get().dotdotdoted || { - *r.repeat_idx.borrow().last().unwrap() == - *r.repeat_len.borrow().last().unwrap() - 1 - } { - - match r.stack.get().up { - None => { - r.cur_tok.set(EOF); + let should_pop = match r.stack.last() { + None => { + assert_eq!(ret_val.tok, EOF); return ret_val; - } - Some(tt_f) => { - if r.stack.get().dotdotdoted { - r.repeat_idx.borrow_mut().pop().unwrap(); - r.repeat_len.borrow_mut().pop().unwrap(); + } + Some(frame) => { + if frame.idx < frame.forest.len() { + break; } - - r.stack.set(tt_f); - r.stack.get().idx.set(r.stack.get().idx.get() + 1u); - } + !frame.dotdotdoted || + *r.repeat_idx.last().unwrap() == *r.repeat_len.last().unwrap() - 1 } + }; - } else { /* repeat */ - r.stack.get().idx.set(0u); - { - let mut repeat_idx = r.repeat_idx.borrow_mut(); - let last_repeat_idx = repeat_idx.len() - 1u; - *repeat_idx.get_mut(last_repeat_idx) += 1u; + /* done with this set; pop or repeat? */ + if should_pop { + let prev = r.stack.pop().unwrap(); + match r.stack.mut_last() { + None => { + r.cur_tok = EOF; + return ret_val; + } + Some(frame) => { + frame.idx += 1; + } } - match r.stack.get().sep.clone() { - Some(tk) => { - r.cur_tok.set(tk); /* repeat same span, I guess */ - return ret_val; - } - None => () + if prev.dotdotdoted { + r.repeat_idx.pop(); + r.repeat_len.pop(); + } + } else { /* repeat */ + *r.repeat_idx.mut_last().unwrap() += 1u; + r.stack.mut_last().unwrap().idx = 0; + match r.stack.last().unwrap().sep.clone() { + Some(tk) => { + r.cur_tok = tk; /* repeat same span, I guess */ + return ret_val; + } + None => {} } } } loop { /* because it's easiest, this handles `TTDelim` not starting - with a `TTTok`, even though it won't happen */ - // FIXME(pcwalton): Bad copy. - match (*r.stack.get().forest.get(r.stack.get().idx.get())).clone() { - TTDelim(tts) => { - r.stack.set(@TtFrame { - forest: tts, - idx: Cell::new(0u), - dotdotdoted: false, - sep: None, - up: Some(r.stack.get()) - }); - // if this could be 0-length, we'd need to potentially recur here - } - TTTok(sp, tok) => { - r.cur_span.set(sp); - r.cur_tok.set(tok); - r.stack.get().idx.set(r.stack.get().idx.get() + 1u); - return ret_val; - } - TTSeq(sp, tts, sep, zerok) => { + with a `TTTok`, even though it won't happen */ + let t = { + let frame = r.stack.last().unwrap(); // FIXME(pcwalton): Bad copy. - let t = TTSeq(sp, tts, sep.clone(), zerok); - match lockstep_iter_size(&t, r) { - LisUnconstrained => { - r.sp_diag.span_fatal( - sp, /* blame macro writer */ - "attempted to repeat an expression \ - containing no syntax \ - variables matched as repeating at this depth"); - } - LisContradiction(ref msg) => { - /* FIXME #2887 blame macro invoker instead*/ - r.sp_diag.span_fatal(sp, (*msg)); - } - LisConstraint(len, _) => { - if len == 0 { - if !zerok { - r.sp_diag.span_fatal(sp, /* FIXME #2887 blame invoker - */ - "this must repeat at least \ - once"); - } - - r.stack.get().idx.set(r.stack.get().idx.get() + 1u); - return tt_next_token(r); - } else { - r.repeat_len.borrow_mut().push(len); - r.repeat_idx.borrow_mut().push(0u); - r.stack.set(@TtFrame { - forest: tts, - idx: Cell::new(0u), - dotdotdoted: true, - sep: sep, - up: Some(r.stack.get()) - }); - } - } + (*frame.forest.get(frame.idx)).clone() + }; + match t { + TTDelim(tts) => { + r.stack.push(TtFrame { + forest: tts, + idx: 0, + dotdotdoted: false, + sep: None + }); + // if this could be 0-length, we'd need to potentially recur here } - } - // FIXME #2887: think about span stuff here - TTNonterminal(sp, ident) => { - match *lookup_cur_matched(r, ident) { - /* sidestep the interpolation tricks for ident because - (a) idents can be in lots of places, so it'd be a pain - (b) we actually can, since it's a token. */ - MatchedNonterminal(NtIdent(~sn,b)) => { - r.cur_span.set(sp); - r.cur_tok.set(IDENT(sn,b)); - r.stack.get().idx.set(r.stack.get().idx.get() + 1u); + TTTok(sp, tok) => { + r.cur_span = sp; + r.cur_tok = tok; + r.stack.mut_last().unwrap().idx += 1; return ret_val; - } - MatchedNonterminal(ref other_whole_nt) => { + } + TTSeq(sp, tts, sep, zerok) => { // FIXME(pcwalton): Bad copy. - r.cur_span.set(sp); - r.cur_tok.set(INTERPOLATED((*other_whole_nt).clone())); - r.stack.get().idx.set(r.stack.get().idx.get() + 1u); - return ret_val; - } - MatchedSeq(..) => { - r.sp_diag.span_fatal( - r.cur_span.get(), /* blame the macro writer */ - format!("variable '{}' is still repeating at this depth", - token::get_ident(ident))); - } + match lockstep_iter_size(&TTSeq(sp, tts, sep.clone(), zerok), r) { + LisUnconstrained => { + r.sp_diag.span_fatal( + sp.clone(), /* blame macro writer */ + "attempted to repeat an expression \ + containing no syntax \ + variables matched as repeating at this depth"); + } + LisContradiction(ref msg) => { + // FIXME #2887 blame macro invoker instead + r.sp_diag.span_fatal(sp.clone(), *msg); + } + LisConstraint(len, _) => { + if len == 0 { + if !zerok { + // FIXME #2887 blame invoker + r.sp_diag.span_fatal(sp.clone(), + "this must repeat at least once"); + } + + r.stack.mut_last().unwrap().idx += 1; + return tt_next_token(r); + } + r.repeat_len.push(len); + r.repeat_idx.push(0); + r.stack.push(TtFrame { + forest: tts, + idx: 0, + dotdotdoted: true, + sep: sep.clone() + }); + } + } + } + // FIXME #2887: think about span stuff here + TTNonterminal(sp, ident) => { + r.stack.mut_last().unwrap().idx += 1; + match *lookup_cur_matched(r, ident) { + /* sidestep the interpolation tricks for ident because + (a) idents can be in lots of places, so it'd be a pain + (b) we actually can, since it's a token. */ + MatchedNonterminal(NtIdent(~sn,b)) => { + r.cur_span = sp; + r.cur_tok = IDENT(sn,b); + return ret_val; + } + MatchedNonterminal(ref other_whole_nt) => { + // FIXME(pcwalton): Bad copy. + r.cur_span = sp; + r.cur_tok = INTERPOLATED((*other_whole_nt).clone()); + return ret_val; + } + MatchedSeq(..) => { + r.sp_diag.span_fatal( + r.cur_span, /* blame the macro writer */ + format!("variable '{}' is still repeating at this depth", + token::get_ident(ident))); + } + } } - } } } - } -- cgit 1.4.1-3-g733a5 From 8f226e56946d20acfdf8c0c48c57fd7ba3571157 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Thu, 27 Mar 2014 16:40:35 +0200 Subject: De-@ TokenTree. --- src/libsyntax/ast.rs | 6 ++++-- src/libsyntax/ext/log_syntax.rs | 4 +++- src/libsyntax/ext/tt/macro_rules.rs | 7 ++++--- src/libsyntax/ext/tt/transcribe.rs | 7 ++++--- src/libsyntax/fold.rs | 8 +++++--- src/libsyntax/parse/mod.rs | 6 +++--- src/libsyntax/parse/parser.rs | 5 +++-- 7 files changed, 26 insertions(+), 17 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a44fbce421b..7c3eb7742d2 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -581,14 +581,16 @@ pub enum TokenTree { TTTok(Span, ::parse::token::Token), // a delimited sequence (the delimiters appear as the first // and last elements of the vector) - TTDelim(@Vec ), + // FIXME(eddyb) #6308 Use Rc<[TokenTree]> after DST. + TTDelim(Rc>), // These only make sense for right-hand-sides of MBE macros: // a kleene-style repetition sequence with a span, a TTForest, // an optional separator, and a boolean where true indicates // zero or more (..), and false indicates one or more (+). - TTSeq(Span, @Vec , Option<::parse::token::Token>, bool), + // FIXME(eddyb) #6308 Use Rc<[TokenTree]> after DST. + TTSeq(Span, Rc>, Option<::parse::token::Token>, bool), // a syntactic variable that will be filled in by macro expansion. TTNonterminal(Span, Ident) diff --git a/src/libsyntax/ext/log_syntax.rs b/src/libsyntax/ext/log_syntax.rs index 1ce08b8303e..c9e444a9b8c 100644 --- a/src/libsyntax/ext/log_syntax.rs +++ b/src/libsyntax/ext/log_syntax.rs @@ -13,6 +13,8 @@ use codemap; use ext::base; use print; +use std::rc::Rc; + pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, sp: codemap::Span, tt: &[ast::TokenTree]) @@ -20,7 +22,7 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, cx.print_backtrace(); println!("{}", print::pprust::tt_to_str(&ast::TTDelim( - @tt.iter().map(|x| (*x).clone()).collect()))); + Rc::new(tt.iter().map(|x| (*x).clone()).collect())))); // any so that `log_syntax` can be invoked as an expression and item. base::MacResult::dummy_any(sp) diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index b3e3023388b..e4e3f51b993 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -28,6 +28,7 @@ use print; use util::small_vector::SmallVector; use std::cell::RefCell; +use std::rc::Rc; struct ParserAnyMacro<'a> { parser: RefCell>, @@ -115,9 +116,9 @@ fn generic_extension(cx: &ExtCtxt, if cx.trace_macros() { println!("{}! \\{ {} \\}", token::get_ident(name), - print::pprust::tt_to_str(&TTDelim(@arg.iter() - .map(|x| (*x).clone()) - .collect()))); + print::pprust::tt_to_str(&TTDelim(Rc::new(arg.iter() + .map(|x| (*x).clone()) + .collect())))); } // Which arm's failure should we report? (the one furthest along) diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 1a32332bee6..1cfe9f1ab96 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -17,12 +17,13 @@ use parse::token::{EOF, INTERPOLATED, IDENT, Token, NtIdent}; use parse::token; use parse::lexer::TokenAndSpan; +use std::rc::Rc; use collections::HashMap; ///an unzipping of `TokenTree`s #[deriving(Clone)] struct TtFrame { - forest: @Vec, + forest: Rc>, idx: uint, dotdotdoted: bool, sep: Option, @@ -52,7 +53,7 @@ pub fn new_tt_reader<'a>(sp_diag: &'a SpanHandler, let mut r = TtReader { sp_diag: sp_diag, stack: vec!(TtFrame { - forest: @src, + forest: Rc::new(src), idx: 0, dotdotdoted: false, sep: None, @@ -212,7 +213,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { } TTSeq(sp, tts, sep, zerok) => { // FIXME(pcwalton): Bad copy. - match lockstep_iter_size(&TTSeq(sp, tts, sep.clone(), zerok), r) { + match lockstep_iter_size(&TTSeq(sp, tts.clone(), sep.clone(), zerok), r) { LisUnconstrained => { r.sp_diag.span_fatal( sp.clone(), /* blame macro writer */ diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 291502ff229..0f8c74f9ee0 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -16,6 +16,8 @@ use parse::token; use owned_slice::OwnedSlice; use util::small_vector::SmallVector; +use std::rc::Rc; + // We may eventually want to be able to fold over type parameters, too. pub trait Folder { fn fold_crate(&mut self, c: Crate) -> Crate { @@ -375,10 +377,10 @@ pub fn fold_tts(tts: &[TokenTree], fld: &mut T) -> Vec { match *tt { TTTok(span, ref tok) => TTTok(span,maybe_fold_ident(tok,fld)), - TTDelim(tts) => TTDelim(@fold_tts(tts.as_slice(), fld)), - TTSeq(span, pattern, ref sep, is_optional) => + TTDelim(ref tts) => TTDelim(Rc::new(fold_tts(tts.as_slice(), fld))), + TTSeq(span, ref pattern, ref sep, is_optional) => TTSeq(span, - @fold_tts(pattern.as_slice(), fld), + Rc::new(fold_tts(pattern.as_slice(), fld)), sep.as_ref().map(|tok|maybe_fold_ident(tok,fld)), is_optional), TTNonterminal(sp,ref ident) => diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 2df93deea14..f2a7f543bd6 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -366,13 +366,13 @@ mod test { [ast::TTTok(_,_), ast::TTTok(_,token::NOT), ast::TTTok(_,_), - ast::TTDelim(delim_elts)] => { + ast::TTDelim(ref delim_elts)] => { let delim_elts: &[ast::TokenTree] = delim_elts.as_slice(); match delim_elts { [ast::TTTok(_,token::LPAREN), - ast::TTDelim(first_set), + ast::TTDelim(ref first_set), ast::TTTok(_,token::FAT_ARROW), - ast::TTDelim(second_set), + ast::TTDelim(ref second_set), ast::TTTok(_,token::RPAREN)] => { let first_set: &[ast::TokenTree] = first_set.as_slice(); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8038baebdcf..3618978d5c6 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -80,6 +80,7 @@ use owned_slice::OwnedSlice; use collections::HashSet; use std::kinds::marker; use std::mem::replace; +use std::rc::Rc; use std::vec; #[allow(non_camel_case_types)] @@ -2101,7 +2102,7 @@ impl<'a> Parser<'a> { let seq = match seq { Spanned { node, .. } => node, }; - TTSeq(mk_sp(sp.lo, p.span.hi), @seq, s, z) + TTSeq(mk_sp(sp.lo, p.span.hi), Rc::new(seq), s, z) } else { TTNonterminal(sp, p.parse_ident()) } @@ -2144,7 +2145,7 @@ impl<'a> Parser<'a> { result.push(parse_any_tt_tok(self)); self.open_braces.pop().unwrap(); - TTDelim(@result) + TTDelim(Rc::new(result)) } _ => parse_non_delim_tt_tok(self) } -- cgit 1.4.1-3-g733a5 From 83c4e25d93ab936567df8fa5c338b5d05c1245ec Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Thu, 27 Mar 2014 16:52:27 +0200 Subject: De-@ NamedMatch. --- src/libsyntax/ext/tt/macro_parser.rs | 29 +++++++++++++++-------------- src/libsyntax/ext/tt/macro_rules.rs | 12 ++++++------ src/libsyntax/ext/tt/transcribe.rs | 12 ++++++------ 3 files changed, 27 insertions(+), 26 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index d730f50c7bc..ac19342f47a 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -21,6 +21,7 @@ use parse::parser::{LifetimeAndTypesWithoutColons, Parser}; use parse::token::{Token, EOF, Nonterminal}; use parse::token; +use std::rc::Rc; use collections::HashMap; /* This is an Earley-like parser, without support for in-grammar nonterminals, @@ -102,7 +103,7 @@ pub struct MatcherPos { sep: Option, idx: uint, up: Option<~MatcherPos>, - matches: Vec>, + matches: Vec>>, match_lo: uint, match_hi: uint, sp_lo: BytePos, } @@ -165,14 +166,14 @@ pub fn initial_matcher_pos(ms: Vec , sep: Option, lo: BytePos) // ast::Matcher it was derived from. pub enum NamedMatch { - MatchedSeq(Vec<@NamedMatch> , codemap::Span), + MatchedSeq(Vec>, codemap::Span), MatchedNonterminal(Nonterminal) } -pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[@NamedMatch]) - -> HashMap { - fn n_rec(p_s: &ParseSess, m: &Matcher, res: &[@NamedMatch], - ret_val: &mut HashMap) { +pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[Rc]) + -> HashMap> { + fn n_rec(p_s: &ParseSess, m: &Matcher, res: &[Rc], + ret_val: &mut HashMap>) { match *m { codemap::Spanned {node: MatchTok(_), .. } => (), codemap::Spanned {node: MatchSeq(ref more_ms, _, _, _, _), .. } => { @@ -189,7 +190,7 @@ pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[@NamedMatch]) p_s.span_diagnostic .span_fatal(span, "duplicated bind name: " + string.get()) } - ret_val.insert(bind_name, res[idx]); + ret_val.insert(bind_name, res[idx].clone()); } } } @@ -199,7 +200,7 @@ pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[@NamedMatch]) } pub enum ParseResult { - Success(HashMap), + Success(HashMap>), Failure(codemap::Span, ~str), Error(codemap::Span, ~str) } @@ -208,7 +209,7 @@ pub fn parse_or_else(sess: &ParseSess, cfg: ast::CrateConfig, rdr: TtReader, ms: Vec ) - -> HashMap { + -> HashMap> { match parse(sess, cfg, rdr, ms.as_slice()) { Success(m) => m, Failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str), @@ -282,8 +283,8 @@ pub fn parse(sess: &ParseSess, let sub = (*ei.matches.get(idx)).clone(); new_pos.matches .get_mut(idx) - .push(@MatchedSeq(sub, mk_sp(ei.sp_lo, - sp.hi))); + .push(Rc::new(MatchedSeq(sub, mk_sp(ei.sp_lo, + sp.hi)))); } new_pos.idx += 1; @@ -325,7 +326,7 @@ pub fn parse(sess: &ParseSess, for idx in range(match_idx_lo, match_idx_hi) { new_ei.matches .get_mut(idx) - .push(@MatchedSeq(Vec::new(), sp)); + .push(Rc::new(MatchedSeq(Vec::new(), sp))); } cur_eis.push(new_ei); @@ -401,8 +402,8 @@ pub fn parse(sess: &ParseSess, match ei.elts.get(ei.idx).node { MatchNonterminal(_, name, idx) => { let name_string = token::get_ident(name); - ei.matches.get_mut(idx).push(@MatchedNonterminal( - parse_nt(&mut rust_parser, name_string.get()))); + ei.matches.get_mut(idx).push(Rc::new(MatchedNonterminal( + parse_nt(&mut rust_parser, name_string.get())))); ei.idx += 1u; } _ => fail!() diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index e4e3f51b993..d4a883a63eb 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -86,8 +86,8 @@ impl<'a> AnyMacro for ParserAnyMacro<'a> { struct MacroRulesMacroExpander { name: Ident, - lhses: @Vec<@NamedMatch> , - rhses: @Vec<@NamedMatch> , + lhses: Vec>, + rhses: Vec>, } impl MacroExpander for MacroRulesMacroExpander { @@ -110,8 +110,8 @@ fn generic_extension(cx: &ExtCtxt, sp: Span, name: Ident, arg: &[ast::TokenTree], - lhses: &[@NamedMatch], - rhses: &[@NamedMatch]) + lhses: &[Rc], + rhses: &[Rc]) -> MacResult { if cx.trace_macros() { println!("{}! \\{ {} \\}", @@ -221,12 +221,12 @@ pub fn add_new_extension(cx: &mut ExtCtxt, // Extract the arguments: let lhses = match **argument_map.get(&lhs_nm) { - MatchedSeq(ref s, _) => /* FIXME (#2543) */ @(*s).clone(), + MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(), _ => cx.span_bug(sp, "wrong-structured lhs") }; let rhses = match **argument_map.get(&rhs_nm) { - MatchedSeq(ref s, _) => /* FIXME (#2543) */ @(*s).clone(), + MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(), _ => cx.span_bug(sp, "wrong-structured rhs") }; diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 1cfe9f1ab96..bc8709befae 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -35,7 +35,7 @@ pub struct TtReader<'a> { // the unzipped tree: priv stack: Vec, /* for MBE-style macro transcription */ - priv interpolations: HashMap, + priv interpolations: HashMap>, priv repeat_idx: Vec, priv repeat_len: Vec, /* cached: */ @@ -47,7 +47,7 @@ pub struct TtReader<'a> { * `src` contains no `TTSeq`s and `TTNonterminal`s, `interp` can (and * should) be none. */ pub fn new_tt_reader<'a>(sp_diag: &'a SpanHandler, - interp: Option>, + interp: Option>>, src: Vec ) -> TtReader<'a> { let mut r = TtReader { @@ -72,19 +72,19 @@ pub fn new_tt_reader<'a>(sp_diag: &'a SpanHandler, r } -fn lookup_cur_matched_by_matched(r: &TtReader, start: @NamedMatch) -> @NamedMatch { +fn lookup_cur_matched_by_matched(r: &TtReader, start: Rc) -> Rc { r.repeat_idx.iter().fold(start, |ad, idx| { match *ad { MatchedNonterminal(_) => { // end of the line; duplicate henceforth - ad + ad.clone() } - MatchedSeq(ref ads, _) => *ads.get(*idx) + MatchedSeq(ref ads, _) => ads.get(*idx).clone() } }) } -fn lookup_cur_matched(r: &TtReader, name: Ident) -> @NamedMatch { +fn lookup_cur_matched(r: &TtReader, name: Ident) -> Rc { let matched_opt = r.interpolations.find_copy(&name); match matched_opt { Some(s) => lookup_cur_matched_by_matched(r, s), -- cgit 1.4.1-3-g733a5