@@ -27,6 +27,9 @@ use middle;
2727use util:: common:: time;
2828use util:: ppaux;
2929
30+ use extra:: json;
31+ use serialize:: Encodable ;
32+
3033use std:: cell:: { Cell , RefCell } ;
3134use std:: hashmap:: { HashMap , HashSet } ;
3235use std:: io;
@@ -154,7 +157,7 @@ pub enum Input {
154157
155158pub fn phase_1_parse_input ( sess : Session , cfg : ast:: CrateConfig , input : & Input )
156159 -> ast:: Crate {
157- time ( sess. time_passes ( ) , "parsing" , ( ) , |_| {
160+ let krate = time ( sess. time_passes ( ) , "parsing" , ( ) , |_| {
158161 match * input {
159162 FileInput ( ref file) => {
160163 parse:: parse_crate_from_file ( & ( * file) , cfg. clone ( ) , sess. parse_sess )
@@ -166,7 +169,15 @@ pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &Input)
166169 sess. parse_sess )
167170 }
168171 }
169- } )
172+ } ) ;
173+
174+ if sess. opts . debugging_opts & session:: AST_JSON_NOEXPAND != 0 {
175+ let mut stdout = io:: stdout ( ) ;
176+ let mut json = json:: PrettyEncoder :: new ( & mut stdout) ;
177+ krate. encode ( & mut json) ;
178+ }
179+
180+ krate
170181}
171182
172183// For continuing compilation after a parsed crate has been
@@ -220,8 +231,16 @@ pub fn phase_2_configure_and_expand(sess: Session,
220231 krate = time ( time_passes, "prelude injection" , krate, |krate|
221232 front:: std_inject:: maybe_inject_prelude ( sess, krate) ) ;
222233
223- time ( time_passes, "assinging node ids and indexing ast" , krate, |krate|
224- front:: assign_node_ids_and_map:: assign_node_ids_and_map ( sess, krate) )
234+ let ( krate, map) = time ( time_passes, "assinging node ids and indexing ast" , krate, |krate|
235+ front:: assign_node_ids_and_map:: assign_node_ids_and_map ( sess, krate) ) ;
236+
237+ if sess. opts . debugging_opts & session:: AST_JSON != 0 {
238+ let mut stdout = io:: stdout ( ) ;
239+ let mut json = json:: PrettyEncoder :: new ( & mut stdout) ;
240+ krate. encode ( & mut json) ;
241+ }
242+
243+ ( krate, map)
225244}
226245
227246pub struct CrateAnalysis {
@@ -428,15 +447,15 @@ pub fn stop_after_phase_1(sess: Session) -> bool {
428447 debug ! ( "invoked with --parse-only, returning early from compile_input" ) ;
429448 return true ;
430449 }
431- return false ;
450+ return sess . opts . debugging_opts & session :: AST_JSON_NOEXPAND != 0 ;
432451}
433452
434453pub fn stop_after_phase_2 ( sess : Session ) -> bool {
435454 if sess. opts . no_analysis {
436455 debug ! ( "invoked with --no-analysis, returning early from compile_input" ) ;
437456 return true ;
438457 }
439- return false ;
458+ return sess . opts . debugging_opts & session :: AST_JSON != 0 ;
440459}
441460
442461pub fn stop_after_phase_5 ( sess : Session ) -> bool {
0 commit comments