]> git.lizzy.rs Git - rust.git/commitdiff
Add missing case in tyencode for ty_constr
authorTim Chevalier <chevalier@alum.wellesley.edu>
Wed, 20 Jul 2011 03:15:27 +0000 (20:15 -0700)
committerTim Chevalier <chevalier@alum.wellesley.edu>
Wed, 20 Jul 2011 03:16:03 +0000 (20:16 -0700)
Fixes the Windoze breakage, I hope.

src/comp/metadata/tydecode.rs
src/comp/metadata/tyencode.rs
src/comp/middle/ty.rs

index 6f55f6d097c2fc9ce2e0110e9e17ddf808431172..4992dc8871a8fb65a0b3b7ea2e285369ed70be81 100644 (file)
@@ -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;
index e239d678174057b60ce0f0101248b2b1aa83b9bd..873ec5c549f57204a3f966a8382ba4fe523f2eca 100644 (file)
@@ -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:
index 138b98b75702bf0f5d766324fed29ce957ef20bc..4717bd56efe8913c402b0ef7541c3618305ac249 100644 (file)
 export ty_chan;
 export ty_char;
 export ty_constr;
+export ty_constr_arg;
 export ty_float;
 export ty_fn;
 export ty_fn_abi;