Author: martin
Date: 2006-09-27 06:11:33 -0400 (Wed, 27 Sep 2006)
New Revision: 65954

Modified:
   branches/martin/anonymous-methods/mcs/ChangeLog
   branches/martin/anonymous-methods/mcs/ecore.cs
   branches/martin/anonymous-methods/mcs/parameter.cs
Log:
2006-09-27  Martin Baulig  <[EMAIL PROTECTED]>

        Merged the Anonymous Methods patch.

        * parameter.cs (Parameter.ResolveVariable): New public method.
        (Parameters.ResolveVariable): Likewise.

        * ecore.cs (TemporaryVariable): Use the new `Variable' framework.



Modified: branches/martin/anonymous-methods/mcs/ChangeLog
===================================================================
--- branches/martin/anonymous-methods/mcs/ChangeLog     2006-09-27 09:53:20 UTC 
(rev 65953)
+++ branches/martin/anonymous-methods/mcs/ChangeLog     2006-09-27 10:11:33 UTC 
(rev 65954)
@@ -1,5 +1,14 @@
 2006-09-27  Martin Baulig  <[EMAIL PROTECTED]>
 
+       Merged the Anonymous Methods patch.
+
+       * parameter.cs (Parameter.ResolveVariable): New public method.
+       (Parameters.ResolveVariable): Likewise.
+
+       * ecore.cs (TemporaryVariable): Use the new `Variable' framework.
+
+2006-09-27  Martin Baulig  <[EMAIL PROTECTED]>
+
        * report.cs
        (InternalErrorException): Added overloaded ctor taking a params array.
 

Modified: branches/martin/anonymous-methods/mcs/ecore.cs
===================================================================
--- branches/martin/anonymous-methods/mcs/ecore.cs      2006-09-27 09:53:20 UTC 
(rev 65953)
+++ branches/martin/anonymous-methods/mcs/ecore.cs      2006-09-27 10:11:33 UTC 
(rev 65954)
@@ -3192,8 +3192,6 @@
                                                        "this");
                                                return null;
                                        }
-                                       if ((am.ContainerAnonymousMethod == 
null) && (InstanceExpression is This))
-                                               ec.CaptureField (this);
                                }
                        }
                        
@@ -4057,10 +4055,10 @@
                }
        }
 
-       
        public class TemporaryVariable : Expression, IMemoryLocation
        {
                LocalInfo li;
+               Variable var;
                
                public TemporaryVariable (Type type, Location loc)
                {
@@ -4078,64 +4076,47 @@
                        li = ec.CurrentBlock.AddTemporaryVariable (te, loc);
                        if (!li.Resolve (ec))
                                return null;
+
+                       if (ec.MustCaptureVariable (li)) {
+                               ScopeInfo scope = li.Block.CreateScopeInfo ();
+                               var = scope.AddLocal (li);
+                               type = var.Type;
+                       }
                        
-                       AnonymousContainer am = ec.CurrentAnonymousMethod;
-                       if ((am != null) && am.IsIterator)
-                               ec.CaptureVariable (li);
-                       
                        return this;
                }
+
+               public Variable Variable {
+                       get { return var != null ? var : li.Variable; }
+               }
                
                public override void Emit (EmitContext ec)
                {
-                       ILGenerator ig = ec.ig;
-                       
-                       if (li.FieldBuilder != null) {
-                               ig.Emit (OpCodes.Ldarg_0);
-                               ig.Emit (OpCodes.Ldfld, li.FieldBuilder);
-                       } else {
-                               ig.Emit (OpCodes.Ldloc, li.LocalBuilder);
-                       }
+                       Variable.EmitInstance (ec);
+                       Variable.Emit (ec);
                }
                
                public void EmitLoadAddress (EmitContext ec)
                {
-                       ILGenerator ig = ec.ig;
-                       
-                       if (li.FieldBuilder != null) {
-                               ig.Emit (OpCodes.Ldarg_0);
-                               ig.Emit (OpCodes.Ldflda, li.FieldBuilder);
-                       } else {
-                               ig.Emit (OpCodes.Ldloca, li.LocalBuilder);
-                       }
+                       Variable.EmitInstance (ec);
+                       Variable.EmitAddressOf (ec);
                }
                
                public void Store (EmitContext ec, Expression right_side)
                {
-                       if (li.FieldBuilder != null)
-                               ec.ig.Emit (OpCodes.Ldarg_0);
-                       
+                       Variable.EmitInstance (ec);
                        right_side.Emit (ec);
-                       if (li.FieldBuilder != null) {
-                               ec.ig.Emit (OpCodes.Stfld, li.FieldBuilder);
-                       } else {
-                               ec.ig.Emit (OpCodes.Stloc, li.LocalBuilder);
-                       }
+                       Variable.EmitAssign (ec);
                }
                
                public void EmitThis (EmitContext ec)
                {
-                       if (li.FieldBuilder != null) {
-                               ec.ig.Emit (OpCodes.Ldarg_0);
-                       }
+                       Variable.EmitInstance (ec);
                }
                
-               public void EmitStore (ILGenerator ig)
+               public void EmitStore (EmitContext ec)
                {
-                       if (li.FieldBuilder != null)
-                               ig.Emit (OpCodes.Stfld, li.FieldBuilder);
-                       else
-                               ig.Emit (OpCodes.Stloc, li.LocalBuilder);
+                       Variable.EmitAssign (ec);
                }
                
                public void AddressOf (EmitContext ec, AddressOp mode)

Modified: branches/martin/anonymous-methods/mcs/parameter.cs
===================================================================
--- branches/martin/anonymous-methods/mcs/parameter.cs  2006-09-27 09:53:20 UTC 
(rev 65953)
+++ branches/martin/anonymous-methods/mcs/parameter.cs  2006-09-27 10:11:33 UTC 
(rev 65954)
@@ -208,11 +208,17 @@
                public Expression TypeName;
                public readonly Modifier ModFlags;
                public string Name;
+               public bool IsCaptured;
                protected Type parameter_type;
                public readonly Location Location;
 
                IResolveContext resolve_context;
 
+               Variable var;
+               public Variable Variable {
+                       get { return var; }
+               }
+
 #if GMCS_SOURCE
                GenericConstraints constraints;
 #endif
@@ -340,6 +346,14 @@
                        return true;
                }
 
