**** Merged r40732-r40872 from MCS ****
[mono.git] / mcs / gmcs / iterators.cs
index 529d67351ac2a68e2ace96224a8fd50987bdee81..56bb333c94bec63521c23aa16b249520298a98c2 100644 (file)
@@ -8,7 +8,7 @@
 //
 // TODO:
 //    Flow analysis for Yield.
-//    Emit calls to parent object constructor.
+//    Emit calls to base object constructor.
 //
 // Generics note:
 //    Current should be defined to return T, and IEnumerator.Current returns object
@@ -139,6 +139,8 @@ namespace Mono.CSharp {
                Type [] param_types;
                InternalParameters parameters;
 
+               MethodInfo dispose_method;
+
                Expression enumerator_type;
                Expression enumerable_type;
                Expression generic_enumerator_type;
@@ -207,7 +209,7 @@ namespace Mono.CSharp {
                        ig.BeginFaultBlock ();
 
                        ig.Emit (OpCodes.Ldarg_0);
-                       ig.Emit (OpCodes.Callvirt, dispose.MethodBuilder);
+                       ig.Emit (OpCodes.Callvirt, dispose_method);
 
                        ig.EndExceptionBlock ();
 
@@ -399,7 +401,7 @@ namespace Mono.CSharp {
                        }
 
                        if (container.CurrentType != null)
-                               this_type = container.CurrentType.ResolveType (ec);
+                               this_type = container.CurrentType;
                        else
                                this_type = container.TypeBuilder;
 
@@ -437,13 +439,40 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               MethodInfo FetchMethodDispose ()
+               {
+                       MemberList dispose_list;
+
+                       dispose_list = FindMembers (
+                               current_type.Type,
+                               MemberTypes.Method, BindingFlags.Public | BindingFlags.Instance,
+                               Type.FilterName, "Dispose");
+
+                       if (dispose_list.Count != 1)
+                               throw new InternalErrorException ("Cannot find Dipose() method.");
+
+                       return (MethodInfo) dispose_list [0];
+               }
+
+               protected override bool DoDefineMembers ()
+               {
+                       if (!base.DoDefineMembers ())
+                               return false;
+
+                       dispose_method = FetchMethodDispose ();
+                       if (dispose_method == null)
+                               return false;
+
+                       return true;
+               }
+
                //
                // Returns the new block for the method, or null on failure
                //
                protected override bool DefineNestedTypes ()
                {
                        if (CurrentType != null)
-                               current_type = CurrentType;
+                               current_type = new TypeExpression (CurrentType, Location);
                        else
                                current_type = new TypeExpression (TypeBuilder, Location);
 
@@ -775,6 +804,11 @@ namespace Mono.CSharp {
                                this.field = field;
                        }
 
+                       public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
+                       {
+                               return DoResolve (ec);
+                       }
+
                        public override Expression DoResolve (EmitContext ec)
                        {
                                FieldExpr fexpr = new FieldExpr (field.FieldBuilder, loc);