diff dmd/ArrayLengthExp.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children cab4c37afb89
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dmd/ArrayLengthExp.d	Sat Oct 24 08:42:06 2009 +0400
@@ -0,0 +1,75 @@
+module dmd.ArrayLengthExp;
+
+import dmd.Expression;
+import dmd.backend.elem;
+import dmd.UnaExp;
+import dmd.InterState;
+import dmd.OutBuffer;
+import dmd.Loc;
+import dmd.Scope;
+import dmd.IRState;
+import dmd.HdrGenState;
+import dmd.TOK;
+import dmd.Type;
+import dmd.WANT;
+
+import dmd.expression.ArrayLength;
+
+import dmd.backend.Util;
+import dmd.backend.OPER;
+
+class ArrayLengthExp : UnaExp
+{
+	this(Loc loc, Expression e1)
+	{
+		super(loc, TOK.TOKarraylength, ArrayLengthExp.sizeof, e1);
+	}
+
+	Expression semantic(Scope sc)
+	{
+		Expression e;
+
+	version (LOGSEMANTIC) {
+		printf("ArrayLengthExp::semantic('%s')\n", toChars());
+	}
+		if (!type)
+		{
+			UnaExp.semantic(sc);
+			e1 = resolveProperties(sc, e1);
+
+			type = Type.tsize_t;
+		}
+		return this;
+	}
+
+	Expression optimize(int result)
+	{
+		//printf("ArrayLengthExp::optimize(result = %d) %s\n", result, toChars());
+		e1 = e1.optimize(WANTvalue | (result & WANTinterpret));
+		Expression e = this;
+		if (e1.op == TOKstring || e1.op == TOKarrayliteral || e1.op == TOKassocarrayliteral)
+		{
+			e = ArrayLength(type, e1);
+		}
+		return e;
+	}
+
+	Expression interpret(InterState* istate)
+	{
+		assert(false);
+	}
+
+	void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	{
+		assert(false);
+	}
+
+	elem* toElem(IRState* irs)
+	{
+		elem *e = e1.toElem(irs);
+		e = el_una(OP64_32, type.totym(), e);
+		el_setLoc(e,loc);
+		return e;
+	}
+}
+