//-----------------------------------------------------------------------------------------------------------------------------------------------------

        private void AddOrUpdateAnonymousMethod(IAnonymousMethodOperand anonymousMethod, AnonymousMethodScope scope)
        {
            AnonymousMethodScope existingScope;

            if (!m_AnonymousMethods.TryGetValue(anonymousMethod, out existingScope) || scope > existingScope)
            {
                m_AnonymousMethods[anonymousMethod] = scope;
            }
        }
示例#2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        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;
                }
            }
        }
示例#4
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------

        public OperandCapture(IScopedOperand sourceOperand, StatementBlock sourceOperandHome, IAnonymousMethodOperand consumerMethod)
        {
            this.SourceOperand     = sourceOperand;
            this.SourceOperandHome = sourceOperandHome;

            m_Consumers = new HashSet <IAnonymousMethodOperand>()
            {
                consumerMethod
            };
        }
示例#5
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------

        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]);
        }
示例#8
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public void AddAnonymousMethod(IAnonymousMethodOperand anonymousMethod)
        {
            m_AnonymousMethodsToHoist.Add(anonymousMethod);
        }