void EmitHoistedFieldsInitialization (ResolveContext rc, EmitContext ec)
{
//
// Initialize all storey reference fields by using local or hoisted variables
//
if (used_parent_storeys != null) {
foreach (StoreyFieldPair sf in used_parent_storeys) {
//
// Get instance expression of storey field
//
Expression instace_expr = GetStoreyInstanceExpression (ec);
var fs = sf.Field.Spec;
if (TypeManager.IsGenericType (instace_expr.Type))
fs = MemberCache.GetMember (instace_expr.Type, fs);
FieldExpr f_set_expr = new FieldExpr (fs, Location);
f_set_expr.InstanceExpression = instace_expr;
SimpleAssign a = new SimpleAssign (f_set_expr, sf.Storey.GetStoreyInstanceExpression (ec));
if (a.Resolve (rc) != null)
a.EmitStatement (ec);
}
}
//
// Define hoisted `this' in top-level storey only
//
if (OriginalSourceBlock.Explicit.HasCapturedThis && !(Parent is AnonymousMethodStorey)) {
AddCapturedThisField (ec);
rc.CurrentBlock.AddScopeStatement (new ThisInitializer (hoisted_this));
}
//
// Setting currect anonymous method to null blocks any further variable hoisting
//
AnonymousExpression ae = ec.CurrentAnonymousMethod;
ec.CurrentAnonymousMethod = null;
if (hoisted_params != null) {
EmitHoistedParameters (ec, hoisted_params);
}
ec.CurrentAnonymousMethod = ae;
}