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