1
+ import std:: uint;
1
2
import std:: vec;
2
3
import std:: str;
3
4
import std:: io;
@@ -30,6 +31,7 @@ const uint default_columns = 78u;
30
31
tag mode {
31
32
mo_untyped;
32
33
mo_typed ( ty:: ctxt) ;
34
+ mo_identified;
33
35
}
34
36
35
37
type ps = @rec ( pp:: printer s,
@@ -161,6 +163,16 @@ fn bclose(&ps s, common::span span) {
161
163
end ( s) ; // close the outer-box
162
164
}
163
165
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
+
164
176
fn commasep[ IN ] ( & ps s, breaks b, vec[ IN ] elts, fn ( & ps, & IN ) op) {
165
177
box ( s, 0 u, b) ;
166
178
auto first = true ;
@@ -503,6 +515,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
503
515
alt ( s. mode ) {
504
516
case ( mo_untyped) { /* no-op */ }
505
517
case ( mo_typed ( _) ) { popen ( s) ; }
518
+ case ( mo_identified) { popen ( s) ; }
506
519
}
507
520
508
521
alt ( expr. node ) {
@@ -844,7 +857,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
844
857
}
845
858
}
846
859
847
- // Print the type if necessary.
860
+ // Print the type or node ID if necessary.
848
861
alt ( s. mode ) {
849
862
case ( mo_untyped) { /* no-op */ }
850
863
case ( mo_typed ( ?tcx) ) {
@@ -854,6 +867,11 @@ fn print_expr(&ps s, &@ast::expr expr) {
854
867
word ( s. s , ty:: ty_to_str ( tcx, ty:: expr_ty ( tcx, expr) ) ) ;
855
868
pclose ( s) ;
856
869
}
870
+ case ( mo_identified) {
871
+ space ( s. s ) ;
872
+ synth_comment ( s, uint:: to_str ( ty:: expr_ann ( expr) . id , 10 u) ) ;
873
+ pclose ( s) ;
874
+ }
857
875
}
858
876
859
877
end ( s) ;
@@ -874,14 +892,15 @@ fn print_decl(&ps s, &@ast::decl decl) {
874
892
case ( _) {
875
893
word_nbsp ( s, "auto" ) ;
876
894
877
- // Print the type if necessary.
895
+ // Print the type or node ID if necessary.
878
896
alt ( s. mode ) {
879
897
case ( mo_untyped) { /* no-op */ }
880
898
case ( mo_typed ( ?tcx) ) {
881
899
auto lty =
882
900
ty:: ann_to_type ( tcx. node_types , loc. ann ) ;
883
901
word_space ( s, ty:: ty_to_str ( tcx, lty) ) ;
884
902
}
903
+ case ( mo_identified) { /* no-op */ }
885
904
}
886
905
}
887
906
}
0 commit comments