Hashtable locals = new Hashtable ();
Hashtable captured_scopes = new Hashtable ();
+ Hashtable captured_params;
protected CapturedScope[] CapturedScopes {
get {
return (Variable) locals [local];
}
+ public bool HostsParameters {
+ get { return captured_params != null; }
+ }
+
+ public Variable GetCapturedParameter (Parameter par)
+ {
+ if (captured_params != null)
+ return (Variable) captured_params [par];
+ else
+ return null;
+ }
+
+ public bool IsParameterCaptured (string name)
+ {
+ if (captured_params != null)
+ return captured_params [name] != null;
+ return false;
+ }
+
+ public Variable AddParameter (Parameter par, int idx)
+ {
+ if (captured_params == null)
+ captured_params = new Hashtable ();
+
+ Variable var = (Variable) captured_params [par];
+ if (var == null) {
+ var = new CapturedParameter (this, par, idx);
+ captured_params.Add (par, var);
+ par.IsCaptured = true;
+ }
+
+ return var;
+ }
+
protected string MakeFieldName (string local_name)
{
return "<" + ID + ":" + local_name + ">";
local.FieldInstance = fe;
}
+ if (Scope.HostsParameters) {
+ foreach (CapturedParameter cp in Scope.captured_params.Values) {
+ FieldExpr fe = (FieldExpr) Expression.MemberLookup (
+ ec.ContainerType, type, cp.Field.Name, loc);
+ if (fe == null)
+ throw new InternalErrorException ();
+
+ fe.InstanceExpression = this;
+ cp.FieldInstance = fe;
+ }
+ }
+
foreach (CapturedScope scope in Scope.CapturedScopes) {
FieldExpr fe = (FieldExpr) Expression.MemberLookup (
ec.ContainerType, type, scope.Field.Name, loc);
protected virtual void EmitParameterReference (EmitContext ec,
CapturedParameter cp)
{
- int extra = ec.IsStatic ? 0 : 1;
+ int extra = ec.MethodIsStatic ? 0 : 1;
ParameterReference.EmitLdArg (ec.ig, cp.Idx + extra);
}
else
captured_scope.EmitAssign (ec);
+ if (Scope.HostsParameters) {
+ foreach (CapturedParameter cp in Scope.captured_params.Values) {
+ Report.Debug (128, "EMIT SCOPE INIT #6", this,
+ ec, ec.IsStatic, Scope, cp, cp.Field.Name);
+ DoEmitInstance (ec);
+ EmitParameterReference (ec, cp);
+ ec.ig.Emit (OpCodes.Stfld, cp.FieldInstance.FieldInfo);
+ }
+ }
+
if (Scope.RootScope.IsIterator)
return;
TypeExpr parent_type;
CapturedVariableField parent_link;
CapturedThis this_variable;
- Hashtable captured_params;
protected ArrayList scopes;
public virtual bool IsIterator {
get { return this_variable; }
}
- public bool HostsParameters {
- get { return captured_params != null; }
- }
-
public Variable CaptureThis ()
{
if (ParentHost != null)
return this_variable;
}
- public Variable GetCapturedParameter (Parameter par)
- {
- if (captured_params != null)
- return (Variable) captured_params [par];
- else
- return null;
- }
-
- public bool IsParameterCaptured (string name)
- {
- if (captured_params != null)
- return captured_params [name] != null;
- return false;
- }
-
- public Variable AddParameter (Parameter par, int idx)
- {
- if (captured_params == null)
- captured_params = new Hashtable ();
-
- Variable var = (Variable) captured_params [par];
- if (var == null) {
- var = new CapturedParameter (this, par, idx);
- captured_params.Add (par, var);
- par.IsCaptured = true;
- }
-
- return var;
- }
-
public void AddScope (ScopeInfo scope)
{
scopes.Add (scope);
pfield.MemberType, "parent", Parameter.Modifier.NONE,
null, Location));
+#if FIXME
if (HostsParameters) {
foreach (CapturedParameter cp in captured_params.Values) {
args.Add (new Parameter (
Parameter.Modifier.NONE, null, Location));
}
}
+#endif
Parameter[] ctor_params = new Parameter [args.Count];
args.CopyTo (ctor_params, 0);
pos++;
}
+#if FIXME
if (HostsParameters) {
foreach (CapturedParameter cp in captured_params.Values) {
ec.ig.Emit (OpCodes.Ldarg_0);
ec.ig.Emit (OpCodes.Stfld, cp.Field.FieldBuilder);
}
}
+#endif
}
protected class TheCtor : Statement
Host.THIS.FieldInstance = fe;
}
+#if FIXME
//
// Copy the parameter values, if any
//
cp.FieldInstance = fe;
}
}
+#endif
return base.DoResolveInternal (ec);
}
} else if (host.ParentLink != null)
ec.ig.Emit (OpCodes.Ldarg_0);
+#if FIXME
if (Host.HostsParameters) {
foreach (CapturedParameter cp in Host.captured_params.Values) {
EmitParameterReference (ec, cp);
}
}
+#endif
base.EmitScopeConstructor (ec);
}
protected class AnonymousMethodMethod : Method
{
- public AnonymousContainer AnonymousMethod;
+ public readonly AnonymousContainer AnonymousMethod;
+ public readonly ScopeInfo Scope;
public AnonymousMethodMethod (AnonymousContainer am, ScopeInfo scope,
GenericMethod generic, TypeExpr return_type,
generic, return_type, mod, false, name, parameters, null)
{
this.AnonymousMethod = am;
+ this.Scope = scope;
if (scope != null) {
scope.CheckMembersDefined ();
{
EmitContext aec = AnonymousMethod.aec;
aec.ig = ig;
+ aec.MethodIsStatic = Scope == null;
return aec;
}
}
member_name = new MemberName (name, args, Location);
+ Report.Debug (128, "CREATE METHOD HOST #5", this, DelegateType,
+ TypeManager.GetTypeArguments (DelegateType),
+ dt, tparam, args);
+
generic_method = new GenericMethod (
Host.NamespaceEntry, scope, member_name,
new TypeExpression (ReturnType, Location), Parameters);