// expr with trailing semi-colon (may have any type):
stmt_semi(@expr, node_id),
- stmt_mac(mac),
+ // bool: is there a trailing sem-colon?
+ stmt_mac(mac, bool),
}
// FIXME (pending discussion of #1697, #2178...): local should really be
stmt_decl(_, id) => id,
stmt_expr(_, id) => id,
stmt_semi(_, id) => id,
- stmt_mac(_) => fail ~"attempted to analyze unexpanded stmt",
+ stmt_mac(*) => fail ~"attempted to analyze unexpanded stmt",
}
}
orig: fn@(&&s: stmt_, span, ast_fold) -> (stmt_, span))
-> (stmt_, span)
{
- let (mac, pth, tts) = biased_match! (
- (s) ~ (stmt_mac(mac)) else return orig(s, sp, fld);
+ let (mac, pth, tts, semi) = biased_match! (
+ (s) ~ (stmt_mac(mac, semi)) else return orig(s, sp, fld);
(mac.node) ~ (mac_invoc_tt(pth, tts)) else {
cx.span_bug(mac.span, ~"naked syntactic bit")
};
- => (mac, pth, tts));
+ => (mac, pth, tts, semi));
assert(vec::len(pth.idents) == 1u);
let extname = cx.parse_sess().interner.get(pth.idents[0]);
Some(normal_tt({expander: exp, span: exp_sp})) => {
let expanded = match exp(cx, mac.span, tts) {
- mr_expr(e) =>
+ mr_expr(e) if !semi =>
@{node: ast::stmt_expr(e, cx.next_id()), span: e.span},
+ mr_expr(e) if semi =>
+ @{node: ast::stmt_semi(e, cx.next_id()), span: e.span},
mr_any(_,_,stmt_mkr) => stmt_mkr(),
_ => cx.span_fatal(
pth.span,
stmt_decl(d, nid) => stmt_decl(fld.fold_decl(d), fld.new_id(nid)),
stmt_expr(e, nid) => stmt_expr(fld.fold_expr(e), fld.new_id(nid)),
stmt_semi(e, nid) => stmt_semi(fld.fold_expr(e), fld.new_id(nid)),
- stmt_mac(mac) => stmt_mac(fold_mac(mac))
+ stmt_mac(mac, semi) => stmt_mac(fold_mac(mac), semi)
};
}
if id == token::special_idents::invalid {
return @spanned(lo, hi, stmt_mac(
- spanned(lo, hi, mac_invoc_tt(pth, tts))));
+ spanned(lo, hi, mac_invoc_tt(pth, tts)), false));
} else {
// if it has a special ident, it's definitely an item
return @spanned(lo, hi, stmt_decl(
}
}
- stmt_mac(m) => {
+ stmt_mac(m, false) => {
// Statement macro; might be an expr
match self.token {
token::SEMI => {
self.bump();
- stmts.push(stmt);
+ stmts.push(@{node: stmt_mac(m, true),
+ ..*stmt});
}
token::RBRACE => {
// if a block ends in `m!(arg)` without
print_expr(s, expr);
word(s.s, ~";");
}
- ast::stmt_mac(mac) => {
+ ast::stmt_mac(mac, semi) => {
space_if_not_bol(s);
print_mac(s, mac);
+ if semi { word(s.s, ~";"); }
}
}
if parse::classify::stmt_ends_with_semi(st) { word(s.s, ~";"); }
stmt_decl(d, _) => v.visit_decl(d, e, v),
stmt_expr(ex, _) => v.visit_expr(ex, e, v),
stmt_semi(ex, _) => v.visit_expr(ex, e, v),
- stmt_mac(mac) => visit_mac(mac, e, v)
+ stmt_mac(mac, _) => visit_mac(mac, e, v)
}
}