Skip to content

Commit cc0a88c

Browse files
committedMar 3, 2013
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.
1 parent 085575d commit cc0a88c

File tree

7 files changed

+44
-37
lines changed

7 files changed

+44
-37
lines changed
 

‎src/librustc/middle/trans/_match.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ pub fn extract_variant_args(bcx: block,
838838
-> ExtractedBlock {
839839
let _icx = bcx.insn_ctxt("match::extract_variant_args");
840840
let args = do vec::from_fn(adt::num_args(repr, disr_val)) |i| {
841-
adt::trans_GEP(bcx, repr, val, disr_val, i)
841+
adt::trans_field_ptr(bcx, repr, val, disr_val, i)
842842
};
843843
844844
ExtractedBlock { vals: args, bcx: bcx }
@@ -1274,7 +1274,7 @@ pub fn compile_submatch(bcx: block,
12741274
do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| {
12751275
let rec_vals = rec_fields.map(|field_name| {
12761276
let ix = ty::field_idx_strict(tcx, *field_name, field_tys);
1277-
adt::trans_GEP(bcx, pat_repr, val, discr, ix)
1277+
adt::trans_field_ptr(bcx, pat_repr, val, discr, ix)
12781278
});
12791279
compile_submatch(
12801280
bcx,
@@ -1293,7 +1293,7 @@ pub fn compile_submatch(bcx: block,
12931293
_ => ccx.sess.bug(~"non-tuple type in tuple pattern")
12941294
};
12951295
let tup_vals = do vec::from_fn(n_tup_elts) |i| {
1296-
adt::trans_GEP(bcx, tup_repr, val, 0, i)
1296+
adt::trans_field_ptr(bcx, tup_repr, val, 0, i)
12971297
};
12981298
compile_submatch(bcx, enter_tup(bcx, dm, m, col, val, n_tup_elts),
12991299
vec::append(tup_vals, vals_left), chk);
@@ -1315,7 +1315,7 @@ pub fn compile_submatch(bcx: block,
13151315
13161316
let struct_repr = adt::represent_type(bcx.ccx(), struct_ty);
13171317
let llstructvals = do vec::from_fn(struct_element_count) |i| {
1318-
adt::trans_GEP(bcx, struct_repr, val, 0, i)
1318+
adt::trans_field_ptr(bcx, struct_repr, val, 0, i)
13191319
};
13201320
compile_submatch(bcx,
13211321
enter_tuple_struct(bcx, dm, m, col, val,
@@ -1753,7 +1753,7 @@ pub fn bind_irrefutable_pat(bcx: block,
17531753
// This is the tuple struct case.
17541754
let repr = adt::represent_node(bcx, pat.id);
17551755
for vec::eachi(elems) |i, elem| {
1756-
let fldptr = adt::trans_GEP(bcx, repr,
1756+
let fldptr = adt::trans_field_ptr(bcx, repr,
17571757
val, 0, i);
17581758
bcx = bind_irrefutable_pat(bcx,
17591759
*elem,
@@ -1776,7 +1776,7 @@ pub fn bind_irrefutable_pat(bcx: block,
17761776
do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| {
17771777
for vec::each(fields) |f| {
17781778
let ix = ty::field_idx_strict(tcx, f.ident, field_tys);
1779-
let fldptr = adt::trans_GEP(bcx, pat_repr, val,
1779+
let fldptr = adt::trans_field_ptr(bcx, pat_repr, val,
17801780
discr, ix);
17811781
bcx = bind_irrefutable_pat(bcx,
17821782
f.pat,
@@ -1789,7 +1789,7 @@ pub fn bind_irrefutable_pat(bcx: block,
17891789
ast::pat_tup(elems) => {
17901790
let repr = adt::represent_node(bcx, pat.id);
17911791
for vec::eachi(elems) |i, elem| {
1792-
let fldptr = adt::trans_GEP(bcx, repr, val, 0, i);
1792+
let fldptr = adt::trans_field_ptr(bcx, repr, val, 0, i);
17931793
bcx = bind_irrefutable_pat(bcx,
17941794
*elem,
17951795
fldptr,

‎src/librustc/middle/trans/adt.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,10 @@ pub fn trans_case(bcx: block, r: &Repr, discr: int) -> _match::opt_result {
300300

301301
/**
302302
* Begin initializing a new value of the given case of the given
303-
* representation. The fields should then be initialized with
304-
* `trans_GEP` and stores.
303+
* representation. The fields, if any, should then be initialized via
304+
* `trans_field_ptr`.
305305
*/
306-
pub fn trans_set_discr(bcx: block, r: &Repr, val: ValueRef, discr: int) {
306+
pub fn trans_start_init(bcx: block, r: &Repr, val: ValueRef, discr: int) {
307307
match *r {
308308
Unit(the_discr) => {
309309
assert discr == the_discr;
@@ -338,8 +338,8 @@ pub fn num_args(r: &Repr, discr: int) -> uint {
338338
}
339339

340340
/// Access a field, at a point when the value's case is known.
341-
pub fn trans_GEP(bcx: block, r: &Repr, val: ValueRef, discr: int, ix: uint)
342-
-> ValueRef {
341+
pub fn trans_field_ptr(bcx: block, r: &Repr, val: ValueRef, discr: int,
342+
ix: uint) -> ValueRef {
343343
// Note: if this ever needs to generate conditionals (e.g., if we
344344
// decide to do some kind of cdr-coding-like non-unique repr
345345
// someday), it will need to return a possibly-new bcx as well.
@@ -353,16 +353,16 @@ pub fn trans_GEP(bcx: block, r: &Repr, val: ValueRef, discr: int, ix: uint)
353353
NonStruct => val,
354354
StructWithDtor | StructWithoutDtor => GEPi(bcx, val, [0, 0])
355355
};
356-
struct_GEP(bcx, st, val, ix, false)
356+
struct_field_ptr(bcx, st, val, ix, false)
357357
}
358358
General(ref cases) => {
359-
struct_GEP(bcx, &cases[discr as uint],
360-
GEPi(bcx, val, [0, 1]), ix, true)
359+
struct_field_ptr(bcx, &cases[discr as uint],
360+
GEPi(bcx, val, [0, 1]), ix, true)
361361
}
362362
}
363363
}
364364

365-
fn struct_GEP(bcx: block, st: &Struct, val: ValueRef, ix: uint,
365+
fn struct_field_ptr(bcx: block, st: &Struct, val: ValueRef, ix: uint,
366366
needs_cast: bool) -> ValueRef {
367367
let ccx = bcx.ccx();
368368

@@ -495,10 +495,15 @@ pub fn const_get_discrim(ccx: @CrateContext, r: &Repr, val: ValueRef)
495495
}
496496
}
497497

498-
/// Access a field of a constant value.
499-
pub fn const_get_element(ccx: @CrateContext, r: &Repr, val: ValueRef,
500-
_discr: int, ix: uint) -> ValueRef {
501-
// Not to be confused with common::const_get_elt.
498+
/**
499+
* Extract a field of a constant value, as appropriate for its
500+
* representation.
501+
*
502+
* (Not to be confused with `common::const_get_elt`, which operates on
503+
* raw LLVM-level structs and arrays.)
504+
*/
505+
pub fn const_get_field(ccx: @CrateContext, r: &Repr, val: ValueRef,
506+
_discr: int, ix: uint) -> ValueRef {
502507
match *r {
503508
Unit(*) | CEnum(*) => ccx.sess.bug(~"element access in C-like enum \
504509
const"),

‎src/librustc/middle/trans/base.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,8 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
641641
let mut cx = cx;
642642

643643
for variant.args.eachi |i, &arg| {
644-
cx = f(cx, adt::trans_GEP(cx, repr, av, variant.disr_val, i),
644+
cx = f(cx,
645+
adt::trans_field_ptr(cx, repr, av, variant.disr_val, i),
645646
ty::subst_tps(tcx, tps, None, arg));
646647
}
647648
return cx;
@@ -653,7 +654,7 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
653654
let repr = adt::represent_type(cx.ccx(), t);
654655
do expr::with_field_tys(cx.tcx(), t, None) |discr, field_tys| {
655656
for vec::eachi(field_tys) |i, field_ty| {
656-
let llfld_a = adt::trans_GEP(cx, repr, av, discr, i);
657+
let llfld_a = adt::trans_field_ptr(cx, repr, av, discr, i);
657658
cx = f(cx, llfld_a, field_ty.mt.ty);
658659
}
659660
}
@@ -666,7 +667,7 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
666667
ty::ty_tup(args) => {
667668
let repr = adt::represent_type(cx.ccx(), t);
668669
for vec::eachi(args) |i, arg| {
669-
let llfld_a = adt::trans_GEP(cx, repr, av, 0, i);
670+
let llfld_a = adt::trans_field_ptr(cx, repr, av, 0, i);
670671
cx = f(cx, llfld_a, *arg);
671672
}
672673
}
@@ -1871,9 +1872,10 @@ pub fn trans_enum_variant(ccx: @CrateContext,
18711872
ty::node_id_to_type(ccx.tcx, enum_id));
18721873
let repr = adt::represent_type(ccx, enum_ty);
18731874

1874-
adt::trans_set_discr(bcx, repr, fcx.llretptr, disr);
1875+
adt::trans_start_init(bcx, repr, fcx.llretptr, disr);
18751876
for vec::eachi(args) |i, va| {
1876-
let lldestptr = adt::trans_GEP(bcx, repr, fcx.llretptr, disr, i);
1877+
let lldestptr = adt::trans_field_ptr(bcx, repr, fcx.llretptr,
1878+
disr, i);
18771879

18781880
// If this argument to this function is a enum, it'll have come in to
18791881
// this function as an opaque blob due to the way that type_of()
@@ -1943,7 +1945,7 @@ pub fn trans_tuple_struct(ccx: @CrateContext,
19431945
let repr = adt::represent_type(ccx, tup_ty);
19441946
19451947
for fields.eachi |i, field| {
1946-
let lldestptr = adt::trans_GEP(bcx, repr, fcx.llretptr, 0, i);
1948+
let lldestptr = adt::trans_field_ptr(bcx, repr, fcx.llretptr, 0, i);
19471949
let llarg = match fcx.llargs.get(&field.node.id) {
19481950
local_mem(x) => x,
19491951
_ => {

‎src/librustc/middle/trans/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
226226
let (bt, bv) = const_autoderef(cx, bt, bv);
227227
do expr::with_field_tys(cx.tcx, bt, None) |discr, field_tys| {
228228
let ix = ty::field_idx_strict(cx.tcx, field, field_tys);
229-
adt::const_get_element(cx, brepr, bv, discr, ix)
229+
adt::const_get_field(cx, brepr, bv, discr, ix)
230230
}
231231
}
232232

‎src/librustc/middle/trans/datum.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ pub impl Datum {
690690
// rather than a ptr to the enum type.
691691
(
692692
Some(Datum {
693-
val: adt::trans_GEP(bcx, repr, self.val,
693+
val: adt::trans_field_ptr(bcx, repr, self.val,
694694
0, 0),
695695
ty: ty,
696696
mode: ByRef,
@@ -732,7 +732,7 @@ pub impl Datum {
732732
// destructors.
733733
(
734734
Some(Datum {
735-
val: adt::trans_GEP(bcx, repr, self.val,
735+
val: adt::trans_field_ptr(bcx, repr, self.val,
736736
0, 0),
737737
ty: ty,
738738
mode: ByRef,

‎src/librustc/middle/trans/expr.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,8 @@ fn trans_def_dps_unadjusted(bcx: block, ref_expr: @ast::expr,
708708
// Nullary variant.
709709
let ty = expr_ty(bcx, ref_expr);
710710
let repr = adt::represent_type(ccx, ty);
711-
adt::trans_set_discr(bcx, repr, lldest,
712-
variant_info.disr_val);
711+
adt::trans_start_init(bcx, repr, lldest,
712+
variant_info.disr_val);
713713
return bcx;
714714
}
715715
}
@@ -813,7 +813,7 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
813813
datum: do base_datum.get_element(bcx,
814814
field_tys[ix].mt.ty,
815815
ZeroMem) |srcval| {
816-
adt::trans_GEP(bcx, repr, srcval, discr, ix)
816+
adt::trans_field_ptr(bcx, repr, srcval, discr, ix)
817817
},
818818
bcx: bcx
819819
}
@@ -1192,9 +1192,9 @@ fn trans_adt(bcx: block, repr: &adt::Repr, discr: int,
11921192
SaveIn(pos) => pos
11931193
};
11941194
let mut temp_cleanups = ~[];
1195-
adt::trans_set_discr(bcx, repr, addr, discr);
1195+
adt::trans_start_init(bcx, repr, addr, discr);
11961196
for fields.each |&(i, e)| {
1197-
let dest = adt::trans_GEP(bcx, repr, addr, discr, i);
1197+
let dest = adt::trans_field_ptr(bcx, repr, addr, discr, i);
11981198
let e_ty = expr_ty(bcx, e);
11991199
bcx = trans_into(bcx, e, SaveIn(dest));
12001200
add_clean_temp_mem(bcx, dest, e_ty);
@@ -1206,9 +1206,9 @@ fn trans_adt(bcx: block, repr: &adt::Repr, discr: int,
12061206
let base_datum = unpack_datum!(bcx, trans_to_datum(bcx, base.expr));
12071207
for base.fields.each |&(i, t)| {
12081208
let datum = do base_datum.get_element(bcx, t, ZeroMem) |srcval| {
1209-
adt::trans_GEP(bcx, repr, srcval, discr, i)
1209+
adt::trans_field_ptr(bcx, repr, srcval, discr, i)
12101210
};
1211-
let dest = adt::trans_GEP(bcx, repr, addr, discr, i);
1211+
let dest = adt::trans_field_ptr(bcx, repr, addr, discr, i);
12121212
bcx = datum.store_to(bcx, base.expr.id, INIT, dest);
12131213
}
12141214
}

‎src/librustc/middle/trans/glue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ pub fn trans_struct_drop(bcx: block,
507507
ty::struct_mutable_fields(bcx.tcx(), class_did,
508508
substs);
509509
for vec::eachi(field_tys) |i, fld| {
510-
let llfld_a = adt::trans_GEP(bcx, repr, v0, 0, i);
510+
let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i);
511511
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
512512
}
513513

0 commit comments

Comments
 (0)
Please sign in to comment.