Skip to content

Commit e24ae85

Browse files
committed
syntax: remove most code handling old-style syntax extensions.
1 parent 9cced55 commit e24ae85

21 files changed

+30
-1226
lines changed

src/libsyntax/ast.rs

-6
Original file line numberDiff line numberDiff line change
@@ -842,13 +842,7 @@ type mac_body = Option<mac_body_>;
842842
#[auto_serialize]
843843
#[auto_deserialize]
844844
enum mac_ {
845-
mac_invoc(@path, mac_arg, mac_body), // old macro-invocation
846845
mac_invoc_tt(@path,~[token_tree]), // new macro-invocation
847-
mac_ellipsis, // old pattern-match (obsolete)
848-
849-
// the span is used by the quoter/anti-quoter ...
850-
mac_aq(span /* span of quote */, @expr), // anti-quote
851-
mac_var(uint)
852846
}
853847

854848
type lit = spanned<lit_>;

src/libsyntax/ext/base.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ use ast_util::dummy_sp;
1616

1717
// obsolete old-style #macro code:
1818
//
19-
// syntax_expander, normal, macro_defining, macro_definer,
20-
// builtin
19+
// syntax_expander, normal, builtin
2120
//
2221
// new-style macro! tt code:
2322
//
2423
// syntax_expander_tt, syntax_expander_tt_item, mac_result,
2524
// normal_tt, item_tt
2625
//
27-
// also note that ast::mac has way too many cases and can probably
28-
// be trimmed down substantially.
26+
// also note that ast::mac used to have a bunch of extraneous cases and
27+
// is now probably a redundant AST node, can be merged with
28+
// ast::mac_invoc_tt.
2929

3030
// second argument is the span to blame for general argument problems
3131
type syntax_expander_ =
@@ -35,10 +35,6 @@ type syntax_expander = {expander: syntax_expander_, span: Option<span>};
3535

3636
type macro_def = {name: ~str, ext: syntax_extension};
3737

38-
// macro_definer is obsolete, remove when #old_macros go away.
39-
type macro_definer =
40-
fn@(ext_ctxt, span, ast::mac_arg, ast::mac_body) -> macro_def;
41-
4238
type item_decorator =
4339
fn@(ext_ctxt, span, ast::meta_item, ~[@ast::item]) -> ~[@ast::item];
4440

