@@ -64,7 +64,7 @@ use middle::trans::type_::Type;
64
64
/// Representations.
65
65
pub enum Repr {
66
66
/// C-like enums; basically an int.
67
- CEnum ( int , int ) , // discriminant range
67
+ CEnum ( uint , uint ) , // discriminant range
68
68
/**
69
69
* Single-case variants, and structs/tuples/records.
70
70
*
@@ -89,7 +89,7 @@ pub enum Repr {
89
89
* is represented such that `None` is a null pointer and `Some` is the
90
90
* identity function.
91
91
*/
92
- NullablePointer { nonnull : Struct , nndiscr : int , ptrfield : uint ,
92
+ NullablePointer { nonnull : Struct , nndiscr : uint , ptrfield : uint ,
93
93
nullfields : ~[ ty:: t ] }
94
94
}
95
95
@@ -140,7 +140,7 @@ fn represent_type_uncached(cx: &mut CrateContext, t: ty::t) -> Repr {
140
140
return Univariant ( mk_struct ( cx, ftys, packed) , dtor)
141
141
}
142
142
ty:: ty_enum( def_id, ref substs) => {
143
- struct Case { discr : int , tys : ~[ ty:: t ] } ;
143
+ struct Case { discr : uint , tys : ~[ ty:: t ] } ;
144
144
impl Case {
145
145
fn is_zerolen ( & self , cx : & mut CrateContext ) -> bool {
146
146
mk_struct ( cx, self . tys , false ) . size == 0
@@ -177,7 +177,7 @@ fn represent_type_uncached(cx: &mut CrateContext, t: ty::t) -> Repr {
177
177
// Since there's at least one
178
178
// non-empty body, explicit discriminants should have
179
179
// been rejected by a checker before this point.
180
- if !cases. iter ( ) . enumerate ( ) . all ( |( i, c) | c. discr == ( i as int ) ) {
180
+ if !cases. iter ( ) . enumerate ( ) . all ( |( i, c) | c. discr == i ) {
181
181
cx. sess . bug ( fmt ! ( "non-C-like enum %s with specified \
182
182
discriminants",
183
183
ty:: item_path_str( cx. tcx, def_id) ) )
@@ -206,7 +206,7 @@ fn represent_type_uncached(cx: &mut CrateContext, t: ty::t) -> Repr {
206
206
}
207
207
208
208
// The general case.
209
- let discr = ~[ ty:: mk_int ( ) ] ;
209
+ let discr = ~[ ty:: mk_uint ( ) ] ;
210
210
return General ( cases. map ( |c| mk_struct ( cx, discr + c. tys , false ) ) )
211
211
}
212
212
_ => cx. sess . bug ( "adt::represent_type called on non-ADT type" )
@@ -305,17 +305,16 @@ pub fn trans_get_discr(bcx: @mut Block, r: &Repr, scrutinee: ValueRef)
305
305
-> ValueRef {
306
306
match * r {
307
307
CEnum ( min, max) => load_discr ( bcx, scrutinee, min, max) ,
308
- Univariant ( * ) => C_int ( bcx. ccx ( ) , 0 ) ,
309
- General ( ref cases) => load_discr ( bcx, scrutinee, 0 ,
310
- ( cases. len ( ) - 1 ) as int ) ,
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 : int , 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: int, 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 : int , max : int )
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: int, max: int)
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 : int ) -> _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_int ( 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_int ( 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: int) -> _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 : int ) {
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_int ( 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: int) {
386
385
assert_eq ! ( discr, 0 ) ;
387
386
}
388
387
General ( * ) => {
389
- Store ( bcx, C_int ( 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,22 +401,22 @@ pub fn trans_start_init(bcx: @mut Block, r: &Repr, val: ValueRef, discr: int) {
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 : int ) -> 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) => {
409
408
assert_eq ! ( discr, 0 ) ;
410
409
st. fields . len ( ) - ( if dtor { 1 } else { 0 } )
411
410
}
412
- General ( ref cases) => cases[ discr as uint ] . fields . len ( ) - 1 ,
411
+ General ( ref cases) => cases[ discr] . fields . len ( ) - 1 ,
413
412
NullablePointer { nonnull : ref nonnull, nndiscr, nullfields : ref nullfields, _ } => {
414
413
if discr == nndiscr { nonnull. fields . len ( ) } else { nullfields. len ( ) }
415
414
}
416
415
}
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 : int ,
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
@@ -431,7 +430,7 @@ pub fn trans_field_ptr(bcx: @mut Block, r: &Repr, val: ValueRef, discr: int,
431
430
struct_field_ptr ( bcx, st, val, ix, false )
432
431
}
433
432
General ( ref cases) => {
434
- struct_field_ptr ( bcx, & cases[ discr as uint ] , val, ix + 1 , true )
433
+ struct_field_ptr ( bcx, & cases[ discr] , val, ix + 1 , true )
435
434
}
436
435
NullablePointer { nonnull : ref nonnull, nullfields : ref nullfields, nndiscr, _ } => {
437
436
if ( discr == nndiscr) {
@@ -495,22 +494,22 @@ 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 : int ,
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_int ( ccx, discr)
503
+ C_uint ( ccx, discr)
505
504
}
506
505
Univariant ( ref st, _dro) => {
507
506
assert_eq ! ( discr, 0 ) ;
508
507
C_struct ( build_const_struct ( ccx, st, vals) )
509
508
}
510
509
General ( ref cases) => {
511
- let case = & cases[ discr as uint ] ;
510
+ let case = & cases[ discr] ;
512
511
let max_sz = cases. iter ( ) . transform ( |x| x. size ) . max ( ) . unwrap ( ) ;
513
- let discr_ty = C_int ( 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,13 +581,18 @@ 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
- -> int {
584
+ -> uint {
586
585
match * r {
587
- CEnum ( * ) => const_to_int ( val) as int ,
586
+ CEnum ( * ) => const_to_uint ( val) as uint ,
588
587
Univariant ( * ) => 0 ,
589
- General ( * ) => const_to_int ( const_get_elt( ccx, val, [ 0 ] ) ) as int ,
588
+ General ( * ) => const_to_uint ( const_get_elt( ccx, val, [ 0 ] ) ) as uint ,
590
589
NullablePointer { nndiscr, ptrfield, _ } => {
591
- if is_null( const_struct_field( ccx, val, ptrfield) ) { 1 - nndiscr } else { nndiscr }
590
+ if is_null( const_struct_field( ccx, val, ptrfield) ) {
591
+ /* subtraction as uint is ok because nndiscr is either 0 or 1 */
592
+ ( 1 - nndiscr) as uint
593
+ } else {
594
+ nndiscr
595
+ }
592
596
}
593
597
}
594
598
}
@@ -601,7 +605,7 @@ pub fn const_get_discrim(ccx: &mut CrateContext, r: &Repr, val: ValueRef)
601
605
* raw LLVM-level structs and arrays.)
602
606
*/
603
607
pub fn const_get_field( ccx: & mut CrateContext , r: & Repr , val: ValueRef ,
604
- _discr: int , ix: uint) -> ValueRef {
608
+ _discr: uint , ix: uint) -> ValueRef {
605
609
match * r {
606
610
CEnum ( * ) => ccx. sess. bug( "element access in C-like enum const" ) ,
607
611
Univariant ( * ) => const_struct_field( ccx, val, ix) ,
0 commit comments