@@ -21,6 +21,7 @@ use util::small_vector::SmallVector;
2121use std:: cell:: RefCell ;
2222use std:: fmt;
2323use std:: gc:: { Gc , GC } ;
24+ use std:: io:: IoResult ;
2425use std:: iter;
2526use std:: slice;
2627
@@ -819,6 +820,34 @@ pub fn map_decoded_item<F: FoldOps>(map: &Map,
819820 ii
820821}
821822
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+
822851fn node_id_to_string ( map : & Map , id : NodeId ) -> String {
823852 match map. find ( id) {
824853 Some ( NodeItem ( item) ) => {
0 commit comments