Procházet zdrojové kódy

Fixed problem with array's of incomplete types

ceriel před 32 roky
rodič
revize
814d63f2fd

+ 3 - 1
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);
 		}

+ 3 - 1
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;)

+ 19 - 7
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;
+	}
+}

+ 2 - 0
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