Skip to content

Commit 83c4e25

Browse files
committed
De-@ NamedMatch.
1 parent 8f226e5 commit 83c4e25

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use parse::parser::{LifetimeAndTypesWithoutColons, Parser};
2121
use parse::token::{Token, EOF, Nonterminal};
2222
use parse::token;
2323

24+
use std::rc::Rc;
2425
use collections::HashMap;
2526

2627
/* This is an Earley-like parser, without support for in-grammar nonterminals,
@@ -102,7 +103,7 @@ pub struct MatcherPos {
102103
sep: Option<Token>,
103104
idx: uint,
104105
up: Option<~MatcherPos>,
105-
matches: Vec<Vec<@NamedMatch>>,
106+
matches: Vec<Vec<Rc<NamedMatch>>>,
106107
match_lo: uint, match_hi: uint,
107108
sp_lo: BytePos,
108109
}
@@ -165,14 +166,14 @@ pub fn initial_matcher_pos(ms: Vec<Matcher> , sep: Option<Token>, lo: BytePos)
165166
// ast::Matcher it was derived from.
166167

167168
pub enum NamedMatch {
168-
MatchedSeq(Vec<@NamedMatch> , codemap::Span),
169+
MatchedSeq(Vec<Rc<NamedMatch>>, codemap::Span),
169170
MatchedNonterminal(Nonterminal)
170171
}
171172

172-
pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[@NamedMatch])
173-
-> HashMap<Ident, @NamedMatch> {
174-
fn n_rec(p_s: &ParseSess, m: &Matcher, res: &[@NamedMatch],
175-
ret_val: &mut HashMap<Ident, @NamedMatch>) {
173+
pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[Rc<NamedMatch>])
174+
-> HashMap<Ident, Rc<NamedMatch>> {
175+
fn n_rec(p_s: &ParseSess, m: &Matcher, res: &[Rc<NamedMatch>],
176+
ret_val: &mut HashMap<Ident, Rc<NamedMatch>>) {
176177
match *m {
177178
codemap::Spanned {node: MatchTok(_), .. } => (),
178179
codemap::Spanned {node: MatchSeq(ref more_ms, _, _, _, _), .. } => {
@@ -189,7 +190,7 @@ pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[@NamedMatch])
189190
p_s.span_diagnostic
190191
.span_fatal(span, "duplicated bind name: " + string.get())
191192
}
192-
ret_val.insert(bind_name, res[idx]);
193+
ret_val.insert(bind_name, res[idx].clone());
193194
}
194195
}
195196
}
@@ -199,7 +200,7 @@ pub fn nameize(p_s: &ParseSess, ms: &[Matcher], res: &[@NamedMatch])
199200
}
200201

201202
pub enum ParseResult {
202-
Success(HashMap<Ident, @NamedMatch>),
203+
Success(HashMap<Ident, Rc<NamedMatch>>),
203204
Failure(codemap::Span, ~str),
204205
Error(codemap::Span, ~str)
205206
}
@@ -208,7 +209,7 @@ pub fn parse_or_else(sess: &ParseSess,
208209
cfg: ast::CrateConfig,
209210
rdr: TtReader,
210211
ms: Vec<Matcher> )
211-
-> HashMap<Ident, @NamedMatch> {
212+
-> HashMap<Ident, Rc<NamedMatch>> {
212213
match parse(sess, cfg, rdr, ms.as_slice()) {
213214
Success(m) => m,
214215
Failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str),
@@ -282,8 +283,8 @@ pub fn parse(sess: &ParseSess,
282283
let sub = (*ei.matches.get(idx)).clone();
283284
new_pos.matches
284285
.get_mut(idx)
285-
.push(@MatchedSeq(sub, mk_sp(ei.sp_lo,
286-
sp.hi)));
286+
.push(Rc::new(MatchedSeq(sub, mk_sp(ei.sp_lo,
287+
sp.hi))));
287288
}
288289

289290
new_pos.idx += 1;
@@ -325,7 +326,7 @@ pub fn parse(sess: &ParseSess,
325326
for idx in range(match_idx_lo, match_idx_hi) {
326327
new_ei.matches
327328
.get_mut(idx)
328-
.push(@MatchedSeq(Vec::new(), sp));
329+
.push(Rc::new(MatchedSeq(Vec::new(), sp)));
329330
}
330331

331332
cur_eis.push(new_ei);
@@ -401,8 +402,8 @@ pub fn parse(sess: &ParseSess,
401402
match ei.elts.get(ei.idx).node {
402403
MatchNonterminal(_, name, idx) => {
403404
let name_string = token::get_ident(name);
404-
ei.matches.get_mut(idx).push(@MatchedNonterminal(
405-
parse_nt(&mut rust_parser, name_string.get())));
405+
ei.matches.get_mut(idx).push(Rc::new(MatchedNonterminal(
406+
parse_nt(&mut rust_parser, name_string.get()))));
406407
ei.idx += 1u;
407408
}
408409
_ => fail!()

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ impl<'a> AnyMacro for ParserAnyMacro<'a> {
8686

8787
struct MacroRulesMacroExpander {
8888
name: Ident,
89-
lhses: @Vec<@NamedMatch> ,
90-
rhses: @Vec<@NamedMatch> ,
89+
lhses: Vec<Rc<NamedMatch>>,
90+
rhses: Vec<Rc<NamedMatch>>,
9191
}
9292

9393
impl MacroExpander for MacroRulesMacroExpander {
@@ -110,8 +110,8 @@ fn generic_extension(cx: &ExtCtxt,
110110
sp: Span,
111111
name: Ident,
112112
arg: &[ast::TokenTree],
113-
lhses: &[@NamedMatch],
114-
rhses: &[@NamedMatch])
113+
lhses: &[Rc<NamedMatch>],
114+
rhses: &[Rc<NamedMatch>])
115115
-> MacResult {
116116
if cx.trace_macros() {
117117
println!("{}! \\{ {} \\}",
@@ -221,12 +221,12 @@ pub fn add_new_extension(cx: &mut ExtCtxt,
221221

222222
// Extract the arguments:
223223
let lhses = match **argument_map.get(&lhs_nm) {
224-
MatchedSeq(ref s, _) => /* FIXME (#2543) */ @(*s).clone(),
224+
MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(),
225225
_ => cx.span_bug(sp, "wrong-structured lhs")
226226
};
227227

