shithub: mc

Download patch

ref: 58bda459dfd58e2b3dc3b9bc31051ca9ede70698
parent: 8bf7a907ceb2f9549041dcfbe87f06eb92c60667
author: Ori Bernstein <[email protected]>
date: Sat Dec 24 14:45:25 EST 2011

Unify subtypes

--- a/parse/parse.h
+++ b/parse/parse.h
@@ -84,16 +84,10 @@
     int tid;
     size_t nsub;      /* For fnsub, tusub, sdecls, udecls, edecls. */
     Bitset *cstrs;    /* the type constraints matched on this type */
+    Type **sub;       /* sub-types; shared by all composite types */
     union {
-        Node *name;   /* Tyname: unresolved name */
-        Type **fnsub; /* Tyfunc: return, args */
-        Type **tusub; /* Tytuple: element types */
-        Type *pbase;  /* Typtr: pointer target */
-        Type *sbase;  /* Tyslice: slice target */
-        struct {      /* Tyarray: array target and size */
-            Type *abase;
-            Node *asize;
-        };
+        Node *name;    /* Tyname: unresolved name */
+        Node *asize;   /* array size */
         char *pname;   /* Typaram: name of type parameter */
         Node **sdecls; /* Tystruct: decls in struct */
         Node **udecls; /* Tyunion: decls in union */
--- a/parse/type.c
+++ b/parse/type.c
@@ -124,7 +124,8 @@
     Type *t;
 
     t = mkty(line, Tyarray);
-    t->abase = base;
+    t->sub = xalloc(sizeof(Type*));
+    t->sub[0] = base;
     t->asize = sz;
 
     return t;
@@ -135,7 +136,8 @@
     Type *t;
 
     t = mkty(line, Tyslice);
-    t->sbase = base;
+    t->sub = xalloc(sizeof(Type*));
+    t->sub[0] = base;
     return t;
 }
 
@@ -144,7 +146,8 @@
     Type *t;
 
     t = mkty(line, Typtr);
-    t->pbase = base;
+    t->sub = xalloc(sizeof(Type*));
+    t->sub[0] = base;
     return t;
 }
 
@@ -155,10 +158,10 @@
 
     t = mkty(line, Tyfunc);
     t->nsub = nargs + 1;
-    t->fnsub = xalloc((1 + nargs)*sizeof(Type));
-    t->fnsub[0] = ret;
+    t->sub = xalloc((1 + nargs)*sizeof(Type));
+    t->sub[0] = ret;
     for (i = 0; i < nargs; i++)
-        t->fnsub[i + 1] = decltype(args[i]);
+        t->sub[i + 1] = decltype(args[i]);
     return t;
 }
 
@@ -293,15 +296,15 @@
         case Tyvalist:  p += snprintf(p, end - p, "...");       break;
 
         case Typtr:     
-            p += tybfmt(p, end - p, t->pbase);
+            p += tybfmt(p, end - p, t->sub[0]);
             p += snprintf(p, end - p, "*");
             break;
         case Tyslice:
-            p += tybfmt(p, end - p, t->sbase);
+            p += tybfmt(p, end - p, t->sub[0]);
             p += snprintf(p, end - p, "[,]");
             break;
         case Tyarray:
-            p += tybfmt(p, end - p, t->abase);
+            p += tybfmt(p, end - p, t->sub[0]);
             p += snprintf(p, end - p, "[LEN]");
             break;
         case Tyfunc:
@@ -308,11 +311,11 @@
             p += snprintf(p, end - p, "(");
             for (i = 1; i < t->nsub; i++) {
                 p += snprintf(p, end - p, "%s", sep);
-                p += tybfmt(p, end - p, t->fnsub[i]);
+                p += tybfmt(p, end - p, t->sub[i]);
                 sep = ", ";
             }
             p += snprintf(p, end - p, " -> ");
-            p += tybfmt(p, end - p, t->fnsub[0]);
+            p += tybfmt(p, end - p, t->sub[0]);
             p += snprintf(p, end - p, ")");
             break;
         case Tytuple:
@@ -319,7 +322,7 @@
             p += snprintf(p, end - p, "[");
             for (i = 1; i < t->nsub; i++) {
                 p += snprintf(p, end - p, "%s", sep);
-                p += tybfmt(p, end - p, t->tusub[i]);
+                p += tybfmt(p, end - p, t->sub[i]);
                 sep = ", ";
             }
             p += snprintf(p, end - p, "]");