pub fn trans_field_ptr(bcx: &Block, r: &Repr, val: ValueRef, discr: Disr,
                       ix: uint) -> ValueRef {
    // Note: if this ever needs to generate conditionals (e.g., if we
    // decide to do some kind of cdr-coding-like non-unique repr
    // someday), it will need to return a possibly-new bcx as well.
    match *r {
        CEnum(..) => {
            bcx.ccx().sess.bug("element access in C-like enum")
        }
        Univariant(ref st, _dtor) => {
            assert_eq!(discr, 0);
            struct_field_ptr(bcx, st, val, ix, false)
        }
        General(_, ref cases) => {
            struct_field_ptr(bcx, &cases[discr], val, ix + 1, true)
        }
        NullablePointer{ nonnull: ref nonnull, nullfields: ref nullfields,
                         nndiscr, .. } => {
            if discr == nndiscr {
                struct_field_ptr(bcx, nonnull, val, ix, false)
            } else {
                // The unit-like case might have a nonzero number of unit-like fields.
                // (e.g., Result or Either with () as one side.)
                let ty = type_of::type_of(bcx.ccx(), nullfields[ix]);
                assert_eq!(machine::llsize_of_alloc(bcx.ccx(), ty), 0);
                // The contents of memory at this pointer can't matter, but use
                // the value that's "reasonable" in case of pointer comparison.
                PointerCast(bcx, val, ty.ptr_to())
            }
        }
    }
}
/// 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.
Access a field at a point when the value ' s case is known .
pub fn trans_field_ptr(bcx: &Block, r: &Repr, val: ValueRef, discr: Disr,
                       ix: uint) -> ValueRef {
    // Note: if this ever needs to generate conditionals (e.g., if we
    // decide to do some kind of cdr-coding-like non-unique repr
    // someday), it will need to return a possibly-new bcx as well.
    match *r {
        CEnum(..) => {
            bcx.ccx().sess.bug("element access in C-like enum")
        }
        Univariant(ref st, _dtor) => {
            assert_eq!(discr, 0);
            struct_field_ptr(bcx, st, val, ix, false)
        }
        General(_, ref cases) => {
            struct_field_ptr(bcx, &cases[discr], val, ix + 1, true)
        }
        NullablePointer{ nonnull: ref nonnull, nullfields: ref nullfields,
                         nndiscr, .. } => {
            if discr == nndiscr {
                struct_field_ptr(bcx, nonnull, val, ix, false)
            } else {
                // The unit-like case might have a nonzero number of unit-like fields.
                // (e.g., Result or Either with () as one side.)
                let ty = type_of::type_of(bcx.ccx(), nullfields[ix]);
                assert_eq!(machine::llsize_of_alloc(bcx.ccx(), ty), 0);
                // The contents of memory at this pointer can't matter, but use
                // the value that's "reasonable" in case of pointer comparison.
                PointerCast(bcx, val, ty.ptr_to())
            }
        }
    }
}
pub fn trans_field_ptr ( bcx : & Block , r : & Repr , val : ValueRef , discr : Disr , ix : uint ) -> ValueRef { // Note: if this ever needs to generate conditionals (e.g., if we // decide to do some kind of cdr-coding-like non-unique repr // someday), it will need to return a possibly-new bcx as well. match * r { CEnum ( .. ) => { bcx . ccx ( ) . sess . bug ( " " ) } Univariant ( ref st , _dtor ) => { assert_eq ! ( discr 0 ) ; struct_field_ptr ( bcx , st , val , ix , false ) } General ( _ , ref cases ) => { struct_field_ptr ( bcx , & cases [ discr ] , val , ix + 1 , true ) } NullablePointer { nonnull : ref nonnull , nullfields : ref nullfields , nndiscr , .. } => { if discr == nndiscr { struct_field_ptr ( bcx , nonnull , val , ix , false ) } else { // The unit-like case might have a nonzero number of unit-like fields. // (e.g., Result or Either with () as one side.) let ty = type_of :: type_of ( bcx . ccx ( ) , nullfields [ ix ] ) ; assert_eq ! ( machine llsize_of_alloc ( bcx ccx ( ) ty ) 0 ) ; // The contents of memory at this pointer can't matter, but use // the value that's "reasonable" in case of pointer comparison. PointerCast ( bcx , val , ty . ptr_to ( ) ) } } } }
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 .
bcx
&Block
r
&Repr
val
ValueRef
discr
Disr
ix
uint
bcx
&Block
r
&Repr
val
ValueRef
discr
Disr
ix
uint