当前位置: 首页>>代码示例>>C#>>正文


C# IStatement.FindCompoundParent方法代码示例

本文整理汇总了C#中IStatement.FindCompoundParent方法的典型用法代码示例。如果您正苦于以下问题:C# IStatement.FindCompoundParent方法的具体用法?C# IStatement.FindCompoundParent怎么用?C# IStatement.FindCompoundParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IStatement的用法示例。


在下文中一共展示了IStatement.FindCompoundParent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindEquivalentAboveAndCombine

        /// <summary>
        /// sToPop is a member of block, and can be or is the first statement. We see if we can pop it up
        /// a level, and then start a scan for an equivalent statement, marching up the list. If we
        /// find an equivalent statement, we will perform the combination and removal.
        /// </summary>
        /// <param name="block">The block of statements that holds sToPop</param>
        /// <param name="sToPop">The statement to try to up level.</param>
        /// <param name="previousStatements">Statements before this one in this block. This block might not actually contain this statement, in which case we must have this!</param>
        /// <param name="followingStatements">Statements after this one in this block. This block might not actually contain this statement, in which case we must have this!</param>
        /// <returns>True if something was done to the statement, false if we aborted for whatever reason.</returns>
        private static bool FindEquivalentAboveAndCombine(IStatementCompound block, IStatement sToPop,
            IEnumerable<IStatement> previousStatements = null,
            IEnumerable<IStatement> followingStatements = null,
            IStatement betweenStatement = null
            )
        {
            // Can we combine these guys? This is when one sits in the other.
            if (!(block is IStatementLoop) && block.TryCombineStatement(sToPop, new BlockRenamer(sToPop.Parent.FindBookingParent(), block.FindBookingParent())))
            {
                sToPop.FindCompoundParent().Remove(sToPop);
                return false;
            }


            // If we can't get data flow information about a statement, then we can't do anything.
            var sInfo = sToPop as ICMStatementInfo;
            if (sInfo == null)
            {
                return false;
            }

            // For this next step we need to fetch the list of statements above us. Either it has
            // been supplied to us, or we will have to generate it.
            if (previousStatements == null)
            {
                previousStatements = block.Statements.TakeWhile(s => s != sInfo).Reverse();
                followingStatements = block.Statements.SkipWhile(s => s != sInfo).Skip(1);
                betweenStatement = sToPop;
            }

            // Make sure we can get the statement to the top of the block. As we move it
            // forward, we want to also see if we can combine it in a straight-up way
            // with each statement as we go by it.
            bool madeItToTheFront = true;
            foreach (var prevStatement in previousStatements)
            {
                if (MakeStatmentsEquivalent(prevStatement, sToPop))
                {
                    return true;
                }
                if (!StatementCommutes(prevStatement, sToPop))
                {
                    madeItToTheFront = false;
                }
            }

            // Next, lets see if there isn't a statement *after* this one that we can combine it with. However,
            // to do this, we have to move the statements *after* forward previous to this one. So a little painful.
            // No need to do this if we working at the level of the statement: this ground will automatically be covered
            // later in the loop.
            if (betweenStatement != sToPop && betweenStatement is ICMCompoundStatementInfo)
            {
                foreach (var followStatement in followingStatements)
                {
                    if (followStatement is ICMStatementInfo)
                    {
                        // Can we commute this statement from where it is to before the statement we are working on?
                        if (StatementCommutes(followStatement, followingStatements.TakeWhile(f => f != followStatement).Reverse()))
                        {
                            // Next is the tricky part. We are now sitting one down from the block that contains
                            // the sToPop statement. Can we move it up above the block? If the statements are the same,
                            // then we know it is ok to move it pass all the contents of the block (otherwise we would not be here).
                            // But what if it is an if statement, and the if statement depends on something in sToPop? Then
                            // we can't move it.
                            var betweenAsBlock = betweenStatement as ICMCompoundStatementInfo;
                            if (betweenAsBlock.CommutesWithGatingExpressions(followStatement as ICMStatementInfo))
                            {
                                if (MakeStatmentsEquivalent(followStatement, sToPop))
                                {
                                    // To keep continuity and unitarity, this follow statement now has to be moved before the betweenStatement!
                                    var parent = followStatement.Parent as IStatementCompound;
                                    parent.Remove(followStatement);
                                    parent.AddBefore(followStatement, betweenStatement);
                                    return true;
                                }
                            }
                        }
                    }
                }
            }

            // Now the only option left is to pop it up one level. We can do that only if we were able to
            // shift the statement all the way to the front.
            if (!madeItToTheFront)
            {
                return false;
            }

            // The statement can be moved to the top of the block, and isn't the same as
            // anything else we passed. Can we pull it out one level?
//.........这里部分代码省略.........
开发者ID:gordonwatts,项目名称:LINQtoROOT,代码行数:101,代码来源:CommonStatementLifter.cs


注:本文中的IStatement.FindCompoundParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。