From 1b3d113f2ca8f7bc9dbef58d9e3ab023f761462f Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Tue, 22 Mar 2005 09:59:34 +0000 Subject: [PATCH] **** Merged r40457-r40460 from MCS **** svn path=/trunk/mcs/; revision=42076 --- mcs/gmcs/ChangeLog | 22 ++++++++++++++++++++++ mcs/gmcs/anonymous.cs | 21 +++++++++++++++------ mcs/gmcs/codegen.cs | 11 ++++++++--- mcs/gmcs/expression.cs | 3 +++ 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/mcs/gmcs/ChangeLog b/mcs/gmcs/ChangeLog index 2c0ac101645..e2305345a63 100644 --- a/mcs/gmcs/ChangeLog +++ b/mcs/gmcs/ChangeLog @@ -1,3 +1,25 @@ +2005-02-11 Miguel de Icaza + + * anonymous.cs (CaptureContext): Track whether `this' has been + referenced. + + * expression.cs (This.ResolveBase): Call CaptureThis. Before we + only captured `this' if it was implicitly done (instance + methods/variables were used). + + * codegen.cs (EmitContext.CaptureThis): New method to flag that + `this' must be captured. + +2005-01-30 Miguel de Icaza + + * anonymous.cs (CreateMethodHost): If there Scope.ScopeTypeBuilder + is null it means that there has been no need to capture anything, + so we just create a sibling. + + Renamed `EmitHelperClasses' to `EmitAnonymousHelperClasses' + + Just a partial fix. The other half is fairly elusive. + 2005-02-10 Raja R Harinath Fix #52586, cs0121-4.cs. diff --git a/mcs/gmcs/anonymous.cs b/mcs/gmcs/anonymous.cs index d77e6d1b792..206b1a96532 100644 --- a/mcs/gmcs/anonymous.cs +++ b/mcs/gmcs/anonymous.cs @@ -113,7 +113,8 @@ namespace Mono.CSharp { // TypeBuilder current_type = ec.TypeContainer.TypeBuilder; - TypeBuilder type_host = Scope == null ? current_type : Scope.ScopeTypeBuilder; + TypeBuilder type_host = (Scope == null ) // || Scope.ScopeTypeBuilder == null) + ? current_type : Scope.ScopeTypeBuilder; if (current_type == null) throw new Exception ("The current_type is null"); @@ -657,7 +658,7 @@ namespace Mono.CSharp { public class CaptureContext { public static int count; public int cc_id; - Location loc; + public Location loc; // // Points to the toplevel block that owns this CaptureContext @@ -665,6 +666,7 @@ namespace Mono.CSharp { ToplevelBlock toplevel_owner; Hashtable scopes = new Hashtable (); bool have_captured_vars = false; + bool referenced_this = false; ScopeInfo topmost = null; // @@ -909,7 +911,14 @@ namespace Mono.CSharp { else captured_fields [fe] = fe; } - + + public void CaptureThis () + { + CaptureContext parent = ParentCaptureContext; + if (parent != null) + parent.CaptureThis (); + referenced_this = true; + } public bool HaveCapturedVariables { get { @@ -948,15 +957,15 @@ namespace Mono.CSharp { return false; } - public void EmitHelperClasses (EmitContext ec) + public void EmitAnonymousHelperClasses (EmitContext ec) { if (topmost != null){ - topmost.NeedThis = HaveCapturedFields; + topmost.NeedThis = HaveCapturedFields || referenced_this; topmost.EmitScopeType (ec); } } - public void CloseHelperClasses () + public void CloseAnonymousHelperClasses () { if (topmost != null) topmost.CloseTypes (); diff --git a/mcs/gmcs/codegen.cs b/mcs/gmcs/codegen.cs index 7f5d62efb21..31d401efd1a 100644 --- a/mcs/gmcs/codegen.cs +++ b/mcs/gmcs/codegen.cs @@ -560,9 +560,14 @@ namespace Mono.CSharp { public void CaptureParameter (string name, Type t, int idx) { - capture_context.AddParameter (this, CurrentAnonymousMethod, name, t, idx); } + + public void CaptureThis () + { + capture_context.CaptureThis (); + } + // // Use to register a field as captured @@ -624,7 +629,7 @@ namespace Mono.CSharp { public void EmitMeta (ToplevelBlock b, InternalParameters ip) { if (capture_context != null) - capture_context.EmitHelperClasses (this); + capture_context.EmitAnonymousHelperClasses (this); b.EmitMeta (this); if (HasReturnLabel) @@ -768,7 +773,7 @@ namespace Mono.CSharp { // Close pending helper classes if we are the toplevel // if (capture_context != null && capture_context.ParentToplevel == null) - capture_context.CloseHelperClasses (); + capture_context.CloseAnonymousHelperClasses (); } /// diff --git a/mcs/gmcs/expression.cs b/mcs/gmcs/expression.cs index 147daa50980..9a5c6b81700 100644 --- a/mcs/gmcs/expression.cs +++ b/mcs/gmcs/expression.cs @@ -6895,6 +6895,9 @@ namespace Mono.CSharp { if ((block != null) && (block.ThisVariable != null)) variable_info = block.ThisVariable.VariableInfo; + if (ec.CurrentAnonymousMethod != null) + ec.CaptureThis (); + return true; } -- 2.25.1