shithub: mc

Download patch

ref: bc5b6f51086f4d6f83ab5a9dfd29bab5dbb7a57e
parent: 4c9035bc17893e3e88b65b5c7d928670e2b5ae38
author: Ori Bernstein <[email protected]>
date: Sun Nov 20 19:34:29 EST 2011

Fix type formatting for func and name types

    Now we print something useful to the user, and sensible

--- a/parse/type.c
+++ b/parse/type.c
@@ -44,7 +44,7 @@
 {
     Type *t;
 
-    t = xalloc(sizeof(Type));
+    t = zalloc(sizeof(Type));
     t->type = ty;
     t->tid = nexttid++;
     return t;
@@ -162,17 +162,33 @@
     (*len)++;
 }
 
+static int namefmt(char *buf, size_t len, Node *name)
+{
+    int i;
+    char *p;
+    char *end;
+
+    p = buf;
+    end = p + len;
+    for (i = 0; i < name->name.nparts; i++) {
+        p += snprintf(p, end - p, name->name.parts[i]);
+        if (i < name->name.nparts - 1)
+            p += snprintf(p, end - p, ".");
+    }
+    return len - (end - p);
+}
+
 int tybfmt(char *buf, size_t len, Type *t)
 {
     char *p;
     char *end;
-    //Type *sub;
+    int i;
 
     p = buf;
     end = p + len;
     if (!t) {
         p += snprintf(p, end - p, "tynil");
-        return end - p;
+        return len - (end - p);
     }
     switch (t->type) {
         case Tybad:     p += snprintf(p, end - p, "BAD");       break;
@@ -210,19 +226,33 @@
             break;
         case Tyfunc:
             p += snprintf(p, end - p, "(");
+            for (i = 1; i < t->nsub; i++) {
+                p += tybfmt(p, end - p, t->fnsub[i]);
+                if (i < t->nsub - 1)
+                    p += snprintf(p, end - p, ", ");
+            }
+            p += snprintf(p, end - p, " -> ");
+            p += tybfmt(p, end - p, t->fnsub[0]);
             p += snprintf(p, end - p, ")");
             break;
         case Tytuple:
             p += snprintf(p, end - p, "[");
+            for (i = 1; i < t->nsub; i++) {
+                p += tybfmt(p, end - p, t->tusub[i]);
+                if (i < t->nsub - 1)
+                    p += snprintf(p, end - p, ", ");
+            }
             p += snprintf(p, end - p, "]");
             break;
         case Tyvar:
-            p += snprintf(p, end - p, "@.%d", t->tid);
+            p += snprintf(p, end - p, "@$%d", t->tid);
             break;
         case Typaram:
             p += snprintf(p, end - p, "@%s", t->pname);
             break;
         case Tyname:
+            p += namefmt(p, end - p, t->name);
+            break;
         case Tystruct:
         case Tyunion:
         case Tyenum:
@@ -230,7 +260,7 @@
             break;
     }
 
-    return end - p;
+    return len - (end - p);
 }
 
 char *tyfmt(char *buf, size_t len, Type *t)