@@ -81,6 +81,7 @@ pub enum PpMode {
8181 PpmFlowGraph ( PpFlowGraphMode ) ,
8282 PpmMir ,
8383 PpmMirCFG ,
84+ PpmAST ,
8485}
8586
8687impl PpMode {
@@ -90,6 +91,8 @@ impl PpMode {
9091 PpmSource ( PpmEveryBodyLoops ) |
9192 PpmSource ( PpmIdentified ) => opt_uii. is_some ( ) ,
9293
94+ PpmAST => false ,
95+
9396 PpmSource ( PpmExpanded ) |
9497 PpmSource ( PpmExpandedIdentified ) |
9598 PpmSource ( PpmExpandedHygiene ) |
@@ -130,6 +133,7 @@ pub fn parse_pretty(sess: &Session,
130133 ( "mir-cfg" , true ) => PpmMirCFG ,
131134 ( "flowgraph" , true ) => PpmFlowGraph ( PpFlowGraphMode :: Default ) ,
132135 ( "flowgraph,unlabelled" , true ) => PpmFlowGraph ( PpFlowGraphMode :: UnlabelledEdges ) ,
136+ ( "ast" , true ) => PpmAST ,
133137 _ => {
134138 if extended {
135139 sess. fatal ( & format ! ( "argument to `unpretty` must be one of `normal`, \
@@ -831,24 +835,26 @@ pub fn print_after_parsing(sess: &Session,
831835 let mut rdr = & * src;
832836 let mut out = Vec :: new ( ) ;
833837
834- if let PpmSource ( s) = ppm {
835- // Silently ignores an identified node.
836- let out: & mut Write = & mut out;
837- s. call_with_pp_support ( sess, None , box out, |annotation, out| {
838- debug ! ( "pretty printing source code {:?}" , s) ;
839- let sess = annotation. sess ( ) ;
840- pprust:: print_crate ( sess. codemap ( ) ,
841- & sess. parse_sess ,
842- krate,
843- src_name. to_string ( ) ,
844- & mut rdr,
845- out,
846- annotation. pp_ann ( ) ,
847- false )
848- } )
849- . unwrap ( )
850- } else {
851- unreachable ! ( ) ;
838+ match ppm {
839+ PpmSource ( s) => {
840+ // Silently ignores an identified node.
841+ let out: & mut Write = & mut out;
842+ s. call_with_pp_support ( sess, None , box out, |annotation, out| {
843+ debug ! ( "pretty printing source code {:?}" , s) ;
844+ let sess = annotation. sess ( ) ;
845+ pprust:: print_crate ( sess. codemap ( ) ,
846+ & sess. parse_sess ,
847+ krate,
848+ src_name. to_string ( ) ,
849+ & mut rdr,
850+ out,
851+ annotation. pp_ann ( ) ,
852+ false )
853+ } )
854+ . unwrap ( )
855+ }
856+ PpmAST => write ! ( out, "{:#?}" , krate) . unwrap ( ) ,
857+ _ => unreachable ! ( ) ,
852858 } ;
853859
854860 write_output ( out, ofile) ;
0 commit comments