diff dmd/UshrExp.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/UshrExp.d	Sat Oct 24 08:42:06 2009 +0400
@@ -0,0 +1,85 @@
+module dmd.UshrExp;
+
+import dmd.Expression;
+import dmd.Identifier;
+import dmd.InterState;
+import dmd.Loc;
+import dmd.Scope;
+import dmd.Id;
+import dmd.IntRange;
+import dmd.IRState;
+import dmd.BinExp;
+import dmd.TOK;
+import dmd.Type;
+
+import dmd.backend.elem;
+import dmd.backend.OPER;
+import dmd.backend.TYFL;
+import dmd.backend.Util;
+import dmd.expression.Util;
+import dmd.expression.Ushr;
+import dmd.expression.shift_optimize;
+
+class UshrExp : BinExp
+{
+	this(Loc loc, Expression e1, Expression e2)
+	{
+		super(loc, TOK.TOKushr, UshrExp.sizeof, e1, e2);
+	}
+
+	Expression semantic(Scope sc)
+	{
+		Expression e;
+
+		if (!type)
+		{	
+			BinExp.semanticp(sc);
+			e = op_overload(sc);
+			if (e)
+				return e;
+			e1 = e1.checkIntegral();
+			e2 = e2.checkIntegral();
+			e1 = e1.integralPromotions(sc);
+			e2 = e2.castTo(sc, Type.tshiftcnt);
+			type = e1.type;
+		}
+		return this;
+	}
+
+	Expression optimize(int result)
+	{
+		//printf("UshrExp.optimize(result = %d) %s\n", result, toChars());
+		return shift_optimize(result, this, &Ushr);
+	}
+
+	Expression interpret(InterState* istate)
+	{
+		assert(false);
+	}
+
+	IntRange getIntRange()
+	{
+		assert(false);
+	}
+
+	Identifier opId()
+	{
+		return Id.ushr;
+	}
+
+	Identifier opId_r()
+	{
+		return Id.ushr_r;
+	}
+
+	elem* toElem(IRState* irs)
+	{
+		elem *eleft  = e1.toElem(irs);
+		eleft.Ety = touns(eleft.Ety);
+		elem *eright = e2.toElem(irs);
+		elem *e = el_bin(OPshr, type.totym(), eleft, eright);
+		el_setLoc(e, loc);
+		return e;
+	}
+}
+