shithub: mc

Download patch

ref: 252e424842be2148b7f6326cf43be8af1c2e19b2
parent: 6a8e8597118325f5d43f065acbec97c2407c228f
author: Ori Bernstein <[email protected]>
date: Sat Jun 23 09:26:05 EDT 2012

Rename type constraint functions.

    They were a bit inconsistent and confusing.

--- a/parse/infer.c
+++ b/parse/infer.c
@@ -204,13 +204,12 @@
     return s;
 }
 
-
-static void constrainby(Node *ctx, Type *a, Cstr *c)
+static void constrain(Node *ctx, Type *a, Cstr *c)
 {
     if (a->type == Tyvar) {
         if (!a->cstrs)
             a->cstrs = mkbs();
-        constrain(a, c);
+        setcstr(a, c);
     } else if (!bshas(a->cstrs, c->cid)) {
             fatal(ctx->line, "%s needs %s near %s", tystr(a), c->name, ctxstr(ctx));
     }
@@ -431,7 +430,7 @@
         case Oidx:      /* @a[@b::tcint] -> @a */
             t = mktyidxhack(n->line, mktyvar(n->line));
             unify(n, type(args[0]), t);
-            constrainby(n, type(args[1]), cstrtab[Tcint]);
+            constrain(n, type(args[1]), cstrtab[Tcint]);
             settype(n, tf(t->sub[0]));
             break;
         case Oslice:    /* @a[@b::tcint,@b::tcint] -> @a[,] */
@@ -640,7 +639,7 @@
             infernode(n->ifstmt.cond, NULL, sawret);
             infernode(n->ifstmt.iftrue, ret, sawret);
             infernode(n->ifstmt.iffalse, ret, sawret);
-            constrain(type(n->ifstmt.cond), cstrtab[Tctest]);
+            constrain(n, type(n->ifstmt.cond), cstrtab[Tctest]);
             break;
         case Nloopstmt:
             infernode(n->loopstmt.init, ret, sawret);
@@ -647,7 +646,7 @@
             infernode(n->loopstmt.cond, NULL, sawret);
             infernode(n->loopstmt.step, ret, sawret);
             infernode(n->loopstmt.body, ret, sawret);
-            constrain(type(n->loopstmt.cond), cstrtab[Tctest]);
+            constrain(n, type(n->loopstmt.cond), cstrtab[Tctest]);
             break;
         case Nexpr:
             inferexpr(n, ret, sawret);
@@ -728,9 +727,9 @@
         t = tf(type(aggr));
         if (t->type == Tyslice || t->type == Tyarray) {
             if (!strcmp(namestr(memb), "len")) {
-                constrain(type(n), cstrtab[Tcnum]);
-                constrain(type(n), cstrtab[Tcint]);
-                constrain(type(n), cstrtab[Tctest]);
+                constrain(n, type(n), cstrtab[Tcnum]);
+                constrain(n, type(n), cstrtab[Tcint]);
+                constrain(n, type(n), cstrtab[Tctest]);
                 found = 1;
             }
         } else {
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -282,7 +282,6 @@
 void pushstab(Stab *st);
 void popstab(void);
 
-
 /* type creation */
 void tyinit(Stab *st); /* sets up built in types */
 
@@ -305,7 +304,7 @@
 /* type manipulation */
 int hascstr(Type *t, Cstr *c);
 int cstreq(Type *t, Cstr **cstrs, size_t len);
-int constrain(Type *t, Cstr *c);
+int setcstr(Type *t, Cstr *c);
 char *tyfmt(char *buf, size_t len, Type *t);
 char *tystr(Type *t);
 
--- a/parse/type.c
+++ b/parse/type.c
@@ -37,7 +37,7 @@
     tytab[t->tid] = NULL;
 
     for(i = 0; tycstrs[ty][i]; i++)
-        constrain(t, tycstrs[ty][i]);
+        setcstr(t, tycstrs[ty][i]);
 
     return t;
 }
@@ -68,7 +68,7 @@
     int i;
 
     for (i = 0; tycstrs[like][i]; i++)
-        constrain(t, tycstrs[like][i]);
+        setcstr(t, tycstrs[like][i]);
     return t;
 }
 
@@ -223,7 +223,7 @@
     return len - (end - p);
 }
 
-int constrain(Type *t, Cstr *c)
+int setcstr(Type *t, Cstr *c)
 {
     if (!t->cstrs)
         t->cstrs = mkbs();