mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-10 06:47:34 +00:00
rustc: Clean up some enum code
This commit is contained in:
parent
dfc81dfa90
commit
582c71731d
@ -680,25 +680,14 @@ fn T_opaque_cbox_ptr(cx: @crate_ctxt) -> TypeRef {
|
||||
ret T_opaque_box_ptr(cx);
|
||||
}
|
||||
|
||||
fn T_enum_variant(cx: @crate_ctxt) -> TypeRef {
|
||||
fn T_enum_discrim(cx: @crate_ctxt) -> TypeRef {
|
||||
ret cx.int_type;
|
||||
}
|
||||
|
||||
fn T_enum(cx: @crate_ctxt, size: uint) -> TypeRef {
|
||||
let s = "enum_" + uint::to_str(size, 10u);
|
||||
alt name_has_type(cx.tn, s) { some(t) { ret t; } _ {} }
|
||||
let t =
|
||||
if size == 0u {
|
||||
T_struct([T_enum_variant(cx)])
|
||||
} else { T_struct([T_enum_variant(cx), T_array(T_i8(), size)]) };
|
||||
associate_type(cx.tn, s, t);
|
||||
ret t;
|
||||
}
|
||||
|
||||
fn T_opaque_enum(cx: @crate_ctxt) -> TypeRef {
|
||||
let s = "opaque_enum";
|
||||
alt name_has_type(cx.tn, s) { some(t) { ret t; } _ {} }
|
||||
let t = T_struct([T_enum_variant(cx), T_i8()]);
|
||||
let t = T_struct([T_enum_discrim(cx), T_i8()]);
|
||||
associate_type(cx.tn, s, t);
|
||||
ret t;
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ fn compute_static_enum_size(ccx: @crate_ctxt, largest_variants: [uint],
|
||||
// FIXME (issue #792): This is wrong. If the enum starts with an 8 byte
|
||||
// aligned quantity, we don't align it.
|
||||
if vec::len(*variants) > 1u {
|
||||
let variant_t = T_enum_variant(ccx);
|
||||
let variant_t = T_enum_discrim(ccx);
|
||||
max_size += llsize_of_real(ccx, variant_t) as u16;
|
||||
let align = llalign_of_pref(ccx, variant_t) as u8;
|
||||
if max_align < align { max_align = align; }
|
||||
|
@ -158,10 +158,10 @@ fn type_of_enum(cx: @crate_ctxt, did: ast::def_id, t: ty::t)
|
||||
let degen = (*ty::enum_variants(cx.tcx, did)).len() == 1u;
|
||||
let size = shape::static_size_of_enum(cx, t);
|
||||
if !degen {
|
||||
[T_enum_variant(cx), T_array(T_i8(), size)]
|
||||
[T_enum_discrim(cx), T_array(T_i8(), size)]
|
||||
}
|
||||
else if size == 0u {
|
||||
[T_enum_variant(cx)]
|
||||
[T_enum_discrim(cx)]
|
||||
}
|
||||
else {
|
||||
[T_array(T_i8(), size)]
|
||||
|
Loading…
Reference in New Issue
Block a user