adt.rs renaming: "field" rather than "element"; set_discr -> start_init.
This way "field" refers to the abstraction and "element" (as in get_elt, "get element pointer", etc.) refers to the low-level LLVM operations.
This commit is contained in:
parent
e13111fc5a
commit
1f9bc64bae
@ -838,7 +838,7 @@ pub fn extract_variant_args(bcx: block,
|
|||||||
-> ExtractedBlock {
|
-> ExtractedBlock {
|
||||||
let _icx = bcx.insn_ctxt("match::extract_variant_args");
|
let _icx = bcx.insn_ctxt("match::extract_variant_args");
|
||||||
let args = do vec::from_fn(adt::num_args(repr, disr_val)) |i| {
|
let args = do vec::from_fn(adt::num_args(repr, disr_val)) |i| {
|
||||||
adt::trans_GEP(bcx, repr, val, disr_val, i)
|
adt::trans_field_ptr(bcx, repr, val, disr_val, i)
|
||||||
};
|
};
|
||||||
|
|
||||||
ExtractedBlock { vals: args, bcx: bcx }
|
ExtractedBlock { vals: args, bcx: bcx }
|
||||||
@ -1274,7 +1274,7 @@ pub fn compile_submatch(bcx: block,
|
|||||||
do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| {
|
do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| {
|
||||||
let rec_vals = rec_fields.map(|field_name| {
|
let rec_vals = rec_fields.map(|field_name| {
|
||||||
let ix = ty::field_idx_strict(tcx, *field_name, field_tys);
|
let ix = ty::field_idx_strict(tcx, *field_name, field_tys);
|
||||||
adt::trans_GEP(bcx, pat_repr, val, discr, ix)
|
adt::trans_field_ptr(bcx, pat_repr, val, discr, ix)
|
||||||
});
|
});
|
||||||
compile_submatch(
|
compile_submatch(
|
||||||
bcx,
|
bcx,
|
||||||
@ -1293,7 +1293,7 @@ pub fn compile_submatch(bcx: block,
|
|||||||
_ => ccx.sess.bug(~"non-tuple type in tuple pattern")
|
_ => ccx.sess.bug(~"non-tuple type in tuple pattern")
|
||||||
};
|
};
|
||||||
let tup_vals = do vec::from_fn(n_tup_elts) |i| {
|
let tup_vals = do vec::from_fn(n_tup_elts) |i| {
|
||||||
adt::trans_GEP(bcx, tup_repr, val, 0, i)
|
adt::trans_field_ptr(bcx, tup_repr, val, 0, i)
|
||||||
};
|
};
|
||||||
compile_submatch(bcx, enter_tup(bcx, dm, m, col, val, n_tup_elts),
|
compile_submatch(bcx, enter_tup(bcx, dm, m, col, val, n_tup_elts),
|
||||||
vec::append(tup_vals, vals_left), chk);
|
vec::append(tup_vals, vals_left), chk);
|
||||||
@ -1315,7 +1315,7 @@ pub fn compile_submatch(bcx: block,
|
|||||||
|
|
||||||
let struct_repr = adt::represent_type(bcx.ccx(), struct_ty);
|
let struct_repr = adt::represent_type(bcx.ccx(), struct_ty);
|
||||||
let llstructvals = do vec::from_fn(struct_element_count) |i| {
|
let llstructvals = do vec::from_fn(struct_element_count) |i| {
|
||||||
adt::trans_GEP(bcx, struct_repr, val, 0, i)
|
adt::trans_field_ptr(bcx, struct_repr, val, 0, i)
|
||||||
};
|
};
|
||||||
compile_submatch(bcx,
|
compile_submatch(bcx,
|
||||||
enter_tuple_struct(bcx, dm, m, col, val,
|
enter_tuple_struct(bcx, dm, m, col, val,
|
||||||
@ -1753,7 +1753,7 @@ pub fn bind_irrefutable_pat(bcx: block,
|
|||||||
// This is the tuple struct case.
|
// This is the tuple struct case.
|
||||||
let repr = adt::represent_node(bcx, pat.id);
|
let repr = adt::represent_node(bcx, pat.id);
|
||||||
for vec::eachi(elems) |i, elem| {
|
for vec::eachi(elems) |i, elem| {
|
||||||
let fldptr = adt::trans_GEP(bcx, repr,
|
let fldptr = adt::trans_field_ptr(bcx, repr,
|
||||||
val, 0, i);
|
val, 0, i);
|
||||||
bcx = bind_irrefutable_pat(bcx,
|
bcx = bind_irrefutable_pat(bcx,
|
||||||
*elem,
|
*elem,
|
||||||
@ -1776,7 +1776,7 @@ pub fn bind_irrefutable_pat(bcx: block,
|
|||||||
do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| {
|
do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| {
|
||||||
for vec::each(fields) |f| {
|
for vec::each(fields) |f| {
|
||||||
let ix = ty::field_idx_strict(tcx, f.ident, field_tys);
|
let ix = ty::field_idx_strict(tcx, f.ident, field_tys);
|
||||||
let fldptr = adt::trans_GEP(bcx, pat_repr, val,
|
let fldptr = adt::trans_field_ptr(bcx, pat_repr, val,
|
||||||
discr, ix);
|
discr, ix);
|
||||||
bcx = bind_irrefutable_pat(bcx,
|
bcx = bind_irrefutable_pat(bcx,
|
||||||
f.pat,
|
f.pat,
|
||||||
@ -1789,7 +1789,7 @@ pub fn bind_irrefutable_pat(bcx: block,
|
|||||||
ast::pat_tup(elems) => {
|
ast::pat_tup(elems) => {
|
||||||
let repr = adt::represent_node(bcx, pat.id);
|
let repr = adt::represent_node(bcx, pat.id);
|
||||||
for vec::eachi(elems) |i, elem| {
|
for vec::eachi(elems) |i, elem| {
|
||||||
let fldptr = adt::trans_GEP(bcx, repr, val, 0, i);
|
let fldptr = adt::trans_field_ptr(bcx, repr, val, 0, i);
|
||||||
bcx = bind_irrefutable_pat(bcx,
|
bcx = bind_irrefutable_pat(bcx,
|
||||||
*elem,
|
*elem,
|
||||||
fldptr,
|
fldptr,
|
||||||
|
@ -301,10 +301,10 @@ pub fn trans_case(bcx: block, r: &Repr, discr: int) -> _match::opt_result {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Begin initializing a new value of the given case of the given
|
* Begin initializing a new value of the given case of the given
|
||||||
* representation. The fields should then be initialized with
|
* representation. The fields, if any, should then be initialized via
|
||||||
* `trans_GEP` and stores.
|
* `trans_field_ptr`.
|
||||||
*/
|
*/
|
||||||
pub fn trans_set_discr(bcx: block, r: &Repr, val: ValueRef, discr: int) {
|
pub fn trans_start_init(bcx: block, r: &Repr, val: ValueRef, discr: int) {
|
||||||
match *r {
|
match *r {
|
||||||
Unit(the_discr) => {
|
Unit(the_discr) => {
|
||||||
assert discr == the_discr;
|
assert discr == the_discr;
|
||||||
@ -339,8 +339,8 @@ pub fn num_args(r: &Repr, discr: int) -> uint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Access a field, at a point when the value's case is known.
|
/// Access a field, at a point when the value's case is known.
|
||||||
pub fn trans_GEP(bcx: block, r: &Repr, val: ValueRef, discr: int, ix: uint)
|
pub fn trans_field_ptr(bcx: block, r: &Repr, val: ValueRef, discr: int,
|
||||||
-> ValueRef {
|
ix: uint) -> ValueRef {
|
||||||
// Note: if this ever needs to generate conditionals (e.g., if we
|
// Note: if this ever needs to generate conditionals (e.g., if we
|
||||||
// decide to do some kind of cdr-coding-like non-unique repr
|
// decide to do some kind of cdr-coding-like non-unique repr
|
||||||
// someday), it will need to return a possibly-new bcx as well.
|
// someday), it will need to return a possibly-new bcx as well.
|
||||||
@ -354,16 +354,16 @@ pub fn trans_GEP(bcx: block, r: &Repr, val: ValueRef, discr: int, ix: uint)
|
|||||||
NonStruct => val,
|
NonStruct => val,
|
||||||
StructWithDtor | StructWithoutDtor => GEPi(bcx, val, [0, 0])
|
StructWithDtor | StructWithoutDtor => GEPi(bcx, val, [0, 0])
|
||||||
};
|
};
|
||||||
struct_GEP(bcx, st, val, ix, false)
|
struct_field_ptr(bcx, st, val, ix, false)
|
||||||
}
|
}
|
||||||
General(ref cases) => {
|
General(ref cases) => {
|
||||||
struct_GEP(bcx, &cases[discr as uint],
|
struct_field_ptr(bcx, &cases[discr as uint],
|
||||||
GEPi(bcx, val, [0, 1]), ix, true)
|
GEPi(bcx, val, [0, 1]), ix, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn struct_GEP(bcx: block, st: &Struct, val: ValueRef, ix: uint,
|
fn struct_field_ptr(bcx: block, st: &Struct, val: ValueRef, ix: uint,
|
||||||
needs_cast: bool) -> ValueRef {
|
needs_cast: bool) -> ValueRef {
|
||||||
let ccx = bcx.ccx();
|
let ccx = bcx.ccx();
|
||||||
|
|
||||||
@ -501,10 +501,15 @@ pub fn const_get_discrim(ccx: @CrateContext, r: &Repr, val: ValueRef)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access a field of a constant value.
|
/**
|
||||||
pub fn const_get_element(ccx: @CrateContext, r: &Repr, val: ValueRef,
|
* Extract a field of a constant value, as appropriate for its
|
||||||
|
* representation.
|
||||||
|
*
|
||||||
|
* (Not to be confused with `common::const_get_elt`, which operates on
|
||||||
|
* raw LLVM-level structs and arrays.)
|
||||||
|
*/
|
||||||
|
pub fn const_get_field(ccx: @CrateContext, r: &Repr, val: ValueRef,
|
||||||
_discr: int, ix: uint) -> ValueRef {
|
_discr: int, ix: uint) -> ValueRef {
|
||||||
// Not to be confused with common::const_get_elt.
|
|
||||||
match *r {
|
match *r {
|
||||||
Unit(*) | CEnum(*) => ccx.sess.bug(~"element access in C-like enum \
|
Unit(*) | CEnum(*) => ccx.sess.bug(~"element access in C-like enum \
|
||||||
const"),
|
const"),
|
||||||
|
@ -630,7 +630,8 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
|
|||||||
let mut cx = cx;
|
let mut cx = cx;
|
||||||
|
|
||||||
for variant.args.eachi |i, &arg| {
|
for variant.args.eachi |i, &arg| {
|
||||||
cx = f(cx, adt::trans_GEP(cx, repr, av, variant.disr_val, i),
|
cx = f(cx,
|
||||||
|
adt::trans_field_ptr(cx, repr, av, variant.disr_val, i),
|
||||||
ty::subst_tps(tcx, tps, None, arg));
|
ty::subst_tps(tcx, tps, None, arg));
|
||||||
}
|
}
|
||||||
return cx;
|
return cx;
|
||||||
@ -642,7 +643,7 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
|
|||||||
let repr = adt::represent_type(cx.ccx(), t);
|
let repr = adt::represent_type(cx.ccx(), t);
|
||||||
do expr::with_field_tys(cx.tcx(), t, None) |discr, field_tys| {
|
do expr::with_field_tys(cx.tcx(), t, None) |discr, field_tys| {
|
||||||
for vec::eachi(field_tys) |i, field_ty| {
|
for vec::eachi(field_tys) |i, field_ty| {
|
||||||
let llfld_a = adt::trans_GEP(cx, repr, av, discr, i);
|
let llfld_a = adt::trans_field_ptr(cx, repr, av, discr, i);
|
||||||
cx = f(cx, llfld_a, field_ty.mt.ty);
|
cx = f(cx, llfld_a, field_ty.mt.ty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -655,7 +656,7 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
|
|||||||
ty::ty_tup(args) => {
|
ty::ty_tup(args) => {
|
||||||
let repr = adt::represent_type(cx.ccx(), t);
|
let repr = adt::represent_type(cx.ccx(), t);
|
||||||
for vec::eachi(args) |i, arg| {
|
for vec::eachi(args) |i, arg| {
|
||||||
let llfld_a = adt::trans_GEP(cx, repr, av, 0, i);
|
let llfld_a = adt::trans_field_ptr(cx, repr, av, 0, i);
|
||||||
cx = f(cx, llfld_a, *arg);
|
cx = f(cx, llfld_a, *arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1864,9 +1865,10 @@ pub fn trans_enum_variant(ccx: @CrateContext,
|
|||||||
ty::node_id_to_type(ccx.tcx, enum_id));
|
ty::node_id_to_type(ccx.tcx, enum_id));
|
||||||
let repr = adt::represent_type(ccx, enum_ty);
|
let repr = adt::represent_type(ccx, enum_ty);
|
||||||
|
|
||||||
adt::trans_set_discr(bcx, repr, fcx.llretptr, disr);
|
adt::trans_start_init(bcx, repr, fcx.llretptr, disr);
|
||||||
for vec::eachi(args) |i, va| {
|
for vec::eachi(args) |i, va| {
|
||||||
let lldestptr = adt::trans_GEP(bcx, repr, fcx.llretptr, disr, i);
|
let lldestptr = adt::trans_field_ptr(bcx, repr, fcx.llretptr,
|
||||||
|
disr, i);
|
||||||
|
|
||||||
// If this argument to this function is a enum, it'll have come in to
|
// If this argument to this function is a enum, it'll have come in to
|
||||||
// this function as an opaque blob due to the way that type_of()
|
// this function as an opaque blob due to the way that type_of()
|
||||||
@ -1936,7 +1938,7 @@ pub fn trans_tuple_struct(ccx: @CrateContext,
|
|||||||
let repr = adt::represent_type(ccx, tup_ty);
|
let repr = adt::represent_type(ccx, tup_ty);
|
||||||
|
|
||||||
for fields.eachi |i, field| {
|
for fields.eachi |i, field| {
|
||||||
let lldestptr = adt::trans_GEP(bcx, repr, fcx.llretptr, 0, i);
|
let lldestptr = adt::trans_field_ptr(bcx, repr, fcx.llretptr, 0, i);
|
||||||
let llarg = match fcx.llargs.get(&field.node.id) {
|
let llarg = match fcx.llargs.get(&field.node.id) {
|
||||||
local_mem(x) => x,
|
local_mem(x) => x,
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -245,7 +245,7 @@ fn const_expr_unchecked(cx: @CrateContext, e: @ast::expr) -> ValueRef {
|
|||||||
let (bt, bv) = const_autoderef(cx, bt, bv);
|
let (bt, bv) = const_autoderef(cx, bt, bv);
|
||||||
do expr::with_field_tys(cx.tcx, bt, None) |discr, field_tys| {
|
do expr::with_field_tys(cx.tcx, bt, None) |discr, field_tys| {
|
||||||
let ix = ty::field_idx_strict(cx.tcx, field, field_tys);
|
let ix = ty::field_idx_strict(cx.tcx, field, field_tys);
|
||||||
adt::const_get_element(cx, brepr, bv, discr, ix)
|
adt::const_get_field(cx, brepr, bv, discr, ix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -687,7 +687,7 @@ pub impl Datum {
|
|||||||
// rather than a ptr to the enum type.
|
// rather than a ptr to the enum type.
|
||||||
(
|
(
|
||||||
Some(Datum {
|
Some(Datum {
|
||||||
val: adt::trans_GEP(bcx, repr, self.val,
|
val: adt::trans_field_ptr(bcx, repr, self.val,
|
||||||
0, 0),
|
0, 0),
|
||||||
ty: ty,
|
ty: ty,
|
||||||
mode: ByRef,
|
mode: ByRef,
|
||||||
@ -729,7 +729,7 @@ pub impl Datum {
|
|||||||
// destructors.
|
// destructors.
|
||||||
(
|
(
|
||||||
Some(Datum {
|
Some(Datum {
|
||||||
val: adt::trans_GEP(bcx, repr, self.val,
|
val: adt::trans_field_ptr(bcx, repr, self.val,
|
||||||
0, 0),
|
0, 0),
|
||||||
ty: ty,
|
ty: ty,
|
||||||
mode: ByRef,
|
mode: ByRef,
|
||||||
|
@ -726,7 +726,7 @@ fn trans_def_dps_unadjusted(bcx: block, ref_expr: @ast::expr,
|
|||||||
// Nullary variant.
|
// Nullary variant.
|
||||||
let ty = expr_ty(bcx, ref_expr);
|
let ty = expr_ty(bcx, ref_expr);
|
||||||
let repr = adt::represent_type(ccx, ty);
|
let repr = adt::represent_type(ccx, ty);
|
||||||
adt::trans_set_discr(bcx, repr, lldest,
|
adt::trans_start_init(bcx, repr, lldest,
|
||||||
variant_info.disr_val);
|
variant_info.disr_val);
|
||||||
return bcx;
|
return bcx;
|
||||||
}
|
}
|
||||||
@ -891,7 +891,7 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
|
|||||||
datum: do base_datum.get_element(bcx,
|
datum: do base_datum.get_element(bcx,
|
||||||
field_tys[ix].mt.ty,
|
field_tys[ix].mt.ty,
|
||||||
ZeroMem) |srcval| {
|
ZeroMem) |srcval| {
|
||||||
adt::trans_GEP(bcx, repr, srcval, discr, ix)
|
adt::trans_field_ptr(bcx, repr, srcval, discr, ix)
|
||||||
},
|
},
|
||||||
bcx: bcx
|
bcx: bcx
|
||||||
}
|
}
|
||||||
@ -1240,9 +1240,9 @@ fn trans_adt(bcx: block, repr: &adt::Repr, discr: int,
|
|||||||
SaveIn(pos) => pos
|
SaveIn(pos) => pos
|
||||||
};
|
};
|
||||||
let mut temp_cleanups = ~[];
|
let mut temp_cleanups = ~[];
|
||||||
adt::trans_set_discr(bcx, repr, addr, discr);
|
adt::trans_start_init(bcx, repr, addr, discr);
|
||||||
for fields.each |&(i, e)| {
|
for fields.each |&(i, e)| {
|
||||||
let dest = adt::trans_GEP(bcx, repr, addr, discr, i);
|
let dest = adt::trans_field_ptr(bcx, repr, addr, discr, i);
|
||||||
let e_ty = expr_ty(bcx, e);
|
let e_ty = expr_ty(bcx, e);
|
||||||
bcx = trans_into(bcx, e, SaveIn(dest));
|
bcx = trans_into(bcx, e, SaveIn(dest));
|
||||||
add_clean_temp_mem(bcx, dest, e_ty);
|
add_clean_temp_mem(bcx, dest, e_ty);
|
||||||
@ -1254,9 +1254,9 @@ fn trans_adt(bcx: block, repr: &adt::Repr, discr: int,
|
|||||||
let base_datum = unpack_datum!(bcx, trans_to_datum(bcx, base.expr));
|
let base_datum = unpack_datum!(bcx, trans_to_datum(bcx, base.expr));
|
||||||
for base.fields.each |&(i, t)| {
|
for base.fields.each |&(i, t)| {
|
||||||
let datum = do base_datum.get_element(bcx, t, ZeroMem) |srcval| {
|
let datum = do base_datum.get_element(bcx, t, ZeroMem) |srcval| {
|
||||||
adt::trans_GEP(bcx, repr, srcval, discr, i)
|
adt::trans_field_ptr(bcx, repr, srcval, discr, i)
|
||||||
};
|
};
|
||||||
let dest = adt::trans_GEP(bcx, repr, addr, discr, i);
|
let dest = adt::trans_field_ptr(bcx, repr, addr, discr, i);
|
||||||
bcx = datum.store_to(bcx, base.expr.id, INIT, dest);
|
bcx = datum.store_to(bcx, base.expr.id, INIT, dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -507,7 +507,7 @@ pub fn trans_struct_drop(bcx: block,
|
|||||||
ty::struct_mutable_fields(bcx.tcx(), class_did,
|
ty::struct_mutable_fields(bcx.tcx(), class_did,
|
||||||
substs);
|
substs);
|
||||||
for vec::eachi(field_tys) |i, fld| {
|
for vec::eachi(field_tys) |i, fld| {
|
||||||
let llfld_a = adt::trans_GEP(bcx, repr, v0, 0, i);
|
let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i);
|
||||||
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
|
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user