shithub: mc

Download patch

ref: b9cf654b6dd5daabf8fd69854443ec04b0cfcea1
parent: b800e22d23759457e662d62c49ec27bed3210992
author: Ori Bernstein <[email protected]>
date: Wed Oct 15 21:51:35 EDT 2014

Stub in parameters needed for generating captures

--- a/opt/match.c
+++ b/opt/match.c
@@ -16,11 +16,13 @@
 typedef struct Dtree Dtree;
 struct Dtree {
     /* If the values are equal, go to 'sub'. If 'val' is null, anything matches. */
-    Node **val;
+    Node **val;         /* values to compare against */
     size_t nval;
-    Dtree **sub;
+    Node **load;        /* values being loaded */
+    size_t nload;
+    Dtree **sub;        /* submatches for an equal comparison */
     size_t nsub;
-    Dtree *any;
+    Dtree *any;         /* tree for a wildcard match. */
 
     /* captured variables and action */
     Node **cap;
@@ -29,7 +31,7 @@
 
 };
 
-static Dtree *addpat(Dtree *t, Node *pat, Node ***cap, size_t *ncap);
+static Dtree *addpat(Dtree *t, Node *pat, Node *val, Node ***cap, size_t *ncap);
 
 static Dtree *mkdtree()
 {
@@ -36,11 +38,11 @@
     return zalloc(sizeof(Dtree));
 }
 
-static Dtree *addwild(Dtree *t, Node *var, Node ***cap, size_t *ncap)
+static Dtree *addwild(Dtree *t, Node *pat, Node *val, Node ***cap, size_t *ncap)
 {
     Node *dcl;
 
-    dcl = decls[var->expr.did];
+    dcl = decls[pat->expr.did];
     /* FIXME: Avoid duplicate constants */
     if (dcl->decl.isconst)
         return NULL;
@@ -47,11 +49,11 @@
     if (t->any)
         return t->any;
     t->any = mkdtree();
-    lappend(cap, ncap, var);
+    lappend(cap, ncap, pat);
     return t->any;
 }
 
-static Dtree *addunion(Dtree *t, Node *pat, Node ***cap, size_t *ncap)
+static Dtree *addunion(Dtree *t, Node *pat, Node *val, Node ***cap, size_t *ncap)
 {
     Dtree *sub;
     size_t i;
@@ -60,7 +62,7 @@
     sub = NULL;
     for (i = 0; i < t->nval; i++) {
         if (nameeq(t->val[i], pat->expr.args[0]))
-            return addpat(t->sub[i], pat->expr.args[1], cap, ncap);
+            return addpat(t->sub[i], pat->expr.args[1], NULL, cap, ncap);
     }
 
     sub = mkdtree();
@@ -67,11 +69,11 @@
     lappend(&t->val, &t->nval, pat->expr.args[0]);
     lappend(&t->sub, &t->nsub, sub);
     if (pat->expr.nargs == 2)
-        sub = addpat(sub, pat->expr.args[1], cap, ncap);
+        sub = addpat(sub, pat->expr.args[1], NULL, cap, ncap);
     return sub;
 }
 
-static Dtree *addlit(Dtree *t, Node *pat, Node ***cap, size_t *ncap)
+static Dtree *addlit(Dtree *t, Node *pat, Node *val, Node ***cap, size_t *ncap)
 {
     Dtree *sub;
     size_t i;
@@ -78,7 +80,7 @@
 
     for (i = 0; i < t->nval; i++) {
         if (liteq(t->val[i]->expr.args[0], pat->expr.args[0]))
-            return addpat(t->sub[i], pat->expr.args[1], cap, ncap);
+            return addpat(t->sub[i], pat->expr.args[1], NULL, cap, ncap);
     }
 
     sub = mkdtree();
@@ -87,25 +89,25 @@
     return sub;
 }
 
-static Dtree *addtup(Dtree *t, Node *pat, Node ***cap, size_t *ncap)
+static Dtree *addtup(Dtree *t, Node *pat, Node *val, Node ***cap, size_t *ncap)
 {
     size_t i;
 
     for (i = 0; i < pat->expr.nargs; i++)
-        t = addpat(t, pat->expr.args[i], cap, ncap);
+        t = addpat(t, pat->expr.args[i], NULL, cap, ncap);
     return t;
 }
 
-static Dtree *addarr(Dtree *t, Node *pat, Node ***cap, size_t *ncap)
+static Dtree *addarr(Dtree *t, Node *pat, Node *val, Node ***cap, size_t *ncap)
 {
     size_t i;
 
     for (i = 0; i < pat->expr.nargs; i++)
-        t = addpat(t, pat->expr.args[i], cap, ncap);
+        t = addpat(t, pat->expr.args[i], NULL, cap, ncap);
     return t;
 }
 
-static Dtree *addstruct(Dtree *t, Node *pat, Node ***cap, size_t *ncap)
+static Dtree *addstruct(Dtree *t, Node *pat, Node *val, Node ***cap, size_t *ncap)
 {
     Node *elt;
     size_t i, j;
@@ -114,7 +116,7 @@
         elt = pat->expr.args[i];
         for (j = 0; j < t->nval; j++) {
             if (!strcmp(namestr(elt->expr.idx), namestr(t->val[j]->expr.idx)))
-                t = addpat(t, pat->expr.args[i], cap, ncap);
+                t = addpat(t, pat->expr.args[i], NULL, cap, ncap);
             break;
         }
     }
@@ -121,7 +123,7 @@
     return t;
 }
 
-static Dtree *addpat(Dtree *t, Node *pat, Node ***cap, size_t *ncap)
+static Dtree *addpat(Dtree *t, Node *pat, Node *val, Node ***cap, size_t *ncap)
 {
     Dtree *ret;
 
@@ -129,22 +131,22 @@
         return t;
     switch (exprop(pat)) {
         case Ovar:
-            ret = addwild(t, pat, cap, ncap);
+            ret = addwild(t, pat, val, cap, ncap);
             break;
         case Oucon:
-            ret = addunion(t, pat, cap, ncap);
+            ret = addunion(t, pat, val, cap, ncap);
             break;
         case Olit:
-            ret = addlit(t, pat, cap, ncap);
+            ret = addlit(t, pat, val, cap, ncap);
             break;
         case Otup:
-            ret = addtup(t, pat, cap, ncap);
+            ret = addtup(t, pat, val, cap, ncap);
             break;
         case Oarr:
-            ret = addarr(t, pat, cap, ncap);
+            ret = addarr(t, pat, val, cap, ncap);
             break;
         case Ostruct:
-            ret = addstruct(t, pat, cap, ncap);
+            ret = addstruct(t, pat, val, cap, ncap);
             break;
         default:
             ret = NULL;
@@ -177,7 +179,7 @@
     cap = NULL;
     ncap = 0;
     for (i = 0; i < npat; i++) {
-        leaf = addpat(t, pat[i]->match.pat, &cap, &ncap);
+        leaf = addpat(t, pat[i]->match.pat, NULL, &cap, &ncap);
         /* TODO: NULL is returned by unsupported patterns. */
         if (!leaf)
             return NULL;