svn path=/branches/martin/anonymous-methods2/mcs/; revision=68387
authorMartin Baulig <martin@novell.com>
Thu, 23 Nov 2006 13:49:14 +0000 (13:49 -0000)
committerMartin Baulig <martin@novell.com>
Thu, 23 Nov 2006 13:49:14 +0000 (13:49 -0000)
mcs/mcs/anonymous.cs
mcs/mcs/codegen.cs
mcs/mcs/statement.cs

index b856e5bd6db22f8c26bc8ce80ecd3f6f8440d46a..695c95a85ca5b67b5ec96e3d18a596677a34da92 100644 (file)
@@ -311,6 +311,19 @@ namespace Mono.CSharp {
                        }
                }
 
+               protected override bool DoDefineMembers ()
+               {
+                       Report.Debug (64, "SCOPE INFO DEFINE MEMBERS", this, GetType (), IsGeneric,
+                                     Parent.IsGeneric, GenericMethod);
+
+                       foreach (CapturedScope child in scopes.Values) {
+                               if (!child.DefineMembers ())
+                                       return false;
+                       }
+
+                       return base.DoDefineMembers ();
+               }
+
                protected override bool DoResolveMembers ()
                {
                        Report.Debug (64, "SCOPE INFO RESOLVE MEMBERS", this, GetType (), IsGeneric,
@@ -361,17 +374,28 @@ namespace Mono.CSharp {
                protected abstract class CapturedVariable : Variable
                {
                        public readonly ScopeInfo Scope;
-                       public readonly Field Field;
+                       public readonly string Name;
 
                        public FieldExpr FieldInstance;
+                       protected Field field;
 
-                       protected CapturedVariable (ScopeInfo scope, string name, Type type)
+                       protected CapturedVariable (ScopeInfo scope, string name)
                        {
                                this.Scope = scope;
-                               this.Field = scope.CaptureVariable (
+                               this.Name = name;
+                       }
+
+                       protected CapturedVariable (ScopeInfo scope, string name, Type type)
+                               : this (scope, name)
+                       {
+                               this.field = scope.CaptureVariable (
                                        scope.MakeFieldName (name), scope.RootScope.InflateType (type));
                        }
 
+                       public Field Field {
+                               get { return field; }
+                       }
+
                        public override Type Type {
                                get { return Field.MemberType; }
                        }
@@ -457,11 +481,19 @@ namespace Mono.CSharp {
                        public readonly ScopeInfo ChildScope;
 
                        public CapturedScope (ScopeInfo root, ScopeInfo child)
-                               : base (root, "scope" + child.ID,
-                                       child.IsGeneric ? child.CurrentType : child.TypeBuilder)
+                               : base (root, "scope" + child.ID)
                        {
                                this.ChildScope = child;
                        }
+
+                       public bool DefineMembers ()
+                       {
+                               Type type = ChildScope.IsGeneric ?
+                                       ChildScope.CurrentType : ChildScope.TypeBuilder;
+                               field = Scope.CaptureVariable (
+                                       Scope.MakeFieldName (Name), Scope.InflateType (type));
+                               return true;
+                       }
                }
 
                static void DoPath (StringBuilder sb, ScopeInfo start)
@@ -727,6 +759,28 @@ namespace Mono.CSharp {
                        scopes.Add (scope);
                }
 
+               bool linked;
+               public void LinkScopes ()
+               {
+                       Report.Debug (128, "LINK SCOPES", this, linked, scopes);
+
+                       if (linked)
+                               return;
+
+                       linked = true;
+                       if (ParentHost != null)
+                               ParentHost.LinkScopes ();
+
+                       foreach (ScopeInfo si in scopes) {
+                               if (!si.Define ())
+                                       throw new InternalErrorException ();
+                               if (si.DefineType () == null)
+                                       throw new InternalErrorException ();
+                               if (!si.ResolveType ())
+                                       throw new InternalErrorException ();
+                       }
+               }
+
                protected override ScopeInitializer CreateScopeInitializer ()
                {
                        foreach (ScopeInfo si in scopes) {
@@ -1324,6 +1378,7 @@ namespace Mono.CSharp {
 
                        method = DoCreateMethodHost (ec);
 
+#if FIXME
                        if (Scope != null) {
                                if (!Scope.Define ())
                                        throw new InternalErrorException ();
@@ -1332,6 +1387,7 @@ namespace Mono.CSharp {
                                if (!Scope.ResolveType ())
                                        throw new InternalErrorException ();
                        }
+#endif
 
                        if (Scope != null)
                                return true;
@@ -1471,6 +1527,7 @@ namespace Mono.CSharp {
                        Report.Debug (128, "CREATE METHOD HOST #1", this, scope, scopes);
 
                        foreach (ScopeInfo si in scopes) {
+#if FIXME
                                Report.Debug (128, "CREATE METHOD HOST #2", this, scope, si);
                                if (!si.Define ())
                                        throw new InternalErrorException ();
@@ -1480,6 +1537,7 @@ namespace Mono.CSharp {
                                              si.TypeBuilder);
                                if (!si.ResolveCurrentType ())
                                        throw new InternalErrorException ();
+#endif
                                scope.CaptureScope (si);
                        }
 
index 5ebf22e0844c4b46509f4629e49665575b552b23..7f95441bc020d33c5cf7108c698c8babace64b7d 100644 (file)
@@ -718,6 +718,9 @@ namespace Mono.CSharp {
                                }
                        }
 
+                       if (!block.CompleteContexts (this))
+                               return false;
+
                        resolved = true;
                        return true;
                }
index 0e6eb81159b0d204ff61f9244ead201ab9127133..9c782893ec9bf668c0e6500342a8d90bc92175e7 100644 (file)
@@ -2300,6 +2300,31 @@ namespace Mono.CSharp {
                        get { return parameters; }
                }
 
+               public bool CompleteContexts (EmitContext ec)
+               {
+                       Report.Debug (64, "TOPLEVEL COMPLETE CONTEXTS", this,
+                                     container, root_scope);
+
+                       if (root_scope != null)
+                               root_scope.LinkScopes ();
+
+                       if ((container == null) && (root_scope != null)) {
+                               Report.Debug (64, "TOPLEVEL COMPLETE CONTEXTS #1", this,
+                                             root_scope);
+
+                               if (root_scope.DefineType () == null)
+                                       return false;
+                               if (!root_scope.ResolveType ())
+                                       return false;
+                               if (!root_scope.ResolveMembers ())
+                                       return false;
+                               if (!root_scope.DefineMembers ())
+                                       return false;
+                       }
+
+                       return true;
+               }
+
                public GenericMethod GenericMethod {
                        get { return generic; }
                }