diff dmd/arrayop.c @ 1587:def7a1d494fd

Merge DMD 1.051
author Christian Kamm <kamm incasoftware de>
date Fri, 06 Nov 2009 23:58:01 +0100
parents afecdb8ee962
children 207a8a438dea
line wrap: on
line diff
--- a/dmd/arrayop.c	Fri Nov 06 21:51:41 2009 +0100
+++ b/dmd/arrayop.c	Fri Nov 06 23:58:01 2009 +0100
@@ -1,5 +1,5 @@
 
-// Copyright (c) 1999-2008 by Digital Mars
+// Copyright (c) 1999-2009 by Digital Mars
 // All Rights Reserved
 // written by Walter Bright
 // http://www.digitalmars.com
@@ -31,6 +31,14 @@
 
 Expression *BinExp::arrayOp(Scope *sc)
 {
+    //printf("BinExp::arrayOp() %s\n", toChars());
+
+    if (type->toBasetype()->nextOf()->toBasetype()->ty == Tvoid)
+    {
+        error("Cannot perform array operations on void[] arrays");
+        return new ErrorExp();
+    }
+
     Expressions *arguments = new Expressions();
 
     /* The expression to generate an array operation for is mangled
@@ -288,6 +296,8 @@
         sc->stc = 0;
         sc->linkage = LINKd;
         fd->semantic(sc);
+	    fd->semantic2(sc);
+	    fd->semantic3(sc);
         sc->pop();
 //     }
 //     else
@@ -318,6 +328,17 @@
     arguments->shift(this);
 }
 
+void CastExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments)
+{
+    Type *tb = type->toBasetype();
+    if (tb->ty == Tarray || tb->ty == Tsarray)
+    {
+	e1->buildArrayIdent(buf, arguments);
+    }
+    else
+	Expression::buildArrayIdent(buf, arguments);
+}
+
 void SliceExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments)
 {
     buf->writestring("Slice");
@@ -402,6 +423,17 @@
     return e;
 }
 
+Expression *CastExp::buildArrayLoop(Arguments *fparams)
+{
+    Type *tb = type->toBasetype();
+    if (tb->ty == Tarray || tb->ty == Tsarray)
+    {
+	return e1->buildArrayLoop(fparams);
+    }
+    else
+	return Expression::buildArrayLoop(fparams);
+}
+
 Expression *SliceExp::buildArrayLoop(Arguments *fparams)
 {
     Identifier *id = Identifier::generateId("p", fparams->dim);
@@ -420,6 +452,14 @@
     /* Evaluate assign expressions right to left
      */
     Expression *ex2 = e2->buildArrayLoop(fparams);
+#if DMDV2
+    /* Need the cast because:
+     *   b = c + p[i];
+     * where b is a byte fails because (c + p[i]) is an int
+     * which cannot be implicitly cast to byte.
+     */
+    ex2 = new CastExp(0, ex2, e1->type->nextOf());
+#endif
     Expression *ex1 = e1->buildArrayLoop(fparams);
     Argument *param = (Argument *)fparams->data[0];
     param->storageClass = 0;
@@ -488,3 +528,34 @@
 #undef X
 
 
+/***********************************************
+ * Test if operand is a valid array op operand.
+ */
+
+int Expression::isArrayOperand()
+{
+    //printf("Expression::isArrayOperand() %s\n", toChars());
+    if (op == TOKslice)
+	return 1;
+    if (type->toBasetype()->ty == Tarray)
+    {
+	switch (op)
+	{
+	    case TOKadd:
+	    case TOKmin:
+	    case TOKmul:
+	    case TOKdiv:
+	    case TOKmod:
+	    case TOKxor:
+	    case TOKand:
+	    case TOKor:
+	    case TOKneg:
+	    case TOKtilde:
+		return 1;
+
+	    default:
+		break;
+	}
+    }
+    return 0;
+}