diff dmd/Expression.d @ 95:ae5b11064a9a

beginning of 2.036 branch
author Trass3r
date Mon, 30 Aug 2010 23:08:44 +0200
parents df6d0f967680
children ceda59b4d255
line wrap: on
line diff
--- a/dmd/Expression.d	Mon Aug 30 22:50:30 2010 +0200
+++ b/dmd/Expression.d	Mon Aug 30 23:08:44 2010 +0200
@@ -126,7 +126,6 @@
 /***************************************
  * Pull out any properties.
  */
-
 Expression resolveProperties(Scope sc, Expression e)
 {
     //printf("resolveProperties(%s)\n", e.toChars());
@@ -166,6 +165,17 @@
     return e;
 }
 
+void indent(int indent)
+{
+    foreach (i; 0 .. indent)
+        writef(" ");
+}
+
+string type_print(Type type)
+{
+    return type ? type.toChars() : "null";
+}
+
 class Expression
 {
     Loc loc;			// file location
@@ -258,9 +268,10 @@
 		return buf.toChars();
 	}
 	
-    void dump(int indent)
+    void dump(int i)
 	{
-		assert(false);
+		indent(i);
+		writef("%p %s type=%s\n", this, Token.toChars(op), type_print(type));
 	}
 
     void error(T...)(string format, T t)
@@ -978,7 +989,38 @@
 		Expression e = new IdentifierExp(Loc(0), id);
 		return e;
 	}
-    
+
+	/***********************************************
+	 * Test if operand is a valid array op operand.
+	 */
+	int isArrayOperand()
+	{
+		//writef("Expression::isArrayOperand() %s\n", toChars());
+		if (op == TOKslice)
+			return 1;
+		if (type.toBasetype().ty == 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;
+	}
+
     // Back end
     elem* toElem(IRState* irs)
 	{