Skip to content

Commit 4e482a8

Browse files
committed
---
yaml --- r: 2903 b: refs/heads/master c: 78374d1 h: refs/heads/master i: 2901: 6414699 2899: ccdd411 2895: ef2adb1 v: v3
1 parent 196379c commit 4e482a8

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: eae3036179ae56876104775c45f120e769de51aa
2+
refs/heads/master: 78374d11ce02ae686035cd8489b58de4c2282b40

trunk/src/comp/driver/rustc.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import back::link::output_type;
3737
tag pp_mode {
3838
ppm_normal;
3939
ppm_typed;
40+
ppm_identified;
4041
}
4142

4243
fn default_environment(session::session sess,
@@ -132,6 +133,7 @@ fn pretty_print_input(session::session sess, eval::env env, str input,
132133
mode = pprust::mo_typed(ty_cx);
133134
}
134135
case (ppm_normal) { mode = pprust::mo_untyped; }
136+
case (ppm_identified) { mode = pprust::mo_identified; }
135137
}
136138

137139
pprust::print_file(sess, crate.node.module, input, std::io::stdout(),
@@ -313,9 +315,10 @@ fn build_session(@session::options sopts) -> session::session {
313315
fn parse_pretty(session::session sess, &str name) -> pp_mode {
314316
if (str::eq(name, "normal")) { ret ppm_normal; }
315317
else if (str::eq(name, "typed")) { ret ppm_typed; }
316-
else {
317-
sess.err("argument to `pretty` must be either `normal` or `typed`");
318-
}
318+
else if (str::eq(name, "identified")) { ret ppm_identified; }
319+
320+
sess.err("argument to `pretty` must be one of `normal`, `typed`, or " +
321+
"`identified`");
319322
}
320323

321324
fn main(vec[str] args) {

trunk/src/comp/pretty/pprust.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import std::uint;
12
import std::vec;
23
import std::str;
34
import std::io;
@@ -30,6 +31,7 @@ const uint default_columns = 78u;
3031
tag mode {
3132
mo_untyped;
3233
mo_typed(ty::ctxt);
34+
mo_identified;
3335
}
3436

3537
type ps = @rec(pp::printer s,
@@ -161,6 +163,16 @@ fn bclose(&ps s, common::span span) {
161163
end(s); // close the outer-box
162164
}
163165

166+
// Synthesizes a comment that was not textually present in the original source
167+
// file.
168+
fn synth_comment(&ps s, str text) {
169+
word(s.s, "/*");
170+
space(s.s);
171+
word(s.s, text);
172+
space(s.s);
173+
word(s.s, "*/");
174+
}
175+
164176
fn commasep[IN](&ps s, breaks b, vec[IN] elts, fn(&ps, &IN) op) {
165177
box(s, 0u, b);
166178
auto first = true;
@@ -503,6 +515,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
503515
alt (s.mode) {
504516
case (mo_untyped) { /* no-op */ }
505517
case (mo_typed(_)) { popen(s); }
518+
case (mo_identified) { popen(s); }
506519
}
507520

508521
alt (expr.node) {
@@ -844,7 +857,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
844857
}
845858
}
846859

847-
// Print the type if necessary.
860+
// Print the type or node ID if necessary.
848861
alt (s.mode) {
849862
case (mo_untyped) { /* no-op */ }
850863
case (mo_typed(?tcx)) {
@@ -854,6 +867,11 @@ fn print_expr(&ps s, &@ast::expr expr) {
854867
word(s.s, ty::ty_to_str(tcx, ty::expr_ty(tcx, expr)));
855868
pclose(s);
856869
}
870+
case (mo_identified) {
871+
space(s.s);
872+
synth_comment(s, uint::to_str(ty::expr_ann(expr).id, 10u));
873+
pclose(s);
874+
}
857875
}
858876

859877
end(s);
@@ -874,14 +892,15 @@ fn print_decl(&ps s, &@ast::decl decl) {
874892
case (_) {
875893
word_nbsp(s, "auto");
876894

877-
// Print the type if necessary.
895+
// Print the type or node ID if necessary.
878896
alt (s.mode) {
879897
case (mo_untyped) { /* no-op */ }
880898
case (mo_typed(?tcx)) {
881899
auto lty =
882900
ty::ann_to_type(tcx.node_types, loc.ann);
883901
word_space(s, ty::ty_to_str(tcx, lty));
884902
}
903+
case (mo_identified) { /* no-op */ }
885904
}
886905
}
887906
}

0 commit comments

Comments
 (0)