1
Fork 0

Allow for macros to occur in statement position.

This commit is contained in:
Paul Stansifer 2012-11-12 23:06:55 -05:00 committed by Graydon Hoare
parent fca52554e7
commit ee076f63f9
13 changed files with 33 additions and 17 deletions

View file

@ -242,7 +242,8 @@ fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
match stmt.node { match stmt.node {
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) | ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
ast::stmt_decl(@{node: ast::decl_local(_), span: _}, _) => true, ast::stmt_decl(@{node: ast::decl_local(_), span: _}, _) => true,
ast::stmt_decl(@{node: ast::decl_item(_), span: _}, _) => false ast::stmt_decl(@{node: ast::decl_item(_), span: _}, _) => false,
ast::stmt_mac(*) => fail ~"unexpanded macro in astencode"
} }
}; };
let blk_sans_items = { stmts: stmts_sans_items,.. blk }; let blk_sans_items = { stmts: stmts_sans_items,.. blk };

View file

@ -980,6 +980,10 @@ impl Liveness {
stmt_expr(expr, _) | stmt_semi(expr, _) => { stmt_expr(expr, _) | stmt_semi(expr, _) => {
return self.propagate_through_expr(expr, succ); return self.propagate_through_expr(expr, succ);
} }
stmt_mac(*) => {
self.tcx.sess.span_bug(stmt.span, ~"unexpanded macro");
}
} }
} }

View file

@ -245,6 +245,7 @@ fn resolve_stmt(stmt: @ast::stmt, cx: ctxt, visitor: visit::vt<ctxt>) {
expr_cx.parent = Some(stmt_id); expr_cx.parent = Some(stmt_id);
visit::visit_stmt(stmt, expr_cx, visitor); visit::visit_stmt(stmt, expr_cx, visitor);
} }
ast::stmt_mac(*) => cx.sess.bug(~"unexpanded macro")
} }
} }

View file

@ -1026,6 +1026,7 @@ fn trans_stmt(cx: block, s: ast::stmt) -> block {
ast::decl_item(i) => trans_item(cx.fcx.ccx, *i) ast::decl_item(i) => trans_item(cx.fcx.ccx, *i)
} }
} }
ast::stmt_mac(*) => cx.tcx().sess.bug(~"unexpanded macro")
} }
return bcx; return bcx;

View file

@ -3437,6 +3437,7 @@ fn stmt_node_id(s: @ast::stmt) -> ast::node_id {
ast::stmt_decl(_, id) | stmt_expr(_, id) | stmt_semi(_, id) => { ast::stmt_decl(_, id) | stmt_expr(_, id) | stmt_semi(_, id) => {
return id; return id;
} }
ast::stmt_mac(*) => fail ~"unexpanded macro in trans"
} }
} }

View file

@ -2344,6 +2344,7 @@ fn check_stmt(fcx: @fn_ctxt, stmt: @ast::stmt) -> bool {
node_id = id; node_id = id;
bot = check_expr(fcx, expr, None); bot = check_expr(fcx, expr, None);
} }
ast::stmt_mac(*) => fcx.ccx.tcx.sess.bug(~"unexpanded macro")
} }
fcx.write_nil(node_id); fcx.write_nil(node_id);
return bot; return bot;

View file

@ -86,7 +86,7 @@ fn record(repl: Repl, blk: @ast::blk, intr: @token::ident_interner) -> Repl {
let new_stmts = do with_pp(intr) |pp, writer| { let new_stmts = do with_pp(intr) |pp, writer| {
for blk.node.stmts.each |stmt| { for blk.node.stmts.each |stmt| {
match stmt.node { match stmt.node {
ast::stmt_decl(*) => { ast::stmt_decl(*) | ast::stmt_mac(*) => {
pprust::print_stmt(pp, **stmt); pprust::print_stmt(pp, **stmt);
writer.write_line(~""); writer.write_line(~"");
} }

View file

@ -665,6 +665,8 @@ enum stmt_ {
// expr with trailing semi-colon (may have any type): // expr with trailing semi-colon (may have any type):
stmt_semi(@expr, node_id), stmt_semi(@expr, node_id),
stmt_mac(mac),
} }
// FIXME (pending discussion of #1697, #2178...): local should really be // FIXME (pending discussion of #1697, #2178...): local should really be

View file

@ -39,7 +39,8 @@ pure fn stmt_id(s: stmt) -> node_id {
match s.node { match s.node {
stmt_decl(_, id) => id, stmt_decl(_, id) => id,
stmt_expr(_, id) => id, stmt_expr(_, id) => id,
stmt_semi(_, id) => id stmt_semi(_, id) => id,
stmt_mac(_) => fail ~"attempted to analyze unexpanded stmt",
} }
} }

View file

@ -305,10 +305,12 @@ fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ {
} }
fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ { fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
let fold_mac = |x| fold_mac_(x, fld);
return match s { return match s {
stmt_decl(d, nid) => stmt_decl(fld.fold_decl(d), fld.new_id(nid)), 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_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_semi(e, nid) => stmt_semi(fld.fold_expr(e), fld.new_id(nid)),
stmt_mac(mac) => stmt_mac(fold_mac(mac))
}; };
} }

View file

@ -21,18 +21,15 @@ fn expr_is_simple_block(e: @ast::expr) -> bool {
} }
fn stmt_ends_with_semi(stmt: ast::stmt) -> bool { fn stmt_ends_with_semi(stmt: ast::stmt) -> bool {
match stmt.node { return match stmt.node {
ast::stmt_decl(d, _) => { ast::stmt_decl(d, _) => {
return match d.node { match d.node {
ast::decl_local(_) => true, ast::decl_local(_) => true,
ast::decl_item(_) => false ast::decl_item(_) => false
} }
} }
ast::stmt_expr(e, _) => { ast::stmt_expr(e, _) => { expr_requires_semi_to_be_stmt(e) }
return expr_requires_semi_to_be_stmt(e); ast::stmt_semi(*) => { false }
} ast::stmt_mac(*) => { false }
ast::stmt_semi(*) => {
return false;
}
} }
} }

View file

@ -882,6 +882,10 @@ fn print_stmt(s: ps, st: ast::stmt) {
print_expr(s, expr); print_expr(s, expr);
word(s.s, ~";"); word(s.s, ~";");
} }
ast::stmt_mac(mac) => {
space_if_not_bol(s);
print_mac(s, mac);
}
} }
if parse::classify::stmt_ends_with_semi(st) { word(s.s, ~";"); } if parse::classify::stmt_ends_with_semi(st) { word(s.s, ~";"); }
maybe_print_trailing_comment(s, st.span, None); maybe_print_trailing_comment(s, st.span, None);

View file

@ -347,7 +347,8 @@ fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
match s.node { match s.node {
stmt_decl(d, _) => v.visit_decl(d, e, v), stmt_decl(d, _) => v.visit_decl(d, e, v),
stmt_expr(ex, _) => v.visit_expr(ex, e, v), stmt_expr(ex, _) => v.visit_expr(ex, e, v),
stmt_semi(ex, _) => v.visit_expr(ex, e, v) stmt_semi(ex, _) => v.visit_expr(ex, e, v),
stmt_mac(mac) => visit_mac(mac, e, v)
} }
} }