コード例 #1
0
        /// <summary>
        /// The containers of the current transform context.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="loopVarsHaveOneContainer"></param>
        internal Containers(BasicTransformContext context, bool loopVarsHaveOneContainer = true) // : this(FindContainers(context))
        {
            if (loopVarsHaveOneContainer)
            {
                int ancIndex2 = Recognizer.GetAncestorIndexOfLoopBeingInitialized(context);
                if (ancIndex2 != -1)
                {
                    // For a loop variable, the loop is the only container.
                    // This is needed to allow re-ordering nested loops.  Otherwise, the inner loop variable would always require the outer loop around it.
                    // It is also useful for ignoring conditioned loops.
                    TransformInfo ti        = context.InputStack[ancIndex2];
                    IForStatement ifs       = (IForStatement)ti.inputElement;
                    IStatement    container = CreateContainer(ifs);
                    inputs.Add(container);
#if ignoreOutput
                    outputs.Add(container);
#else
                    outputs.Add((IStatement)ti.PrimaryOutput);
#endif
                    var  loopVar    = Recognizer.LoopVariable(ifs);
                    bool mustRemove = false;
                    if (!context.InputAttributes.Has <Containers>(loopVar))
                    {
                        context.InputAttributes.Set(loopVar, this);
                        mustRemove = true;
                    }
                    var initExpr = ((IExpressionStatement)ifs.Initializer).Expression;
                    this.AddContainersNeededForExpression(context, initExpr);
                    this.AddContainersNeededForExpression(context, ifs.Condition);
                    if (mustRemove)
                    {
                        context.InputAttributes.Remove <Containers>(loopVar);
                    }
                    return;
                }
            }
            // exclude the current statement.
            int ancIndex = context.FindAncestorIndex <IStatement>();
            for (int i = 0; i < ancIndex; i++)
            {
                TransformInfo ti           = context.InputStack[i];
                IStatement    inputElement = ti.inputElement as IStatement;
                if (IsContainer(inputElement) && !context.InputAttributes.Has <ConvergenceLoop>(inputElement))
                {
                    inputs.Add(CreateContainer(inputElement));
                    outputs.Add((IStatement)ti.PrimaryOutput);
                }
            }
        }