ref: 529a44cfde2e1e34060c545c915a9ebf40f5b1a6
parent: ec12afb46eb536836e9d13b1c4156f2a7ad81517
author: Ori Bernstein <[email protected]>
date: Wed Nov 5 15:14:43 EST 2014
Handle wildcards in patterns correctly. If we have a wildcard, prefer it over any equal node. This means that something like: match x | (x, false): | (false, x): | (false, false) ;; will correctly be detected as having a redundant match.
--- a/mi/match.c
+++ b/mi/match.c
@@ -34,6 +34,7 @@
};
static Dtree *addpat(Dtree *t, Node *pat, Node *val, Node ***cap, size_t *ncap);
+void dtdump(Dtree *dt, FILE *f);
/* We treat all integer types, boolean types, etc, as having 2^n constructors.
*
@@ -110,6 +111,8 @@
Dtree *sub;
size_t i;
+ if (t->any)
+ return t->any;
/* if we have the value already... */
sub = NULL;
for (i = 0; i < t->nval; i++) {
@@ -131,6 +134,8 @@
Dtree *sub;
size_t i;
+ if (t->any)
+ return t->any;
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], NULL, cap, ncap);
@@ -147,6 +152,8 @@
{
size_t i;
+ if (t->any)
+ return t->any;
for (i = 0; i < pat->expr.nargs; i++)
t = addpat(t, pat->expr.args[i], NULL, cap, ncap);
return t;
@@ -156,6 +163,8 @@
{
size_t i;
+ if (t->any)
+ return t->any;
for (i = 0; i < pat->expr.nargs; i++)
t = addpat(t, pat->expr.args[i], NULL, cap, ncap);
return t;
@@ -166,6 +175,8 @@
Node *elt;
size_t i, j;
+ if (t->any)
+ return t->any;
for (i = 0; i < pat->expr.nargs; i++) {
elt = pat->expr.args[i];
for (j = 0; j < t->nval; j++) {