From: ceriel Date: Tue, 14 Apr 1992 13:30:37 +0000 (+0000) Subject: Fixed problem with array's of incomplete types X-Git-Tag: release-5-5~495 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=60c44af82ba2dbb145de86997bde35a8cf805a90;p=ack.git Fixed problem with array's of incomplete types --- diff --git a/lang/cem/cemcom.ansi/code.c b/lang/cem/cemcom.ansi/code.c index d7763cdc1..09b12f86e 100644 --- a/lang/cem/cemcom.ansi/code.c +++ b/lang/cem/cemcom.ansi/code.c @@ -624,7 +624,9 @@ bss(idf) #endif /* DBSYMTAB */ if (df->df_type->tp_size <= 0) { if (df->df_sc != STATIC && - df->df_type->tp_fund == ARRAY && df->df_type->tp_up) { + df->df_type->tp_fund == ARRAY && + df->df_type->tp_up && + df->df_type->tp_up->tp_size >= 0) { C_df_dnam(idf->id_text); C_bss_cst(ATW(df->df_type->tp_up->tp_size), (arith)0, 1); } diff --git a/lang/cem/cemcom.ansi/declar.g b/lang/cem/cemcom.ansi/declar.g index 6759a9465..e9744188b 100644 --- a/lang/cem/cemcom.ansi/declar.g +++ b/lang/cem/cemcom.ansi/declar.g @@ -490,7 +490,9 @@ struct_declaration_pack(register struct type *stp;) '{' struct_declaration(stp, &sdefp, &size)+ '}' - {stp->tp_size = align(size, stp->tp_align);} + {stp->tp_size = align(size, stp->tp_align); + completed(stp); + } ; struct_declaration(struct type *stp; struct sdef ***sdefpp; arith *szp;) diff --git a/lang/cem/cemcom.ansi/type.c b/lang/cem/cemcom.ansi/type.c index 27565cc6c..12f980d2b 100644 --- a/lang/cem/cemcom.ansi/type.c +++ b/lang/cem/cemcom.ansi/type.c @@ -105,12 +105,7 @@ construct_type(fund, tp, qual, count, pl) if (tp->tp_fund == VOID) { error("cannot construct array of void"); count = (arith) -1; - } else if (count >= 0 && tp->tp_size < 0) { - error("cannot construct array of unknown type"); - count = (arith)-1; } - if (count > (arith)0) - count *= tp->tp_size; dtp = array_of(tp, count, qual); break; default: @@ -199,17 +194,21 @@ array_of(tp, count, qual) register struct type *dtp = tp->tp_array; /* look for a type with the right size */ - while (dtp && (dtp->tp_size != count || dtp->tp_typequal != qual)) + while (dtp && (dtp->tp_nel != count || dtp->tp_typequal != qual)) dtp = dtp->next; if (!dtp) { dtp = create_type(ARRAY); dtp->tp_up = tp; - dtp->tp_size = count; + dtp->tp_nel = count; dtp->tp_align = tp->tp_align; dtp->tp_typequal = qual; dtp->next = tp->tp_array; tp->tp_array = dtp; + if (tp->tp_size >= 0 && count >= 0) { + dtp->tp_size = count * tp->tp_size; + } + else dtp->tp_size = -1; } return dtp; } @@ -286,3 +285,16 @@ standard_type(fund, sgn, algn, sz) return tp; } + +completed(tp) + struct type *tp; +{ + register struct type *atp = tp->tp_array; + + while (atp) { + if (atp->tp_nel >= 0) { + atp->tp_size = atp->tp_nel * tp->tp_size; + } + atp = atp->next; + } +} diff --git a/lang/cem/cemcom.ansi/type.str b/lang/cem/cemcom.ansi/type.str index f6a5287d8..4f5ef360b 100644 --- a/lang/cem/cemcom.ansi/type.str +++ b/lang/cem/cemcom.ansi/type.str @@ -33,6 +33,7 @@ struct type { /* tp__up: from FIELD, POINTER, ARRAY or FUNCTION to fund. */ struct type *tp__up; union { + arith tp__nel; /* # of elements for array */ /* tp__field: field descriptor if fund == FIELD */ struct field *tp__field; struct { @@ -49,6 +50,7 @@ struct type { #define tp_sdef tp_union.tp_istagged.tp__sdef #define tp_up tp_union.tp_nottagged.tp__up #define tp_field tp_union.tp_nottagged.tp_f.tp__field +#define tp_nel tp_union.tp_nottagged.tp_f.tp__nel #define tp_proto tp_union.tp_nottagged.tp_f.tp_isfunc.tp__proto #define tp_pseudoproto tp_union.tp_nottagged.tp_f.tp_isfunc.tp__pseudoproto