//
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");
throw new Exception ("Type host is null");
if (current_type == type_host && ec.IsStatic){
- if (ec.IsStatic)
+ if (ec.IsStatic){
method_modifiers |= Modifiers.STATIC;
+ }
current_type = null;
}
method_modifiers, false, new MemberName ("<#AnonymousMethod>" + anonymous_method_count++),
Parameters, null, loc);
method.Block = Block;
-
//
// Swap the TypeBuilder while we define the method, then restore
//
invoke_mb = (MethodInfo) Delegate.GetInvokeMethod (ec, delegate_type, loc);
- ParameterData invoke_pd = Invocation.GetParameterData (invoke_mb);
+ ParameterData invoke_pd = TypeManager.GetParameterData (invoke_mb);
//
// If implicit parameters are set, then we must check for out in the parameters
ec.TypeContainer, ec.DeclSpace, loc, null,
invoke_mb.ReturnType,
/* REVIEW */ (ec.InIterator ? Modifiers.METHOD_YIELDS : 0) |
- (ec.InUnsafe ? Modifiers.UNSAFE : 0),
+ (ec.InUnsafe ? Modifiers.UNSAFE : 0) |
+ (ec.IsStatic ? Modifiers.STATIC : 0),
/* No constructor */ false);
aec.CurrentAnonymousMethod = this;
ContainerAnonymousMethod = ec.CurrentAnonymousMethod;
ContainingBlock = ec.CurrentBlock;
-
+
if (aec.ResolveTopBlock (ec, Block, amp, loc, out unreachable))
return new AnonymousDelegate (this, delegate_type, loc).Resolve (ec);
// Adjust based on the computed state of the
// method from CreateMethodHost
- if ((method_modifiers & Modifiers.STATIC) != 0)
- aec.IsStatic = true;
+ aec.MethodIsStatic = (method_modifiers & Modifiers.STATIC) != 0;
aec.EmitMeta (Block, amp);
aec.EmitResolvedTopBlock (Block, unreachable);
if (ScopeTypeBuilder != null)
return;
- ILGenerator ig = ec.ig;
TypeBuilder container = ec.TypeContainer.TypeBuilder;
ScopeTypeBuilder = container.DefineNestedType (
public void CloseTypes ()
{
- RootContext.RegisterHelperClass (ScopeTypeBuilder);
+ RootContext.RegisterCompilerGeneratedType (ScopeTypeBuilder);
foreach (ScopeInfo si in children)
si.CloseTypes ();
}
Hashtable captured_parameters = CaptureContext.captured_parameters;
foreach (DictionaryEntry de in captured_parameters){
- string name = (string) de.Key;
CapturedParameter cp = (CapturedParameter) de.Value;
ig.Emit (OpCodes.Ldloc, ScopeInstance);
}
if (ParentScope != null){
+ if (!ParentScope.inited)
+ ParentScope.EmitInitScope (ec);
+
//
// Only emit initialization in our capturecontext world
//
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
ToplevelBlock toplevel_owner;
Hashtable scopes = new Hashtable ();
bool have_captured_vars = false;
+ bool referenced_this = false;
ScopeInfo topmost = null;
//
public override string ToString ()
{
- ToplevelBlock parent = ParentToplevel;
StringBuilder sb = new StringBuilder ();
-
sb.Append ("[");
DoPath (sb, this);
sb.Append ("]");
else
captured_fields [fe] = fe;
}
-
+
+ public void CaptureThis ()
+ {
+ CaptureContext parent = ParentCaptureContext;
+ if (parent != null)
+ parent.CaptureThis ();
+ referenced_this = true;
+ }
public bool HaveCapturedVariables {
get {
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 ();
cc.EmitParameterInstance (ec, name);
return;
}
- Block invocation_block = ec.CurrentBlock;
+
CapturedParameter par_info = (CapturedParameter) captured_parameters [name];
+ if (par_info != null){
+ //
+ // FIXME: implementing this.
+ //
+ }
ILGenerator ig = ec.ig;
ScopeInfo si;
}
EmitParameterInstance (ec, name);
CapturedParameter par_info = (CapturedParameter) captured_parameters [name];
+ if (par_info != null){
+ //
+ // FIXME: implementing this.
+ //
+ }
ec.ig.Emit (OpCodes.Ldfld, par_info.FieldBuilder);
}