@@ -53,13 +53,13 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
5353 let extname = & pth. segments [ 0 ] . identifier ;
5454 let extnamestr = ident_to_str ( extname) ;
5555 // 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 ) {
5757 None => {
5858 fld. cx . span_fatal (
5959 pth. span ,
6060 format ! ( "macro undefined: '{}'" , extnamestr) )
6161 }
62- Some ( & NormalTT ( expandfun, exp_span) ) => {
62+ Some ( & NormalTT ( ref expandfun, exp_span) ) => {
6363 fld. cx . bt_push ( ExpnInfo {
6464 call_site : e. span ,
6565 callee : NameAndSpan {
@@ -79,46 +79,46 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
7979 // the macro.
8080 let mac_span = original_span ( fld. cx ) ;
8181
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
9694 )
97- }
98- } ;
95+ )
96+ }
97+ } ;
98+
9999 // 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)
115101 }
116102 _ => {
117103 fld. cx . span_fatal (
118104 pth. span ,
119105 format ! ( "'{}' is not a tt-style macro" , extnamestr)
120106 )
121107 }
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 ,
122122 }
123123 }
124124 }
@@ -301,7 +301,7 @@ pub fn expand_item_mac(it: @ast::item, fld: &mut MacroExpander)
301301 None => fld. cx . span_fatal ( pth. span ,
302302 format ! ( "macro undefined: '{}!'" , extnamestr) ) ,
303303
304- Some ( & NormalTT ( expander, span) ) => {
304+ Some ( & NormalTT ( ref expander, span) ) => {
305305 if it. ident . name != parse:: token:: special_idents:: invalid. name {
306306 fld. cx . span_fatal ( pth. span ,
307307 format ! ( "macro {}! expects no ident argument, \
@@ -321,7 +321,7 @@ pub fn expand_item_mac(it: @ast::item, fld: &mut MacroExpander)
321321 let marked_ctxt = new_mark ( fm, ctxt) ;
322322 expander. expand ( fld. cx , it. span , marked_before, marked_ctxt)
323323 }
324- Some ( & IdentTT ( expander, span) ) => {
324+ Some ( & IdentTT ( ref expander, span) ) => {
325325 if it. ident . name == parse:: token:: special_idents:: invalid. name {
326326 fld. cx . span_fatal ( pth. span ,
327327 format ! ( "macro {}! expects an ident argument" ,
@@ -361,10 +361,10 @@ pub fn expand_item_mac(it: @ast::item, fld: &mut MacroExpander)
361361 . flat_map ( |i| fld. fold_item ( i) . move_iter ( ) )
362362 . collect ( )
363363 }
364- MRDef ( ref mdef ) => {
364+ MRDef ( MacroDef { name , ext } ) => {
365365 // yikes... no idea how to apply the mark to this. I'm afraid
366366 // 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) ;
368368 SmallVector :: zero ( )
369369 }
370370 } ;
@@ -392,12 +392,12 @@ pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> {
392392 }
393393 let extname = & pth. segments [ 0 ] . identifier ;
394394 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 ) {
396396 None => {
397397 fld. cx . span_fatal ( pth. span , format ! ( "macro undefined: '{}'" , extnamestr) )
398398 }
399399
400- Some ( & NormalTT ( expandfun, exp_span) ) => {
400+ Some ( & NormalTT ( ref expandfun, exp_span) ) => {
401401 fld. cx . bt_push ( ExpnInfo {
402402 call_site : s. span ,
403403 callee : NameAndSpan {
@@ -430,18 +430,8 @@ pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> {
430430 pth. span ,
431431 format ! ( "non-stmt macro in stmt pos: {}" , extnamestr) )
432432 } ;
433- let marked_after = mark_stmt ( expanded, fm) ;
434433
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)
445435 }
446436
447437 _ => {
@@ -451,6 +441,17 @@ pub fn expand_stmt(s: &Stmt, fld: &mut MacroExpander) -> SmallVector<@Stmt> {
451441 }
452442 } ;
453443
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+
454455 fully_expanded. move_iter ( ) . map ( |s| {
455456 match s. node {
456457 StmtExpr ( e, stmt_id) if semi => {
@@ -1109,10 +1110,8 @@ mod test {
11091110 use codemap:: Spanned ;
11101111 use fold;
11111112 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} ;
11131114 use parse:: token;
1114- use print:: pprust;
1115- use std;
11161115 use util:: parser_testing:: { string_to_crate, string_to_crate_and_sess} ;
11171116 use util:: parser_testing:: { string_to_pat, string_to_tts, strs_to_idents} ;
11181117 use visit;
0 commit comments