In mcs:
[mono.git] / mcs / mcs / anonymous.cs
index 823352de1e2dd31bd2159f2285f9c19a868805e0..7aead944f6c58c8c825f81972ce96f4985184b3e 100644 (file)
@@ -77,22 +77,18 @@ namespace Mono.CSharp {
                        //
                        // The order is important: this setups the CaptureContext tree hierarchy.
                        //
+                       if (container == null) {
+                               Report.Error (1706, l, "Anonymous methods are not allowed in attribute declaration");
+                               return;
+                       }
                        container.SetHaveAnonymousMethods (l, this);
                        block.SetHaveAnonymousMethods (l, this);
                }
 
                protected AnonymousContainer (Parameters parameters, ToplevelBlock container,
-                                             Location l)
+                                             Location l):
+                       this (parameters, container, new ToplevelBlock (container, parameters, l), l)
                {
-                       Parameters = parameters;
-                       Block = new ToplevelBlock (container, Parameters, l);
-                       loc = l;
-
-                       //
-                       // The order is important: this setups the CaptureContext tree hierarchy.
-                       //
-                       container.SetHaveAnonymousMethods (loc, this);
-                       Block.SetHaveAnonymousMethods (loc, this);
                }
 
                public override Expression DoResolve (EmitContext ec)
@@ -319,6 +315,12 @@ namespace Mono.CSharp {
                        return null;
                }
 
+               public override string ExprClassName {
+                       get {
+                               return "anonymous method";
+                       }
+               }
+
                public MethodBuilder GetMethodBuilder ()
                {
                        return method.MethodData.MethodBuilder;
@@ -555,7 +557,7 @@ namespace Mono.CSharp {
                        Console.WriteLine ("NeedThis=" + NeedThis);
                        foreach (LocalInfo li in locals){
                                Pad ();
-                               Console.WriteLine ("var {0}", li.Name);
+                               Console.WriteLine ("var {0}", MakeFieldName (li.Name));
                        }
                        
                        foreach (ScopeInfo si in children)
@@ -570,6 +572,11 @@ namespace Mono.CSharp {
                        return String.Format ("<>AnonHelp<{0}>", id);
                }
 
+               private string MakeFieldName (string local_name)
+               {
+                       return "<" + id + ":" + local_name + ">";
+               }
+
                public void EmitScopeType (EmitContext ec)
                {
                        // EmitDebug ();
@@ -599,7 +606,7 @@ namespace Mono.CSharp {
 
                        foreach (LocalInfo info in locals)
                                info.FieldBuilder = ScopeTypeBuilder.DefineField (
-                                       info.Name, info.VariableType, FieldAttributes.Assembly);
+                                       MakeFieldName (info.Name), info.VariableType, FieldAttributes.Assembly);
 
                        if (HostsParameters){
                                Hashtable captured_parameters = CaptureContext.captured_parameters;
@@ -1022,24 +1029,12 @@ namespace Mono.CSharp {
                        AdjustMethodScope (am, topmost);
                }
 
-               public void CaptureThis (AnonymousContainer am)
+               public void CaptureThis ()
                {
                        CaptureContext parent = ParentCaptureContext;
-                       if (parent != null) {
-                               parent.CaptureThis (am);
-                               return;
-                       }
+                       if (parent != null)
+                               parent.CaptureThis ();
                        referenced_this = true;
-
-                       if (topmost == null){
-                               //
-                               // Create one ScopeInfo, if there are none.
-                               //
-                               topmost = new ScopeInfo (this, toplevel_owner);
-                               scopes [toplevel_owner.ID] = topmost;
-                       }
-                       
-                       AdjustMethodScope (am, topmost);
                }
 
                public bool HaveCapturedVariables {