@@ -75,35 +75,50 @@ impl Repr for bool {
7575 }
7676}
7777
78- macro_rules! int_repr( ( $ty: ident) => ( impl Repr for $ty {
78+ impl Repr for int {
79+ fn write_repr ( & self , writer : @Writer ) {
80+ do :: int:: to_str_bytes ( * self , 10 u) |bits| {
81+ writer. write ( bits) ;
82+ }
83+ }
84+ }
85+
86+ macro_rules! int_repr( ( $ty: ident, $suffix: expr) => ( impl Repr for $ty {
7987 fn write_repr( & self , writer: @Writer ) {
8088 do :: $ty:: to_str_bytes( * self , 10 u) |bits| {
8189 writer. write( bits) ;
90+ writer. write( bytes!( $suffix) ) ;
8291 }
8392 }
8493} ) )
8594
86- int_repr ! ( int)
87- int_repr ! ( i8 )
88- int_repr ! ( i16 )
89- int_repr ! ( i32 )
90- int_repr ! ( i64 )
91- int_repr ! ( uint)
92- int_repr ! ( u8 )
93- int_repr ! ( u16 )
94- int_repr ! ( u32 )
95- int_repr ! ( u64 )
96-
97- macro_rules! num_repr( ( $ty: ident) => ( impl Repr for $ty {
95+ int_repr ! ( i8 , "i8" )
96+ int_repr ! ( i16 , "i16" )
97+ int_repr ! ( i32 , "i32" )
98+ int_repr ! ( i64 , "i64" )
99+ int_repr ! ( uint, "u" )
100+ int_repr ! ( u8 , "u8" )
101+ int_repr ! ( u16 , "u16" )
102+ int_repr ! ( u32 , "u32" )
103+ int_repr ! ( u64 , "u64" )
104+
105+ impl Repr for float {
106+ fn write_repr ( & self , writer : @Writer ) {
107+ let s = self . to_str ( ) ;
108+ writer. write ( s. as_bytes ( ) ) ;
109+ }
110+ }
111+
112+ macro_rules! num_repr( ( $ty: ident, $suffix: expr) => ( impl Repr for $ty {
98113 fn write_repr( & self , writer: @Writer ) {
99114 let s = self . to_str( ) ;
100115 writer. write( s. as_bytes( ) ) ;
116+ writer. write( bytes!( $suffix) ) ;
101117 }
102118} ) )
103119
104- num_repr ! ( float)
105- num_repr ! ( f32 )
106- num_repr ! ( f64 )
120+ num_repr ! ( f32 , "f32" )
121+ num_repr ! ( f64 , "f64" )
107122
108123// New implementation using reflect::MovePtr
109124
@@ -267,12 +282,14 @@ impl TyVisitor for ReprVisitor {
267282 self . write_escaped_slice ( * s) ;
268283 }
269284 }
285+
270286 fn visit_estr_uniq ( & self ) -> bool {
271287 do self . get :: < ~str > |s| {
272288 self . writer . write_char ( '~' ) ;
273289 self . write_escaped_slice ( * s) ;
274290 }
275291 }
292+
276293 fn visit_estr_slice ( & self ) -> bool {
277294 do self . get :: < & str > |s| {
278295 self . write_escaped_slice ( * s) ;
@@ -307,13 +324,23 @@ impl TyVisitor for ReprVisitor {
307324 }
308325 }
309326
327+ #[ cfg( stage0) ]
310328 fn visit_ptr ( & self , _mtbl : uint , _inner : * TyDesc ) -> bool {
311329 do self . get :: < * c_void > |p| {
312330 self . writer . write_str ( fmt ! ( "(0x%x as *())" ,
313331 * p as uint) ) ;
314332 }
315333 }
316334
335+ #[ cfg( not( stage0) ) ]
336+ fn visit_ptr ( & self , mtbl : uint , _inner : * TyDesc ) -> bool {
337+ do self . get :: < * c_void > |p| {
338+ self . writer . write_str ( fmt ! ( "(0x%x as *" , * p as uint) ) ;
339+ self . write_mut_qualifier ( mtbl) ;
340+ self . writer . write_str ( "())" ) ;
341+ }
342+ }
343+
317344 fn visit_rptr ( & self , mtbl : uint , inner : * TyDesc ) -> bool {
318345 self . writer . write_char ( '&' ) ;
319346 self . write_mut_qualifier ( mtbl) ;
@@ -536,8 +563,6 @@ impl TyVisitor for ReprVisitor {
536563
537564
538565 fn visit_trait ( & self ) -> bool { true }
539- fn visit_var ( & self ) -> bool { true }
540- fn visit_var_integral ( & self ) -> bool { true }
541566 fn visit_param ( & self , _i : uint ) -> bool { true }
542567 fn visit_self ( & self ) -> bool { true }
543568 fn visit_type ( & self ) -> bool { true }
@@ -550,9 +575,6 @@ impl TyVisitor for ReprVisitor {
550575 }
551576 }
552577
553- // Type no longer exists, vestigial function.
554- fn visit_constr ( & self , _inner : * TyDesc ) -> bool { fail ! ( ) ; }
555-
556578 fn visit_closure_ptr ( & self , _ck : uint ) -> bool { true }
557579}
558580
@@ -598,11 +620,14 @@ fn test_repr() {
598620 exact_test ( & ( & mut x) , "&mut 10" ) ;
599621 exact_test ( & ( @mut [ 1 , 2 ] ) , "@mut [1, 2]" ) ;
600622
623+ exact_test ( & ( 0 as * ( ) ) , "(0x0 as *())" ) ;
624+ exact_test ( & ( 0 as * mut ( ) ) , "(0x0 as *mut ())" ) ;
625+
601626 exact_test ( & ( 1 , ) , "(1,)" ) ;
602627 exact_test ( & ( @[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ,
603628 "@[1, 2, 3, 4, 5, 6, 7, 8]" ) ;
604629 exact_test ( & ( @[ 1u8 , 2u8 , 3u8 , 4u8 ] ) ,
605- "@[1, 2, 3, 4 ]" ) ;
630+ "@[1u8, 2u8, 3u8, 4u8 ]" ) ;
606631 exact_test ( & ( @[ "hi" , "there" ] ) ,
607632 "@[\" hi\" , \" there\" ]" ) ;
608633 exact_test ( & ( ~[ "hi" , "there" ] ) ,
@@ -615,14 +640,14 @@ fn test_repr() {
615640 "@{a: 10, b: 1.234}" ) ;
616641 exact_test ( & ( ~P { a : 10 , b : 1.234 } ) ,
617642 "~{a: 10, b: 1.234}" ) ;
618- exact_test ( & ( 10_u8 , ~"hello") ,
619- "(10 , ~\" hello\" )" ) ;
620- exact_test ( & ( 10_u16 , ~"hello") ,
621- "(10 , ~\" hello\" )" ) ;
622- exact_test ( & ( 10_u32 , ~"hello") ,
623- "(10 , ~\" hello\" )" ) ;
624- exact_test ( & ( 10_u64 , ~"hello") ,
625- "(10 , ~\" hello\" )" ) ;
643+ exact_test ( & ( 10u8 , ~"hello") ,
644+ "(10u8 , ~\" hello\" )" ) ;
645+ exact_test ( & ( 10u16 , ~"hello") ,
646+ "(10u16 , ~\" hello\" )" ) ;
647+ exact_test ( & ( 10u32 , ~"hello") ,
648+ "(10u32 , ~\" hello\" )" ) ;
649+ exact_test ( & ( 10u64 , ~"hello") ,
650+ "(10u64 , ~\" hello\" )" ) ;
626651
627652 struct Foo ;
628653 exact_test ( & ( ~[ Foo , Foo , Foo ] ) , "~[{}, {}, {}]" ) ;
0 commit comments