[Commit] nickle compile.c,1.134,1.135

Keith Packard commit@keithp.com
Wed, 28 May 2003 23:13:11 -0700


Committed by: keithp

Update of /local/src/CVS/nickle
In directory home.keithp.com:/tmp/cvs-serv14894

Modified Files:
	compile.c 
Log Message:
Fix implicit multi-dimensional array initializers

Index: compile.c
===================================================================
RCS file: /local/src/CVS/nickle/compile.c,v
retrieving revision 1.134
retrieving revision 1.135
diff -u -d -r1.134 -r1.135
--- compile.c	28 May 2003 19:10:09 -0000	1.134
+++ compile.c	29 May 2003 06:13:09 -0000	1.135
@@ -1467,6 +1467,30 @@
     RETURN(obj);
 }
 
+/*
+ * typedef struct { int x; } foo;
+ * typedef struct { foo[2,2] q; } bar;
+ * bar y = { q = { { { x = 1 } ... } ... } };
+ *
+ * 
+ *                           ARRAY
+ *                          /     \
+ *                       COMMA     0
+ *                      /     \
+ *                   ARRAY     COMMA
+ *                  /     \    |    \
+ *               COMMA     0  DOTS   0
+ *              /     \
+ *          STRUCT     COMMA
+ *         /      \    |    \
+ *      COMMA      0   DOTS  0
+ *     /     \
+ *  ASSIGN    0
+ *  |     \
+ * NAME  TEN_NUM
+ *  "x"    1
+ */
+
 static ObjPtr
 CompileArrayInit (ObjPtr obj, ExprPtr expr, Type *type, ExprPtr stat, CodePtr code)
 {
@@ -1633,15 +1657,17 @@
 	    init = CompileImplicitInit (sub);
 	    if (init)
 	    {
-		init = NewExprTree (COMMA,
-				    init,
-				    NewExprTree (COMMA,
-						 NewExprTree (DOTS, 0, 0),
-						 0));
 		dim = CompileCountDeclDimensions (type->array.dimensions);
-		while (--dim)
-		    init = NewExprTree (OC, init, 0);
-		init = NewExprTree (ARRAY, init, 0);
+		while (--dim >= 0)
+		{
+		    init = NewExprTree (ARRAY,
+					NewExprTree (COMMA,
+						     init,
+						     NewExprTree (COMMA,
+								  NewExprTree (DOTS, 0, 0),
+								  0)),
+					0);
+		}
 	    }
 	    else
 		init = NewExprTree (ANONINIT, 0, 0);