mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-08 05:47:40 +00:00
auto merge of #8947 : thestinger/rust/name, r=huonw
Storing the type name in the `tydesc` aims to avoid the need to pass a type name in almost every single visitor method. It would likely be much saner for `repr` to simply be passed the `TyDesc` corresponding to the function or just the type name, but this is good enough for now.
This commit is contained in:
commit
c14daba3b2
@ -47,7 +47,8 @@ pub static tydesc_field_drop_glue: uint = 3u;
|
||||
pub static tydesc_field_free_glue: uint = 4u;
|
||||
pub static tydesc_field_visit_glue: uint = 5u;
|
||||
pub static tydesc_field_borrow_offset: uint = 6u;
|
||||
pub static n_tydesc_fields: uint = 7u;
|
||||
pub static tydesc_field_name_offset: uint = 7u;
|
||||
pub static n_tydesc_fields: uint = 8u;
|
||||
|
||||
// The two halves of a closure: code and environment.
|
||||
pub static fn_field_code: uint = 0u;
|
||||
|
@ -56,6 +56,7 @@ pub struct tydesc_info {
|
||||
size: ValueRef,
|
||||
align: ValueRef,
|
||||
borrow_offset: ValueRef,
|
||||
name: ValueRef,
|
||||
take_glue: Option<ValueRef>,
|
||||
drop_glue: Option<ValueRef>,
|
||||
free_glue: Option<ValueRef>,
|
||||
|
@ -678,12 +678,16 @@ pub fn declare_tydesc(ccx: &mut CrateContext, t: ty::t) -> @mut tydesc_info {
|
||||
llvm::LLVMAddGlobal(ccx.llmod, ccx.tydesc_type.to_ref(), buf)
|
||||
}
|
||||
};
|
||||
|
||||
let ty_name = C_estr_slice(ccx, ppaux::ty_to_str(ccx.tcx, t).to_managed());
|
||||
|
||||
let inf = @mut tydesc_info {
|
||||
ty: t,
|
||||
tydesc: gvar,
|
||||
size: llsize,
|
||||
align: llalign,
|
||||
borrow_offset: borrow_offset,
|
||||
name: ty_name,
|
||||
take_glue: None,
|
||||
drop_glue: None,
|
||||
free_glue: None,
|
||||
@ -809,14 +813,14 @@ pub fn emit_tydescs(ccx: &mut CrateContext) {
|
||||
drop_glue, // drop_glue
|
||||
free_glue, // free_glue
|
||||
visit_glue, // visit_glue
|
||||
ti.borrow_offset]); // borrow_offset
|
||||
ti.borrow_offset, // borrow_offset
|
||||
ti.name]); // name
|
||||
|
||||
unsafe {
|
||||
let gvar = ti.tydesc;
|
||||
llvm::LLVMSetInitializer(gvar, tydesc);
|
||||
llvm::LLVMSetGlobalConstant(gvar, True);
|
||||
lib::llvm::SetLinkage(gvar, lib::llvm::InternalLinkage);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -216,8 +216,8 @@ impl Type {
|
||||
glue_fn_ty, // drop
|
||||
glue_fn_ty, // free
|
||||
glue_fn_ty, // visit
|
||||
int_ty]; // borrow_offset
|
||||
|
||||
int_ty, // borrow_offset
|
||||
Type::struct_([Type::i8p(), Type::int(arch)], false)]; // name
|
||||
tydesc.set_struct_body(elems, false);
|
||||
|
||||
return tydesc;
|
||||
|
@ -566,14 +566,22 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
|
||||
true
|
||||
}
|
||||
|
||||
fn visit_fn_input(&mut self, _i: uint, _mode: uint, _inner: *TyDesc) -> bool {
|
||||
// FIXME: #8917: should print out the parameter types here, separated by commas
|
||||
fn visit_fn_input(&mut self, i: uint, _mode: uint, inner: *TyDesc) -> bool {
|
||||
if i != 0 {
|
||||
self.writer.write(", ".as_bytes());
|
||||
}
|
||||
let name = unsafe { (*inner).name };
|
||||
self.writer.write(name.as_bytes());
|
||||
true
|
||||
}
|
||||
|
||||
fn visit_fn_output(&mut self, _retstyle: uint, _inner: *TyDesc) -> bool {
|
||||
fn visit_fn_output(&mut self, _retstyle: uint, inner: *TyDesc) -> bool {
|
||||
self.writer.write(")".as_bytes());
|
||||
// FIXME: #8917: should print out the output type here, as `-> T`
|
||||
let name = unsafe { (*inner).name };
|
||||
if name != "()" {
|
||||
self.writer.write(" -> ".as_bytes());
|
||||
self.writer.write(name.as_bytes());
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
@ -620,6 +628,8 @@ fn test_repr() {
|
||||
use str;
|
||||
use str::Str;
|
||||
use rt::io::Decorator;
|
||||
use util::swap;
|
||||
use char::is_alphabetic;
|
||||
|
||||
fn exact_test<T>(t: &T, e:&str) {
|
||||
let mut m = io::mem::MemWriter::new();
|
||||
@ -674,7 +684,9 @@ fn test_repr() {
|
||||
exact_test(&(10u64, ~"hello"),
|
||||
"(10u64, ~\"hello\")");
|
||||
|
||||
exact_test(&(&println), "&fn()");
|
||||
exact_test(&println, "fn(&str)");
|
||||
exact_test(&swap::<int>, "fn(&mut int, &mut int)");
|
||||
exact_test(&is_alphabetic, "fn(char) -> bool");
|
||||
exact_test(&(~5 as ~ToStr), "~to_str::ToStr:Send");
|
||||
|
||||
struct Foo;
|
||||
|
@ -66,6 +66,9 @@ pub struct TyDesc {
|
||||
// `U`, but in the case of `@Trait` or `~Trait` objects, the type
|
||||
// `U` is unknown.
|
||||
borrow_offset: uint,
|
||||
|
||||
// Name corresponding to the type
|
||||
name: &'static str
|
||||
}
|
||||
|
||||
#[lang="opaque"]
|
||||
|
@ -52,6 +52,11 @@ static inline void *box_body(rust_opaque_box *box) {
|
||||
return (void*)(box + 1);
|
||||
}
|
||||
|
||||
struct slice {
|
||||
void *data;
|
||||
size_t length;
|
||||
};
|
||||
|
||||
struct type_desc {
|
||||
size_t size;
|
||||
size_t align;
|
||||
@ -60,6 +65,7 @@ struct type_desc {
|
||||
glue_fn *free_glue;
|
||||
glue_fn *visit_glue;
|
||||
size_t borrow_offset;
|
||||
slice name;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user