From 41212792c605ee4dcc50031cb187b39f9f0f56fc Mon Sep 17 00:00:00 2001
From: Tim Chevalier <chevalier@alum.wellesley.edu>
Date: Tue, 19 Jul 2011 20:15:27 -0700
Subject: [PATCH] Add missing case in tyencode for ty_constr

Fixes the Windoze breakage, I hope.
---
 src/comp/metadata/tydecode.rs | 37 +++++++++++++++++++++++++++++++++++
 src/comp/metadata/tyencode.rs | 28 ++++++++++++++++++++++++++
 src/comp/middle/ty.rs         |  1 +
 3 files changed, 66 insertions(+)

diff --git a/src/comp/metadata/tydecode.rs b/src/comp/metadata/tydecode.rs
index 6f55f6d097c..4992dc8871a 100644
--- a/src/comp/metadata/tydecode.rs
+++ b/src/comp/metadata/tydecode.rs
@@ -82,6 +82,23 @@ fn parse_constrs(@pstate st, str_def sd) -> (@ty::constr)[] {
     ret rslt;
 }
 
+// FIXME less copy-and-paste
+fn parse_ty_constrs(@pstate st, str_def sd) -> (@ty::type_constr)[] {
+    let (@ty::type_constr)[] rslt = ~[];
+    alt (peek(st) as char) {
+        case (':') {
+            do {
+                next(st);
+                let @ty::type_constr one = parse_constr[path](st, sd,
+                                                  parse_ty_constr_arg);
+                rslt += ~[one];
+            } while (peek(st) as char == ';')
+        }
+        case (_) { }
+    }
+    ret rslt;
+}
+
 fn parse_path(@pstate st, str_def sd) -> ast::path {
     let ast::ident[] idents = ~[];
     fn is_last(char c) -> bool {
@@ -136,6 +153,19 @@ fn parse_constr_arg(@pstate st, str_def sd) -> ast::fn_constr_arg {
     }
 }
 
+fn parse_ty_constr_arg(@pstate st, str_def sd)
+    -> ast::constr_arg_general_[path] {
+     alt (peek(st) as char) {
+      case ('*') {
+        st.pos += 1u;
+        ret ast::carg_base;
+      }
+      case (?c) {
+          ret ast::carg_ident(parse_path(st, sd));
+      }
+    }
+}
+
 fn parse_constr[T](@pstate st, str_def sd, arg_parser[T] pser)
     -> @ty::constr_general[T] {
     auto sp = rec(lo=0u,hi=0u); // FIXME: use a real span
@@ -294,6 +324,13 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
                 }
             }
         }
+        case ('A') {
+            assert (next(st) as char == '[');
+            auto tt = parse_ty(st, sd);
+            auto tcs = parse_ty_constrs(st, sd);
+            assert (next(st) as char == ']');
+            ret ty::mk_constr(st.tcx, tt, tcs);
+        }
         case (?c) {
             log_err "unexpected char in type string: ";
             log_err c;
diff --git a/src/comp/metadata/tyencode.rs b/src/comp/metadata/tyencode.rs
index e239d678174..873ec5c549f 100644
--- a/src/comp/metadata/tyencode.rs
+++ b/src/comp/metadata/tyencode.rs
@@ -191,6 +191,14 @@ fn enc_sty(&ioivec::writer w, &@ctxt cx, &ty::sty st) {
         }
         case (ty::ty_type) { w.write_char('Y'); }
         case (ty::ty_task) { w.write_char('a'); }
+        case (ty::ty_constr(?ty, ?cs)) {
+            w.write_str("A[");
+            enc_ty(w, cx, ty);
+            for (@ty::type_constr tc in cs) {
+                enc_ty_constr(w, cx, tc);
+            }
+            w.write_char(']');
+        }
     }
 }
 fn enc_proto(&ioivec::writer w, proto proto) {
@@ -229,6 +237,7 @@ fn enc_ty_fn(&ioivec::writer w, &@ctxt cx, &ty::arg[] args, &ty::t out,
 
 }
 
+// FIXME less copy-and-paste
 fn enc_constr(&ioivec::writer w, &@ctxt cx, &@ty::constr c) {
     w.write_str(path_to_str(c.node.path));
     w.write_char('(');
@@ -248,6 +257,25 @@ fn enc_constr(&ioivec::writer w, &@ctxt cx, &@ty::constr c) {
     w.write_char(')');
 }
 
+fn enc_ty_constr(&ioivec::writer w, &@ctxt cx, &@ty::type_constr c) {
+    w.write_str(path_to_str(c.node.path));
+    w.write_char('(');
+    w.write_str(cx.ds(c.node.id));
+    w.write_char('|');
+    auto semi = false;
+    for (@ty::ty_constr_arg a in c.node.args) {
+        if (semi) { w.write_char(';'); } else { semi = true; }
+        alt (a.node) {
+            case (carg_base) { w.write_char('*'); }
+            case (carg_ident(?p)) {
+                w.write_str(path_to_str(p));
+            }
+            case (carg_lit(?l)) { w.write_str(lit_to_str(l)); }
+        }
+    }
+    w.write_char(')');
+}
+
 
 //
 // Local Variables:
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs
index 138b98b7570..4717bd56efe 100644
--- a/src/comp/middle/ty.rs
+++ b/src/comp/middle/ty.rs
@@ -122,6 +122,7 @@ export ty_box;
 export ty_chan;
 export ty_char;
 export ty_constr;
+export ty_constr_arg;
 export ty_float;
 export ty_fn;
 export ty_fn_abi;