public override Statement CloneStatementOnly() { BlockStatement clonedBody = body != null ? body.CloneStatementOnly() as BlockStatement : null; DoWhileStatement result = new DoWhileStatement(this.Condition.CloneExpressionOnly(), clonedBody); result.ConditionBlock = null; CopyParentAndLabel(result); return result; }
public override Statement CloneStatementOnly() { BlockStatement clonedBody = body != null?body.CloneStatementOnly() as BlockStatement : null; DoWhileStatement result = new DoWhileStatement(this.Condition.CloneExpressionOnly(), clonedBody); result.ConditionBlock = null; CopyParentAndLabel(result); return(result); }
public override Statement CloneStatementOnly() { if (this.body != null) { stackVariable5 = this.body.CloneStatementOnly() as BlockStatement; } else { stackVariable5 = null; } V_1 = new DoWhileStatement(this.get_Condition().CloneExpressionOnly(), stackVariable5); V_1.set_ConditionBlock(null); this.CopyParentAndLabel(V_1); return(V_1); }
public override void VisitBlockStatement(BlockStatement node) { for (int i = 0; i < node.Statements.Count - 1; i++) { if (node.Statements[i] is ForStatement) { ForStatement forStatement = node.Statements[i] as ForStatement; BinaryExpression assingExpression = GetForAssignExpression(forStatement.Initializer); BinaryExpression binaryExpression = GetForBinaryExpression(forStatement.Condition); Expression incrementExpression = GetForIncrementExpression(forStatement.Increment); if (assingExpression == null || binaryExpression == null || incrementExpression == null) { DoWhileStatement doWhileStatement = new DoWhileStatement(forStatement.Condition, forStatement.Body); doWhileStatement.Body.AddStatement(new ExpressionStatement(forStatement.Increment)); node.Statements[i] = new ExpressionStatement(forStatement.Initializer); node.Statements.Insert(i + 1, doWhileStatement); } } } base.VisitBlockStatement(node); }
public override void VisitDoWhileStatement(DoWhileStatement node) { WriteKeyword(KeyWordWriter.Do); WriteLine(); Visit(node.Body); WriteLine(); WriteKeyword(KeyWordWriter.LoopWhile); WriteSpace(); WriteSpecialBetweenParenthesis(node.Condition); WriteEndOfStatement(); }
public override void VisitDoWhileStatement(DoWhileStatement node) { return; }
public override void VisitDoWhileStatement(DoWhileStatement node) { TryProcessConditionStatement(node); states.Push(Step.Expression); Visit(node.Condition); states.Pop(); Visit(node.Body); if (processStep == ProcessStep.Search) { SetVariablesExpressionStatements(node); } }
/// <summary> /// Performs lifting operation on the goto statement. For more information, see /// Chapter "2.2.3 Goto-lifting Transformation" in <see cref="Taming Control Flow A Structured Approach to Eliminating Goto Statements.pdf"/>. /// </summary> /// <param name="gotoStatement">The goto to be lifted.</param> /// <param name="labelContainingStatement">The statement, containing the target of the goto.</param> /// <param name="label">The label of the target.</param> private void LiftGoto(IfStatement gotoStatement, Statement labelContainingStatement, string label) { BlockStatement containingBlock = GetOuterBlock(gotoStatement); VariableReferenceExpression variableEx = new VariableReferenceExpression(GetLabelVariable(label), null); ExtractConditionIntoVariable(variableEx, gotoStatement, containingBlock); /// Extract the do-while loop body from the current block int gotoIndex = containingBlock.Statements.IndexOf(gotoStatement); int labelIndex = containingBlock.Statements.IndexOf(labelContainingStatement); BlockStatement loopBody = CollectStatements(labelIndex, gotoIndex, containingBlock); /// Add the goto statement as the first one in the new do-while loop loopBody.AddStatementAt(0, gotoStatement); /// Remove the goto from its old parent block and attach the do-while loop on its place gotoIndex = containingBlock.Statements.IndexOf(gotoStatement); containingBlock.Statements.Remove(gotoStatement); DoWhileStatement doWhileLoop = new DoWhileStatement(gotoStatement.Condition.CloneExpressionOnly(), loopBody); containingBlock.AddStatementAt(gotoIndex, doWhileLoop); }
/// <summary> /// Eliminates the goto statement via introducing do-while. Should be used when the goto comes after the label. /// </summary> /// <param name="gotoStatement">The goto statement.</param> /// <param name="labeledStatement">The labeled statement.</param> private void EliminateViaDoWhile(IfStatement gotoStatement, Statement labeledStatement) { ICollection<BreakStatement> breaks = new List<BreakStatement>(); ICollection<ContinueStatement> continues = new List<ContinueStatement>(); BlockStatement containingBlock = GetOuterBlock(labeledStatement); int labelIndex = containingBlock.Statements.IndexOf(labeledStatement); int gotoIndex = containingBlock.Statements.IndexOf(gotoStatement); BlockStatement loopBody = CollectStatements(labelIndex, gotoIndex, containingBlock); /// Checks if the gotoStatement is inside a loop/switch statement. /// If so, then some breaks might be enclosed in the new do-while. Additional breaks need to be included in this case if (ShouldCheck(gotoStatement)) { ContinueAndBreakFinder finder = new ContinueAndBreakFinder(); finder.Visit(loopBody); breaks = finder.Breaks; continues = finder.Continues; } /// Add condition = true before each enclosed break statement. foreach (BreakStatement statement in breaks) { BlockStatement breakBlock = GetOuterBlock(statement); int breakIndex = breakBlock.Statements.IndexOf(statement); BinaryExpression assign = new BinaryExpression(BinaryOperator.Assign, new VariableReferenceExpression(breakVariable, null), GetLiteralExpression(true), typeSystem, null); usedBreakVariable = true; ExpressionStatement assignment = new ExpressionStatement(assign); breakBlock.AddStatementAt(breakIndex, assignment); } /// Add condition = true before each enclosed continue statement /// and replace the continue statement with break statement foreach (ContinueStatement statement in continues) { BlockStatement continueBlock = GetOuterBlock(statement); int continueIndex = continueBlock.Statements.IndexOf(statement); BinaryExpression assign = new BinaryExpression(BinaryOperator.Assign, new VariableReferenceExpression(continueVariable, null), GetLiteralExpression(true), typeSystem, null); usedContinueVariable = true; ExpressionStatement assignment = new ExpressionStatement(assign); continueBlock.Statements.RemoveAt(continueIndex); continueBlock.AddStatementAt(continueIndex, new BreakStatement(null)); continueBlock.AddStatementAt(continueIndex, assignment); } /// Replace the goto with do-while loop. DoWhileStatement doWhileLoop = new DoWhileStatement(gotoStatement.Condition, loopBody); gotoIndex = containingBlock.Statements.IndexOf(gotoStatement); containingBlock.AddStatementAt(gotoIndex, doWhileLoop); containingBlock.Statements.Remove(gotoStatement); if (breaks.Count > 0) { /// Add condition for the outer break, accounting for the enclosed breaks. AddBreakContinueConditional(gotoIndex + 1, containingBlock, new BreakStatement(null), breakVariable);//gotoindex + 1 should be the place after the newly inserted do-while loop } if (continues.Count > 0) { /// Add condition for the outer break, accounting for the enclosed continues. AddBreakContinueConditional(gotoIndex + 1, containingBlock, new ContinueStatement(null), continueVariable); } }
public virtual void VisitDoWhileStatement(DoWhileStatement node) { Visit(node.Body); Visit(node.Condition); }
public override void VisitDoWhileStatement(DoWhileStatement node) { TryMergeExpressions(node); base.VisitDoWhileStatement(node); }