private List <int> GetStatementsToInline(StatementCollection statements) { List <int> result = new List <int>(); HashSet <VariableDefinition> variablesToNotInline = this.finder.Find(statements); BlockStatement parent = (BlockStatement)statements[0].Parent; if (parent == null) { throw new NullReferenceException("parent"); } foreach (KeyValuePair <VariableDefinition, DefineUseCount> pair in patternsContext.VariableToDefineUseCountContext) { if (pair.Value.DefineCount != 1 || pair.Value.UseCount != 1) { continue; } if (variablesToNotInline.Contains(pair.Key)) { continue; } ExpressionStatement defineExpression = patternsContext.VariableToSingleAssignmentMap[pair.Key]; if (defineExpression.Parent != parent) { continue; } int index = statements.IndexOf(defineExpression); if (index == -1) { throw new IndexOutOfRangeException("index"); } result.Add(index); } result.Sort(); return(result); }
/// <summary> /// Executes the statements and returns the result. /// </summary> /// <param name="statements">The statements to be executed.</param> /// <returns>The execution result of <paramref name="statements"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="statements"/> is <see langword="null"/>, or contains <see langword="null"/>.</exception> /// <exception cref="RuntimeException">An exception occurred during the execution of the statements.</exception> public ExecuteResult ExecuteStatements(StatementCollection statements) { if (statements == null || statements.Contains(null)) { throw new ArgumentNullException(); } if (Labels == null) { Labels = new Dictionary <string, LabelStatement>(); } HoistingExecuteStatements(statements); ExecuteResult flow; for (int i = 0; i < statements.Count; i++) { CancellationToken.ThrowIfCancellationRequested(); flow = ExecuteStatement(statements[i]); label: if (flow.FlowControl == FlowControl.Goto) { var go = (string)flow.Data; if (Labels.ContainsKey(go)) { i = statements.IndexOf(Labels[go]); flow = ExecuteStatement(Labels[go]); goto label; } else { return(flow); } } else if (flow.FlowControl == FlowControl.Break || flow.FlowControl == FlowControl.Return || flow.FlowControl == FlowControl.Continue) { return(flow); } } Labels.Clear(); return(ExecuteResult.Next); }
private List <int> GetStatementsToInline(StatementCollection statements) { V_0 = new List <int>(); V_1 = this.finder.Find(statements); V_2 = (BlockStatement)statements.get_Item(0).get_Parent(); if (V_2 == null) { throw new NullReferenceException("parent"); } V_3 = this.patternsContext.get_VariableToDefineUseCountContext().GetEnumerator(); try { while (V_3.MoveNext()) { V_4 = V_3.get_Current(); if (V_4.get_Value().DefineCount != 1 || V_4.get_Value().UseCount != 1 || V_1.Contains(V_4.get_Key())) { continue; } V_5 = this.patternsContext.get_VariableToSingleAssignmentMap().get_Item(V_4.get_Key()); if (V_5.get_Parent() != V_2) { continue; } V_6 = statements.IndexOf(V_5); if (V_6 == -1) { throw new IndexOutOfRangeException("index"); } V_0.Add(V_6); } } finally { ((IDisposable)V_3).Dispose(); } V_0.Sort(); return(V_0); }
private List<int> GetStatementsToInline(StatementCollection statements) { List<int> result = new List<int>(); HashSet<VariableDefinition> variablesToNotInline = this.finder.Find(statements); BlockStatement parent = (BlockStatement)statements[0].Parent; if (parent == null) { throw new NullReferenceException("parent"); } foreach (KeyValuePair<VariableDefinition, DefineUseCount> pair in patternsContext.VariableToDefineUseCountContext) { if (pair.Value.DefineCount != 1 || pair.Value.UseCount != 1) { continue; } if (variablesToNotInline.Contains(pair.Key)) { continue; } ExpressionStatement defineExpression = patternsContext.VariableToSingleAssignmentMap[pair.Key]; if (defineExpression.Parent != parent) { continue; } int index = statements.IndexOf(defineExpression); if (index == -1) { throw new IndexOutOfRangeException("index"); } result.Add(index); } result.Sort(); return result; }