diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index d730f50c7bca..ac19342f47a1 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 e4e3f51b993f..d4a883a63ebb 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 1cfe9f1ab96f..bc8709befaee 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),