@@ -63,9 +59,6 @@ enum syntax_extension {
6359
// normal() is obsolete, remove when #old_macros go away.
6460
normal(syntax_expander),
6561

66-
// macro_defining() is obsolete, remove when #old_macros go away.
67-
macro_defining(macro_definer),
68-
6962
// #[auto_serialize] and such. will probably survive death of #old_macros
7063
item_decorator(item_decorator),
7164

@@ -89,8 +82,6 @@ fn syntax_expander_table() -> HashMap<~str, syntax_extension> {
8982
item_tt({expander: f, span: None})
9083
}
9184
let syntax_expanders = HashMap();
92-
syntax_expanders.insert(~"macro",
93-
macro_defining(ext::simplext::add_new_extension));
9485
syntax_expanders.insert(~"macro_rules",
9586
builtin_item_tt(
9687
ext::tt::macro_rules::add_new_extension));

src/libsyntax/ext/expand.rs

+17-80
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use std::map::HashMap;
1212

13-
use ast::{crate, expr_, expr_mac, mac_invoc, mac_invoc_tt,
13+
use ast::{crate, expr_, expr_mac, mac_invoc_tt,
1414
tt_delim, tt_tok, item_mac, stmt_, stmt_mac, stmt_expr, stmt_semi};
1515
use fold::*;
1616
use ext::base::*;
@@ -31,51 +31,6 @@ fn expand_expr(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
3131
expr_mac(ref mac) => {
3232

3333
match (*mac).node {
34-
// Old-style macros. For compatibility, will erase this whole
35-
// block once we've transitioned.
36-
mac_invoc(pth, args, body) => {
37-
assert (vec::len(pth.idents) > 0u);
38-
/* using idents and token::special_idents would make the
39-
the macro names be hygienic */
40-
let extname = cx.parse_sess().interner.get(pth.idents[0]);
41-
match exts.find(*extname) {
42-
None => {
43-
cx.span_fatal(pth.span,
44-
fmt!("macro undefined: '%s'", *extname))
45-
}
46-
Some(item_decorator(_)) => {
47-
cx.span_fatal(
48-
pth.span,
49-
fmt!("%s can only be used as a decorator", *extname));
50-
}
51-
Some(normal({expander: exp, span: exp_sp})) => {
52-
53-
cx.bt_push(ExpandedFrom({call_site: s,
54-
callie: {name: *extname, span: exp_sp}}));
55-
let expanded = exp(cx, (*mac).span, args, body);
56-
57-
//keep going, outside-in
58-
let fully_expanded = fld.fold_expr(expanded).node;
59-
cx.bt_pop();
60-
61-
(fully_expanded, s)
62-
}
63-
Some(macro_defining(ext)) => {
64-
let named_extension = ext(cx, (*mac).span, args, body);
65-
exts.insert(named_extension.name, named_extension.ext);
66-
(ast::expr_rec(~[], None), s)
67-
}
68-
Some(normal_tt(_)) => {
69-
cx.span_fatal(pth.span,
70-
fmt!("this tt-style macro should be \
71-
invoked '%s!(...)'", *extname))
72-
}
73-
Some(item_tt(*)) => {
74-
cx.span_fatal(pth.span,
75-
~"cannot use item macros in this context");
76-
}
77-
}
78-
}
7934

8035
// Token-tree macros, these will be the only case when we're
8136
// finished transitioning.
@@ -130,7 +85,6 @@ fn expand_expr(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
13085

13186
}
13287
}
133-
_ => cx.span_bug((*mac).span, ~"naked syntactic bit")
13488
}
13589
}
13690
_ => orig(e, s, fld)
@@ -165,8 +119,8 @@ fn expand_mod_items(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
165119
ast::meta_list(ref n, _) => (*n)
166120
};
167121
match exts.find(mname) {
168-
None | Some(normal(_)) | Some(macro_defining(_))
169-
| Some(normal_tt(_)) | Some(item_tt(*)) => items,
122+
None | Some(normal(_))
123+
| Some(normal_tt(_)) | Some(item_tt(*)) => items,
170124
Some(item_decorator(dec_fn)) => {
171125
cx.bt_push(ExpandedFrom({call_site: attr.span,
172126
callie: {name: copy mname,
@@ -209,36 +163,16 @@ fn expand_item(exts: HashMap<~str, syntax_extension>,
209163
}
210164
}
211165

212-
// avoid excess indentation when a series of nested `match`es
213-
// has only one "good" outcome
214-
macro_rules! biased_match (
215-
( ($e :expr) ~ ($p :pat) else $err :stmt ;
216-
$( ($e_cdr:expr) ~ ($p_cdr:pat) else $err_cdr:stmt ; )*
217-
=> $body:expr
218-
) => (
219-
match $e {
220-
$p => {
221-
biased_match!($( ($e_cdr) ~ ($p_cdr) else $err_cdr ; )*
222-
=> $body)
223-
}
224-
_ => { $err }
225-
}
226-
);
227-
( => $body:expr ) => ( $body )
228-
)
229-
230-
231166
// Support for item-position macro invocations, exactly the same
232167
// logic as for expression-position macro invocations.
233168
fn expand_item_mac(exts: HashMap<~str, syntax_extension>,
234169
cx: ext_ctxt, &&it: @ast::item,
235170
fld: ast_fold) -> Option<@ast::item> {
236-
let (pth, tts) = biased_match!(
237-
(it.node) ~ (item_mac({node: mac_invoc_tt(pth, ref tts), _})) else {
238-
cx.span_bug(it.span, ~"invalid item macro invocation")
239-
};
240-
=> (pth, (*tts))
241-
);
171+
172+
let (pth, tts) = match it.node {
173+
item_mac({node: mac_invoc_tt(pth, ref tts), _}) => (pth, (*tts)),
174+
_ => cx.span_bug(it.span, ~"invalid item macro invocation")
175+
};
242176

243177
let extname = cx.parse_sess().interner.get(pth.idents[0]);
244178
let expanded = match exts.find(*extname) {
@@ -293,12 +227,15 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
293227
orig: fn@(&&s: stmt_, span, ast_fold) -> (stmt_, span))
294228
-> (stmt_, span)
295229
{
296-
let (mac, pth, tts, semi) = biased_match! (
297-
(s) ~ (stmt_mac(ref mac, semi)) else return orig(s, sp, fld);
298-
((*mac).node) ~ (mac_invoc_tt(pth, ref tts)) else {
299-
cx.span_bug((*mac).span, ~"naked syntactic bit")
300-
};
301-
=> ((*mac), pth, (*tts), semi));
230+
231+
let (mac, pth, tts, semi) = match s {
232+
stmt_mac(ref mac, semi) => {
233+
match (*mac).node {
234+
mac_invoc_tt(pth, ref tts) => ((*mac), pth, (*tts), semi)
235+
}
236+
}
237+
_ => return orig(s, sp, fld)
238+
};
302239
303240
assert(vec::len(pth.idents) == 1u);
304241
let extname = cx.parse_sess().interner.get(pth.idents[0]);

src/libsyntax/ext/quote.rs

-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ fn mk_token(cx: ext_ctxt, sp: span, tok: token::Token) -> @ast::expr {
406406
AT => "AT",
407407
DOT => "DOT",
408408
DOTDOT => "DOTDOT",
409-
ELLIPSIS => "ELLIPSIS",
410409
COMMA => "COMMA",
411410
SEMI => "SEMI",
412411
COLON => "COLON",

0 commit comments

Comments
 (0)