diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index aa02afe00cb1..0d5223d87023 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -37,6 +37,7 @@ import back::link::output_type; 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) { diff --git a/src/comp/pretty/pprust.rs b/src/comp/pretty/pprust.rs index 6a957d4553f9..ed73cb936b22 100644 --- a/src/comp/pretty/pprust.rs +++ b/src/comp/pretty/pprust.rs @@ -1,3 +1,4 @@ +import std::uint; import std::vec; import std::str; import std::io; @@ -30,6 +31,7 @@ const uint default_columns = 78u; 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 print_expr(&ps s, &@ast::expr expr) { } } - // 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 print_expr(&ps s, &@ast::expr expr) { 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 */ } } } }