Author: martin
Date: 2005-03-07 00:55:39 -0500 (Mon, 07 Mar 2005)
New Revision: 41500

Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/generic.cs
Log:
2005-03-07  Martin Baulig  <[EMAIL PROTECTED]>

        * generic.cs (Nullable.Unwrap): Implement IMemoryLocation and make
        it work if `expr' is not an IMemoryLocation.
        (Nullable.Lifted): Implement IMemoryLocation.
        (Nullable.LiftedConversion.ResolveUnderlying): Use the correct
        target type.



Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2005-03-07 05:31:56 UTC (rev 41499)
+++ trunk/mcs/gmcs/ChangeLog    2005-03-07 05:55:39 UTC (rev 41500)
@@ -1,3 +1,11 @@
+2005-03-07  Martin Baulig  <[EMAIL PROTECTED]>
+
+       * generic.cs (Nullable.Unwrap): Implement IMemoryLocation and make
+       it work if `expr' is not an IMemoryLocation.
+       (Nullable.Lifted): Implement IMemoryLocation.
+       (Nullable.LiftedConversion.ResolveUnderlying): Use the correct
+       target type.
+
 2005-03-05  Martin Baulig  <[EMAIL PROTECTED]>
 
        * generic.cs (Nullable.Unwrap, Wrap): New protected classes.

Modified: trunk/mcs/gmcs/generic.cs
===================================================================
--- trunk/mcs/gmcs/generic.cs   2005-03-07 05:31:56 UTC (rev 41499)
+++ trunk/mcs/gmcs/generic.cs   2005-03-07 05:55:39 UTC (rev 41500)
@@ -2314,11 +2314,14 @@
                        }
                }
 
-               protected class Unwrap : Expression
+               protected class Unwrap : Expression, IMemoryLocation
                {
                        Expression expr;
                        NullableInfo info;
 
+                       LocalTemporary temp;
+                       bool has_temp;
+
                        public Unwrap (Expression expr, Location loc)
                        {
                                this.expr = expr;
@@ -2331,6 +2334,9 @@
                                if (expr == null)
                                        return null;
 
+                               if (!(expr is IMemoryLocation))
+                                       temp = new LocalTemporary (ec, 
expr.Type);
+
                                info = new NullableInfo (expr.Type);
                                type = info.UnderlyingType;
                                eclass = expr.eclass;
@@ -2339,15 +2345,28 @@
 
                        public override void Emit (EmitContext ec)
                        {
-                               ((IMemoryLocation) expr).AddressOf (ec, 
AddressOp.LoadStore);
+                               AddressOf (ec, AddressOp.LoadStore);
                                ec.ig.EmitCall (OpCodes.Call, info.Value, null);
                        }
 
-                       public void EmitCheck (EmitContext ec)
+                       public void EmitCheck (EmitContext ec, Label label)
                        {
-                               ((IMemoryLocation) expr).AddressOf (ec, 
AddressOp.LoadStore);
+                               AddressOf (ec, AddressOp.LoadStore);
                                ec.ig.EmitCall (OpCodes.Call, info.HasValue, 
null);
+                               ec.ig.Emit (OpCodes.Brfalse, label);
                        }
+
+                       public void AddressOf (EmitContext ec, AddressOp mode)
+                       {
+                               if (temp != null) {
+                                       if (!has_temp) {
+                                               temp.Store (ec);
+                                               has_temp = true;
+                                       }
+                                       temp.AddressOf (ec, 
AddressOp.LoadStore);
+                               } else
+                                       ((IMemoryLocation) expr).AddressOf (ec, 
AddressOp.LoadStore);
+                       }
                }
 
                protected class Wrap : Expression
@@ -2418,7 +2437,7 @@
                        }
                }
 
-               public abstract class Lifted : Expression
+               public abstract class Lifted : Expression, IMemoryLocation
                {
                        Expression expr, underlying, wrap, null_value;
                        Unwrap unwrap;
@@ -2464,8 +2483,7 @@
                                Label is_null_label = ig.DefineLabel ();
                                Label end_label = ig.DefineLabel ();
 
-                               unwrap.EmitCheck (ec);
-                               ig.Emit (OpCodes.Brfalse, is_null_label);
+                               unwrap.EmitCheck (ec, is_null_label);
 
                                wrap.Emit (ec);
                                ig.Emit (OpCodes.Br, end_label);
@@ -2475,6 +2493,11 @@
 
                                ig.MarkLabel (end_label);
                        }
+
+                       public void AddressOf (EmitContext ec, AddressOp mode)
+                       {
+                               unwrap.AddressOf (ec, mode);
+                       }
                }
 
                public class LiftedConversion : Lifted
@@ -2494,14 +2517,15 @@
 
                        protected override Expression ResolveUnderlying 
(Expression unwrap, EmitContext ec)
                        {
+                               Type type = TypeManager.GetTypeArguments 
(TargetType) [0];
+
                                if (IsUser) {
-                                       return Convert.UserDefinedConversion (
-                                               ec, unwrap, TargetType, loc, 
IsExplicit);
+                                       return Convert.UserDefinedConversion 
(ec, unwrap, type, loc, IsExplicit);
                                } else {
                                        if (IsExplicit)
-                                               return 
Convert.ExplicitConversion (ec, unwrap, TargetType, loc);
+                                               return 
Convert.ExplicitConversion (ec, unwrap, type, loc);
                                        else
-                                               return 
Convert.ImplicitConversion (ec, unwrap, TargetType, loc);
+                                               return 
Convert.ImplicitConversion (ec, unwrap, type, loc);
                                }
                        }
                }
@@ -2602,15 +2626,11 @@
                                Label is_null_label = ig.DefineLabel ();
                                Label end_label = ig.DefineLabel ();
 
-                               if (left_unwrap != null) {
-                                       left_unwrap.EmitCheck (ec);
-                                       ig.Emit (OpCodes.Brfalse, 
is_null_label);
-                               }
+                               if (left_unwrap != null)
+                                       left_unwrap.EmitCheck (ec, 
is_null_label);
 
-                               if (right_unwrap != null) {
-                                       right_unwrap.EmitCheck (ec);
-                                       ig.Emit (OpCodes.Brfalse, 
is_null_label);
-                               }
+                               if (right_unwrap != null)
+                                       right_unwrap.EmitCheck (ec, 
is_null_label);
 
                                underlying.Emit (ec);
                                ig.Emit (OpCodes.Br, end_label);

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

Reply via email to