@@ -55,7 +55,6 @@ use middle::trans::common::*;
55
55
use middle:: trans:: machine;
56
56
use middle:: trans:: type_of;
57
57
use middle:: ty;
58
- use middle:: ty:: Disr ;
59
58
use syntax:: ast;
60
59
use util:: ppaux:: ty_to_str;
61
60
@@ -65,7 +64,7 @@ use middle::trans::type_::Type;
65
64
/// Representations.
66
65
pub enum Repr {
67
66
/// C-like enums; basically an int.
68
- CEnum ( Disr , Disr ) , // discriminant range
67
+ CEnum ( uint , uint ) , // discriminant range
69
68
/**
70
69
* Single-case variants, and structs/tuples/records.
71
70
*
@@ -90,7 +89,7 @@ pub enum Repr {
90
89
* is represented such that `None` is a null pointer and `Some` is the
91
90
* identity function.
92
91
*/
93
- NullablePointer { nonnull : Struct , nndiscr : Disr , ptrfield : uint ,
92
+ NullablePointer { nonnull : Struct , nndiscr : uint , ptrfield : uint ,
94
93
nullfields : ~[ ty:: t ] }
95
94
}
96
95
@@ -141,7 +140,7 @@ fn represent_type_uncached(cx: &mut CrateContext, t: ty::t) -> Repr {
141
140
return Univariant ( mk_struct ( cx, ftys, packed) , dtor)
142
141
}
143
142
ty:: ty_enum( def_id, ref substs) => {
144
- struct Case { discr : Disr , tys : ~[ ty:: t ] } ;
143
+ struct Case { discr : uint , tys : ~[ ty:: t ] } ;
145
144
impl Case {
146
145
fn is_zerolen ( & self , cx : & mut CrateContext ) -> bool {
147
146
mk_struct ( cx, self . tys , false ) . size == 0
@@ -178,7 +177,7 @@ fn represent_type_uncached(cx: &mut CrateContext, t: ty::t) -> Repr {
178
177
// Since there's at least one
179
178
// non-empty body, explicit discriminants should have
180
179
// been rejected by a checker before this point.
181
- if !cases. iter ( ) . enumerate ( ) . all ( |( i, c) | c. discr == ( i as Disr ) ) {
180
+ if !cases. iter ( ) . enumerate ( ) . all ( |( i, c) | c. discr == i ) {
182
181
cx. sess . bug ( fmt ! ( "non-C-like enum %s with specified \
183
182
discriminants",
184
183
ty:: item_path_str( cx. tcx, def_id) ) )
@@ -306,16 +305,16 @@ pub fn trans_get_discr(bcx: @mut Block, r: &Repr, scrutinee: ValueRef)
306
305
-> ValueRef {
307
306
match * r {
308
307
CEnum ( min, max) => load_discr ( bcx, scrutinee, min, max) ,
309
- Univariant ( * ) => C_disr ( bcx. ccx ( ) , 0 ) ,
310
- General ( ref cases) => load_discr ( bcx, scrutinee, 0 , ( cases. len ( ) - 1 ) as Disr ) ,
308
+ Univariant ( * ) => C_uint ( bcx. ccx ( ) , 0 ) ,
309
+ General ( ref cases) => load_discr ( bcx, scrutinee, 0 , cases. len ( ) - 1 ) ,
311
310
NullablePointer { nonnull : ref nonnull, nndiscr, ptrfield, _ } => {
312
311
ZExt ( bcx, nullable_bitdiscr ( bcx, nonnull, nndiscr, ptrfield, scrutinee) ,
313
312
Type :: enum_discrim ( bcx. ccx ( ) ) )
314
313
}
315
314
}
316
315
}
317
316
318
- fn nullable_bitdiscr ( bcx : @mut Block , nonnull : & Struct , nndiscr : Disr , ptrfield : uint ,
317
+ fn nullable_bitdiscr ( bcx : @mut Block , nonnull : & Struct , nndiscr : uint , ptrfield : uint ,
319
318
scrutinee : ValueRef ) -> ValueRef {
320
319
let cmp = if nndiscr == 0 { IntEQ } else { IntNE } ;
321
320
let llptr = Load ( bcx, GEPi ( bcx, scrutinee, [ 0 , ptrfield] ) ) ;
@@ -324,7 +323,7 @@ fn nullable_bitdiscr(bcx: @mut Block, nonnull: &Struct, nndiscr: Disr, ptrfield:
324
323
}
325
324
326
325
/// Helper for cases where the discriminant is simply loaded.
327
- fn load_discr ( bcx : @mut Block , scrutinee : ValueRef , min : Disr , max : Disr )
326
+ fn load_discr ( bcx : @mut Block , scrutinee : ValueRef , min : uint , max : uint )
328
327
-> ValueRef {
329
328
let ptr = GEPi ( bcx, scrutinee, [ 0 , 0 ] ) ;
330
329
if max + 1 == min {
@@ -348,16 +347,16 @@ fn load_discr(bcx: @mut Block, scrutinee: ValueRef, min: Disr, max: Disr)
348
347
*
349
348
* This should ideally be less tightly tied to `_match`.
350
349
*/
351
- pub fn trans_case ( bcx : @mut Block , r : & Repr , discr : Disr ) -> _match:: opt_result {
350
+ pub fn trans_case ( bcx : @mut Block , r : & Repr , discr : uint ) -> _match:: opt_result {
352
351
match * r {
353
352
CEnum ( * ) => {
354
- _match:: single_result ( rslt ( bcx, C_disr ( bcx. ccx ( ) , discr) ) )
353
+ _match:: single_result ( rslt ( bcx, C_uint ( bcx. ccx ( ) , discr) ) )
355
354
}
356
355
Univariant ( * ) => {
357
356
bcx. ccx ( ) . sess . bug ( "no cases for univariants or structs" )
358
357
}
359
358
General ( * ) => {
360
- _match:: single_result ( rslt ( bcx, C_disr ( bcx. ccx ( ) , discr) ) )
359
+ _match:: single_result ( rslt ( bcx, C_uint ( bcx. ccx ( ) , discr) ) )
361
360
}
362
361
NullablePointer { _ } => {
363
362
assert ! ( discr == 0 || discr == 1 ) ;
@@ -371,11 +370,11 @@ pub fn trans_case(bcx: @mut Block, r: &Repr, discr: Disr) -> _match::opt_result
371
370
* representation. The fields, if any, should then be initialized via
372
371
* `trans_field_ptr`.
373
372
*/
374
- pub fn trans_start_init ( bcx : @mut Block , r : & Repr , val : ValueRef , discr : Disr ) {
373
+ pub fn trans_start_init ( bcx : @mut Block , r : & Repr , val : ValueRef , discr : uint ) {
375
374
match * r {
376
375
CEnum ( min, max) => {
377
376
assert ! ( min <= discr && discr <= max) ;
378
- Store ( bcx, C_disr ( bcx. ccx ( ) , discr) , GEPi ( bcx, val, [ 0 , 0 ] ) )
377
+ Store ( bcx, C_uint ( bcx. ccx ( ) , discr) , GEPi ( bcx, val, [ 0 , 0 ] ) )
379
378
}
380
379
Univariant ( ref st, true ) => {
381
380
assert_eq ! ( discr, 0 ) ;
@@ -386,7 +385,7 @@ pub fn trans_start_init(bcx: @mut Block, r: &Repr, val: ValueRef, discr: Disr) {
386
385
assert_eq ! ( discr, 0 ) ;
387
386
}
388
387
General ( * ) => {
389
- Store ( bcx, C_disr ( bcx. ccx ( ) , discr) , GEPi ( bcx, val, [ 0 , 0 ] ) )
388
+ Store ( bcx, C_uint ( bcx. ccx ( ) , discr) , GEPi ( bcx, val, [ 0 , 0 ] ) )
390
389
}
391
390
NullablePointer { nonnull : ref nonnull, nndiscr, ptrfield, _ } => {
392
391
if discr != nndiscr {
@@ -402,7 +401,7 @@ pub fn trans_start_init(bcx: @mut Block, r: &Repr, val: ValueRef, discr: Disr) {
402
401
* The number of fields in a given case; for use when obtaining this
403
402
* information from the type or definition is less convenient.
404
403
*/
405
- pub fn num_args ( r : & Repr , discr : Disr ) -> uint {
404
+ pub fn num_args ( r : & Repr , discr : uint ) -> uint {
406
405
match * r {
407
406
CEnum ( * ) => 0 ,
408
407
Univariant ( ref st, dtor) => {
@@ -417,7 +416,7 @@ pub fn num_args(r: &Repr, discr: Disr) -> uint {
417
416
}
418
417
419
418
/// Access a field, at a point when the value's case is known.
420
- pub fn trans_field_ptr ( bcx : @mut Block , r : & Repr , val : ValueRef , discr : Disr ,
419
+ pub fn trans_field_ptr ( bcx : @mut Block , r : & Repr , val : ValueRef , discr : uint ,
421
420
ix : uint ) -> ValueRef {
422
421
// Note: if this ever needs to generate conditionals (e.g., if we
423
422
// decide to do some kind of cdr-coding-like non-unique repr
@@ -495,13 +494,13 @@ pub fn trans_drop_flag_ptr(bcx: @mut Block, r: &Repr, val: ValueRef) -> ValueRef
495
494
* this could be changed in the future to avoid allocating unnecessary
496
495
* space after values of shorter-than-maximum cases.
497
496
*/
498
- pub fn trans_const ( ccx : & mut CrateContext , r : & Repr , discr : Disr ,
497
+ pub fn trans_const ( ccx : & mut CrateContext , r : & Repr , discr : uint ,
499
498
vals : & [ ValueRef ] ) -> ValueRef {
500
499
match * r {
501
500
CEnum ( min, max) => {
502
501
assert_eq ! ( vals. len( ) , 0 ) ;
503
502
assert ! ( min <= discr && discr <= max) ;
504
- C_disr ( ccx, discr)
503
+ C_uint ( ccx, discr)
505
504
}
506
505
Univariant ( ref st, _dro) => {
507
506
assert_eq ! ( discr, 0 ) ;
@@ -510,7 +509,7 @@ pub fn trans_const(ccx: &mut CrateContext, r: &Repr, discr: Disr,
510
509
General ( ref cases) => {
511
510
let case = & cases[ discr] ;
512
511
let max_sz = cases. iter ( ) . map ( |x| x. size ) . max ( ) . unwrap ( ) ;
513
- let discr_ty = C_disr ( ccx, discr) ;
512
+ let discr_ty = C_uint ( ccx, discr) ;
514
513
let contents = build_const_struct ( ccx, case,
515
514
~[ discr_ty] + vals) ;
516
515
C_struct ( contents + & [ padding ( max_sz - case. size ) ] )
@@ -582,15 +581,15 @@ fn roundup(x: u64, a: u64) -> u64 { ((x + (a - 1)) / a) * a }
582
581
583
582
/// Get the discriminant of a constant value. (Not currently used.)
584
583
pub fn const_get_discrim ( ccx : & mut CrateContext , r : & Repr , val : ValueRef )
585
- -> Disr {
584
+ -> uint {
586
585
match * r {
587
- CEnum ( * ) => const_to_uint ( val) as Disr ,
586
+ CEnum ( * ) => const_to_uint ( val) as uint ,
588
587
Univariant ( * ) => 0 ,
589
- General ( * ) => const_to_uint ( const_get_elt ( ccx, val, [ 0 ] ) ) as Disr ,
588
+ General ( * ) => const_to_uint ( const_get_elt ( ccx, val, [ 0 ] ) ) as uint ,
590
589
NullablePointer { nndiscr, ptrfield, _ } => {
591
590
if is_null ( const_struct_field ( ccx, val, ptrfield) ) {
592
591
/* subtraction as uint is ok because nndiscr is either 0 or 1 */
593
- ( 1 - nndiscr) as Disr
592
+ ( 1 - nndiscr) as uint
594
593
} else {
595
594
nndiscr
596
595
}
@@ -606,7 +605,7 @@ pub fn const_get_discrim(ccx: &mut CrateContext, r: &Repr, val: ValueRef)
606
605
* raw LLVM-level structs and arrays.)
607
606
*/
608
607
pub fn const_get_field ( ccx : & mut CrateContext , r : & Repr , val : ValueRef ,
609
- _discr : Disr , ix : uint ) -> ValueRef {
608
+ _discr : uint , ix : uint ) -> ValueRef {
610
609
match * r {
611
610
CEnum ( * ) => ccx. sess . bug ( "element access in C-like enum const" ) ,
612
611
Univariant ( * ) => const_struct_field ( ccx, val, ix) ,
@@ -645,7 +644,3 @@ pub fn is_newtypeish(r: &Repr) -> bool {
645
644
_ => false
646
645
}
647
646
}
648
-
649
- fn C_disr ( cx : & CrateContext , i : Disr ) -> ValueRef {
650
- return C_integral ( cx. int_type , i, false ) ;
651
- }
0 commit comments