228228
let rhses = match **argument_map.get(&rhs_nm) {
229-
MatchedSeq(ref s, _) => /* FIXME (#2543) */ @(*s).clone(),
229+
MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(),
230230
_ => cx.span_bug(sp, "wrong-structured rhs")
231231
};
232232

src/libsyntax/ext/tt/transcribe.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct TtReader<'a> {
3535
// the unzipped tree:
3636
priv stack: Vec<TtFrame>,
3737
/* for MBE-style macro transcription */
38-
priv interpolations: HashMap<Ident, @NamedMatch>,
38+
priv interpolations: HashMap<Ident, Rc<NamedMatch>>,
3939
priv repeat_idx: Vec<uint>,
4040
priv repeat_len: Vec<uint>,
4141
/* cached: */
@@ -47,7 +47,7 @@ pub struct TtReader<'a> {
4747
* `src` contains no `TTSeq`s and `TTNonterminal`s, `interp` can (and
4848
* should) be none. */
4949
pub fn new_tt_reader<'a>(sp_diag: &'a SpanHandler,
50-
interp: Option<HashMap<Ident, @NamedMatch>>,
50+
interp: Option<HashMap<Ident, Rc<NamedMatch>>>,
5151
src: Vec<ast::TokenTree> )
5252
-> TtReader<'a> {
5353
let mut r = TtReader {
@@ -72,19 +72,19 @@ pub fn new_tt_reader<'a>(sp_diag: &'a SpanHandler,
7272
r
7373
}
7474

75-
fn lookup_cur_matched_by_matched(r: &TtReader, start: @NamedMatch) -> @NamedMatch {
75+
fn lookup_cur_matched_by_matched(r: &TtReader, start: Rc<NamedMatch>) -> Rc<NamedMatch> {
7676
r.repeat_idx.iter().fold(start, |ad, idx| {
7777
match *ad {
7878
MatchedNonterminal(_) => {
7979
// end of the line; duplicate henceforth
80-
ad
80+
ad.clone()
8181
}
82-
MatchedSeq(ref ads, _) => *ads.get(*idx)
82+
MatchedSeq(ref ads, _) => ads.get(*idx).clone()
8383
}
8484
})
8585
}
8686

87-
fn lookup_cur_matched(r: &TtReader, name: Ident) -> @NamedMatch {
87+
fn lookup_cur_matched(r: &TtReader, name: Ident) -> Rc<NamedMatch> {
8888
let matched_opt = r.interpolations.find_copy(&name);
8989
match matched_opt {
9090
Some(s) => lookup_cur_matched_by_matched(r, s),

0 commit comments

Comments
 (0)