diff dmd/BinExp.d @ 115:6caaf0256da1

+ interpretation of (non-assign) binary expressions + BinExp.isunsigned + EqualExp.isBit
author Trass3r
date Thu, 02 Sep 2010 01:29:29 +0200
parents e28b18c23469
children 352a5164f692
line wrap: on
line diff
--- a/dmd/BinExp.d	Wed Sep 01 18:21:58 2010 +0200
+++ b/dmd/BinExp.d	Thu Sep 02 01:29:29 2010 +0200
@@ -655,7 +655,7 @@
 
     bool isunsigned()
 	{
-		assert(false);
+		return e1.type.isunsigned() || e2.type.isunsigned();
 	}
 	
     void incompatibleTypes()
@@ -670,19 +670,75 @@
 		assert(false);
 	}
 
-    void scanForNestedRef(Scope *sc)
-	{
-		assert(false);
-	}
-	
-    Expression interpretCommon(InterState istate, Expression *(*fp)(Type *, Expression *, Expression *))
+    void scanForNestedRef(Scope sc)
 	{
 		assert(false);
 	}
 
-    Expression interpretCommon2(InterState istate, Expression *(*fp)(TOK, Type *, Expression *, Expression *))
+	Expression interpretCommon(InterState istate, Expression function(Type, Expression, Expression) fp)
+	{
+		   Expression e;
+			Expression e1;
+			Expression e2;
+
+version(LOG)
+{
+			writef("BinExp::interpretCommon() %s\n", toChars());
+}
+			e1 = this.e1.interpret(istate);
+			if (e1 == EXP_CANT_INTERPRET)
+				goto Lcant;
+			if (e1.isConst() != 1)
+				goto Lcant;
+
+			e2 = this.e2.interpret(istate);
+			if (e2 == EXP_CANT_INTERPRET)
+				goto Lcant;
+			if (e2.isConst() != 1)
+				goto Lcant;
+
+			e = fp(type, e1, e2);
+			return e;
+
+		Lcant:
+			return EXP_CANT_INTERPRET;
+	}
+
+	Expression interpretCommon2(InterState istate, Expression function(TOK, Type, Expression, Expression) fp)
 	{
-		assert(false);
+		   Expression e;
+			Expression e1;
+			Expression e2;
+
+version(LOG)
+{
+			writef("BinExp::interpretCommon2() %s\n", toChars());
+}
+			e1 = this.e1.interpret(istate);
+			if (e1 == EXP_CANT_INTERPRET)
+				goto Lcant;
+			if (e1.isConst() != 1 &&
+				e1.op != TOKnull &&
+				e1.op != TOKstring &&
+				e1.op != TOKarrayliteral &&
+				e1.op != TOKstructliteral)
+				goto Lcant;
+
+			e2 = this.e2.interpret(istate);
+			if (e2 == EXP_CANT_INTERPRET)
+				goto Lcant;
+			if (e2.isConst() != 1 &&
+				e2.op != TOKnull &&
+				e2.op != TOKstring &&
+				e2.op != TOKarrayliteral &&
+				e2.op != TOKstructliteral)
+				goto Lcant;
+
+			e = fp(op, type, e1, e2);
+			return e;
+
+		Lcant:
+			return EXP_CANT_INTERPRET;
 	}
 	
     Expression interpretAssignCommon(InterState istate, Expression (*fp)(Type, Expression, Expression), int post = 0)
@@ -1324,7 +1380,8 @@
 		}
 		return e;
 	}
-	
+
+	version(DMDV2)
     override bool canThrow()
 	{
 		return e1.canThrow() || e2.canThrow();