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


C# IStatement.WalkParents方法代码示例

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


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

示例1: FindEquivalentAboveAndCombine


//.........这里部分代码省略.........
                                    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?
            // The key to answering this is: are all the variables it needs defined at the next
            // level up? And if not, are the missing ones simply declared down here and need to be moved up?
            var nParent = block.Parent.FindBookingParent();
            if (nParent == null)
            {
                return false;
            }

            var sDependent = sInfo.DependentVariables;
            var availAtParent = nParent.AllDeclaredVariables.Select(n => n.RawValue).Intersect(sDependent);
            IEnumerable<string> declaredInBlock = Enumerable.Empty<string>();
            if (block is IBookingStatementBlock)
            {
                declaredInBlock = (block as IBookingStatementBlock).DeclaredVariables.Select(np => np.RawValue).Intersect(sDependent);
            }
            if ((availAtParent.Count() + declaredInBlock.Count()) != sDependent.Count())
            {
                return false;
            }

            // If this there is a variable declared in the block internally, then we can't lift it up and out.
            // Also make sure that we can lift it past if there is a gating expression.
            if (block is ICMCompoundStatementInfo)
            {
                var compoundInfo = block as ICMCompoundStatementInfo;
                if (compoundInfo.InternalResultVarialbes.Select(p => p.RawValue).Intersect(sDependent).Any())
                {
                    return false;
                }
                if (!compoundInfo.CommutesWithGatingExpressions(sInfo))
                {
                    return false;
                }
            }

            // If we are going to try to lift past a loop, we have to make sure the statement is idempotent.
            if (block is IStatementLoop && !StatementIdempotent(sToPop))
            {
                return false;
            }

            // And the next figure out where we are in the list of statements.
            var nPrevStatements = nParent.Statements.TakeWhile(ps => ps != block).Reverse();
            var nFollowStatements = nParent.Statements.SkipWhile(ps => ps != block).Skip(1);

            // And repeat one level up with some tail recursion!
            var statementMoved = FindEquivalentAboveAndCombine(nParent, sToPop, nPrevStatements, nFollowStatements, block);

            // There is one other thing to try. If we couldn't move it above us (e.g. statementMoved is false), it could be
            // we can leave the statement here, rather than in its original location.
            if (!statementMoved)
            {
                var parentsToBlock = sToPop
                    .WalkParents(false)
                    .TakeWhile(s => s != block)
                    .Concat(new IStatementCompound[] { block }).ToArray();

                // If no lifting out of some statement between us and the statement, then don't do it.
                var parentsNotOK = parentsToBlock
                    .Where(s => s is ICMCompoundStatementInfo)
                    .Cast<ICMCompoundStatementInfo>()
                    .Where(s => !s.AllowNormalBubbleUp);
                if (parentsNotOK.Any())
                {
                    return false;
                }

                // The next thing we have to double check is that we can do the lifting, and nothing we are going to
                // lift is going to impact some variable.
                var dependents = sInfo.DependentVariables;
                var dependentAffected = parentsToBlock
                    .Select(p => p.CheckForVariableAsInternalResult(dependents))
                    .Where(t => t);
                if (dependentAffected.Any())
                {
                    return false;
                }

                return MoveStatement(sToPop, block);
            }

            return statementMoved;
        }
开发者ID:gordonwatts,项目名称:LINQtoROOT,代码行数:101,代码来源:CommonStatementLifter.cs

示例2: CheckForVariableAsResult

        /// <summary>
        /// Given a statement, check to see if somewhere else the variable is modified or altered, both before or after
        /// the current statement.
        /// </summary>
        /// <param name="s2"></param>
        /// <param name="variables"></param>
        /// <returns>true if it was used as a result somewhere else, false otherwise</returns>
        private static bool CheckForVariableAsResult(IStatement s2, IEnumerable<string> variables)
        {
            // Check that we can get past each parental boundary.
            if (s2.WalkParents(false).Select(s => s.CheckForVariableAsInternalResult(variables)).Where(t => t).Any())
                return true;

            // Now check that we aren't also going to try to do something with a variable that is
            // being set somewhere else... that gets into grouping statements which is too much for this
            // optimizer. :-)
            if (s2.AllStatementsPrevious().Select(s => s.CheckForVariableAsReult(variables)).Where(t => t).Any())
                return true;

            if (s2.AllStatementsAfter().Select(s => s.CheckForVariableAsReult(variables)).Where(t => t).Any())
                return true;

            return false;
        }
开发者ID:gordonwatts,项目名称:LINQtoROOT,代码行数:24,代码来源:OptimizationUtils.cs


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