repr: print the name of structs

This commit is contained in:
Daniel Micay 2013-08-31 00:15:55 -04:00
parent 6a225951e3
commit 874611b348
12 changed files with 50 additions and 34 deletions

View File

@ -252,8 +252,8 @@ impl Reflector {
let tcx = bcx.ccx().tcx;
let fields = ty::struct_fields(tcx, did, substs);
let extra = ~[self.c_uint(fields.len())]
+ self.c_size_and_align(t);
let extra = ~[self.c_slice(ty_to_str(tcx, t).to_managed()),
self.c_uint(fields.len())] + self.c_size_and_align(t);
do self.bracketed("class", extra) |this| {
for (i, field) in fields.iter().enumerate() {
let extra = ~[this.c_uint(i),

View File

@ -331,17 +331,15 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
true
}
fn visit_enter_class(&mut self, n_fields: uint, sz: uint, align: uint)
-> bool {
fn visit_enter_class(&mut self, name: &str, n_fields: uint, sz: uint, align: uint) -> bool {
self.align(align);
if ! self.inner.visit_enter_class(n_fields, sz, align) {
if ! self.inner.visit_enter_class(name, n_fields, sz, align) {
return false;
}
true
}
fn visit_class_field(&mut self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool {
fn visit_class_field(&mut self, i: uint, name: &str, mtbl: uint, inner: *TyDesc) -> bool {
unsafe { self.align((*inner).align); }
if ! self.inner.visit_class_field(i, name, mtbl, inner) {
return false;
@ -350,9 +348,8 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
true
}
fn visit_leave_class(&mut self, n_fields: uint, sz: uint, align: uint)
-> bool {
if ! self.inner.visit_leave_class(n_fields, sz, align) {
fn visit_leave_class(&mut self, name: &str, n_fields: uint, sz: uint, align: uint) -> bool {
if ! self.inner.visit_leave_class(name, n_fields, sz, align) {
return false;
}
true

View File

@ -346,7 +346,6 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
// Type no longer exists, vestigial function.
fn visit_vec(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool { fail!(); }
fn visit_unboxed_vec(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
do self.get::<raw::Vec<()>> |this, b| {
this.write_unboxed_vec_repr(mtbl, b, inner);
@ -413,11 +412,13 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
true
}
fn visit_enter_class(&mut self, _n_fields: uint,
fn visit_enter_class(&mut self, name: &str, _n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write(name.as_bytes());
self.writer.write(['{' as u8]);
true
}
fn visit_class_field(&mut self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool {
if i != 0 {
@ -429,7 +430,8 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
self.visit_inner(inner);
true
}
fn visit_leave_class(&mut self, _n_fields: uint,
fn visit_leave_class(&mut self, _name: &str, _n_fields: uint,
_sz: uint, _align: uint) -> bool {
self.writer.write(['}' as u8]);
true
@ -440,6 +442,7 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
self.writer.write(['(' as u8]);
true
}
fn visit_tup_field(&mut self, i: uint, inner: *TyDesc) -> bool {
if i != 0 {
self.writer.write(", ".as_bytes());
@ -447,6 +450,7 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
self.visit_inner(inner);
true
}
fn visit_leave_tup(&mut self, _n_fields: uint,
_sz: uint, _align: uint) -> bool {
if _n_fields == 1 {
@ -544,12 +548,15 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
fn visit_enter_fn(&mut self, _purity: uint, _proto: uint,
_n_inputs: uint, _retstyle: uint) -> bool { true }
fn visit_fn_input(&mut self, _i: uint, _mode: uint, _inner: *TyDesc) -> bool {
true
}
fn visit_fn_output(&mut self, _retstyle: uint, _inner: *TyDesc) -> bool {
true
}
fn visit_leave_fn(&mut self, _purity: uint, _proto: uint,
_n_inputs: uint, _retstyle: uint) -> bool { true }
@ -628,11 +635,11 @@ fn test_repr() {
exact_test(&(&["hi", "there"]),
"&[\"hi\", \"there\"]");
exact_test(&(P{a:10, b:1.234}),
"{a: 10, b: 1.234}");
"repr::P{a: 10, b: 1.234}");
exact_test(&(@P{a:10, b:1.234}),
"@{a: 10, b: 1.234}");
"@repr::P{a: 10, b: 1.234}");
exact_test(&(~P{a:10, b:1.234}),
"~{a: 10, b: 1.234}");
"~repr::P{a: 10, b: 1.234}");
exact_test(&(10u8, ~"hello"),
"(10u8, ~\"hello\")");
exact_test(&(10u16, ~"hello"),
@ -643,5 +650,5 @@ fn test_repr() {
"(10u64, ~\"hello\")");
struct Foo;
exact_test(&(~[Foo, Foo, Foo]), "~[{}, {}, {}]");
exact_test(&(~[Foo, Foo]), "~[repr::test_repr::Foo{}, repr::test_repr::Foo{}]");
}

View File

@ -220,11 +220,11 @@ pub trait TyVisitor {
fn visit_leave_rec(&mut self, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_enter_class(&mut self, n_fields: uint,
fn visit_enter_class(&mut self, name: &str, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_class_field(&mut self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool;
fn visit_leave_class(&mut self, n_fields: uint,
fn visit_leave_class(&mut self, name: &str, n_fields: uint,
sz: uint, align: uint) -> bool;
fn visit_enter_tup(&mut self, n_fields: uint,

View File

@ -3681,10 +3681,12 @@ mod tests {
assert_eq!(cnt, 11);
let xs = ~[Foo, Foo, Foo];
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()), ~"~[{}, {}]");
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()),
~"~[vec::tests::Foo{}, vec::tests::Foo{}]");
let xs: [Foo, ..3] = [Foo, Foo, Foo];
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()), ~"~[{}, {}]");
assert_eq!(fmt!("%?", xs.slice(0, 2).to_owned()),
~"~[vec::tests::Foo{}, vec::tests::Foo{}]");
cnt = 0;
for f in xs.iter() {
assert!(*f == Foo);

View File

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-fast
use std::sys;
struct Struc { a: u8, b: [int, ..3], c: int }
@ -16,5 +18,5 @@ pub fn main() {
let arr = [1,2,3];
let struc = Struc {a: 13u8, b: arr, c: 42};
let s = sys::log_str(&struc);
assert_eq!(s, ~"{a: 13u8, b: [1, 2, 3], c: 42}");
assert_eq!(s, ~"Struc{a: 13u8, b: [1, 2, 3], c: 42}");
}

View File

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-fast
use std::fmt;
struct A;
@ -27,7 +29,7 @@ pub fn main() {
// Make sure there's a poly formatter that takes anything
t!(format!("{:?}", 1), "1");
t!(format!("{:?}", A), "{}");
t!(format!("{:?}", A), "A{}");
t!(format!("{:?}", ()), "()");
t!(format!("{:?}", @(~1, "foo")), "@(~1, \"foo\")");

View File

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-fast
// Issue #2303
use std::sys;
@ -64,6 +66,6 @@ pub fn main() {
// because `inner`s alignment was 4.
assert_eq!(sys::size_of::<Outer>(), m::size());
assert_eq!(y, ~"{c8: 22u8, t: {c64: 44u32}}");
assert_eq!(y, ~"Outer{c8: 22u8, t: Inner{c64: 44u32}}");
}
}

View File

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-fast
// Issue #2303
use std::sys;
@ -86,6 +88,6 @@ pub fn main() {
// because `Inner`s alignment was 4.
assert_eq!(sys::size_of::<Outer>(), m::m::size());
assert_eq!(y, ~"{c8: 22u8, t: {c64: 44u64}}");
assert_eq!(y, ~"Outer{c8: 22u8, t: Inner{c64: 44u64}}");
}
}

View File

@ -318,10 +318,10 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
true
}
fn visit_enter_class(&mut self, n_fields: uint, sz: uint, align: uint)
fn visit_enter_class(&mut self, name: &str, n_fields: uint, sz: uint, align: uint)
-> bool {
self.align(align);
if ! self.inner.visit_enter_class(n_fields, sz, align) {
if ! self.inner.visit_enter_class(name, n_fields, sz, align) {
return false;
}
true
@ -335,9 +335,9 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
true
}
fn visit_leave_class(&mut self, n_fields: uint, sz: uint, align: uint)
fn visit_leave_class(&mut self, name: &str, n_fields: uint, sz: uint, align: uint)
-> bool {
if ! self.inner.visit_leave_class(n_fields, sz, align) {
if ! self.inner.visit_leave_class(name, n_fields, sz, align) {
return false;
}
true
@ -566,13 +566,13 @@ impl TyVisitor for my_visitor {
fn visit_leave_rec(&mut self, _n_fields: uint,
_sz: uint, _align: uint) -> bool { true }
fn visit_enter_class(&mut self, _n_fields: uint,
fn visit_enter_class(&mut self, _name: &str, _n_fields: uint,
_sz: uint, _align: uint) -> bool { true }
fn visit_class_field(&mut self, _i: uint, _name: &str,
_mtbl: uint, inner: *TyDesc) -> bool {
self.visit_inner(inner)
}
fn visit_leave_class(&mut self, _n_fields: uint,
fn visit_leave_class(&mut self, _name: &str, _n_fields: uint,
_sz: uint, _align: uint) -> bool { true }
fn visit_enter_tup(&mut self, _n_fields: uint,

View File

@ -99,11 +99,11 @@ impl TyVisitor for MyVisitor {
fn visit_leave_rec(&mut self, _n_fields: uint,
_sz: uint, _align: uint) -> bool { true }
fn visit_enter_class(&mut self, _n_fields: uint,
fn visit_enter_class(&mut self, _name: &str, _n_fields: uint,
_sz: uint, _align: uint) -> bool { true }
fn visit_class_field(&mut self, _i: uint, _name: &str,
_mtbl: uint, _inner: *TyDesc) -> bool { true }
fn visit_leave_class(&mut self, _n_fields: uint,
fn visit_leave_class(&mut self, _name: &str, _n_fields: uint,
_sz: uint, _align: uint) -> bool { true }
fn visit_enter_tup(&mut self, _n_fields: uint,

View File

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-fast
enum a_tag {
a_tag(u64)
}
@ -21,5 +23,5 @@ pub fn main() {
let x = t_rec {c8: 22u8, t: a_tag(44u64)};
let y = fmt!("%?", x);
info!("y = %s", y);
assert_eq!(y, ~"{c8: 22u8, t: a_tag(44u64)}");
assert_eq!(y, ~"t_rec{c8: 22u8, t: a_tag(44u64)}");
}