Author: marek
Date: 2007-10-04 11:45:48 -0400 (Thu, 04 Oct 2007)
New Revision: 86885

Modified:
   trunk/mcs/gmcs/generic.cs
   trunk/mcs/mcs/ChangeLog
   trunk/mcs/mcs/assign.cs
   trunk/mcs/mcs/expression.cs
Log:
2007-10-04  Marek Safar  <[EMAIL PROTECTED]>
        
        * expression.cs, assign.cs, generics.cs: Print correct operator when
        compound assignment is used.
        


Modified: trunk/mcs/gmcs/generic.cs
===================================================================
--- trunk/mcs/gmcs/generic.cs   2007-10-04 15:10:59 UTC (rev 86884)
+++ trunk/mcs/gmcs/generic.cs   2007-10-04 15:45:48 UTC (rev 86885)
@@ -3488,26 +3488,27 @@
                        }
                }
 
-               public class LiftedBinaryOperator : Expression
+               public class LiftedBinaryOperator : Binary
                {
-                       public readonly Binary.Operator Oper;
-
-                       Expression left, right, original_left, original_right;
                        Expression underlying, null_value, bool_wrap;
                        Unwrap left_unwrap, right_unwrap;
                        bool is_equality, is_comparision, is_boolean;
 
                        public LiftedBinaryOperator (Binary.Operator op, 
Expression left, Expression right,
                                                     Location loc)
+                               : base (op, left, right)
                        {
-                               this.Oper = op;
-                               this.left = original_left = left;
-                               this.right = original_right = right;
                                this.loc = loc;
                        }
 
                        public override Expression DoResolve (EmitContext ec)
                        {
+                               if ((Oper == Binary.Operator.LogicalAnd) ||
+                                   (Oper == Binary.Operator.LogicalOr)) {
+                                       Error_OperatorCannotBeApplied ();
+                                       return null;
+                               }
+                               
                                if (TypeManager.IsNullableType (left.Type)) {
                                        left = left_unwrap = Unwrap.Create 
(left, ec);
                                        if (left == null)
@@ -3520,15 +3521,6 @@
                                                return null;
                                }
 
-                               if ((Oper == Binary.Operator.LogicalAnd) ||
-                                   (Oper == Binary.Operator.LogicalOr)) {
-                                       Binary.Error_OperatorCannotBeApplied (
-                                               loc, Binary.OperName (Oper),
-                                               
original_left.GetSignatureForError (),
-                                               
original_right.GetSignatureForError ());
-                                       return null;
-                               }
-
                                if (((Oper == Binary.Operator.BitwiseAnd) || 
(Oper == Binary.Operator.BitwiseOr)) &&
                                    ((left.Type == TypeManager.bool_type) && 
(right.Type == TypeManager.bool_type))) {
                                        Expression empty = new EmptyExpression 
(TypeManager.bool_type);
@@ -3734,6 +3726,12 @@
 
                                ig.MarkLabel (end_label);
                        }
+                       
+                       public override void EmitBranchable (EmitContext ec, 
Label target, bool onTrue)
+                       {
+                               Emit (ec);
+                               ec.ig.Emit (onTrue ? OpCodes.Brtrue : 
OpCodes.Brfalse, target);
+                       }                       
 
                        public override void Emit (EmitContext ec)
                        {

Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog     2007-10-04 15:10:59 UTC (rev 86884)
+++ trunk/mcs/mcs/ChangeLog     2007-10-04 15:45:48 UTC (rev 86885)
@@ -1,5 +1,10 @@
 2007-10-04  Marek Safar  <[EMAIL PROTECTED]>
        
+       * expression.cs, assign.cs, generics.cs: Print correct operator when
+       compound assignment is used.
+       
+2007-10-04  Marek Safar  <[EMAIL PROTECTED]>
+       
        A fix for bug #325841
        * expression.cs (ArrayAccess): Use full argument cloning only for
        string compound concatenation.

Modified: trunk/mcs/mcs/assign.cs
===================================================================
--- trunk/mcs/mcs/assign.cs     2007-10-04 15:10:59 UTC (rev 86884)
+++ trunk/mcs/mcs/assign.cs     2007-10-04 15:45:48 UTC (rev 86885)
@@ -679,7 +679,7 @@
                        // into a tree, to guarantee that we do not have side
                        // effects.
                        //
-                       source = new Binary (op, target, original_source);
+                       source = new Binary (op, target, original_source, true);
                        return base.DoResolve (ec);
                }
 

Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2007-10-04 15:10:59 UTC (rev 86884)
+++ trunk/mcs/mcs/expression.cs 2007-10-04 15:45:48 UTC (rev 86885)
@@ -1446,7 +1446,8 @@
                }
 
                readonly Operator oper;
-               Expression left, right;
+               protected Expression left, right;
+               readonly bool is_compound;
 
                // This must be kept in sync with Operator!!!
                public static readonly string [] oper_names;
@@ -1475,6 +1476,12 @@
                        oper_names [(int) Operator.LogicalAnd] = 
"op_LogicalAnd";
                }
 
