about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJed Davis <jld@panix.com>2013-02-28 12:13:00 -0800
committerJed Davis <jld@panix.com>2013-03-06 20:41:58 -0800
commit6840b48074ddb97d3a77f87c833fa8b9f10c1ccc (patch)
tree18ba2fdfcc2bbcc4faa929c5fbfa2958bc5f27da
parent8dca7be1dfac6193832575495e3f6483634189f1 (diff)
downloadrust-6840b48074ddb97d3a77f87c833fa8b9f10c1ccc.tar.gz
rust-6840b48074ddb97d3a77f87c833fa8b9f10c1ccc.zip
trans_cast_to_int is hard to explain; make it trans_get_discr instead.
-rw-r--r--src/librustc/middle/trans/adt.rs20
-rw-r--r--src/librustc/middle/trans/expr.rs2
2 files changed, 10 insertions, 12 deletions
diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs
index 6b347287ae4..98f15290470 100644
--- a/src/librustc/middle/trans/adt.rs
+++ b/src/librustc/middle/trans/adt.rs
@@ -231,14 +231,16 @@ fn generic_fields_of(cx: @CrateContext, r: &Repr, sizing: bool)
 }
 
 /**
- * Obtain as much of a "discriminant" as this representation has.
+ * Obtain a representation of the discriminant sufficient to translate
+ * destructuring; this may or may not involve the actual discriminant.
+ *
  * This should ideally be less tightly tied to `_match`.
  */
 pub fn trans_switch(bcx: block, r: &Repr, scrutinee: ValueRef)
     -> (_match::branch_kind, Option<ValueRef>) {
     match *r {
         CEnum(*) | General(*) => {
-            (_match::switch, Some(trans_cast_to_int(bcx, r, scrutinee)))
+            (_match::switch, Some(trans_get_discr(bcx, r, scrutinee)))
         }
         Unit(*) | Univariant(*) => {
             (_match::single, None)
@@ -246,24 +248,19 @@ pub fn trans_switch(bcx: block, r: &Repr, scrutinee: ValueRef)
     }
 }
 
-/**
- * If the representation is potentially of a C-like enum, implement
- * coercion to numeric types.
- */
-pub fn trans_cast_to_int(bcx: block, r: &Repr, scrutinee: ValueRef)
+/// Obtain the actual discriminant of a value.
+pub fn trans_get_discr(bcx: block, r: &Repr, scrutinee: ValueRef)
     -> ValueRef {
     match *r {
         Unit(the_disc) => C_int(bcx.ccx(), the_disc),
         CEnum(min, max) => load_discr(bcx, scrutinee, min, max),
-        Univariant(*) => bcx.ccx().sess.bug(~"type has no explicit \
-                                              discriminant"),
-        // Note: this case is used internally by trans_switch,
-        // even though it shouldn't be reached by an external caller.
+        Univariant(*) => C_int(bcx.ccx(), 0),
         General(ref cases) => load_discr(bcx, scrutinee, 0,
                                          (cases.len() - 1) as int)
     }
 }
 
+/// Helper for cases where the discriminant is simply loaded.
 fn load_discr(bcx: block, scrutinee: ValueRef, min: int, max: int)
     -> ValueRef {
     let ptr = GEPi(bcx, scrutinee, [0, 0]);
@@ -285,6 +282,7 @@ fn load_discr(bcx: block, scrutinee: ValueRef, min: int, max: int)
 /**
  * Yield information about how to dispatch a case of the
  * discriminant-like value returned by `trans_switch`.
+ *
  * This should ideally be less tightly tied to `_match`.
  */
 pub fn trans_case(bcx: block, r: &Repr, discr: int) -> _match::opt_result {
diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs
index 3df34e53ae3..edda2f6c2c1 100644
--- a/src/librustc/middle/trans/expr.rs
+++ b/src/librustc/middle/trans/expr.rs
@@ -1645,7 +1645,7 @@ fn trans_imm_cast(bcx: block, expr: @ast::expr,
             (cast_enum, cast_float) => {
                 let bcx = bcx;
                 let repr = adt::represent_type(ccx, t_in);
-                let lldiscrim_a = adt::trans_cast_to_int(bcx, repr, llexpr);
+                let lldiscrim_a = adt::trans_get_discr(bcx, repr, llexpr);
                 match k_out {
                     cast_integral => int_cast(bcx, ll_t_out,
                                               val_ty(lldiscrim_a),