From 5252b760d9e60a6400b5903ac81175c7c6af87c5 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 29 Nov 1988 13:13:03 +0000 Subject: [PATCH] handle intorcard_type better in case statements --- lang/m2/comp/chk_expr.c | 8 +++----- lang/m2/comp/declar.g | 6 +++++- lang/m2/comp/type.H | 1 + lang/m2/comp/type.c | 17 +++++++++++++++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 68f755fdc..696cadc2a 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -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; } } diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index 82ff2cc7d..246443b98 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -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); /* ??? */ diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index b6ee4a0ac..b65710a1e 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -187,6 +187,7 @@ extern t_type *proc_type(), *enum_type(), *qualified_type(), + *intorcard(), *RemoveEqual(); /* All from type.c */ #define NULLTYPE ((t_type *) 0) diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index 265ce7f90..43708365c 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -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; -- 2.34.1