changeset 335:17b844102023 trunk

[svn r356] Fixed problem with array length assignment introduced in [355]
author lindquist
date Sat, 12 Jul 2008 17:04:36 +0200
parents 20446d22f832
children aaade6ded589
files gen/dvalue.h gen/toir.cpp tangotests/lazy2.d
diffstat 3 files changed, 34 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/gen/dvalue.h	Sat Jul 12 15:43:13 2008 +0200
+++ b/gen/dvalue.h	Sat Jul 12 17:04:36 2008 +0200
@@ -192,13 +192,6 @@
     virtual DLRValue* isLRValue() { return this; }
 };
 
-// array length d-value
-struct DArrayLenValue : DLRValue
-{
-    DArrayLenValue(Type* lt, LLValue* l, Type* rt, LLValue* r) : DLRValue(lt, l, rt, r) {}
-    virtual DArrayLenValue* isArrayLen() { return this; }
-};
-
 // complex number immediate d-value (much like slice)
 struct DComplexValue : DValue
 {
--- a/gen/toir.cpp	Sat Jul 12 15:43:13 2008 +0200
+++ b/gen/toir.cpp	Sat Jul 12 17:04:36 2008 +0200
@@ -563,27 +563,23 @@
     Logger::print("AssignExp::toElem: %s | %s = %s\n", toChars(), e1->type->toChars(), e2->type ? e2->type->toChars() : 0);
     LOG_SCOPE;
 
+    if (e1->op == TOKarraylength)
+    {
+        Logger::println("performing array.length assignment");
+        ArrayLengthExp *ale = (ArrayLengthExp *)e1;
+        DValue* arr = ale->e1->toElem(p);
+        DVarValue arrval(ale->e1->type, arr->getLVal(), true);
+        DValue* newlen = e2->toElem(p);
+        DSliceValue* slice = DtoResizeDynArray(arrval.getType(), &arrval, newlen);
+        DtoAssign(&arrval, slice);
+        return newlen;
+    }
+
+    Logger::println("performing normal assignment");
+
     DValue* l = e1->toElem(p);
     DValue* r = e2->toElem(p);
-
-    Logger::println("performing assignment");
-
-    DImValue* im = r->isIm();
-    if (!im || !im->inPlace()) {
-        Logger::println("assignment not inplace");
-        if (DArrayLenValue* al = l->isArrayLen())
-        {
-            DLRValue* arrlenval = l->isLRValue();
-            assert(arrlenval);
-            DVarValue arrval(arrlenval->getLType(), arrlenval->getLVal(), true);
-            DSliceValue* slice = DtoResizeDynArray(arrval.getType(), &arrval, r);
-            DtoAssign(&arrval, slice);
-        }
-        else
-        {
-            DtoAssign(l, r);
-        }
-    }
+    DtoAssign(l, r);
 
     if (l->isSlice() || l->isComplex())
         return l;
@@ -1945,9 +1941,7 @@
     LOG_SCOPE;
 
     DValue* u = e1->toElem(p);
-    Logger::println("e1 = %s", e1->type->toChars());
-
-    return new DArrayLenValue(e1->type, u->getLVal(), type, DtoArrayLen(u));
+    return new DImValue(type, DtoArrayLen(u));
 }
 
 //////////////////////////////////////////////////////////////////////////////////////////
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tangotests/lazy2.d	Sat Jul 12 17:04:36 2008 +0200
@@ -0,0 +1,18 @@
+module tangotests.lazy2;
+
+extern(C) int printf(char*, ...);
+
+void main()
+{
+    lazy1("hello\n");
+}
+
+void lazy1(lazy char[] str)
+{
+    lazy2(str);
+}
+
+void lazy2(lazy char[] msg)
+{
+    printf("%.*s", msg.length, msg.ptr);
+}