handle intorcard_type better in case statements
authorceriel <none@none>
Tue, 29 Nov 1988 13:13:03 +0000 (13:13 +0000)
committerceriel <none@none>
Tue, 29 Nov 1988 13:13:03 +0000 (13:13 +0000)
lang/m2/comp/chk_expr.c
lang/m2/comp/declar.g
lang/m2/comp/type.H
lang/m2/comp/type.c

index 68f755f..696cadc 100644 (file)
@@ -832,13 +832,11 @@ ChkBinOper(expp)
        tpl = BaseType(expp->nd_left->nd_type);
        tpr = BaseType(expp->nd_right->nd_type);
 
-       if (tpl == intorcard_type) {
-               if (tpr == int_type || tpr == card_type) {
+       if (intorcard(tpl, tpr) != 0) {
+               if (tpl == intorcard_type) {
                         expp->nd_left->nd_type = tpl = tpr;
                }
-       }
-       if (tpr == intorcard_type) {
-               if (tpl == int_type || tpl == card_type) {
+               if (tpr == intorcard_type) {
                        expp->nd_right->nd_type = tpr = tpl;
                }
        }
index 82ff2cc..246443b 100644 (file)
@@ -400,7 +400,11 @@ CaseLabels(t_type **ptp; register t_node **pnd;)
 }:
        ConstExpression(pnd)
                        { 
-                         if (*ptp != 0 && ChkCompat(pnd, *ptp, "case label")) {
+                         if (*ptp != 0) {
+                               t_type *tp = intorcard(*ptp,
+                                       BaseType((*pnd)->nd_type), 0);
+                               if (tp) *ptp = tp;
+                               ChkCompat(pnd, *ptp, "case label");
                          }
                          nd = *pnd;
                          nd->nd_type = BaseType(nd->nd_type);  /* ??? */
index b6ee4a0..b65710a 100644 (file)
@@ -187,6 +187,7 @@ extern t_type
        *proc_type(),
        *enum_type(),
        *qualified_type(),
+       *intorcard(),
        *RemoveEqual(); /* All from type.c */
 
 #define NULLTYPE ((t_type *) 0)
index 265ce7f..4370836 100644 (file)
@@ -795,6 +795,23 @@ lcm(m, n)
        return m * (n / gcd(m, n));
 }
 
+t_type *
+intorcard(left, right)
+       register t_type *left, *right;
+{
+       if (left == intorcard_type) {
+               if (right == int_type || right == card_type) {
+                       return right;
+               }
+       }
+       else if (right == intorcard_type) {
+               if (left == int_type || left == card_type) {
+                       return left;
+               }
+       }
+       return 0;
+}
+
 #ifdef DEBUG
 DumpType(tp)
        register t_type *tp;