Esempio n. 1
0
        /// <summary>
        /// Remove loops (and their dependent containers) that are not needed to evaluate the expression.
        /// </summary>
        /// <param name="containers"></param>
        /// <param name="context"></param>
        /// <param name="needed"></param>
        /// <returns></returns>
        internal static Containers RemoveUnusedLoops(Containers containers, BasicTransformContext context, Containers needed)
        {
            Containers result = new Containers();
            Set <IVariableDeclaration> allowedVars = Containers.GetConditionedLoopVariables(context);

            allowedVars.Clear(); // for ReplicateWithConditionedIndexTest
            for (int i = 0; i < containers.inputs.Count; i++)
            {
                IStatement container = containers.inputs[i];
                if (container is IForStatement)
                {
                    IForStatement        ifs     = container as IForStatement;
                    IVariableDeclaration loopVar = Recognizer.LoopVariable(ifs);
                    if (!allowedVars.Contains(loopVar) && !needed.Contains(container))
                    {
                        continue;
                    }
                }
                result.inputs.Add(container);
                result.outputs.Add(containers.outputs[i]);
            }
            // Removing unused loops may have left us with containers that refer to the removed loop index.  We must remove these also.
            // Note this routine could be merged with RemoveUnusedLoops.
            result = Containers.RemoveInvalidConditions(result, context);
            return(result);
        }
Esempio n. 2
0
        internal static Containers Append(Containers containers, Containers extraContainers)
        {
            Containers result = new Containers();

            result.inputs  = new List <IStatement>(containers.inputs);
            result.outputs = new List <IStatement>(containers.outputs);
            for (int i = 0; i < extraContainers.inputs.Count; i++)
            {
                IStatement input = extraContainers.inputs[i];
                if (!containers.Contains(input))
                {
                    result.inputs.Add(input);
                    result.outputs.Add(extraContainers.outputs[i]);
                }
            }
            return(result);
        }
Esempio n. 3
0
 internal bool SetEquals(Containers c)
 {
     return(Contains(c) && c.Contains(this));
 }