2006-12-30 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / iterators.cs
index 5b603b56c43c7fe4222c518284511f629319ed67..8720298fca897c6039fcf59d0f5efe8f9fc2ec46 100644 (file)
@@ -124,7 +124,7 @@ namespace Mono.CSharp {
                }
        }
 
-       public class IteratorHost : AnonymousMethodHost
+       public class IteratorHost : RootScopeInfo
        {
                public readonly Iterator Iterator;
 
@@ -229,6 +229,27 @@ namespace Mono.CSharp {
                        return base.DoResolveMembers ();
                }
 
+               public void CaptureScopes ()
+               {
+                       Report.Debug (128, "DEFINE ITERATOR HOST", this, scopes);
+
+                       foreach (ScopeInfo si in scopes)
+                               CaptureScope (si);
+
+                       foreach (ScopeInfo si in scopes) {
+                               if (!si.Define ())
+                                       throw new InternalErrorException ();
+                               if (si.DefineType () == null)
+                                       throw new InternalErrorException ();
+                               if (!si.ResolveType ())
+                                       throw new InternalErrorException ();
+                               if (!si.ResolveMembers ())
+                                       throw new InternalErrorException ();
+                               if (!si.DefineMembers ())
+                                       throw new InternalErrorException ();
+                       }
+               }
+
                protected override bool DoDefineMembers ()
                {
                        if (!base.DoDefineMembers ())
@@ -311,12 +332,8 @@ namespace Mono.CSharp {
 
                ConstructorInfo GetInvalidOperationException ()
                {
-                       MethodGroupExpr mg = (MethodGroupExpr) Expression.MemberLookup (
-                               TypeBuilder, TypeManager.invalid_operation_exception_type,
-                               ".ctor", Location);
-                       if (mg == null)
-                               throw new InternalErrorException ();
-                       return (ConstructorInfo) mg.Methods [0];
+                       return TypeManager.GetConstructor (
+                               TypeManager.invalid_operation_exception_type, Type.EmptyTypes);
                }
 
                protected override ScopeInitializer CreateScopeInitializer ()
@@ -324,7 +341,7 @@ namespace Mono.CSharp {
                        return new IteratorHostInitializer (this);
                }
 
-               protected class IteratorHostInitializer : AnonymousMethodHostInitializer
+               protected class IteratorHostInitializer : RootScopeInitializer
                {
                        new public readonly IteratorHost Host;
                        protected Iterator.State state;
@@ -785,14 +802,18 @@ namespace Mono.CSharp {
                        get { return true; }
                }
 
-               public override AnonymousMethodHost RootScope {
+               public override RootScopeInfo RootScope {
+                       get { return IteratorHost; }
+               }
+
+               public override ScopeInfo Scope {
                        get { return IteratorHost; }
                }
 
                //
                // Our constructor
                //
-               public Iterator (IMethodData m_container, TypeContainer host, GenericMethod generic,
+               private Iterator (IMethodData m_container, DeclSpace host, GenericMethod generic,
                                 int modifiers, Type iterator_type, bool is_enumerable)
                        : base (null, host, generic, m_container.ParameterInfo,
                                new ToplevelBlock (m_container.ParameterInfo, m_container.Location),
@@ -877,6 +898,8 @@ namespace Mono.CSharp {
                        Report.Debug (64, "RESOLVE ITERATOR #1", this, method, method.Parent,
                                      RootScope, ec);
 
+                       if (!RootScope.ResolveType ())
+                               return false;
                        if (!RootScope.ResolveMembers ())
                                return false;
                        if (!RootScope.DefineMembers ())
@@ -892,8 +915,12 @@ namespace Mono.CSharp {
 
                protected override Method DoCreateMethodHost (EmitContext ec)
                {
+                       Report.Debug (128, "CREATE METHOD HOST", this, IteratorHost);
+
+                       IteratorHost.CaptureScopes ();
+
                        return new AnonymousMethodMethod (
-                               this, null, TypeManager.system_boolean_expr,
+                               this, RootScope, null, TypeManager.system_boolean_expr,
                                Modifiers.PUBLIC, new MemberName ("MoveNext", Location),
                                Parameters.EmptyReadOnlyParameters);
                }
@@ -953,7 +980,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               public static Iterator CreateIterator (IMethodData method, TypeContainer parent,
+               public static Iterator CreateIterator (IMethodData method, DeclSpace parent,
                                                       GenericMethod generic, int modifiers)
                {
                        bool is_enumerable;