@@ -21,6 +21,7 @@ use util::small_vector::SmallVector;
21
21
use std:: cell:: RefCell ;
22
22
use std:: fmt;
23
23
use std:: gc:: { Gc , GC } ;
24
+ use std:: io:: IoResult ;
24
25
use std:: iter;
25
26
use std:: slice;
26
27
@@ -819,6 +820,34 @@ pub fn map_decoded_item<F: FoldOps>(map: &Map,
819
820
ii
820
821
}
821
822
823
+ pub trait NodePrinter {
824
+ fn print_node ( & mut self , node : & Node ) -> IoResult < ( ) > ;
825
+ }
826
+
827
+ impl < ' a > NodePrinter for pprust:: State < ' a > {
828
+ fn print_node ( & mut self , node : & Node ) -> IoResult < ( ) > {
829
+ match * node {
830
+ NodeItem ( a) => self . print_item ( & * a) ,
831
+ NodeForeignItem ( a) => self . print_foreign_item ( & * a) ,
832
+ NodeTraitMethod ( a) => self . print_trait_method ( & * a) ,
833
+ NodeMethod ( a) => self . print_method ( & * a) ,
834
+ NodeVariant ( a) => self . print_variant ( & * a) ,
835
+ NodeExpr ( a) => self . print_expr ( & * a) ,
836
+ NodeStmt ( a) => self . print_stmt ( & * a) ,
837
+ NodePat ( a) => self . print_pat ( & * a) ,
838
+ NodeBlock ( a) => self . print_block ( & * a) ,
839
+ NodeLifetime ( a) => self . print_lifetime ( & * a) ,
840
+
841
+ // these cases do not carry enough information in the
842
+ // ast_map to reconstruct their full structure for pretty
843
+ // printing.
844
+ NodeLocal ( _) => fail ! ( "cannot print isolated Local" ) ,
845
+ NodeArg ( _) => fail ! ( "cannot print isolated Arg" ) ,
846
+ NodeStructCtor ( _) => fail ! ( "cannot print isolated StructCtor" ) ,
847
+ }
848
+ }
849
+ }
850
+
822
851
fn node_id_to_string ( map : & Map , id : NodeId ) -> String {
823
852
match map. find ( id) {
824
853
Some ( NodeItem ( item) ) => {
0 commit comments