Author: miguel
Date: 2008-02-15 11:48:42 -0500 (Fri, 15 Feb 2008)
New Revision: 95765

Modified:
   trunk/mcs/mcs/ChangeLog
   trunk/mcs/mcs/constant.cs
   trunk/mcs/mcs/expression.cs
Log:
2008-02-15  Miguel de Icaza  <[EMAIL PROTECTED]>

        * constant.cs (SideEffectConstant): a constant value that happens
        to have a side effect.   

        Fixes the build regressions introduced by the fix for #359789



Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog     2008-02-15 16:35:24 UTC (rev 95764)
+++ trunk/mcs/mcs/ChangeLog     2008-02-15 16:48:42 UTC (rev 95765)
@@ -1,3 +1,10 @@
+2008-02-15  Miguel de Icaza  <[EMAIL PROTECTED]>
+
+       * constant.cs (SideEffectConstant): a constant value that happens
+       to have a side effect.   
+
+       Fixes the build regressions introduced by the fix for #359789
+
 2008-02-14  Rodrigo Kumpera  <[EMAIL PROTECTED]>
 
        * expression.cs (Conditional.Emit): when emitting the ternary

Modified: trunk/mcs/mcs/constant.cs
===================================================================
--- trunk/mcs/mcs/constant.cs   2008-02-15 16:35:24 UTC (rev 95764)
+++ trunk/mcs/mcs/constant.cs   2008-02-15 16:48:42 UTC (rev 95765)
@@ -1754,6 +1754,69 @@
                }
        }
 
+       /// <summary>
+       ///   The value is constant, but when emitted has a side effect.  This 
is
+       ///   used by BitwiseAnd to ensure that the second expression is invoked
+       ///   regardless of the value of the left side.  
+       /// </summary>
+       
+       public class SideEffectConstant : Constant {
+               Constant left;
+               Expression right;
+               
+               public SideEffectConstant (Constant left, Expression right, 
Location loc) : base (loc)
+               {
+                       this.left = left;
+                       this.right = right;
+                       eclass = ExprClass.Value;
+                       type = left.Type;
+               }
+
+               public override string AsString ()
+               {
+                       return left.AsString ();
+               }
+
+               public override object GetValue ()
+               {
+                       return left.GetValue ();
+               }
+
+               public override void Emit (EmitContext ec)
+               {
+                       left.Emit (ec);
+                       right.Emit (ec);
+                       ec.ig.Emit (OpCodes.Pop);
+               }
+
+               public override bool IsDefaultValue {
+                       get {
+                               return left.IsDefaultValue;
+                       }
+               }
+
+               public override Constant Increment ()
+               {
+                       throw new NotSupportedException ();
+               }
+               
+               public override bool IsNegative {
+                       get {
+                               return left.IsNegative;
+                       }
+               }
+
+               public override bool IsZeroInteger {
+                       get {
+                               return left.IsZeroInteger;
+                       }
+               }
+
+               public override Constant ConvertExplicitly (bool 
in_checked_context, Type target_type)
+               {
+                       return left.ConvertExplicitly (in_checked_context, 
target_type);
+               }
+       }
 }
 
 

Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2008-02-15 16:35:24 UTC (rev 95764)
+++ trunk/mcs/mcs/expression.cs 2008-02-15 16:48:42 UTC (rev 95765)
@@ -2566,8 +2566,16 @@
                                if (lc != null && lc.IsZeroInteger) {
                                        if (rc is EnumConstant)
                                                return new EnumConstant (lc, 
rc.Type);
-                                       Type = TypeManager.bool_type;
-                                       return this;
+
+                                       //
+                                       // Optimize cases that have no 
side-effects, to avoid
+                                       // emitting code that gets popped
+                                       //
+                                       if (right is FieldExpr)
+                                               return lc;
+
+                                       // Side effect code:
+                                       return new SideEffectConstant (lc, 
right, loc);
                                }
                        }
                        else if (oper == Operator.BitwiseOr) {

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

Reply via email to