diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-02-28 12:54:01 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-03-01 22:40:52 -0800 |
| commit | 198cc3d850136582651489328fec221a2b98bfef (patch) | |
| tree | fe47f6fab3d4ead61053684613d0b1852ec7e311 /src/libsyntax/ext/tt | |
| parent | 58fd6ab90db3eb68c94695e1254a73e57bc44658 (diff) | |
| download | rust-198cc3d850136582651489328fec221a2b98bfef.tar.gz rust-198cc3d850136582651489328fec221a2b98bfef.zip | |
libsyntax: Fix errors arising from the automated `~[T]` conversion
Diffstat (limited to 'src/libsyntax/ext/tt')
| -rw-r--r-- | src/libsyntax/ext/tt/macro_parser.rs | 41 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 28 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/transcribe.rs | 8 |
3 files changed, 52 insertions, 25 deletions
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index cb86f2cecaa..c9d3150c2cd 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -22,7 +22,7 @@ use parse::token::{Token, EOF, Nonterminal}; use parse::token; use collections::HashMap; -use std::vec; +use std::vec_ng::Vec; /* This is an Earley-like parser, without support for in-grammar nonterminals, only by calling out to the main rust parser for named nonterminals (which it @@ -103,7 +103,7 @@ pub struct MatcherPos { sep: Option<Token>, idx: uint, up: Option<~MatcherPos>, - matches: vec!(Vec<@NamedMatch> ), + matches: Vec<Vec<@NamedMatch>>, match_lo: uint, match_hi: uint, sp_lo: BytePos, } @@ -112,7 +112,9 @@ pub fn count_names(ms: &[Matcher]) -> uint { ms.iter().fold(0, |ct, m| { ct + match m.node { MatchTok(_) => 0u, - MatchSeq(ref more_ms, _, _, _, _) => count_names((*more_ms)), + MatchSeq(ref more_ms, _, _, _, _) => { + count_names(more_ms.as_slice()) + } MatchNonterminal(_, _, _) => 1u }}) } @@ -131,7 +133,7 @@ pub fn initial_matcher_pos(ms: Vec<Matcher> , sep: Option<Token>, lo: BytePos) } } } - let matches = vec::from_fn(count_names(ms), |_i| Vec::new()); + let matches = Vec::from_fn(count_names(ms.as_slice()), |_i| Vec::new()); ~MatcherPos { elts: ms, sep: sep, @@ -208,7 +210,7 @@ pub fn parse_or_else<R: Reader>(sess: @ParseSess, rdr: R, ms: Vec<Matcher> ) -> HashMap<Ident, @NamedMatch> { - match parse(sess, cfg, rdr, ms) { + match parse(sess, cfg, rdr, ms.as_slice()) { Success(m) => m, Failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str), Error(sp, str) => sess.span_diagnostic.span_fatal(sp, str) @@ -231,7 +233,11 @@ pub fn parse<R: Reader>(sess: @ParseSess, ms: &[Matcher]) -> ParseResult { let mut cur_eis = Vec::new(); - cur_eis.push(initial_matcher_pos(ms.to_owned(), None, rdr.peek().sp.lo)); + cur_eis.push(initial_matcher_pos(ms.iter() + .map(|x| (*x).clone()) + .collect(), + None, + rdr.peek().sp.lo)); loop { let mut bb_eis = Vec::new(); // black-box parsed by parser.rs @@ -274,8 +280,9 @@ pub fn parse<R: Reader>(sess: @ParseSess, // Only touch the binders we have actually bound for idx in range(ei.match_lo, ei.match_hi) { - let sub = ei.matches[idx].clone(); - new_pos.matches[idx] + let sub = (*ei.matches.get(idx)).clone(); + new_pos.matches + .get_mut(idx) .push(@MatchedSeq(sub, mk_sp(ei.sp_lo, sp.hi))); } @@ -308,7 +315,7 @@ pub fn parse<R: Reader>(sess: @ParseSess, eof_eis.push(ei); } } else { - match ei.elts[idx].node.clone() { + match ei.elts.get(idx).node.clone() { /* need to descend into sequence */ MatchSeq(ref matchers, ref sep, zero_ok, match_idx_lo, match_idx_hi) => { @@ -317,13 +324,15 @@ pub fn parse<R: Reader>(sess: @ParseSess, new_ei.idx += 1u; //we specifically matched zero repeats. for idx in range(match_idx_lo, match_idx_hi) { - new_ei.matches[idx].push(@MatchedSeq(Vec::new(), sp)); + new_ei.matches + .get_mut(idx) + .push(@MatchedSeq(Vec::new(), sp)); } cur_eis.push(new_ei); } - let matches = vec::from_elem(ei.matches.len(), Vec::new()); + let matches = Vec::from_elem(ei.matches.len(), Vec::new()); let ei_t = ei; cur_eis.push(~MatcherPos { elts: (*matchers).clone(), @@ -352,10 +361,10 @@ pub fn parse<R: Reader>(sess: @ParseSess, if token_name_eq(&tok, &EOF) { if eof_eis.len() == 1u { let mut v = Vec::new(); - for dv in eof_eis[0u].matches.mut_iter() { + for dv in eof_eis.get_mut(0).matches.mut_iter() { v.push(dv.pop().unwrap()); } - return Success(nameize(sess, ms, v)); + return Success(nameize(sess, ms, v.as_slice())); } else if eof_eis.len() > 1u { return Error(sp, ~"ambiguity: multiple successful parses"); } else { @@ -365,7 +374,7 @@ pub fn parse<R: Reader>(sess: @ParseSess, if (bb_eis.len() > 0u && next_eis.len() > 0u) || bb_eis.len() > 1u { let nts = bb_eis.map(|ei| { - match ei.elts[ei.idx].node { + match ei.elts.get(ei.idx).node { MatchNonterminal(bind, name, _) => { format!("{} ('{}')", token::get_ident(name), @@ -390,10 +399,10 @@ pub fn parse<R: Reader>(sess: @ParseSess, let mut rust_parser = Parser(sess, cfg.clone(), rdr.dup()); let mut ei = bb_eis.pop().unwrap(); - match ei.elts[ei.idx].node { + match ei.elts.get(ei.idx).node { MatchNonterminal(_, name, idx) => { let name_string = token::get_ident(name); - ei.matches[idx].push(@MatchedNonterminal( + ei.matches.get_mut(idx).push(@MatchedNonterminal( parse_nt(&mut rust_parser, name_string.get()))); ei.idx += 1u; } diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index ed127c43117..712d5f6bd27 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -25,9 +25,11 @@ use parse::token::{special_idents, gensym_ident}; use parse::token::{FAT_ARROW, SEMI, NtMatchers, NtTT, EOF}; use parse::token; use print; -use std::cell::RefCell; use util::small_vector::SmallVector; +use std::cell::RefCell; +use std::vec_ng::Vec; + struct ParserAnyMacro { parser: RefCell<Parser>, } @@ -100,7 +102,12 @@ impl MacroExpander for MacroRulesMacroExpander { sp: Span, arg: &[ast::TokenTree]) -> MacResult { - generic_extension(cx, sp, self.name, arg, *self.lhses, *self.rhses) + generic_extension(cx, + sp, + self.name, + arg, + self.lhses.as_slice(), + self.rhses.as_slice()) } } @@ -115,7 +122,9 @@ fn generic_extension(cx: &ExtCtxt, if cx.trace_macros() { println!("{}! \\{ {} \\}", token::get_ident(name), - print::pprust::tt_to_str(&TTDelim(@arg.to_owned()))); + print::pprust::tt_to_str(&TTDelim(@arg.iter() + .map(|x| (*x).clone()) + .collect()))); } // Which arm's failure should we report? (the one furthest along) @@ -128,8 +137,12 @@ fn generic_extension(cx: &ExtCtxt, match **lhs { MatchedNonterminal(NtMatchers(ref mtcs)) => { // `None` is because we're not interpolating - let arg_rdr = new_tt_reader(s_d, None, arg.to_owned()); - match parse(cx.parse_sess(), cx.cfg(), arg_rdr, *mtcs) { + let arg_rdr = new_tt_reader(s_d, + None, + arg.iter() + .map(|x| (*x).clone()) + .collect()); + match parse(cx.parse_sess(), cx.cfg(), arg_rdr, mtcs.as_slice()) { Success(named_matches) => { let rhs = match *rhses[i] { // okay, what's your transcriber? @@ -137,7 +150,10 @@ fn generic_extension(cx: &ExtCtxt, match *tt { // cut off delimiters; don't parse 'em TTDelim(ref tts) => { - (*tts).slice(1u,(*tts).len()-1u).to_owned() + (*tts).slice(1u,(*tts).len()-1u) + .iter() + .map(|x| (*x).clone()) + .collect() } _ => cx.span_fatal( sp, "macro rhs must be delimited") diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 690ae82741c..a3f179e851a 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -18,6 +18,7 @@ use parse::token; use parse::lexer::TokenAndSpan; use std::cell::{Cell, RefCell}; +use std::vec_ng::Vec; use collections::HashMap; ///an unzipping of `TokenTree`s @@ -106,7 +107,7 @@ fn lookup_cur_matched_by_matched(r: &TtReader, start: @NamedMatch) // end of the line; duplicate henceforth ad } - MatchedSeq(ref ads, _) => ads[*idx] + MatchedSeq(ref ads, _) => *ads.get(*idx) } } let repeat_idx = r.repeat_idx.borrow(); @@ -217,7 +218,8 @@ pub fn tt_next_token(r: &TtReader) -> TokenAndSpan { r.stack.get().idx.set(0u); { let mut repeat_idx = r.repeat_idx.borrow_mut(); - repeat_idx.get()[repeat_idx.get().len() - 1u] += 1u; + let last_repeat_idx = repeat_idx.get().len() - 1u; + *repeat_idx.get().get_mut(last_repeat_idx) += 1u; } match r.stack.get().sep.clone() { Some(tk) => { @@ -231,7 +233,7 @@ pub fn tt_next_token(r: &TtReader) -> TokenAndSpan { 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[r.stack.get().idx.get()].clone() { + match (*r.stack.get().forest.get(r.stack.get().idx.get())).clone() { TTDelim(tts) => { r.stack.set(@TtFrame { forest: tts, |
