+ public AnonymousMethodStorey AnonymousMethodStorey {
+ get { return am_storey; }
+ }
+
+ //
+ // Creates anonymous method storey in current block
+ //
+ public AnonymousMethodStorey CreateAnonymousMethodStorey (EmitContext ec)
+ {
+ //
+ // When referencing a variable in iterator storey from children anonymous method
+ //
+ if (Toplevel.am_storey is IteratorStorey) {
+ ec.CurrentAnonymousMethod.AddStoreyReference (Toplevel.am_storey);
+ return Toplevel.am_storey;
+ }
+
+ //
+ // An iterator has only 1 storey block
+ //
+ if (ec.CurrentIterator != null)
+ return ec.CurrentIterator.Storey;
+
+ if (am_storey == null) {
+ MemberBase mc = ec.ResolveContext as MemberBase;
+ GenericMethod gm = mc == null ? null : mc.GenericMethod;
+
+ //
+ // Create anonymous method storey for this block
+ //
+ am_storey = new AnonymousMethodStorey (this, ec.TypeContainer, mc, gm, "AnonStorey");
+ }
+
+ //
+ // Creates a link between this block and the anonymous method
+ //
+ // An anonymous method can reference variables from any outer block, but they are
+ // hoisted in their own ExplicitBlock. When more than one block is referenced we
+ // need to create another link between those variable storeys
+ //
+ ec.CurrentAnonymousMethod.AddStoreyReference (am_storey);
+ return am_storey;
+ }
+
+ public override void Emit (EmitContext ec)
+ {
+ if (am_storey != null)
+ am_storey.EmitHoistedVariables (ec);
+
+ bool emit_debug_info = SymbolWriter.HasSymbolWriter;
+ bool is_lexical_block = Parent != null && !(am_storey is IteratorStorey);
+ if (emit_debug_info && is_lexical_block)
+ ec.BeginScope ();
+
+ base.Emit (ec);
+
+ if (emit_debug_info) {
+ EmitSymbolInfo (ec);
+ if (is_lexical_block)
+ ec.EndScope ();
+ }
+ }
+
+ public override void EmitMeta (EmitContext ec)
+ {
+ base.EmitMeta (ec);
+
+ //
+ // It has to be done when all storey references are resolved
+ //
+ if (am_storey != null && am_storey.HasHoistedVariables)
+ am_storey.DefineMembers ();
+ }
+
+ protected override void EmitSymbolInfo (EmitContext ec)
+ {
+ if (am_storey != null)
+ SymbolWriter.DefineScopeVariable (am_storey.ID);
+
+ base.EmitSymbolInfo (ec);
+ }
+