@@ -42,6 +42,7 @@ pub enum PpSourceMode {
4242 PpmTyped ,
4343 PpmIdentified ,
4444 PpmExpandedIdentified ,
45+ PpmExpandedHygiene ,
4546}
4647
4748#[ deriving( PartialEq , Show ) ]
@@ -59,6 +60,7 @@ pub fn parse_pretty(sess: &Session, name: &str) -> (PpMode, Option<UserIdentifie
5960 "expanded" => PpmSource ( PpmExpanded ) ,
6061 "typed" => PpmSource ( PpmTyped ) ,
6162 "expanded,identified" => PpmSource ( PpmExpandedIdentified ) ,
63+ "expanded,hygiene" => PpmSource ( PpmExpandedHygiene ) ,
6264 "identified" => PpmSource ( PpmIdentified ) ,
6365 "flowgraph" => PpmFlowGraph ,
6466 _ => {
@@ -106,6 +108,10 @@ impl PpSourceMode {
106108 let annotation = IdentifiedAnnotation { sess : sess, ast_map : ast_map } ;
107109 f ( & annotation, payload)
108110 }
111+ PpmExpandedHygiene => {
112+ let annotation = HygieneAnnotation { sess : sess, ast_map : ast_map } ;
113+ f ( & annotation, payload)
114+ }
109115 PpmTyped => {
110116 let ast_map = ast_map. expect ( "--pretty=typed missing ast_map" ) ;
111117 let analysis = driver:: phase_3_run_analysis_passes ( sess, krate, ast_map, id) ;
@@ -191,6 +197,8 @@ impl pprust::PpAnn for IdentifiedAnnotation {
191197 s : & mut pprust:: State ,
192198 node : pprust:: AnnNode ) -> io:: IoResult < ( ) > {
193199 match node {
200+ pprust:: NodeIdent ( _) | pprust:: NodeName ( _) => Ok ( ( ) ) ,
201+
194202 pprust:: NodeItem ( item) => {
195203 try!( pp:: space ( & mut s. s ) ) ;
196204 s. synth_comment ( item. id . to_string ( ) )
@@ -212,6 +220,46 @@ impl pprust::PpAnn for IdentifiedAnnotation {
212220 }
213221}
214222
223+ struct HygieneAnnotation {
224+ sess : Session ,
225+ ast_map : Option < ast_map:: Map > ,
226+ }
227+
228+ impl PrinterSupport for HygieneAnnotation {
229+ fn pp_ann < ' a > ( & ' a self ) -> & ' a pprust:: PpAnn { self as & pprust:: PpAnn }
230+ }
231+
232+ impl SessionCarrier for HygieneAnnotation {
233+ fn sess < ' a > ( & ' a self ) -> & ' a Session { & self . sess }
234+ }
235+
236+ impl AstMapCarrier for HygieneAnnotation {
237+ fn ast_map < ' a > ( & ' a self ) -> Option < & ' a ast_map:: Map > {
238+ self . ast_map . as_ref ( )
239+ }
240+ }
241+
242+ impl pprust:: PpAnn for HygieneAnnotation {
243+ fn post ( & self ,
244+ s : & mut pprust:: State ,
245+ node : pprust:: AnnNode ) -> io:: IoResult < ( ) > {
246+ match node {
247+ pprust:: NodeIdent ( & ast:: Ident { name : ast:: Name ( nm) , ctxt } ) => {
248+ try!( pp:: space ( & mut s. s ) ) ;
249+ // FIXME #16420: this doesn't display the connections
250+ // between syntax contexts
251+ s. synth_comment ( format ! ( "{}#{}" , nm, ctxt) )
252+ }
253+ pprust:: NodeName ( & ast:: Name ( nm) ) => {
254+ try!( pp:: space ( & mut s. s ) ) ;
255+ s. synth_comment ( nm. to_string ( ) )
256+ }
257+ _ => Ok ( ( ) )
258+ }
259+ }
260+ }
261+
262+
215263struct TypedAnnotation {
216264 analysis : CrateAnalysis ,
217265}
@@ -364,6 +412,7 @@ fn needs_ast_map(ppm: &PpMode, opt_uii: &Option<UserIdentifiedItem>) -> bool {
364412
365413 PpmSource ( PpmExpanded ) |
366414 PpmSource ( PpmExpandedIdentified ) |
415+ PpmSource ( PpmExpandedHygiene ) |
367416 PpmSource ( PpmTyped ) |
368417 PpmFlowGraph => true
369418 }
@@ -376,6 +425,7 @@ fn needs_expansion(ppm: &PpMode) -> bool {
376425
377426 PpmSource ( PpmExpanded ) |
378427 PpmSource ( PpmExpandedIdentified ) |
428+ PpmSource ( PpmExpandedHygiene ) |
379429 PpmSource ( PpmTyped ) |
380430 PpmFlowGraph => true
381431 }
0 commit comments