about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-01-15 21:42:10 -0800
committerNiko Matsakis <niko@alum.mit.edu>2012-01-17 10:33:28 -0800
commita83ad1b9e657307f395361be0c687a4690bbcd6f (patch)
tree570214cea440be14fc55ec90483a7e2006d567b6 /src/comp
parentc3bc8fada838c15e09e76a9d5d85438667c1636c (diff)
downloadrust-a83ad1b9e657307f395361be0c687a4690bbcd6f.tar.gz
rust-a83ad1b9e657307f395361be0c687a4690bbcd6f.zip
encode variant names and have log print them out.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/metadata/decoder.rs5
-rw-r--r--src/comp/metadata/encoder.rs1
-rw-r--r--src/comp/middle/shape.rs14
-rw-r--r--src/comp/middle/ty.rs5
4 files changed, 20 insertions, 5 deletions
diff --git a/src/comp/metadata/decoder.rs b/src/comp/metadata/decoder.rs
index c076b044f52..ace34b79a0c 100644
--- a/src/comp/metadata/decoder.rs
+++ b/src/comp/metadata/decoder.rs
@@ -246,6 +246,7 @@ fn get_tag_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
     for did: ast::def_id in variant_ids {
         let item = find_item(did.node, items);
         let ctor_ty = item_type(item, tcx, cdata);
+        let name = item_name(item);
         let arg_tys: [ty::t] = [];
         alt ty::struct(tcx, ctor_ty) {
           ty::ty_fn(f) {
@@ -257,8 +258,8 @@ fn get_tag_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
           some(val) { disr_val = val; }
           _         { /* empty */ }
         }
-        infos += [@{args: arg_tys, ctor_ty: ctor_ty, id: did,
-                    disr_val: disr_val}];
+        infos += [@{args: arg_tys, ctor_ty: ctor_ty, name: name,
+                    id: did, disr_val: disr_val}];
         disr_val += 1;
     }
     ret infos;
diff --git a/src/comp/metadata/encoder.rs b/src/comp/metadata/encoder.rs
index 41235c01d3d..1a0a6cfef90 100644
--- a/src/comp/metadata/encoder.rs
+++ b/src/comp/metadata/encoder.rs
@@ -239,6 +239,7 @@ fn encode_tag_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
         ebml::start_tag(ebml_w, tag_items_data_item);
         encode_def_id(ebml_w, local_def(variant.node.id));
         encode_family(ebml_w, 'v' as u8);
+        encode_name(ebml_w, variant.node.name);
         encode_tag_id(ebml_w, local_def(id));
         encode_type(ecx, ebml_w,
                     node_id_to_monotype(ecx.ccx.tcx, variant.node.id));
diff --git a/src/comp/middle/shape.rs b/src/comp/middle/shape.rs
index b867bd67b8f..8e49aeaa080 100644
--- a/src/comp/middle/shape.rs
+++ b/src/comp/middle/shape.rs
@@ -458,6 +458,15 @@ fn shape_of_variant(ccx: @crate_ctxt, v: ty::variant_info,
     ret s;
 }
 
+//fn variant_names(ccx: @crate_ctxt, tag_id: ast::def_id) -> [str] {
+//    assert ast::local_crate == tag_id.crate;
+//    alt ccx.tcx.items.get(tag_id.node) {
+//      ast_map::node_item(@{node: ast::item_tag(variants, _), _}) {
+//        vec::map(variants) {|variant| variant.node.name}
+//      }
+//    }
+//}
+
 fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
     // Loop over all the tag variants and write their shapes into a data
     // buffer. As we do this, it's possible for us to discover new tags, so we
@@ -471,11 +480,14 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
         let item_tyt = ty::lookup_item_type(ccx.tcx, did);
         let ty_param_count = vec::len(*item_tyt.bounds);
 
-        for v: ty::variant_info in *variants {
+        vec::iter(*variants) {|v|
             offsets += [vec::len(data) as u16];
 
             let variant_shape = shape_of_variant(ccx, v, ty_param_count);
             add_substr(data, variant_shape);
+
+            let zname = str::bytes(v.name) + [0u8];
+            add_substr(data, zname);
         }
 
         i += 1u;
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs
index 59fd826791a..18ec1e86f3e 100644
--- a/src/comp/middle/ty.rs
+++ b/src/comp/middle/ty.rs
@@ -2633,8 +2633,8 @@ fn impl_iface(cx: ctxt, id: ast::def_id) -> option::t<t> {
 }
 
 // Tag information
-type variant_info = @{args: [ty::t], ctor_ty: ty::t, id: ast::def_id,
-                      disr_val: int};
+type variant_info = @{args: [ty::t], ctor_ty: ty::t, name: str,
+                      id: ast::def_id, disr_val: int};
 
 fn tag_variants(cx: ctxt, id: ast::def_id) -> @[variant_info] {
     alt cx.tag_var_cache.find(id) {
@@ -2666,6 +2666,7 @@ fn tag_variants(cx: ctxt, id: ast::def_id) -> @[variant_info] {
                 }
                 @{args: arg_tys,
                   ctor_ty: ctor_ty,
+                  name: variant.node.name,
                   id: ast_util::local_def(variant.node.id),
                   disr_val: disr_val
                  }