public static Set <IVariableDeclaration> GetConditionedLoopVariables(BasicTransformContext context) { Set <IVariableDeclaration> loopVars = new Set <IVariableDeclaration>(); foreach (IConditionStatement ics in context.FindAncestors <IConditionStatement>()) { ConditionBinding binding = new ConditionBinding(ics.Condition); if (binding.lhs is IVariableReferenceExpression) { IVariableReferenceExpression ivre = (IVariableReferenceExpression)binding.lhs; if (Recognizer.GetLoopForVariable(context, ivre) != null) { loopVars.Add(Recognizer.GetVariableDeclaration(ivre)); } } if (binding.rhs is IVariableReferenceExpression) { IVariableReferenceExpression ivre = (IVariableReferenceExpression)binding.rhs; if (Recognizer.GetLoopForVariable(context, ivre) != null) { loopVars.Add(Recognizer.GetVariableDeclaration(ivre)); } } } return(loopVars); }
/// <summary> /// Gets the reference loop context for a reference to a local variable. A reference loop context /// is the set of loops that a variable reference occurs in, less any loops that the variable declaration /// occurred in. /// </summary> /// <returns></returns> internal RefRepeatContext GetReferenceRepeatContext(BasicTransformContext context) { List <IRepeatStatement> reps = context.FindAncestors <IRepeatStatement>(); // Make a cloned list of repeat counts and remove when found var rcs = new List <IExpression>(repeatCounts); RefRepeatContext rlc = new RefRepeatContext(); foreach (IRepeatStatement rep in reps) { IExpression repCount = rep.Count; int k = rcs.IndexOf(repCount); if (k != -1) { rcs.RemoveAt(k); // remove this count so we don't use it again. continue; } rlc.repeatCounts.Add(repCount); rlc.repeats.Add(rep); } return(rlc); }
/// <summary> /// Gets the reference loop context for a reference to a local variable. A reference loop context /// is the set of loops that a variable reference occurs in, less any loops that the variable declaration /// occurred in. /// </summary> /// <returns></returns> internal RefLoopContext GetReferenceLoopContext(BasicTransformContext context) { List <IForStatement> loops = context.FindAncestors <IForStatement>(); RefLoopContext rlc = new RefLoopContext(); try { foreach (IForStatement loop in loops) { IVariableDeclaration loopVar = Recognizer.LoopVariable(loop); if (loopVariables.Contains(loopVar)) { continue; } rlc.loopVariables.Add(loopVar); rlc.loops.Add(loop); } } catch (Exception ex) { context.Error("Could not get loop index variables", ex); } return(rlc); }
/// <summary> /// Returns a list of the open containers, outermost first. /// </summary> /// <param name="context"></param> /// <returns></returns> internal static List <IStatement> FindContainers(BasicTransformContext context) { return(context.FindAncestors <IStatement>().FindAll(IsContainer)); }
/// <summary> /// Creates a repeat context, given the current transform context. /// </summary> internal RepeatContext(BasicTransformContext context) : this(context.FindAncestors <IRepeatStatement>()) { }
/// <summary> /// Creates a loop context, given the current transform context. /// </summary> internal LoopContext(BasicTransformContext context) : this(context.FindAncestors <IForStatement>()) { }