提交 78374d11 编写于 作者: P Patrick Walton

rustc: Add a new mode to the pretty printer that prints out node IDs, for debugging

上级 eae30361
......@@ -37,6 +37,7 @@
tag pp_mode {
ppm_normal;
ppm_typed;
ppm_identified;
}
fn default_environment(session::session sess,
......@@ -132,6 +133,7 @@ fn pretty_print_input(session::session sess, eval::env env, str input,
mode = pprust::mo_typed(ty_cx);
}
case (ppm_normal) { mode = pprust::mo_untyped; }
case (ppm_identified) { mode = pprust::mo_identified; }
}
pprust::print_file(sess, crate.node.module, input, std::io::stdout(),
......@@ -313,9 +315,10 @@ fn build_session(@session::options sopts) -> session::session {
fn parse_pretty(session::session sess, &str name) -> pp_mode {
if (str::eq(name, "normal")) { ret ppm_normal; }
else if (str::eq(name, "typed")) { ret ppm_typed; }
else {
sess.err("argument to `pretty` must be either `normal` or `typed`");
}
else if (str::eq(name, "identified")) { ret ppm_identified; }
sess.err("argument to `pretty` must be one of `normal`, `typed`, or " +
"`identified`");
}
fn main(vec[str] args) {
......
import std::uint;
import std::vec;
import std::str;
import std::io;
......@@ -30,6 +31,7 @@
tag mode {
mo_untyped;
mo_typed(ty::ctxt);
mo_identified;
}
type ps = @rec(pp::printer s,
......@@ -161,6 +163,16 @@ fn bclose(&ps s, common::span span) {
end(s); // close the outer-box
}
// Synthesizes a comment that was not textually present in the original source
// file.
fn synth_comment(&ps s, str text) {
word(s.s, "/*");
space(s.s);
word(s.s, text);
space(s.s);
word(s.s, "*/");
}
fn commasep[IN](&ps s, breaks b, vec[IN] elts, fn(&ps, &IN) op) {
box(s, 0u, b);
auto first = true;
......@@ -503,6 +515,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
alt (s.mode) {
case (mo_untyped) { /* no-op */ }
case (mo_typed(_)) { popen(s); }
case (mo_identified) { popen(s); }
}
alt (expr.node) {
......@@ -844,7 +857,7 @@ fn do_else(&ps s, option::t[@ast::expr] els) {
}
}
// Print the type if necessary.
// Print the type or node ID if necessary.
alt (s.mode) {
case (mo_untyped) { /* no-op */ }
case (mo_typed(?tcx)) {
......@@ -854,6 +867,11 @@ fn do_else(&ps s, option::t[@ast::expr] els) {
word(s.s, ty::ty_to_str(tcx, ty::expr_ty(tcx, expr)));
pclose(s);
}
case (mo_identified) {
space(s.s);
synth_comment(s, uint::to_str(ty::expr_ann(expr).id, 10u));
pclose(s);
}
}
end(s);
......@@ -874,7 +892,7 @@ fn print_decl(&ps s, &@ast::decl decl) {
case (_) {
word_nbsp(s, "auto");
// Print the type if necessary.
// Print the type or node ID if necessary.
alt (s.mode) {
case (mo_untyped) { /* no-op */ }
case (mo_typed(?tcx)) {
......@@ -882,6 +900,7 @@ fn print_decl(&ps s, &@ast::decl decl) {
ty::ann_to_type(tcx.node_types, loc.ann);
word_space(s, ty::ty_to_str(tcx, lty));
}
case (mo_identified) { /* no-op */ }
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册