Author: marek
Date: 2008-02-18 11:50:37 -0500 (Mon, 18 Feb 2008)
New Revision: 96075

Modified:
   trunk/mcs/mcs/ChangeLog
   trunk/mcs/mcs/constant.cs
   trunk/mcs/mcs/expression.cs
   trunk/mcs/mcs/statement.cs
Log:
2008-02-18  Marek Safar  <[EMAIL PROTECTED]>

        A fix for bug #328136
        * constant.cs (SideEffectConstant): Don't emit boolean constant.
        
        * expression.cs: Do not fold immediately LogicalAnd operators when the 
left
        side is a false constant, because we still need to evaluate the 
right-hand
        side.
        
        * statement.cs (If): Emit two types of boolean constants (simple 
constant,
        side-effect constant).
        


Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog     2008-02-18 16:49:36 UTC (rev 96074)
+++ trunk/mcs/mcs/ChangeLog     2008-02-18 16:50:37 UTC (rev 96075)
@@ -1,5 +1,17 @@
 2008-02-18  Marek Safar  <[EMAIL PROTECTED]>
 
+       A fix for bug #328136
+       * constant.cs (SideEffectConstant): Don't emit boolean constant.
+       
+       * expression.cs: Do not fold immediately LogicalAnd operators when the 
left
+       side is a false constant, because we still need to evaluate the 
right-hand
+       side.
+       
+       * statement.cs (If): Emit two types of boolean constants (simple 
constant,
+       side-effect constant).
+       
+2008-02-18  Marek Safar  <[EMAIL PROTECTED]>
+
        A fix for bug #361457
        * ecore.cs (IsApplicable): Params methods have lower priority.
        

Modified: trunk/mcs/mcs/constant.cs
===================================================================
--- trunk/mcs/mcs/constant.cs   2008-02-18 16:49:36 UTC (rev 96074)
+++ trunk/mcs/mcs/constant.cs   2008-02-18 16:50:37 UTC (rev 96075)
@@ -1784,9 +1784,7 @@
 
                public override void Emit (EmitContext ec)
                {
-                       left.Emit (ec);
                        right.Emit (ec);
-                       ec.ig.Emit (OpCodes.Pop);
                }
 
                public override bool IsDefaultValue {

Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2008-02-18 16:49:36 UTC (rev 96074)
+++ trunk/mcs/mcs/expression.cs 2008-02-18 16:50:37 UTC (rev 96075)
@@ -2586,8 +2586,13 @@
                                    lc != null && lc.IsZeroInteger)
                                        return rc;
                        } else if (oper == Operator.LogicalAnd) {
-                               if (rc != null && rc.IsDefaultValue && rc.Type 
== TypeManager.bool_type)
-                                       return rc;
+                               if (rc != null && rc.IsDefaultValue && rc.Type 
== TypeManager.bool_type) {
+                                       if (lc != null)
+                                               return rc;
+
+                                       return new SideEffectConstant (rc, 
left, loc);
+                               }
+
                                if (lc != null && lc.IsDefaultValue && lc.Type 
== TypeManager.bool_type)
                                        return lc;
                        }

Modified: trunk/mcs/mcs/statement.cs
===================================================================
--- trunk/mcs/mcs/statement.cs  2008-02-18 16:49:36 UTC (rev 96074)
+++ trunk/mcs/mcs/statement.cs  2008-02-18 16:50:37 UTC (rev 96075)
@@ -253,8 +253,8 @@
                        //
                        // Dead code elimination
                        //
-                       if (expr is BoolConstant){
-                               bool take = ((BoolConstant) expr).Value;
+                       if (expr is Constant){
+                               bool take = !((Constant) expr).IsDefaultValue;
 
                                if (take){
                                        if (!TrueStatement.Resolve (ec))
@@ -302,15 +302,34 @@
                        Label end;
 
                        //
-                       // If we're a boolean expression, Resolve() already
+                       // If we're a boolean constant, Resolve() already
                        // eliminated dead code for us.
                        //
-                       if (expr is BoolConstant){
-                               bool take = ((BoolConstant) expr).Value;
+                       if (expr is Constant){
+                               
+                               //
+                               // Simple bool constant
+                               //
+                               if (expr is BoolConstant) {
+                                       bool take = ((BoolConstant) expr).Value;
 
-                               if (take)
+                                       if (take)
+                                               TrueStatement.Emit (ec);
+                                       else if (FalseStatement != null)
+                                               FalseStatement.Emit (ec);
+                                       
+                                       return;
+                               }
+
+                               //
+                               // Bool constant with side-effects
+                               //
+                               expr.Emit (ec);
+                               ig.Emit (OpCodes.Pop);
+
+                               if (TrueStatement != null)
                                        TrueStatement.Emit (ec);
-                               else if (FalseStatement != null)
+                               if (FalseStatement != null)
                                        FalseStatement.Emit (ec);
 
                                return;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to