From 510406993136da82a5db74bb13f465256c950f7b Mon Sep 17 00:00:00 2001 From: Raja R Harinath Date: Wed, 11 Jan 2006 12:20:59 +0000 Subject: [PATCH] Fix #77200. * 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 | 6 ++++++ mcs/mcs/cfold.cs | 33 +++++++++++++++++---------------- mcs/tests/ChangeLog | 2 ++ mcs/tests/known-issues-gmcs | 1 + mcs/tests/test-484.cs | 29 +++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 mcs/tests/test-484.cs diff --git a/mcs/mcs/ChangeLog b/mcs/mcs/ChangeLog index eecf7e119db..fa18e7b046b 100644 --- a/mcs/mcs/ChangeLog +++ b/mcs/mcs/ChangeLog @@ -1,3 +1,9 @@ +2006-01-11 Raja R Harinath + + Fix #77200. + * cfold.cs (BinaryFold): Implement folding of BinaryOr, BinaryAnd + and ExclusiveOr for boolean constants too. + 2006-01-09 Raja R Harinath Fix #75636. diff --git a/mcs/mcs/cfold.cs b/mcs/mcs/cfold.cs index fdf1ded3260..303002901a6 100644 --- a/mcs/mcs/cfold.cs +++ b/mcs/mcs/cfold.cs @@ -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 ( diff --git a/mcs/tests/ChangeLog b/mcs/tests/ChangeLog index d9df163d11c..7a1480670f5 100644 --- a/mcs/tests/ChangeLog +++ b/mcs/tests/ChangeLog @@ -1,5 +1,7 @@ 2006-01-11 Raja R Harinath + * 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. diff --git a/mcs/tests/known-issues-gmcs b/mcs/tests/known-issues-gmcs index fa5f02cf2cb..acc7a2345a4 100644 --- a/mcs/tests/known-issues-gmcs +++ b/mcs/tests/known-issues-gmcs @@ -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 index 00000000000..ea6e1914ac7 --- /dev/null +++ b/mcs/tests/test-484.cs @@ -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 (); + } + } +} -- 2.25.1