right = ((EnumConstant) right).Child;
}
+ if (left is BoolConstant && right is BoolConstant) {
+ bool lv = ((BoolConstant) left ).Value;
+ bool rv = ((BoolConstant) right).Value;
+ switch (oper) {
+ case Binary.Operator.BitwiseAnd:
+ case Binary.Operator.LogicalAnd:
+ return new BoolConstant (lv && rv, left.Location);
+ case Binary.Operator.BitwiseOr:
+ case Binary.Operator.LogicalOr:
+ return new BoolConstant (lv || rv, left.Location);
+ case Binary.Operator.ExclusiveOr:
+ return new BoolConstant (lv ^ rv, left.Location);
+ default:
+ throw new InternalErrorException ("Invalid operator on booleans: " + oper);
+ }
+ }
+
Type wrap_as;
Constant result = null;
switch (oper){
Binary.Error_OperatorCannotBeApplied (loc, ">>", lt, rt);
break;
- case Binary.Operator.LogicalAnd:
- if (left is BoolConstant && right is BoolConstant){
- return new BoolConstant (
- ((BoolConstant) left).Value &&
- ((BoolConstant) right).Value, left.Location);
- }
- break;
-
- case Binary.Operator.LogicalOr:
- if (left is BoolConstant && right is BoolConstant){
- return new BoolConstant (
- ((BoolConstant) left).Value ||
- ((BoolConstant) right).Value, left.Location);
- }
- break;
-
case Binary.Operator.Equality:
if (left is BoolConstant && right is BoolConstant){
return new BoolConstant (
--- /dev/null
+using System;
+
+namespace Test
+{
+ public class TestBit {
+ const bool a00 = false & false;
+ const bool a01 = false & true;
+ const bool a10 = true & false;
+ const bool a11 = true & true;
+
+ const bool o00 = false | false;
+ const bool o01 = false | true;
+ const bool o10 = true | false;
+ const bool o11 = true | true;
+
+ const bool x00 = false ^ false;
+ const bool x01 = false ^ true;
+ const bool x10 = true ^ false;
+ const bool x11 = true ^ true;
+
+ const bool correct = !a00 & !a01 & !a10 & a11 & !o00 & o01 & o10 & o11 & !x00 & x01 & x10 & !x11;
+
+ public static void Main()
+ {
+ if (!correct)
+ throw new Exception ();
+ }
+ }
+}