//----------------------------------------------------------------------------------------------------------------------------------------------------- private void AddOrUpdateAnonymousMethod(IAnonymousMethodOperand anonymousMethod, AnonymousMethodScope scope) { AnonymousMethodScope existingScope; if (!m_AnonymousMethods.TryGetValue(anonymousMethod, out existingScope) || scope > existingScope) { m_AnonymousMethods[anonymousMethod] = scope; } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private void WriteAnonymousMethodThatHasNoClosure(IAnonymousMethodOperand anonymousMethod, AnonymousMethodScope scope) { anonymousMethod.CreateAnonymousMethod( OwnerMethod.OwnerClass, closure: null, isStatic: scope == AnonymousMethodScope.Static, isPublic: false); anonymousMethod.WriteCallSite(); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private void OnVisitAnonymousMethod(IAnonymousMethodOperand anonymousMethodOperand) { var isTopLevelAnonymousMethod = (m_CurrentAnonymousMethod == null); try { if (isTopLevelAnonymousMethod) { m_CurrentAnonymousMethod = anonymousMethodOperand; m_AnonymousMethods.Add(anonymousMethodOperand, AnonymousMethodScope.Static); } base.VisitStatementBlock(anonymousMethodOperand.Statements); } finally { if (isTopLevelAnonymousMethod) { m_CurrentAnonymousMethod = null; } } }
//------------------------------------------------------------------------------------------------------------------------------------------------- public OperandCapture(IScopedOperand sourceOperand, StatementBlock sourceOperandHome, IAnonymousMethodOperand consumerMethod) { this.SourceOperand = sourceOperand; this.SourceOperandHome = sourceOperandHome; m_Consumers = new HashSet <IAnonymousMethodOperand>() { consumerMethod }; }
//------------------------------------------------------------------------------------------------------------------------------------------------- public void AddConsumer(IAnonymousMethodOperand consumerMethod) { m_Consumers.Add(consumerMethod); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public AnonymousMethodIdentificationVisitor(MethodMember hostMethod) { m_HostMethod = hostMethod; m_CurrentAnonymousMethod = null; }
//----------------------------------------------------------------------------------------------------------------------------------------------------- //public void Merge(IAnonymousMethodIdentification other) //{ // if ( this.ClosuresOuterToInner != null ) // { // throw new InvalidOperationException("Cannot merge other identifications because current identification already has defined closures."); // } // if ( other.ClosuresOuterToInner != null ) // { // throw new ArgumentException("Cannot merge specified identification because it already has defined closures."); // } // m_MustCloseOverOperands.UnionWith(other.MustCloseOverOperands); // foreach ( var otherCapture in other.Captures ) // { // var existingCapture = m_Captures.FirstOrDefault(c => c.SourceOperand == otherCapture.SourceOperand); // if ( existingCapture != null ) // { // existingCapture.Merge(otherCapture); // } // else // { // m_Captures.Add(otherCapture); // } // } // foreach ( var anonymousMethod in other.AnonymousMethods ) // { // AddOrUpdateAnonymousMethod(anonymousMethod, other.GetAnonymousMethodScope(anonymousMethod)); // } //} //----------------------------------------------------------------------------------------------------------------------------------------------------- public AnonymousMethodScope GetAnonymousMethodScope(IAnonymousMethodOperand anonymousMethod) { return(m_AnonymousMethods[anonymousMethod]); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public void AddAnonymousMethod(IAnonymousMethodOperand anonymousMethod) { m_AnonymousMethodsToHoist.Add(anonymousMethod); }