@@ -34,6 +34,7 @@ use syntax::ptr::P;
34
34
35
35
use graphviz as dot;
36
36
37
+ use std:: borrow:: { Cow , IntoCow } ;
37
38
use std:: old_io:: { self , BufReader } ;
38
39
use std:: option;
39
40
use std:: str:: FromStr ;
@@ -44,6 +45,7 @@ pub enum PpSourceMode {
44
45
PpmEveryBodyLoops ,
45
46
PpmExpanded ,
46
47
PpmTyped ,
48
+ PpmTypedUnsuffixedLiterals ,
47
49
PpmIdentified ,
48
50
PpmExpandedIdentified ,
49
51
PpmExpandedHygiene ,
@@ -76,6 +78,7 @@ pub fn parse_pretty(sess: &Session,
76
78
( "everybody_loops" , true ) => PpmSource ( PpmEveryBodyLoops ) ,
77
79
( "expanded" , _) => PpmSource ( PpmExpanded ) ,
78
80
( "typed" , _) => PpmSource ( PpmTyped ) ,
81
+ ( "typed,unsuffixed_literals" , true ) => PpmSource ( PpmTypedUnsuffixedLiterals ) ,
79
82
( "expanded,identified" , _) => PpmSource ( PpmExpandedIdentified ) ,
80
83
( "expanded,hygiene" , _) => PpmSource ( PpmExpandedHygiene ) ,
81
84
( "identified" , _) => PpmSource ( PpmIdentified ) ,
@@ -85,7 +88,8 @@ pub fn parse_pretty(sess: &Session,
85
88
if extended {
86
89
sess. fatal ( & format ! (
87
90
"argument to `xpretty` must be one of `normal`, \
88
- `expanded`, `flowgraph[,unlabelled]=<nodeid>`, `typed`, `identified`, \
91
+ `expanded`, `flowgraph[,unlabelled]=<nodeid>`, `typed`, \
92
+ `typed,unsuffixed_literals`, `identified`, \
89
93
`expanded,identified`, or `everybody_loops`; got {}", name) ) ;
90
94
} else {
91
95
sess. fatal ( & format ! (
@@ -163,6 +167,7 @@ impl pprust::PpAnn for HygieneAnnotation {
163
167
}
164
168
}
165
169
170
+ #[ derive( Copy ) ]
166
171
struct TypedAnnotation < ' a , ' tcx : ' a > {
167
172
tcx : & ' a ty:: ctxt < ' tcx > ,
168
173
}
@@ -193,6 +198,44 @@ impl<'a, 'tcx> pprust::PpAnn for TypedAnnotation<'a, 'tcx> {
193
198
}
194
199
}
195
200
201
+ struct UnsuffixedLitAnnotation < A > {
202
+ ann : A
203
+ }
204
+
205
+ impl < A : pprust:: PpAnn > pprust:: PpAnn for UnsuffixedLitAnnotation < A > {
206
+ fn pre ( & self ,
207
+ s : & mut pprust:: State ,
208
+ node : pprust:: AnnNode ) -> old_io:: IoResult < ( ) > {
209
+ self . ann . pre ( s, node)
210
+ }
211
+ fn post ( & self ,
212
+ s : & mut pprust:: State ,
213
+ node : pprust:: AnnNode ) -> old_io:: IoResult < ( ) > {
214
+ self . ann . post ( s, node)
215
+ }
216
+ fn literal_to_string < ' a > ( & self ,
217
+ s : & mut pprust:: State ,
218
+ lit : & ' a ast:: Lit ) -> Cow < ' a , str > {
219
+ match lit. node {
220
+ ast:: LitInt ( i, t) => {
221
+ match t {
222
+ ast:: UnsignedIntLit ( _) |
223
+ ast:: SignedIntLit ( _, ast:: Plus ) |
224
+ ast:: UnsuffixedIntLit ( ast:: Plus ) => {
225
+ format ! ( "{}" , i)
226
+ }
227
+ ast:: SignedIntLit ( _, ast:: Minus ) |
228
+ ast:: UnsuffixedIntLit ( ast:: Minus ) => {
229
+ format ! ( "-{}" , i)
230
+ }
231
+ } . into_cow ( )
232
+ }
233
+ ast:: LitFloat ( ref f, _) => f. into_cow ( ) ,
234
+ _ => self . ann . literal_to_string ( s, lit)
235
+ }
236
+ }
237
+ }
238
+
196
239
fn gather_flowgraph_variants ( sess : & Session ) -> Vec < borrowck_dot:: Variant > {
197
240
let print_loans = sess. opts . debugging_opts . flowgraph_print_loans ;
198
241
let print_moves = sess. opts . debugging_opts . flowgraph_print_moves ;
@@ -374,6 +417,7 @@ pub fn printing_phase<'a, 'b>(control: &'a mut driver::CompileController<'b>,
374
417
}
375
418
376
419
PpmSource ( PpmTyped ) |
420
+ PpmSource ( PpmTypedUnsuffixedLiterals ) |
377
421
PpmFlowGraph ( _) => {
378
422
& mut control. after_analysis
379
423
}
@@ -405,7 +449,10 @@ pub fn print_from_phase(state: driver::CompileState,
405
449
PpmSource ( mode) => {
406
450
debug ! ( "pretty printing source code {:?}" , mode) ;
407
451
408
- let typed_annotation = state. tcx . map ( |tcx| TypedAnnotation { tcx : tcx } ) ;
452
+ let typed_ann = state. tcx . map ( |tcx| TypedAnnotation { tcx : tcx } ) ;
453
+ let typed_unsuffixed_lit_ann = typed_ann. map ( |ann| {
454
+ UnsuffixedLitAnnotation { ann : ann }
455
+ } ) ;
409
456
let annotation: & pprust:: PpAnn = match mode {
410
457
PpmNormal | PpmEveryBodyLoops | PpmExpanded => {
411
458
NO_ANNOTATION
@@ -417,7 +464,11 @@ pub fn print_from_phase(state: driver::CompileState,
417
464
HYGIENE_ANNOTATION
418
465
}
419
466
PpmTyped => {
420
- typed_annotation. as_ref ( ) . expect ( "--pretty=typed missing type context" )
467
+ typed_ann. as_ref ( ) . expect ( "--pretty=typed missing type context" )
468
+ }
469
+ PpmTypedUnsuffixedLiterals => {
470
+ typed_unsuffixed_lit_ann. as_ref ( ) . expect (
471
+ "--xpretty=typed,unsuffixed_literals missing type context" )
421
472
}
422
473
} ;
423
474
0 commit comments