+               public Binary (Operator oper, Expression left, Expression 
right, bool isCompound)
+                       : this (oper, left, right)
+               {
+                       this.is_compound = isCompound;
+               }
+
                public Binary (Operator oper, Expression left, Expression right)
                {
                        this.oper = oper;
@@ -1492,48 +1499,73 @@
                /// <summary>
                ///   Returns a stringified representation of the Operator
                /// </summary>
-               public static string OperName (Operator oper)
+               string OperName (Operator oper)
                {
+                       string s;
                        switch (oper){
                        case Operator.Multiply:
-                               return "*";
+                               s = "*";
+                               break;
                        case Operator.Division:
-                               return "/";
+                               s = "/";
+                               break;
                        case Operator.Modulus:
-                               return "%";
+                               s = "%";
+                               break;
                        case Operator.Addition:
-                               return "+";
+                               s = "+";
+                               break;
                        case Operator.Subtraction:
-                               return "-";
+                               s = "-";
+                               break;
                        case Operator.LeftShift:
-                               return "<<";
+                               s = "<<";
+                               break;
                        case Operator.RightShift:
-                               return ">>";
+                               s = ">>";
+                               break;
                        case Operator.LessThan:
-                               return "<";
+                               s = "<";
+                               break;
                        case Operator.GreaterThan:
-                               return ">";
+                               s = ">";
+                               break;
                        case Operator.LessThanOrEqual:
-                               return "<=";
+                               s = "<=";
+                               break;
                        case Operator.GreaterThanOrEqual:
-                               return ">=";
+                               s = ">=";
+                               break;
                        case Operator.Equality:
-                               return "==";
+                               s = "==";
+                               break;
                        case Operator.Inequality:
-                               return "!=";
+                               s = "!=";
+                               break;
                        case Operator.BitwiseAnd:
-                               return "&";
+                               s = "&";
+                               break;
                        case Operator.BitwiseOr:
-                               return "|";
+                               s = "|";
+                               break;
                        case Operator.ExclusiveOr:
-                               return "^";
+                               s = "^";
+                               break;
                        case Operator.LogicalOr:
-                               return "||";
+                               s = "||";
+                               break;
                        case Operator.LogicalAnd:
-                               return "&&";
+                               s = "&&";
+                               break;
+                       default:
+                               s = oper.ToString ();
+                               break;
                        }
 
-                       return oper.ToString ();
+                       if (is_compound)
+                               return s + "=";
+
+                       return s;
                }
 
                public override string ToString ()
@@ -1550,7 +1582,7 @@
                        return Convert.ImplicitConversion (ec, expr, 
target_type, loc);
                }
 
-               public static void Error_OperatorAmbiguous (Location loc, 
Operator oper, Type l, Type r)
+               void Error_OperatorAmbiguous (Location loc, Operator oper, Type 
l, Type r)
                {
                        Report.Error (
                                34, loc, "Operator `" + OperName (oper) 
@@ -1627,7 +1659,7 @@
                                name, left, right);
                }
                
-               void Error_OperatorCannotBeApplied ()
+               protected void Error_OperatorCannotBeApplied ()
                {
                        Error_OperatorCannotBeApplied (Location, OperName 
(oper), TypeManager.CSharpName (left.Type),
                                TypeManager.CSharpName(right.Type));
@@ -2341,7 +2373,7 @@
                                                break;
                                        return left;
                        }
-                       Error_OperatorCannotBeApplied (loc, Binary.OperName 
(oper), left.Type, right.Type);
+                       Error_OperatorCannotBeApplied ();
                        return null;
                }
 

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

Reply via email to