+               public void ResolveVariable (ToplevelBlock toplevel, int idx)
+               {
+                       if (toplevel.AnonymousMethodHost != null)
+                               var = 
toplevel.AnonymousMethodHost.GetCapturedParameter (this);
+                       if (var == null)
+                               var = new ParameterVariable (this, idx);
+               }
+
                public Type ExternalType ()
                {
                        if ((ModFlags & Parameter.Modifier.ISBYREF) != 0)
@@ -460,6 +474,78 @@
                                return attribute_targets;
                        }
                }
+
+               protected class ParameterVariable : Variable
+               {
+                       public readonly Parameter Parameter;
+                       public readonly int Idx;
+                       public readonly bool IsRef;
+
+                       public ParameterVariable (Parameter par, int idx)
+                       {
+                               this.Parameter = par;
+                               this.Idx = idx;
+                               this.IsRef = (par.ModFlags & 
Parameter.Modifier.ISBYREF) != 0;
+                       }
+
+                       public override Type Type {
+                               get { return Parameter.ParameterType; }
+                       }
+
+                       public override bool HasInstance {
+                               get { return false; }
+                       }
+
+                       public override bool NeedsTemporary {
+                               get { return false; }
+                       }
+
+                       public override void EmitInstance (EmitContext ec)
+                       {
+                       }
+
+                       public override void Emit (EmitContext ec)
+                       {
+                               int arg_idx = Idx;
+                               if (!ec.MethodIsStatic)
+                                       arg_idx++;
+
+                               ParameterReference.EmitLdArg (ec.ig, arg_idx);
+                       }
+
+                       public override void EmitAssign (EmitContext ec)
+                       {
+                               int arg_idx = Idx;
+                               if (!ec.MethodIsStatic)
+                                       arg_idx++;
+
+                               if (arg_idx <= 255)
+                                       ec.ig.Emit (OpCodes.Starg_S, (byte) 
arg_idx);
+                               else
+                                       ec.ig.Emit (OpCodes.Starg, arg_idx);
+                       }
+
+                       public override void EmitAddressOf (EmitContext ec)
+                       {
+                               int arg_idx = Idx;
+
+                               if (!ec.MethodIsStatic)
+                                       arg_idx++;
+
+                               if (IsRef) {
+                                       if (arg_idx <= 255)
+                                               ec.ig.Emit (OpCodes.Ldarg_S, 
(byte) arg_idx);
+                                       else
+                                               ec.ig.Emit (OpCodes.Ldarg, 
arg_idx);
+                               } else {
+                                       if (arg_idx <= 255)
+                                               ec.ig.Emit (OpCodes.Ldarga_S, 
(byte) arg_idx);
+                                       else
+                                               ec.ig.Emit (OpCodes.Ldarga, 
arg_idx);
+                               }
+                       }
+               }
+
        }
 
        /// <summary>
@@ -617,6 +703,14 @@
                        return ok;
                }
 
+               public void ResolveVariable (ToplevelBlock toplevel)
+               {
+                       for (int i = 0; i < FixedParameters.Length; ++i) {
+                               Parameter p = FixedParameters [i];
+                               p.ResolveVariable (toplevel, i);
+                       }
+               }
+
                public CallingConventions CallingConvention
                {
                        get {
@@ -675,7 +769,7 @@
                        }
                }
 
-               Parameter this [int pos]
+               public Parameter this [int pos]
                {
                        get {
                                if (pos >= count && (HasArglist || HasParams)) {

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

Reply via email to