Skip to content

Remove tps from trans_enum_def and trans_struct_def #4703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ pub fn trans_struct_dtor(ccx: @crate_ctxt,
}

pub fn trans_enum_def(ccx: @crate_ctxt, enum_definition: ast::enum_def,
id: ast::node_id, tps: ~[ast::ty_param], degen: bool,
id: ast::node_id, degen: bool,
path: @ast_map::path, vi: @~[ty::VariantInfo],
i: &mut uint) {
for vec::each(enum_definition.variants) |variant| {
Expand All @@ -2003,14 +2003,13 @@ pub fn trans_enum_def(ccx: @crate_ctxt, enum_definition: ast::enum_def,
// Nothing to do.
}
ast::struct_variant_kind(struct_def) => {
trans_struct_def(ccx, struct_def, /*bad*/copy tps, path,
trans_struct_def(ccx, struct_def, path,
variant.node.id);
}
ast::enum_variant_kind(ref enum_definition) => {
trans_enum_def(ccx,
*enum_definition,
id,
/*bad*/copy tps,
degen,
path,
vi,
Expand Down Expand Up @@ -2062,11 +2061,11 @@ pub fn trans_item(ccx: @crate_ctxt, item: ast::item) {
trans_mod(ccx, m);
}
ast::item_enum(ref enum_definition, ref tps) => {
if tps.len() == 0u {
if tps.is_empty() {
let degen = (*enum_definition).variants.len() == 1u;
let vi = ty::enum_variants(ccx.tcx, local_def(item.id));
let mut i = 0;
trans_enum_def(ccx, (*enum_definition), item.id, /*bad*/copy *tps,
trans_enum_def(ccx, (*enum_definition), item.id,
degen, path, vi, &mut i);
}
}
Expand All @@ -2080,35 +2079,33 @@ pub fn trans_item(ccx: @crate_ctxt, item: ast::item) {
foreign::trans_foreign_mod(ccx, foreign_mod, abi);
}
ast::item_struct(struct_def, tps) => {
trans_struct_def(ccx, struct_def, tps, path, item.id);
if tps.is_empty() {
trans_struct_def(ccx, struct_def, path, item.id);
}
}
_ => {/* fall through */ }
}
}

pub fn trans_struct_def(ccx: @crate_ctxt, struct_def: @ast::struct_def,
tps: ~[ast::ty_param], path: @ast_map::path,
path: @ast_map::path,
id: ast::node_id) {
// If there are type parameters, the destructor and constructor will be
// monomorphized, so we don't translate them here.
if tps.len() == 0u {
// Translate the destructor.
do option::iter(&struct_def.dtor) |dtor| {
trans_struct_dtor(ccx, /*bad*/copy *path, dtor.node.body,
dtor.node.id, None, None, local_def(id));
};
// Translate the destructor.
do option::iter(&struct_def.dtor) |dtor| {
trans_struct_dtor(ccx, /*bad*/copy *path, dtor.node.body,
dtor.node.id, None, None, local_def(id));
};

// If this is a tuple-like struct, translate the constructor.
match struct_def.ctor_id {
// We only need to translate a constructor if there are fields;
// otherwise this is a unit-like struct.
Some(ctor_id) if struct_def.fields.len() > 0 => {
let llfndecl = get_item_val(ccx, ctor_id);
trans_tuple_struct(ccx, /*bad*/copy struct_def.fields,
ctor_id, None, llfndecl);
}
Some(_) | None => {}
// If this is a tuple-like struct, translate the constructor.
match struct_def.ctor_id {
// We only need to translate a constructor if there are fields;
// otherwise this is a unit-like struct.
Some(ctor_id) if struct_def.fields.len() > 0 => {
let llfndecl = get_item_val(ccx, ctor_id);
trans_tuple_struct(ccx, /*bad*/copy struct_def.fields,
ctor_id, None, llfndecl);
}
Some(_) | None => {}
}
}

Expand Down