@@ -595,33 +595,36 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
595
595
struct IdentifiedAnnotation ;
596
596
597
597
impl pprust:: PpAnn for IdentifiedAnnotation {
598
- fn pre ( & self , node : pprust:: AnnNode ) -> io:: IoResult < ( ) > {
598
+ fn pre ( & self ,
599
+ s : & mut pprust:: State < IdentifiedAnnotation > ,
600
+ node : pprust:: AnnNode ) -> io:: IoResult < ( ) > {
599
601
match node {
600
- pprust:: NodeExpr ( s , _) => pprust :: popen ( s ) ,
602
+ pprust:: NodeExpr ( _) => s . popen ( ) ,
601
603
_ => Ok ( ( ) )
602
604
}
603
605
}
604
- fn post ( & self , node : pprust:: AnnNode ) -> io:: IoResult < ( ) > {
606
+ fn post ( & self ,
607
+ s : & mut pprust:: State < IdentifiedAnnotation > ,
608
+ node : pprust:: AnnNode ) -> io:: IoResult < ( ) > {
605
609
match node {
606
- pprust:: NodeItem ( s , item) => {
610
+ pprust:: NodeItem ( item) => {
607
611
try!( pp:: space ( & mut s. s ) ) ;
608
- try! ( pprust :: synth_comment ( s , item. id . to_str ( ) ) ) ;
612
+ s . synth_comment ( item. id . to_str ( ) )
609
613
}
610
- pprust:: NodeBlock ( s , blk) => {
614
+ pprust:: NodeBlock ( blk) => {
611
615
try!( pp:: space ( & mut s. s ) ) ;
612
- try! ( pprust :: synth_comment ( s , ~"block " + blk.id.to_str()));
616
+ s . synth_comment ( ~"block " + blk.id.to_str())
613
617
}
614
- pprust::NodeExpr(s, expr) => {
618
+ pprust::NodeExpr(expr) => {
615
619
try!(pp::space(&mut s.s));
616
- try!(pprust:: synth_comment(s, expr.id.to_str()));
617
- try!(pprust:: pclose(s));
620
+ try!(s. synth_comment(expr.id.to_str()));
621
+ s. pclose()
618
622
}
619
- pprust::NodePat(s, pat) => {
623
+ pprust::NodePat(pat) => {
620
624
try!(pp::space(&mut s.s));
621
- try!(pprust:: synth_comment(s, ~" pat " + pat.id.to_str()));
625
+ s. synth_comment(~" pat " + pat.id.to_str())
622
626
}
623
627
}
624
- Ok(())
625
628
}
626
629
}
627
630
@@ -630,26 +633,29 @@ struct TypedAnnotation {
630
633
}
631
634
632
635
impl pprust::PpAnn for TypedAnnotation {
633
- fn pre(&self, node: pprust::AnnNode) -> io::IoResult<()> {
636
+ fn pre(&self,
637
+ s: &mut pprust::State<TypedAnnotation>,
638
+ node: pprust::AnnNode) -> io::IoResult<()> {
634
639
match node {
635
- pprust::NodeExpr(s, _) => pprust:: popen(s ),
640
+ pprust::NodeExpr(_) => s. popen(),
636
641
_ => Ok(())
637
642
}
638
643
}
639
- fn post(&self, node: pprust::AnnNode) -> io::IoResult<()> {
644
+ fn post(&self,
645
+ s: &mut pprust::State<TypedAnnotation>,
646
+ node: pprust::AnnNode) -> io::IoResult<()> {
640
647
let tcx = &self.analysis.ty_cx;
641
648
match node {
642
- pprust::NodeExpr(s, expr) => {
649
+ pprust::NodeExpr(expr) => {
643
650
try!(pp::space(&mut s.s));
644
651
try!(pp::word(&mut s.s, " as ") ) ;
645
652
try!( pp:: space ( & mut s. s ) ) ;
646
653
try!( pp:: word ( & mut s. s ,
647
654
ppaux:: ty_to_str ( tcx, ty:: expr_ty ( tcx, expr) ) ) ) ;
648
- try! ( pprust :: pclose ( s ) ) ;
655
+ s . pclose ( )
649
656
}
650
- _ => ( )
657
+ _ => Ok ( ( ) )
651
658
}
652
- Ok ( ( ) )
653
659
}
654
660
}
655
661
@@ -670,34 +676,48 @@ pub fn pretty_print_input(sess: Session,
670
676
_ => ( krate, None , false )
671
677
} ;
672
678
673
- let codemap = sess. codemap ;
674
- let span_diagnostic = sess. span_diagnostic ;
679
+ let src_name = source_name ( input) ;
680
+ let src = sess. codemap ( ) . get_filemap ( src_name) . deref ( ) . src . as_bytes ( ) . to_owned ( ) ;
681
+ let mut rdr = MemReader :: new ( src) ;
675
682
676
- let annotation = match ppm {
683
+ match ppm {
677
684
PpmIdentified | PpmExpandedIdentified => {
678
- ~IdentifiedAnnotation as ~pprust:: PpAnn
685
+ pprust:: print_crate ( sess. codemap ( ) ,
686
+ sess. diagnostic ( ) ,
687
+ & krate,
688
+ src_name,
689
+ & mut rdr,
690
+ ~io:: stdout ( ) ,
691
+ & IdentifiedAnnotation ,
692
+ is_expanded)
679
693
}
680
694
PpmTyped => {
681
695
let ast_map = ast_map. expect ( "--pretty=typed missing ast_map" ) ;
682
696
let analysis = phase_3_run_analysis_passes ( sess, & krate, ast_map) ;
683
- ~ TypedAnnotation {
697
+ let annotation = TypedAnnotation {
684
698
analysis : analysis
685
- } as ~pprust:: PpAnn :
699
+ } ;
700
+ pprust:: print_crate ( annotation. analysis . ty_cx . sess . codemap ( ) ,
701
+ annotation. analysis . ty_cx . sess . diagnostic ( ) ,
702
+ & krate,
703
+ src_name,
704
+ & mut rdr,
705
+ ~io:: stdout ( ) ,
706
+ & annotation,
707
+ is_expanded)
686
708
}
687
- _ => ~pprust:: NoAnn as ~pprust:: PpAnn : ,
688
- } ;
709
+ _ => {
710
+ pprust:: print_crate ( sess. codemap ( ) ,
711
+ sess. diagnostic ( ) ,
712
+ & krate,
713
+ src_name,
714
+ & mut rdr,
715
+ ~io:: stdout ( ) ,
716
+ & pprust:: NoAnn ,
717
+ is_expanded)
718
+ }
719
+ } . unwrap ( )
689
720
690
- let src = & codemap. get_filemap ( source_name ( input) ) . src ;
691
- let mut rdr = MemReader :: new ( src. as_bytes ( ) . to_owned ( ) ) ;
692
- let stdout = io:: stdout ( ) ;
693
- pprust:: print_crate ( codemap,
694
- span_diagnostic,
695
- & krate,
696
- source_name ( input) ,
697
- & mut rdr,
698
- ~stdout as ~io:: Writer ,
699
- annotation,
700
- is_expanded) . unwrap ( ) ;
701
721
}
702
722
703
723
pub fn get_os ( triple : & str ) -> Option < abi:: Os > {
@@ -778,8 +798,7 @@ pub fn host_triple() -> ~str {
778
798
( env ! ( "CFG_COMPILER" ) ) . to_owned ( )
779
799
}
780
800
781
- pub fn build_session_options ( matches : & getopts:: Matches )
782
- -> @session:: Options {
801
+ pub fn build_session_options ( matches : & getopts:: Matches ) -> session:: Options {
783
802
let mut crate_types: Vec < CrateType > = Vec :: new ( ) ;
784
803
let unparsed_crate_types = matches. opt_strs ( "crate-type" ) ;
785
804
for unparsed_crate_type in unparsed_crate_types. iter ( ) {
0 commit comments