@@ -595,33 +595,36 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
595595struct IdentifiedAnnotation ;
596596
597597impl 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 < ( ) > {
599601 match node {
600- pprust:: NodeExpr ( s , _) => pprust :: popen ( s ) ,
602+ pprust:: NodeExpr ( _) => s . popen ( ) ,
601603 _ => Ok ( ( ) )
602604 }
603605 }
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 < ( ) > {
605609 match node {
606- pprust:: NodeItem ( s , item) => {
610+ pprust:: NodeItem ( item) => {
607611 try!( pp:: space ( & mut s. s ) ) ;
608- try! ( pprust :: synth_comment ( s , item. id . to_str ( ) ) ) ;
612+ s . synth_comment ( item. id . to_str ( ) )
609613 }
610- pprust:: NodeBlock ( s , blk) => {
614+ pprust:: NodeBlock ( blk) => {
611615 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())
613617 }
614- pprust::NodeExpr(s, expr) => {
618+ pprust::NodeExpr(expr) => {
615619 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()
618622 }
619- pprust::NodePat(s, pat) => {
623+ pprust::NodePat(pat) => {
620624 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())
622626 }
623627 }
624- Ok(())
625628 }
626629}
627630
@@ -630,26 +633,29 @@ struct TypedAnnotation {
630633}
631634
632635impl 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<()> {
634639 match node {
635- pprust::NodeExpr(s, _) => pprust:: popen(s ),
640+ pprust::NodeExpr(_) => s. popen(),
636641 _ => Ok(())
637642 }
638643 }
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<()> {
640647 let tcx = &self.analysis.ty_cx;
641648 match node {
642- pprust::NodeExpr(s, expr) => {
649+ pprust::NodeExpr(expr) => {
643650 try!(pp::space(&mut s.s));
644651 try!(pp::word(&mut s.s, " as ") ) ;
645652 try!( pp:: space ( & mut s. s ) ) ;
646653 try!( pp:: word ( & mut s. s ,
647654 ppaux:: ty_to_str ( tcx, ty:: expr_ty ( tcx, expr) ) ) ) ;
648- try! ( pprust :: pclose ( s ) ) ;
655+ s . pclose ( )
649656 }
650- _ => ( )
657+ _ => Ok ( ( ) )
651658 }
652- Ok ( ( ) )
653659 }
654660}
655661
@@ -670,34 +676,48 @@ pub fn pretty_print_input(sess: Session,
670676 _ => ( krate, None , false )
671677 } ;
672678
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) ;
675682
676- let annotation = match ppm {
683+ match ppm {
677684 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)
679693 }
680694 PpmTyped => {
681695 let ast_map = ast_map. expect ( "--pretty=typed missing ast_map" ) ;
682696 let analysis = phase_3_run_analysis_passes ( sess, & krate, ast_map) ;
683- ~ TypedAnnotation {
697+ let annotation = TypedAnnotation {
684698 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)
686708 }
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 ( )
689720
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 ( ) ;
701721}
702722
703723pub fn get_os ( triple : & str ) -> Option < abi:: Os > {
@@ -778,8 +798,7 @@ pub fn host_triple() -> ~str {
778798 ( env ! ( "CFG_COMPILER" ) ) . to_owned ( )
779799}
780800
781- pub fn build_session_options ( matches : & getopts:: Matches )
782- -> @session:: Options {
801+ pub fn build_session_options ( matches : & getopts:: Matches ) -> session:: Options {
783802 let mut crate_types: Vec < CrateType > = Vec :: new ( ) ;
784803 let unparsed_crate_types = matches. opt_strs ( "crate-type" ) ;
785804 for unparsed_crate_type in unparsed_crate_types. iter ( ) {
0 commit comments