Skip to content

Commit ee076f6

Browse files
paulstansifergraydon
authored andcommitted
Allow for macros to occur in statement position.
1 parent fca5255 commit ee076f6

File tree

13 files changed

+33
-17
lines changed

13 files changed

+33
-17
lines changed

src/librustc/middle/astencode.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
242242
match stmt.node {
243243
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
244244
ast::stmt_decl(@{node: ast::decl_local(_), span: _}, _) => true,
245-
ast::stmt_decl(@{node: ast::decl_item(_), span: _}, _) => false
245+
ast::stmt_decl(@{node: ast::decl_item(_), span: _}, _) => false,
246+
ast::stmt_mac(*) => fail ~"unexpanded macro in astencode"
246247
}
247248
};
248249
let blk_sans_items = { stmts: stmts_sans_items,.. blk };

src/librustc/middle/liveness.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,10 @@ impl Liveness {
980980
stmt_expr(expr, _) | stmt_semi(expr, _) => {
981981
return self.propagate_through_expr(expr, succ);
982982
}
983+
984+
stmt_mac(*) => {
985+
self.tcx.sess.span_bug(stmt.span, ~"unexpanded macro");
986+
}
983987
}
984988
}
985989

src/librustc/middle/region.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ fn resolve_stmt(stmt: @ast::stmt, cx: ctxt, visitor: visit::vt<ctxt>) {
245245
expr_cx.parent = Some(stmt_id);
246246
visit::visit_stmt(stmt, expr_cx, visitor);
247247
}
248+
ast::stmt_mac(*) => cx.sess.bug(~"unexpanded macro")
248249
}
249250
}
250251

src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,7 @@ fn trans_stmt(cx: block, s: ast::stmt) -> block {
10261026
ast::decl_item(i) => trans_item(cx.fcx.ccx, *i)
10271027
}
10281028
}
1029+
ast::stmt_mac(*) => cx.tcx().sess.bug(~"unexpanded macro")
10291030
}
10301031

10311032
return bcx;

src/librustc/middle/ty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3437,6 +3437,7 @@ fn stmt_node_id(s: @ast::stmt) -> ast::node_id {
34373437
ast::stmt_decl(_, id) | stmt_expr(_, id) | stmt_semi(_, id) => {
34383438
return id;
34393439
}
3440+
ast::stmt_mac(*) => fail ~"unexpanded macro in trans"
34403441
}
34413442
}
34423443

src/librustc/middle/typeck/check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,6 +2344,7 @@ fn check_stmt(fcx: @fn_ctxt, stmt: @ast::stmt) -> bool {
23442344
node_id = id;
23452345
bot = check_expr(fcx, expr, None);
23462346
}
2347+
ast::stmt_mac(*) => fcx.ccx.tcx.sess.bug(~"unexpanded macro")
23472348
}
23482349
fcx.write_nil(node_id);
23492350
return bot;

src/librusti/rusti.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn record(repl: Repl, blk: @ast::blk, intr: @token::ident_interner) -> Repl {
8686
let new_stmts = do with_pp(intr) |pp, writer| {
8787
for blk.node.stmts.each |stmt| {
8888
match stmt.node {
89-
ast::stmt_decl(*) => {
89+
ast::stmt_decl(*) | ast::stmt_mac(*) => {
9090
pprust::print_stmt(pp, **stmt);
9191
writer.write_line(~"");
9292
}

src/libsyntax/ast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ enum stmt_ {
665665

666666
// expr with trailing semi-colon (may have any type):
667667
stmt_semi(@expr, node_id),
668+
669+
stmt_mac(mac),
668670
}
669671

670672
// FIXME (pending discussion of #1697, #2178...): local should really be

src/libsyntax/ast_util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ pure fn stmt_id(s: stmt) -> node_id {
3939
match s.node {
4040
stmt_decl(_, id) => id,
4141
stmt_expr(_, id) => id,
42-
stmt_semi(_, id) => id
42+
stmt_semi(_, id) => id,
43+
stmt_mac(_) => fail ~"attempted to analyze unexpanded stmt",
4344
}
4445
}
4546

src/libsyntax/fold.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,12 @@ fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ {
305305
}
306306

307307
fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
308+
let fold_mac = |x| fold_mac_(x, fld);
308309
return match s {
309310
stmt_decl(d, nid) => stmt_decl(fld.fold_decl(d), fld.new_id(nid)),
310311
stmt_expr(e, nid) => stmt_expr(fld.fold_expr(e), fld.new_id(nid)),
311-
stmt_semi(e, nid) => stmt_semi(fld.fold_expr(e), fld.new_id(nid))
312+
stmt_semi(e, nid) => stmt_semi(fld.fold_expr(e), fld.new_id(nid)),
313+
stmt_mac(mac) => stmt_mac(fold_mac(mac))
312314
};
313315
}
314316

src/libsyntax/parse/classify.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@ fn expr_is_simple_block(e: @ast::expr) -> bool {
2121
}
2222

2323
fn stmt_ends_with_semi(stmt: ast::stmt) -> bool {
24-
match stmt.node {
25-
ast::stmt_decl(d, _) => {
26-
return match d.node {
27-
ast::decl_local(_) => true,
28-
ast::decl_item(_) => false
24+
return match stmt.node {
25+
ast::stmt_decl(d, _) => {
26+
match d.node {
27+
ast::decl_local(_) => true,
28+
ast::decl_item(_) => false
2929
}
30-
}
31-
ast::stmt_expr(e, _) => {
32-
return expr_requires_semi_to_be_stmt(e);
33-
}
34-
ast::stmt_semi(*) => {
35-
return false;
36-
}
30+
}
31+
ast::stmt_expr(e, _) => { expr_requires_semi_to_be_stmt(e) }
32+
ast::stmt_semi(*) => { false }
33+
ast::stmt_mac(*) => { false }
3734
}
3835
}

src/libsyntax/print/pprust.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,10 @@ fn print_stmt(s: ps, st: ast::stmt) {
882882
print_expr(s, expr);
883883
word(s.s, ~";");
884884
}
885+
ast::stmt_mac(mac) => {
886+
space_if_not_bol(s);
887+
print_mac(s, mac);
888+
}
885889
}
886890
if parse::classify::stmt_ends_with_semi(st) { word(s.s, ~";"); }
887891
maybe_print_trailing_comment(s, st.span, None);

src/libsyntax/visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
347347
match s.node {
348348
stmt_decl(d, _) => v.visit_decl(d, e, v),
349349
stmt_expr(ex, _) => v.visit_expr(ex, e, v),
350-
stmt_semi(ex, _) => v.visit_expr(ex, e, v)
350+
stmt_semi(ex, _) => v.visit_expr(ex, e, v),
351+
stmt_mac(mac) => visit_mac(mac, e, v)
351352
}
352353
}
353354

0 commit comments

Comments
 (0)