From 3af275f8d652d1a8fd03a884e0f4fb701a0d1315 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 22 Jul 1987 17:02:54 +0000 Subject: [PATCH] A different way of detecting conformant arrays --- lang/m2/comp/chk_expr.c | 17 +++++------------ lang/m2/comp/declar.g | 5 ++++- lang/m2/comp/type.H | 2 +- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index 2bf6fec87..0f4787243 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -128,10 +128,9 @@ ChkArr(expp) /* Type of the index must be assignment compatible with the index type of the array (Def 8.1). However, the index type of a conformant array is not specified. - Either INTEGER or CARDINAL seems reasonable. + In our implementation it is CARDINAL. */ - if (IsConformantArray(tpl) ? !TstAssCompat(card_type, tpr) - : !TstAssCompat(IndexType(tpl), tpr)) { + if (!TstAssCompat(IndexType(tpl), tpr)) { node_error(expp, "incompatible index type"); return 0; } @@ -983,17 +982,11 @@ ChkStandard(expp, left) if (!(left = getarg(&arg, T_ARRAY|T_STRING|T_CHAR, 0, edf))) { return 0; } - if (IsConformantArray(left->nd_type)) { - /* A conformant array has no explicit index type, - but it is a subrange with lower bound 0, so - it is of type CARDINAL !!! - */ - expp->nd_type = card_type; - break; - } if (left->nd_type->tp_fund == T_ARRAY) { expp->nd_type = IndexType(left->nd_type); - cstcall(expp, S_MAX); + if (! IsConformantArray(left->nd_type)) { + cstcall(expp, S_MAX); + } break; } if (left->nd_symb != STRING) { diff --git a/lang/m2/comp/declar.g b/lang/m2/comp/declar.g index d6f89c3d1..4da0391ad 100644 --- a/lang/m2/comp/declar.g +++ b/lang/m2/comp/declar.g @@ -143,7 +143,10 @@ FormalType(struct type **ptp;) extern arith ArrayElSize(); } : ARRAY OF qualtype(ptp) - { register struct type *tp = construct_type(T_ARRAY, NULLTYPE); + { /* index type of conformant array is "CARDINAL". + Recognize a conformant array by size 0. + */ + register struct type *tp = construct_type(T_ARRAY, card_type); tp->arr_elem = *ptp; *ptp = tp; diff --git a/lang/m2/comp/type.H b/lang/m2/comp/type.H index 767d7fab3..b5448064a 100644 --- a/lang/m2/comp/type.H +++ b/lang/m2/comp/type.H @@ -152,7 +152,7 @@ struct type #define NULLTYPE ((struct type *) 0) -#define IsConformantArray(tpx) ((tpx)->tp_fund==T_ARRAY && (tpx)->tp_next==0) +#define IsConformantArray(tpx) ((tpx)->tp_fund==T_ARRAY && (tpx)->tp_size==0) #define bounded(tpx) ((tpx)->tp_fund & T_INDEX) #define complex(tpx) ((tpx)->tp_fund & (T_RECORD|T_ARRAY)) #define WA(sz) (align(sz, (int) word_size))