]> git.lizzy.rs Git - rust.git/commitdiff
Distinguish `stmt_mac`s that are followed by semicolons and those that aren't.
authorPaul Stansifer <paul.stansifer@gmail.com>
Wed, 21 Nov 2012 18:37:43 +0000 (13:37 -0500)
committerGraydon Hoare <graydon@mozilla.com>
Thu, 29 Nov 2012 20:09:10 +0000 (12:09 -0800)
src/libsyntax/ast.rs
src/libsyntax/ast_util.rs
src/libsyntax/ext/expand.rs
src/libsyntax/fold.rs
src/libsyntax/parse/parser.rs
src/libsyntax/print/pprust.rs
src/libsyntax/visit.rs

index bc3ae65618a2f10fd401db1263ccf4fde50e9698..252ccdc3e1bbfcb8b90e7934210e831bf4452629 100644 (file)
@@ -666,7 +666,8 @@ enum stmt_ {
     // 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
index e6cd413c430728538525723293f796a2aaa18573..5686ea11bc544e45de54ffedc05be44c313e8335 100644 (file)
@@ -40,7 +40,7 @@
       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",
     }
 }
 
index 07290c9248b61edee1fc3677dd9c837f5ccf217c..0d5b0070d2fe3cebee39999664fa98b4a7556972 100644 (file)
@@ -272,12 +272,12 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
                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]);
@@ -287,8 +287,10 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
 
         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,
index a92c902ae3fbaa95b7a78bcef67eabd56518fb9e..b3ab5897045dc5b5d2de1078e7a3eec0e7414523 100644 (file)
@@ -310,7 +310,7 @@ fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
       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)
     };
 }
 
index b548695d187188d4163ce05a1723a1b2bf4b5d82..6851bebccc36f5afb4b5821d9582b6914757329f 100644 (file)
@@ -2228,7 +2228,7 @@ fn check_expected_item(p: Parser, current_attrs: ~[attribute]) {
 
             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(
@@ -2380,12 +2380,13 @@ fn parse_block_tail_(lo: BytePos, s: blk_check_mode,
                             }
                         }
 
-                        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
index b55eec80a93028f7f2fe6f8e6f803bcb37892811..75b962bcc93421c40d14a610350462adf46211b3 100644 (file)
@@ -882,9 +882,10 @@ fn print_stmt(s: ps, st: ast::stmt) {
         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, ~";"); }
index ca2af67771ea40af731ad2279ac00a9a2a749eec..2ddeba1f1cbbbc5c8f5cd9e35b42c995286ec6d9 100644 (file)
@@ -348,7 +348,7 @@ fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
       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)
     }
 }