diff dmd/OrExp.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children a8b50ff7f201
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dmd/OrExp.d	Sat Oct 24 08:42:06 2009 +0400
@@ -0,0 +1,133 @@
+module dmd.OrExp;
+
+import dmd.Expression;
+import dmd.Identifier;
+import dmd.InterState;
+import dmd.MATCH;
+import dmd.Type;
+import dmd.OutBuffer;
+import dmd.Loc;
+import dmd.Scope;
+import dmd.IntRange;
+import dmd.IRState;
+import dmd.ArrayTypes;
+import dmd.BinExp;
+import dmd.TOK;
+import dmd.TY;
+import dmd.Id;
+
+import dmd.backend.elem;
+import dmd.backend.OPER;
+
+import dmd.expression.Or;
+
+class OrExp : BinExp
+{
+	this(Loc loc, Expression e1, Expression e2)
+	{
+		super(loc, TOK.TOKor, OrExp.sizeof, e1, e2);
+	}
+
+	Expression semantic(Scope sc)
+	{
+		Expression e;
+
+		if (!type)
+		{	
+			BinExp.semanticp(sc);
+			e = op_overload(sc);
+
+			if (e)
+				return e;
+
+			if (e1.type.toBasetype().ty == TY.Tbool && e2.type.toBasetype().ty == TY.Tbool)
+			{
+				type = e1.type;
+				e = this;
+			}
+			else
+			{
+				typeCombine(sc);
+				if (e1.op != TOK.TOKslice && e2.op != TOK.TOKslice)
+				{
+					e1.checkIntegral();
+					e2.checkIntegral();
+				}
+			}
+		}
+
+		return this;
+	}
+
+	Expression optimize(int result)
+	{
+		Expression e;
+
+		e1 = e1.optimize(result);
+		e2 = e2.optimize(result);
+
+		if (e1.isConst() == 1 && e2.isConst() == 1)
+			e = Or(type, e1, e2);
+		else
+			e = this;
+
+		return e;
+	}
+
+	Expression interpret(InterState* istate)
+	{
+		assert(false);
+	}
+
+	void buildArrayIdent(OutBuffer buf, Expressions arguments)
+	{
+		assert(false);
+	}
+
+	Expression buildArrayLoop(Arguments fparams)
+	{
+		assert(false);
+	}
+
+	MATCH implicitConvTo(Type t)
+	{
+		MATCH result = Expression.implicitConvTo(t);
+
+		if (result == MATCH.MATCHnomatch)
+		{
+			MATCH m1 = e1.implicitConvTo(t);
+			MATCH m2 = e2.implicitConvTo(t);
+
+			// Pick the worst match
+			result = (m1 < m2) ? m1 : m2;
+		}
+
+		return result;
+	}
+
+	IntRange getIntRange()
+	{
+		assert(false);
+	}
+
+	bool isCommutative()
+	{
+		return true;
+	}
+
+	Identifier opId()
+	{
+		return Id.ior;
+	}
+
+	Identifier opId_r()
+	{
+		return Id.ior_r;
+	}
+
+	elem* toElem(IRState* irs)
+	{
+		return toElemBin(irs, OPER.OPor);
+	}
+}
+