bug fix in constant set computations

This commit is contained in:
ceriel 1987-05-13 13:04:28 +00:00
parent e4cc45b56f
commit 6fc7d0f866
2 changed files with 12 additions and 60 deletions

View file

@ -399,14 +399,8 @@ ChkSet(expp)
nd = expp->nd_right; nd = expp->nd_right;
/* Now check the elements given, and try to compute a constant set. /* Now check the elements given, and try to compute a constant set.
First allocate room for the set, but only if it is'nt empty. First allocate room for the set.
*/ */
if (! nd) {
/* The resulting set IS empty, so we just return
*/
expp->nd_set = 0;
return 1;
}
size = tp->tp_size * (sizeof(arith) / word_size); size = tp->tp_size * (sizeof(arith) / word_size);
expp->nd_set = (arith *) Malloc(size); expp->nd_set = (arith *) Malloc(size);
clear((char *) (expp->nd_set) , size); clear((char *) (expp->nd_set) , size);

View file

@ -259,10 +259,9 @@ cstset(expp)
i = expp->nd_left->nd_INT; i = expp->nd_left->nd_INT;
expp->nd_class = Value; expp->nd_class = Value;
expp->nd_INT = (i >= 0 && set2 != 0 && expp->nd_INT = (i >= 0 && i < setsize * wrd_bits &&
i < setsize * wrd_bits &&
(set2[i / wrd_bits] & (1 << (i % wrd_bits)))); (set2[i / wrd_bits] & (1 << (i % wrd_bits))));
if (set2) free((char *) set2); free((char *) set2);
} }
else { else {
set1 = expp->nd_left->nd_set; set1 = expp->nd_left->nd_set;
@ -272,12 +271,7 @@ cstset(expp)
case '+': case '+':
/* Set union /* Set union
*/ */
if (!set1) { for (j = 0; j < setsize; j++) {
resultset = set2;
expp->nd_right->nd_set = 0;
break;
}
if (set2) for (j = 0; j < setsize; j++) {
*set1++ |= *set2++; *set1++ |= *set2++;
} }
break; break;
@ -285,14 +279,6 @@ cstset(expp)
case '-': case '-':
/* Set difference /* Set difference
*/ */
if (!set1 || !set2) {
/* The set from which something is substracted
is already empty, or the set that is
substracted is empty. In either case, the
result set is set1.
*/
break;
}
for (j = 0; j < setsize; j++) { for (j = 0; j < setsize; j++) {
*set1++ &= ~*set2++; *set1++ &= ~*set2++;
} }
@ -301,19 +287,6 @@ cstset(expp)
case '*': case '*':
/* Set intersection /* Set intersection
*/ */
if (!set1) {
/* set1 is empty, and so is the result set
*/
break;
}
if (!set2) {
/* set 2 is empty, so the result set must be
empty too.
*/
resultset = set2;
expp->nd_right->nd_set = 0;
break;
}
for (j = 0; j < setsize; j++) { for (j = 0; j < setsize; j++) {
*set1++ &= *set2++; *set1++ &= *set2++;
} }
@ -322,16 +295,9 @@ cstset(expp)
case '/': case '/':
/* Symmetric set difference /* Symmetric set difference
*/ */
if (!set1) {
resultset = set2;
expp->nd_right->nd_set = 0;
break;
}
if (set2) {
for (j = 0; j < setsize; j++) { for (j = 0; j < setsize; j++) {
*set1++ ^= *set2++; *set1++ ^= *set2++;
} }
}
break; break;
case GREATEREQUAL: case GREATEREQUAL:
@ -344,34 +310,26 @@ cstset(expp)
for (j = 0; j < setsize; j++) { for (j = 0; j < setsize; j++) {
switch(expp->nd_symb) { switch(expp->nd_symb) {
case GREATEREQUAL: case GREATEREQUAL:
if (!set2) {j = setsize; break; }
if (!set1) break;
if ((*set1 | *set2++) != *set1) break; if ((*set1 | *set2++) != *set1) break;
set1++; set1++;
continue; continue;
case LESSEQUAL: case LESSEQUAL:
if (!set1) {j = setsize; break; }
if (!set2) break;
if ((*set2 | *set1++) != *set2) break; if ((*set2 | *set1++) != *set2) break;
set2++; set2++;
continue; continue;
case '=': case '=':
case '#': case '#':
if (!set1 && !set2) {
j = setsize; break;
}
if (!set1 || !set2) break;
if (*set1++ != *set2++) break; if (*set1++ != *set2++) break;
continue; continue;
} }
break;
}
if (j < setsize) { if (j < setsize) {
expp->nd_INT = expp->nd_symb == '#'; expp->nd_INT = expp->nd_symb == '#';
} }
else { else {
expp->nd_INT = expp->nd_symb != '#'; expp->nd_INT = expp->nd_symb != '#';
} }
break;
}
expp->nd_class = Value; expp->nd_class = Value;
expp->nd_symb = INTEGER; expp->nd_symb = INTEGER;
if (expp->nd_left->nd_set) { if (expp->nd_left->nd_set) {