@@ -153,7 +153,7 @@ fn compile_input(session::session sess, ast::crate_cfg cfg, str input,
153
153
}
154
154
155
155
fn pretty_print_input ( session:: session sess, ast:: crate_cfg cfg,
156
- str input , pp_mode ppm) {
156
+ str input , pp_mode ppm, bool expand ) {
157
157
fn ann_paren_for_expr ( & pprust:: ann_node node) {
158
158
alt ( node) {
159
159
case ( pprust:: node_expr ( ?s, ?expr) ) {
@@ -195,6 +195,7 @@ fn pretty_print_input(session::session sess, ast::crate_cfg cfg,
195
195
}
196
196
197
197
auto crate = parse_input ( sess, cfg, input) ;
198
+ if ( expand) { crate = syntax:: ext:: expand:: expand_crate ( sess, crate ) ; }
198
199
auto ann;
199
200
alt ( ppm) {
200
201
case ( ppm_typed) {
@@ -238,6 +239,7 @@ options:
238
239
--lib compile a library crate
239
240
--static use or produce static libraries
240
241
--pretty [type] pretty-print the input instead of compiling
242
+ --expand [type] expand and pretty-print the input instead of compiling
241
243
--ls list the symbols defined by a crate file
242
244
-L <path> add a directory to the library search path
243
245
--noverify suppress LLVM verification step (slight speedup)
@@ -395,15 +397,15 @@ fn parse_pretty(session::session sess, &str name) -> pp_mode {
395
397
} else if ( str:: eq ( name, "typed" ) ) {
396
398
ret ppm_typed;
397
399
} else if ( str:: eq ( name, "identified" ) ) { ret ppm_identified; }
398
- sess. fatal ( "argument to `pretty` must be one of `normal`, `typed`, or " +
399
- " `identified`") ;
400
+ sess. fatal ( "argument to `pretty` or `expand` must be one of `normal`, "
401
+ + "`typed`, or `identified`") ;
400
402
}
401
403
402
404
fn opts ( ) -> vec[ getopts:: opt ] {
403
405
ret [ optflag ( "h" ) , optflag ( "help" ) , optflag ( "v" ) , optflag ( "version" ) ,
404
406
optflag ( "glue" ) , optflag ( "emit-llvm" ) , optflagopt ( "pretty" ) ,
405
- optflag ( "ls ") , optflag ( "parse-only " ) , optflag ( "O " ) ,
406
- optopt ( "OptLevel" ) , optmulti ( "L" ) , optflag ( "S" ) ,
407
+ optflagopt ( "expand ") , optflag ( "ls " ) , optflag ( "parse-only " ) ,
408
+ optflag ( "O" ) , optopt ( "OptLevel" ) , optmulti ( "L" ) , optflag ( "S" ) ,
407
409
optflag ( "c" ) , optopt ( "o" ) , optflag ( "g" ) , optflag ( "save-temps" ) ,
408
410
optopt ( "sysroot" ) , optflag ( "stats" ) , optflag ( "time-passes" ) ,
409
411
optflag ( "time-llvm-passes" ) , optflag ( "no-typestate" ) ,
@@ -451,18 +453,29 @@ fn main(vec[str] args) {
451
453
auto ifile = match . free . ( 0 ) ;
452
454
let str saved_out_filename = "" ;
453
455
auto cfg = build_configuration ( sess, binary, ifile) ;
456
+ auto expand =
457
+ option:: map[ str,
458
+ pp_mode] ( bind parse_pretty ( sess, _) ,
459
+ getopts:: opt_default ( match , "expand" , "normal" ) ) ;
460
+ alt ( expand) {
461
+ case ( some[ pp_mode] ( ?ppm) ) {
462
+ pretty_print_input ( sess, cfg, ifile, ppm, true ) ;
463
+ ret;
464
+ }
465
+ case ( none[ pp_mode] ) { /* continue */ }
466
+ }
454
467
auto pretty =
455
468
option:: map[ str,
456
469
pp_mode] ( bind parse_pretty ( sess, _) ,
457
470
getopts:: opt_default ( match , "pretty" , "normal" ) ) ;
458
- auto ls = opt_present ( match , "ls" ) ;
459
471
alt ( pretty) {
460
472
case ( some[ pp_mode] ( ?ppm) ) {
461
- pretty_print_input ( sess, cfg, ifile, ppm) ;
473
+ pretty_print_input ( sess, cfg, ifile, ppm, false ) ;
462
474
ret;
463
475
}
464
476
case ( none[ pp_mode] ) { /* continue */ }
465
477
}
478
+ auto ls = opt_present ( match , "ls" ) ;
466
479
if ( ls) {
467
480
metadata:: creader:: list_file_metadata ( ifile, ioivec:: stdout ( ) ) ;
468
481
ret;
0 commit comments