@@ -27,6 +27,9 @@ use middle;
27
27
use util:: common:: time;
28
28
use util:: ppaux;
29
29
30
+ use extra:: json;
31
+ use serialize:: Encodable ;
32
+
30
33
use std:: cell:: { Cell , RefCell } ;
31
34
use std:: hashmap:: { HashMap , HashSet } ;
32
35
use std:: io;
@@ -154,7 +157,7 @@ pub enum Input {
154
157
155
158
pub fn phase_1_parse_input ( sess : Session , cfg : ast:: CrateConfig , input : & Input )
156
159
-> ast:: Crate {
157
- time ( sess. time_passes ( ) , "parsing" , ( ) , |_| {
160
+ let krate = time ( sess. time_passes ( ) , "parsing" , ( ) , |_| {
158
161
match * input {
159
162
FileInput ( ref file) => {
160
163
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)
166
169
sess. parse_sess )
167
170
}
168
171
}
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
170
181
}
171
182
172
183
// For continuing compilation after a parsed crate has been
@@ -220,8 +231,16 @@ pub fn phase_2_configure_and_expand(sess: Session,
220
231
krate = time ( time_passes, "prelude injection" , krate, |krate|
221
232
front:: std_inject:: maybe_inject_prelude ( sess, krate) ) ;
222
233
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)
225
244
}
226
245
227
246
pub struct CrateAnalysis {
@@ -428,15 +447,15 @@ pub fn stop_after_phase_1(sess: Session) -> bool {
428
447
debug ! ( "invoked with --parse-only, returning early from compile_input" ) ;
429
448
return true ;
430
449
}
431
- return false ;
450
+ return sess . opts . debugging_opts & session :: AST_JSON_NOEXPAND != 0 ;
432
451
}
433
452
434
453
pub fn stop_after_phase_2 ( sess : Session ) -> bool {
435
454
if sess. opts . no_analysis {
436
455
debug ! ( "invoked with --no-analysis, returning early from compile_input" ) ;
437
456
return true ;
438
457
}
439
- return false ;
458
+ return sess . opts . debugging_opts & session :: AST_JSON != 0 ;
440
459
}
441
460
442
461
pub fn stop_after_phase_5 ( sess : Session ) -> bool {
0 commit comments