Skip to content

Commit d631f29

Browse files
committed
Add block_to_str and expr_to_str methods to the pprust module.
Since pprust is authed impure these can be used for debug logging.
1 parent 2490cd3 commit d631f29

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/comp/pretty/pprust.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@ fn ty_to_str(&@ast.ty ty) -> str {
3232
ret writer.get_str();
3333
}
3434

35+
fn block_to_str(&ast.block blk) -> str {
36+
auto writer = io.string_writer();
37+
auto s = @rec(s=pp.mkstate(writer.get_writer(), 78u),
38+
comments=option.none[vec[lexer.cmnt]],
39+
mutable cur_cmnt=0u);
40+
print_block(s, blk);
41+
ret writer.get_str();
42+
}
43+
44+
fn expr_to_str(&@ast.expr e) -> str {
45+
auto writer = io.string_writer();
46+
auto s = @rec(s=pp.mkstate(writer.get_writer(), 78u),
47+
comments=option.none[vec[lexer.cmnt]],
48+
mutable cur_cmnt=0u);
49+
print_expr(s, e);
50+
ret writer.get_str();
51+
}
52+
3553
impure fn hbox(ps s) {
3654
pp.hbox(s.s, indent_unit);
3755
}

0 commit comments

Comments
 (0)