Fix #77200.
authorRaja R Harinath <harinath@hurrynot.org>
Wed, 11 Jan 2006 12:20:59 +0000 (12:20 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Wed, 11 Jan 2006 12:20:59 +0000 (12:20 -0000)
* mcs/cfold.cs (BinaryFold): Implement folding of BinaryOr, BinaryAnd
and ExclusiveOr for boolean constants too.
* tests/test-484.cs: New test based on #77200.

svn path=/trunk/mcs/; revision=55367

mcs/mcs/ChangeLog
mcs/mcs/cfold.cs
mcs/tests/ChangeLog
mcs/tests/known-issues-gmcs
mcs/tests/test-484.cs [new file with mode: 0644]

index eecf7e119db2de9763348b187bc511002c8f413f..fa18e7b046b4763c1d1d9e992cbea489255e200c 100644 (file)
@@ -1,3 +1,9 @@
+2006-01-11  Raja R Harinath  <rharinath@novell.com>
+
+       Fix #77200.
+       * cfold.cs (BinaryFold): Implement folding of BinaryOr, BinaryAnd
+       and ExclusiveOr for boolean constants too.
+
 2006-01-09  Raja R Harinath  <rharinath@novell.com>
 
        Fix #75636.
index fdf1ded3260ba34a5d2e6ba82c1d5b594d7729d0..303002901a6b7ee6bc213133c99036fa84fae3fa 100644 (file)
@@ -202,6 +202,23 @@ namespace Mono.CSharp {
                                        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){
@@ -998,22 +1015,6 @@ namespace Mono.CSharp {
                                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 (
index d9df163d11ce0444e07c8245a2bd1fb1838cde7e..7a1480670f5baaf750972ad505982ac04df4510c 100644 (file)
@@ -1,5 +1,7 @@
 2006-01-11  Raja R Harinath  <rharinath@novell.com>
 
+       * test-484.cs: New test based on #77200.
+
        * test-xml-050.cs: Set output to xml-050.xml, not xml-050.cs.
        * gtest-233.cs: Rename from gtest-233-exe.cs.
 
index fa5f02cf2cb00693825009af209b948660b1de22..acc7a2345a424d111dc6a3d4fb7b3f6326933818 100644 (file)
@@ -10,5 +10,6 @@ test-anon-27.cs
 test-xml-027.cs
 test-465.cs IGNORE     # need to fix the path separator to work both on Unix and Windows
 test-476.cs
+test-484.cs
 
 gtest-230.cs
diff --git a/mcs/tests/test-484.cs b/mcs/tests/test-484.cs
new file mode 100644 (file)
index 0000000..ea6e191
--- /dev/null
@@ -0,0 +1,29 @@
+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 ();
+                }
+        }
+}