private void LiftGoto(IfStatement gotoStatement, Statement labelContainingStatement, string label) { V_0 = this.GetOuterBlock(gotoStatement); V_1 = new VariableReferenceExpression(this.GetLabelVariable(label), null); this.ExtractConditionIntoVariable(V_1, gotoStatement, V_0); V_2 = V_0.get_Statements().IndexOf(gotoStatement); V_3 = V_0.get_Statements().IndexOf(labelContainingStatement); V_4 = this.CollectStatements(V_3, V_2, V_0); V_4.AddStatementAt(0, gotoStatement); V_2 = V_0.get_Statements().IndexOf(gotoStatement); dummyVar0 = V_0.get_Statements().Remove(gotoStatement); V_5 = new DoWhileStatement(gotoStatement.get_Condition().CloneExpressionOnly(), V_4); V_0.AddStatementAt(V_2, V_5); return; }
private void EmbedIntoDefaultIf(GotoStatement jump) { V_0 = jump.get_Parent() as BlockStatement; V_1 = new BlockStatement(); V_1.AddStatement(jump); V_2 = new IfStatement(this.GetLiteralExpression(true), V_1, null); V_1.set_Parent(V_2); V_3 = V_0.get_Statements().IndexOf(jump); V_0.get_Statements().RemoveAt(V_3); V_0.AddStatementAt(V_3, V_2); if (V_0.get_Parent() as ConditionCase != null && V_0.get_Statements().IndexOf(V_2) == V_0.get_Statements().get_Count()) { V_0.AddStatement(new BreakStatement(null)); } return; }
private void MoveOut(IfStatement gotoStatement, string label) { V_0 = gotoStatement.get_Parent() as BlockStatement; V_1 = this.GetOuterBlock(V_0); V_2 = new VariableReferenceExpression(this.GetLabelVariable(label), null); this.ExtractConditionIntoVariable(V_2.CloneExpressionOnly() as VariableReferenceExpression, gotoStatement, V_0); V_3 = V_0.get_Parent(); if (V_3 as SwitchCase != null) { V_3 = V_3.get_Parent(); } if (V_0.get_Parent() as SwitchCase != null || V_0.get_Parent() as WhileStatement != null || V_0.get_Parent() as DoWhileStatement != null || V_0.get_Parent() as ForStatement != null || V_0.get_Parent() as ForEachStatement != null) { V_4 = new BlockStatement(); V_4.AddStatement(new BreakStatement(null)); V_5 = new IfStatement(V_2.CloneExpressionOnly(), V_4, null); V_6 = V_0.get_Statements().IndexOf(gotoStatement); dummyVar0 = V_0.get_Statements().Remove(gotoStatement); V_0.AddStatementAt(V_6, V_5); } else { if (V_0.get_Parent() as IfStatement == null && V_0.get_Parent() as TryStatement == null && V_0.get_Parent() as IfElseIfStatement == null) { throw new ArgumentOutOfRangeException("Goto statement can not leave this parent construct."); } V_7 = V_0.get_Statements().IndexOf(gotoStatement) + 1; V_8 = new BlockStatement(); while (V_7 < V_0.get_Statements().get_Count()) { V_8.AddStatement(V_0.get_Statements().get_Item(V_7)); V_0.get_Statements().RemoveAt(V_7); } V_9 = new IfStatement(new UnaryExpression(1, V_2.CloneExpressionOnly(), null), V_8, null); dummyVar1 = V_0.get_Statements().Remove(gotoStatement); if (V_9.get_Then().get_Statements().get_Count() != 0) { V_0.AddStatement(V_9); } } V_1.AddStatementAt(V_1.get_Statements().IndexOf(V_3) + 1, gotoStatement); return; }
private void MoveIn(IfStatement gotoStatement, Statement targetStatement, string label) { V_0 = gotoStatement.get_Parent() as BlockStatement; V_1 = new VariableReferenceExpression(this.GetLabelVariable(label), null); this.ExtractConditionIntoVariable(V_1.CloneExpressionOnly() as VariableReferenceExpression, gotoStatement, V_0); V_2 = V_0.get_Statements().IndexOf(gotoStatement); V_3 = V_0.get_Statements().IndexOf(targetStatement); V_4 = this.CollectStatements(V_2 + 1, V_3, V_0); V_5 = new IfStatement(new UnaryExpression(1, V_1.CloneExpressionOnly(), null), V_4, null); if (V_5.get_Then().get_Statements().get_Count() > 0) { V_0.AddStatementAt(V_2, V_5); } dummyVar0 = V_0.get_Statements().Remove(gotoStatement); if (targetStatement as DoWhileStatement != null) { (targetStatement as DoWhileStatement).get_Body().AddStatementAt(0, gotoStatement); return; } if (targetStatement as IfStatement != null) { V_6 = targetStatement as IfStatement; V_6.set_Condition(this.UpdateCondition(V_6.get_Condition(), V_1.CloneExpressionOnly() as VariableReferenceExpression)); V_6.get_Then().AddStatementAt(0, gotoStatement); return; } if (targetStatement as SwitchCase != null) { this.MoveInCase(gotoStatement, targetStatement as SwitchCase, label); return; } if (targetStatement as WhileStatement == null) { throw new NotSupportedException("Unsupported target statement for goto jump."); } V_7 = targetStatement as WhileStatement; V_7.get_Body().AddStatementAt(0, gotoStatement); V_7.set_Condition(this.UpdateCondition(V_7.get_Condition(), V_1.CloneExpressionOnly() as VariableReferenceExpression)); return; }