diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2014-03-27 16:52:27 +0200 |
|---|---|---|
| committer | Eduard Burtescu <edy.burt@gmail.com> | 2014-03-28 18:28:04 +0200 |
| commit | 83c4e25d93ab936567df8fa5c338b5d05c1245ec (patch) | |
| tree | 2f1cb1c61b9ad8476748942213dc8ff141b23cfa /src/libsyntax | |
| parent | 8f226e56946d20acfdf8c0c48c57fd7ba3571157 (diff) | |
| download | rust-83c4e25d93ab936567df8fa5c338b5d05c1245ec.tar.gz rust-83c4e25d93ab936567df8fa5c338b5d05c1245ec.zip | |
De-@ NamedMatch.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/tt/macro_parser.rs | 29 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/transcribe.rs | 12 |
3 files changed, 27 insertions, 26 deletions
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<Token>, idx: uint, up: Option<~MatcherPos>, - matches: Vec<Vec<@NamedMatch>>, + matches: Vec<Vec<Rc<NamedMatch>>>, match_lo: uint, match_hi: uint, sp_lo: BytePos, } @@ -165,14 +166,14 @@ pub fn initial_matcher_pos(ms: Vec<Matcher> , sep: Option<Token>, lo: BytePos) // ast::Matcher it was derived from. pub enum NamedMatch { - MatchedSeq(Vec<@NamedMatch> , codemap::Span), + MatchedSeq(Vec<Rc<NamedMatch>>, codemap::Span), MatchedNonterminal(Nonterminal) } -pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[@NamedMatch]) - -> HashMap<Ident, @NamedMatch> { - fn n_rec(p_s: &ParseSess, m: &Matcher, res: &[@NamedMatch], - ret_val: &mut HashMap<Ident, @NamedMatch>) { +pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[Rc<NamedMatch>]) + -> HashMap<Ident, Rc<NamedMatch>> { + fn n_rec(p_s: &ParseSess, m: &Matcher, res: &[Rc<NamedMatch>], + ret_val: &mut HashMap<Ident, Rc<NamedMatch>>) { 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<Ident, @NamedMatch>), + Success(HashMap<Ident, Rc<NamedMatch>>), 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<Matcher> ) - -> HashMap<Ident, @NamedMatch> { + -> HashMap<Ident, Rc<NamedMatch>> { 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<Rc<NamedMatch>>, + rhses: Vec<Rc<NamedMatch>>, } 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<NamedMatch>], + rhses: &[Rc<NamedMatch>]) -> 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<TtFrame>, /* for MBE-style macro transcription */ - priv interpolations: HashMap<Ident, @NamedMatch>, + priv interpolations: HashMap<Ident, Rc<NamedMatch>>, priv repeat_idx: Vec<uint>, priv repeat_len: Vec<uint>, /* 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<HashMap<Ident, @NamedMatch>>, + interp: Option<HashMap<Ident, Rc<NamedMatch>>>, src: Vec<ast::TokenTree> ) -> 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<NamedMatch>) -> Rc<NamedMatch> { 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<NamedMatch> { let matched_opt = r.interpolations.find_copy(&name); match matched_opt { Some(s) => lookup_cur_matched_by_matched(r, s), |
