@@ -53,13 +53,13 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
53
53
let extname = & pth. segments [ 0 ] . identifier ;
54
54
let extnamestr = ident_to_str ( extname) ;
55
55
// leaving explicit deref here to highlight unbox op:
56
- match fld. extsbox . find ( & extname. name ) {
56
+ let marked_after = match fld. extsbox . find ( & extname. name ) {
57
57
None => {
58
58
fld. cx . span_fatal (
59
59
pth. span ,
60
60
format ! ( "macro undefined: '{}'" , extnamestr) )
61
61
}
62
- Some ( & NormalTT ( expandfun, exp_span) ) => {
62
+ Some ( & NormalTT ( ref expandfun, exp_span) ) => {
63
63
fld. cx . bt_push ( ExpnInfo {
64
64
call_site : e. span ,
65
65
callee : NameAndSpan {
@@ -79,46 +79,46 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
79
79
// the macro.
80
80
let mac_span = original_span ( fld. cx ) ;
81
81
82
- let expanded =
83
- match expandfun. expand ( fld. cx ,
84
- mac_span. call_site ,
85
- marked_before,
86
- marked_ctxt) {
87
- MRExpr ( e) => e,
88
- MRAny ( any_macro) => any_macro. make_expr ( ) ,
89
- _ => {
90
- fld. cx . span_fatal (
91
- pth. span ,
92
- format ! (
93
- "non-expr macro in expr pos: {}" ,
94
- extnamestr
95
- )
82
+ let expanded = match expandfun. expand ( fld. cx ,
83
+ mac_span. call_site ,
84
+ marked_before,
85
+ marked_ctxt) {
86
+ MRExpr ( e) => e,
87
+ MRAny ( any_macro) => any_macro. make_expr ( ) ,
88
+ _ => {
89
+ fld. cx . span_fatal (
90
+ pth. span ,
91
+ format ! (
92
+ "non-expr macro in expr pos: {}" ,
93
+ extnamestr
96
94
)
97
- }
98
- } ;
95
+ )
96
+ }
97
+ } ;
98
+
99
99
// mark after:
100
- let marked_after = mark_expr ( expanded, fm) ;
101
-
102
- // Keep going, outside-in.
103
- //
104
- // XXX(pcwalton): Is it necessary to clone the
105
- // node here?
106
- let fully_expanded =
107
- fld. fold_expr ( marked_after) . node . clone ( ) ;
108
- fld. cx . bt_pop ( ) ;
109
-
110
- @ast:: Expr {
111
- id : ast:: DUMMY_NODE_ID ,
112
- node : fully_expanded,
113
- span : e. span ,
114
- }
100
+ mark_expr ( expanded, fm)
115
101
}
116
102
_ => {
117
103
fld. cx . span_fatal (
118
104
pth. span ,
119
105
format ! ( "'{}' is not a tt-style macro" , extnamestr)
120
106
)
121
107
}
108
+ } ;
109
+
110
+ // Keep going, outside-in.
111
+ //
112
+ // XXX(pcwalton): Is it necessary to clone the
113
+ // node here?
114
+ let fully_expanded =
115
+ fld. fold_expr ( marked_after) . node . clone ( ) ;
116
+ fld. cx . bt_pop ( ) ;
117
+
118
+ @ast:: Expr {
119
+ id : ast:: DUMMY_NODE_ID ,
120
+ node : fully_expanded,
121
+ span : e. span ,
122
122
}
123
123
}
124
124
}
@@ -301,7 +301,7 @@ pub fn expand_item_mac(it: @ast::item, fld: &mut MacroExpander)
301
301
None => fld. cx . span_fatal ( pth. span ,
302
302
format ! ( "macro undefined: '{}!'" , extnamestr) ) ,
303
303
304
- Some ( & NormalTT ( expander, span) ) => {
304
+ Some ( & NormalTT ( ref expander, span) ) => {
305
305
if it. ident . name != parse:: token:: special_idents:: invalid. name {
306
306
fld. cx . span_fatal ( pth. span ,
307
307
format ! ( "macro {}! expects no ident argument, \
@@ -321,7 +321,7 @@ pub fn expand_item_mac(it: @ast::item, fld: &mut MacroExpander)
321
321
let marked_ctxt = new_mark ( fm, ctxt) ;
322
322
expander. expand ( fld. cx , it. span , marked_before, marked_ctxt)
323
323
}
324
- Some ( & IdentTT ( expander, span) ) => {
324
+ Some ( & IdentTT ( ref expander, span) ) => {
325
325
if it. ident . name == parse:: token:: special_idents:: invalid. name {
326
326
fld. cx . span_fatal ( pth. span ,
327
327
format ! ( "macro {}! expects an ident argument" ,
@@ -361,10 +361,10 @@ pub fn expand_item_mac(it: @ast::item, fld: &mut MacroExpander)
361
361
. flat_map ( |i| fld. fold_item ( i) . move_iter ( ) )
362
362
. collect ( )
363
363
}
364
- MRDef ( ref mdef ) => {
364
+ MRDef ( MacroDef { name , ext } ) => {
365
365
// yikes... no idea how to apply the mark to this. I'm afraid
366
366
// we're going to have to wait-and-see on this one.
367
- fld. extsbox . insert ( intern ( mdef . name ) , ( * mdef ) . ext ) ;
367
+ fld. extsbox . insert ( intern ( name) , ext) ;
368
368
SmallVector :: zero ( )
369
369
}
370
370
} ;
@@ -392,12 +392,12 @@ pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> {
392
392
}
393
393
let extname = & pth. segments [ 0 ] . identifier ;
394
394
let extnamestr = ident_to_str ( extname) ;
395
- let fully_expanded : SmallVector < @ Stmt > = match fld. extsbox . find ( & extname. name ) {
395
+ let marked_after = match fld. extsbox . find ( & extname. name ) {
396
396
None => {
397
397
fld. cx . span_fatal ( pth. span , format ! ( "macro undefined: '{}'" , extnamestr) )
398
398
}
399
399
400
- Some ( & NormalTT ( expandfun, exp_span) ) => {
400
+ Some ( & NormalTT ( ref expandfun, exp_span) ) => {
401
401
fld. cx . bt_push ( ExpnInfo {
402
402
call_site : s. span ,
403
403
callee : NameAndSpan {
@@ -430,18 +430,8 @@ pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> {
430
430
pth. span ,
431
431
format ! ( "non-stmt macro in stmt pos: {}" , extnamestr) )
432
432
} ;
433
- let marked_after = mark_stmt ( expanded, fm) ;
434
433
435
- // Keep going, outside-in.
436
- let fully_expanded = fld. fold_stmt ( marked_after) ;
437
- if fully_expanded. is_empty ( ) {
438
- fld. cx . span_fatal ( pth. span ,
439
- "macro didn't expand to a statement" ) ;
440
- }
441
- fld. cx . bt_pop ( ) ;
442
- fully_expanded. move_iter ( )
443
- . map ( |s| @Spanned { span : s. span , node : s. node . clone ( ) } )
444
- . collect ( )
434
+ mark_stmt ( expanded, fm)
445
435
}
446
436
447
437
_ => {
@@ -451,6 +441,17 @@ pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> {
451
441
}
452
442
} ;
453
443
444
+ // Keep going, outside-in.
445
+ let fully_expanded = fld. fold_stmt ( marked_after) ;
446
+ if fully_expanded. is_empty ( ) {
447
+ fld. cx . span_fatal ( pth. span ,
448
+ "macro didn't expand to a statement" ) ;
449
+ }
450
+ fld. cx . bt_pop ( ) ;
451
+ let fully_expanded: SmallVector < @Stmt > = fully_expanded. move_iter ( )
452
+ . map ( |s| @Spanned { span : s. span , node : s. node . clone ( ) } )
453
+ . collect ( ) ;
454
+
454
455
fully_expanded. move_iter ( ) . map ( |s| {
455
456
match s. node {
456
457
StmtExpr ( e, stmt_id) if semi => {
@@ -1109,10 +1110,8 @@ mod test {
1109
1110
use codemap:: Spanned ;
1110
1111
use fold;
1111
1112
use parse;
1112
- use parse:: token:: { fresh_mark, gensym, intern, get_ident_interner , ident_to_str} ;
1113
+ use parse:: token:: { fresh_mark, gensym, intern, ident_to_str} ;
1113
1114
use parse:: token;
1114
- use print:: pprust;
1115
- use std;
1116
1115
use util:: parser_testing:: { string_to_crate, string_to_crate_and_sess} ;
1117
1116
use util:: parser_testing:: { string_to_pat, string_to_tts, strs_to_idents} ;
1118
1117
use visit;
0 commit comments