1
Fork 0

repr: add support for trait objects

Closes #8916
This commit is contained in:
Daniel Micay 2013-09-02 01:15:03 -04:00
parent 7a52154d78
commit cc1f0027c7
6 changed files with 20 additions and 13 deletions

View file

@ -146,6 +146,7 @@ impl Reflector {
// Entrypoint // Entrypoint
pub fn visit_ty(&mut self, t: ty::t) { pub fn visit_ty(&mut self, t: ty::t) {
let bcx = self.bcx; let bcx = self.bcx;
let tcx = bcx.ccx().tcx;
debug!("reflect::visit_ty %s", ty_to_str(bcx.ccx().tcx, t)); debug!("reflect::visit_ty %s", ty_to_str(bcx.ccx().tcx, t));
match ty::get(t).sty { match ty::get(t).sty {
@ -248,8 +249,6 @@ impl Reflector {
} }
ty::ty_struct(did, ref substs) => { ty::ty_struct(did, ref substs) => {
let bcx = self.bcx;
let tcx = bcx.ccx().tcx;
let fields = ty::struct_fields(tcx, did, substs); let fields = ty::struct_fields(tcx, did, substs);
let extra = ~[self.c_slice(ty_to_str(tcx, t).to_managed()), let extra = ~[self.c_slice(ty_to_str(tcx, t).to_managed()),
@ -270,7 +269,6 @@ impl Reflector {
// let the visitor tell us if it wants to visit only a particular // let the visitor tell us if it wants to visit only a particular
// variant? // variant?
ty::ty_enum(did, ref substs) => { ty::ty_enum(did, ref substs) => {
let bcx = self.bcx;
let ccx = bcx.ccx(); let ccx = bcx.ccx();
let repr = adt::represent_type(bcx.ccx(), t); let repr = adt::represent_type(bcx.ccx(), t);
let variants = ty::substd_enum_variants(ccx.tcx, did, substs); let variants = ty::substd_enum_variants(ccx.tcx, did, substs);
@ -336,8 +334,12 @@ impl Reflector {
} }
} }
// Miscallaneous extra types ty::ty_trait(_, _, _, _, _) => {
ty::ty_trait(_, _, _, _, _) => self.leaf("trait"), let extra = [self.c_slice(ty_to_str(tcx, t).to_managed())];
self.visit("trait", extra);
}
// Miscellaneous extra types
ty::ty_infer(_) => self.leaf("infer"), ty::ty_infer(_) => self.leaf("infer"),
ty::ty_err => self.leaf("err"), ty::ty_err => self.leaf("err"),
ty::ty_param(ref p) => { ty::ty_param(ref p) => {

View file

@ -450,9 +450,9 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
true true
} }
fn visit_trait(&mut self) -> bool { fn visit_trait(&mut self, name: &str) -> bool {
self.align_to::<@TyVisitor>(); self.align_to::<@TyVisitor>();
if ! self.inner.visit_trait() { return false; } if ! self.inner.visit_trait(name) { return false; }
self.bump_past::<@TyVisitor>(); self.bump_past::<@TyVisitor>();
true true
} }

View file

@ -571,7 +571,11 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
_n_inputs: uint, _retstyle: uint) -> bool { true } _n_inputs: uint, _retstyle: uint) -> bool { true }
fn visit_trait(&mut self) -> bool { true } fn visit_trait(&mut self, name: &str) -> bool {
self.writer.write(name.as_bytes());
true
}
fn visit_param(&mut self, _i: uint) -> bool { true } fn visit_param(&mut self, _i: uint) -> bool { true }
fn visit_self(&mut self) -> bool { true } fn visit_self(&mut self) -> bool { true }
fn visit_type(&mut self) -> bool { true } fn visit_type(&mut self) -> bool { true }
@ -661,6 +665,7 @@ fn test_repr() {
"(10u64, ~\"hello\")"); "(10u64, ~\"hello\")");
exact_test(&(&println), "&fn()"); exact_test(&(&println), "&fn()");
exact_test(&(~5 as ~ToStr), "~to_str::ToStr:Send");
struct Foo; struct Foo;
exact_test(&(~[Foo, Foo]), "~[repr::test_repr::Foo, repr::test_repr::Foo]"); exact_test(&(~[Foo, Foo]), "~[repr::test_repr::Foo, repr::test_repr::Foo]");

View file

@ -256,7 +256,7 @@ pub trait TyVisitor {
fn visit_leave_fn(&mut self, purity: uint, proto: uint, fn visit_leave_fn(&mut self, purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool; n_inputs: uint, retstyle: uint) -> bool;
fn visit_trait(&mut self) -> bool; fn visit_trait(&mut self, name: &str) -> bool;
fn visit_param(&mut self, i: uint) -> bool; fn visit_param(&mut self, i: uint) -> bool;
fn visit_self(&mut self) -> bool; fn visit_self(&mut self) -> bool;
fn visit_type(&mut self) -> bool; fn visit_type(&mut self) -> bool;

View file

@ -428,9 +428,9 @@ impl<V:TyVisitor + movable_ptr> TyVisitor for ptr_visit_adaptor<V> {
true true
} }
fn visit_trait(&mut self) -> bool { fn visit_trait(&mut self, name: &str) -> bool {
self.align_to::<@TyVisitor>(); self.align_to::<@TyVisitor>();
if ! self.inner.visit_trait() { return false; } if ! self.inner.visit_trait(name) { return false; }
self.bump_past::<@TyVisitor>(); self.bump_past::<@TyVisitor>();
true true
} }
@ -616,7 +616,7 @@ impl TyVisitor for my_visitor {
_n_inputs: uint, _retstyle: uint) -> bool { true } _n_inputs: uint, _retstyle: uint) -> bool { true }
fn visit_trait(&mut self) -> bool { true } fn visit_trait(&mut self, _name: &str) -> bool { true }
fn visit_param(&mut self, _i: uint) -> bool { true } fn visit_param(&mut self, _i: uint) -> bool { true }
fn visit_self(&mut self) -> bool { true } fn visit_self(&mut self) -> bool { true }
fn visit_type(&mut self) -> bool { true } fn visit_type(&mut self) -> bool { true }

View file

@ -139,7 +139,7 @@ impl TyVisitor for MyVisitor {
_n_inputs: uint, _retstyle: uint) -> bool { true } _n_inputs: uint, _retstyle: uint) -> bool { true }
fn visit_trait(&mut self) -> bool { true } fn visit_trait(&mut self, _name: &str) -> bool { true }
fn visit_param(&mut self, _i: uint) -> bool { true } fn visit_param(&mut self, _i: uint) -> bool { true }
fn visit_self(&mut self) -> bool { true } fn visit_self(&mut self) -> bool { true }
fn visit_type(&mut self) -> bool { true } fn visit_type(&mut self) -> bool { true }