@@ -231,39 +231,36 @@ fn generic_fields_of(cx: @CrateContext, r: &Repr, sizing: bool)
231
231
}
232
232
233
233
/**
234
- * Obtain as much of a "discriminant" as this representation has.
234
+ * Obtain a representation of the discriminant sufficient to translate
235
+ * destructuring; this may or may not involve the actual discriminant.
236
+ *
235
237
* This should ideally be less tightly tied to `_match`.
236
238
*/
237
239
pub fn trans_switch ( bcx : block , r : & Repr , scrutinee : ValueRef )
238
240
-> ( _match:: branch_kind , Option < ValueRef > ) {
239
241
match * r {
240
242
CEnum ( * ) | General ( * ) => {
241
- ( _match:: switch, Some ( trans_cast_to_int ( bcx, r, scrutinee) ) )
243
+ ( _match:: switch, Some ( trans_get_discr ( bcx, r, scrutinee) ) )
242
244
}
243
245
Unit ( * ) | Univariant ( * ) => {
244
246
( _match:: single, None )
245
247
}
246
248
}
247
249
}
248
250
249
- /**
250
- * If the representation is potentially of a C-like enum, implement
251
- * coercion to numeric types.
252
- */
253
- pub fn trans_cast_to_int ( bcx : block , r : & Repr , scrutinee : ValueRef )
251
+ /// Obtain the actual discriminant of a value.
252
+ pub fn trans_get_discr ( bcx : block , r : & Repr , scrutinee : ValueRef )
254
253
-> ValueRef {
255
254
match * r {
256
255
Unit ( the_disc) => C_int ( bcx. ccx ( ) , the_disc) ,
257
256
CEnum ( min, max) => load_discr ( bcx, scrutinee, min, max) ,
258
- Univariant ( * ) => bcx. ccx ( ) . sess . bug ( ~"type has no explicit \
259
- discriminant") ,
260
- // Note: this case is used internally by trans_switch,
261
- // even though it shouldn't be reached by an external caller.
257
+ Univariant ( * ) => C_int ( bcx. ccx ( ) , 0 ) ,
262
258
General ( ref cases) => load_discr ( bcx, scrutinee, 0 ,
263
259
( cases. len ( ) - 1 ) as int )
264
260
}
265
261
}
266
262
263
+ /// Helper for cases where the discriminant is simply loaded.
267
264
fn load_discr ( bcx : block , scrutinee : ValueRef , min : int , max : int )
268
265
-> ValueRef {
269
266
let ptr = GEPi ( bcx, scrutinee, [ 0 , 0 ] ) ;
@@ -285,6 +282,7 @@ fn load_discr(bcx: block, scrutinee: ValueRef, min: int, max: int)
285
282
/**
286
283
* Yield information about how to dispatch a case of the
287
284
* discriminant-like value returned by `trans_switch`.
285
+ *
288
286
* This should ideally be less tightly tied to `_match`.
289
287
*/
290
288
pub fn trans_case( bcx : block , r : & Repr , discr : int ) -> _match:: opt_result {
0 commit comments