diff gen/toir.cpp @ 286:a3b7c19c866c trunk

[svn r307] Fixed: multidimensional new expressions now work. Eg.: auto ma = new int[][] (3,9);
author lindquist
date Sat, 21 Jun 2008 04:47:14 +0200
parents 70c370e97944
children 068cb3c60afb
line wrap: on
line diff
--- a/gen/toir.cpp	Sat Jun 21 03:14:49 2008 +0200
+++ b/gen/toir.cpp	Sat Jun 21 04:47:14 2008 +0200
@@ -1899,10 +1899,21 @@
         Logger::println("new dynamic array: %s", newtype->toChars());
         // get dim
         assert(arguments);
-        assert(arguments->dim == 1);
-        DValue* sz = ((Expression*)arguments->data[0])->toElem(p);
-        // allocate & init
-        return DtoNewDynArray(newtype, sz, true);
+        assert(arguments->dim >= 1);
+        if (arguments->dim == 1)
+        {
+            DValue* sz = ((Expression*)arguments->data[0])->toElem(p);
+            // allocate & init
+            return DtoNewDynArray(newtype, sz, true);
+        }
+        else
+        {
+            size_t ndims = arguments->dim;
+            std::vector<DValue*> dims(ndims);
+            for (size_t i=0; i<ndims; ++i)
+                dims[i] = ((Expression*)arguments->data[i])->toElem(p);
+            return DtoNewMulDimDynArray(newtype, &dims[0], ndims, true);
+        }
     }
     // new static array
     else if (ntype->ty == Tsarray)