1
1
use std:: map:: HashMap ;
2
2
3
3
use ast:: { crate , expr_, expr_mac, mac_invoc, mac_invoc_tt,
4
- tt_delim, tt_tok, item_mac, stmt_, stmt_mac} ;
4
+ tt_delim, tt_tok, item_mac, stmt_, stmt_mac, stmt_expr , stmt_semi } ;
5
5
use fold:: * ;
6
6
use ext:: base:: * ;
7
7
use ext:: qquote:: { qq_helper} ;
@@ -281,16 +281,14 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
281
281
282
282
assert(vec::len(pth.idents) == 1u);
283
283
let extname = cx.parse_sess().interner.get(pth.idents[0]);
284
- match exts.find(*extname) {
284
+ let (fully_expanded, sp) = match exts.find(*extname) {
285
285
None =>
286
286
cx.span_fatal(pth.span, fmt!(" macro undefined: ' %s' ", *extname)),
287
287
288
288
Some(normal_tt({expander: exp, span: exp_sp})) => {
289
289
let expanded = match exp(cx, mac.span, tts) {
290
- mr_expr(e) if !semi =>
291
- @{node: ast::stmt_expr(e, cx.next_id()), span: e.span},
292
- mr_expr(e) if semi =>
293
- @{node: ast::stmt_semi(e, cx.next_id()), span: e.span},
290
+ mr_expr(e) =>
291
+ @{node: stmt_expr(e, cx.next_id()), span: e.span},
294
292
mr_any(_,_,stmt_mkr) => stmt_mkr(),
295
293
_ => cx.span_fatal(
296
294
pth.span,
@@ -303,14 +301,14 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
303
301
let fully_expanded = fld.fold_stmt(expanded).node;
304
302
cx.bt_pop();
305
303
306
- return (fully_expanded, sp)
304
+ (fully_expanded, sp)
307
305
}
308
306
309
307
Some(normal({expander: exp, span: exp_sp})) => {
310
308
//convert the new-style invoc for the old-style macro
311
309
let arg = base::tt_args_to_original_flavor(cx, pth.span, tts);
312
310
let exp_expr = exp(cx, mac.span, arg, None);
313
- let expanded = @{node: ast:: stmt_expr(exp_expr, cx.next_id()),
311
+ let expanded = @{node: stmt_expr(exp_expr, cx.next_id()),
314
312
span: exp_expr.span};
315
313
316
314
cx.bt_push(ExpandedFrom({call_site: sp,
@@ -325,10 +323,14 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
325
323
326
324
_ => {
327
325
cx.span_fatal(pth.span,
328
- fmt!(" ' %s' is not a tt-style macro",
329
- *extname))
326
+ fmt!(" ' %s' is not a tt-style macro", *extname))
330
327
}
331
- }
328
+ };
329
+
330
+ return (match fully_expanded {
331
+ stmt_expr(e, stmt_id) if semi => stmt_semi(e, stmt_id),
332
+ _ => { fully_expanded } /* might already have a semi */
333
+ }, sp)
332
334
333
335
}
334
336
0 commit comments