public override Statement CloneStatementOnly() { BlockStatement clonedBody = body != null ? body.CloneStatementOnly() as BlockStatement : null; WhileStatement result = new WhileStatement(Condition.CloneExpressionOnly(), clonedBody); CopyParentAndLabel(result); return result; }
protected override bool CheckTheLoop(WhileStatement theWhile, VariableReference forVariable) { bool isProperForVBForLoop = base.CheckTheLoop(theWhile, forVariable) && theWhile.Condition is BinaryExpression; if (!isProperForVBForLoop) { return false; } ExpressionStatement incrementCandidate = theWhile.Body.Statements[theWhile.Body.Statements.Count - 1] as ExpressionStatement; BinaryExpression assignmentExpression = incrementCandidate.Expression as BinaryExpression; if (assignmentExpression != null) { BinaryExpression incrementExpression = assignmentExpression.Right as BinaryExpression; if (incrementExpression != null && (incrementExpression.Operator == Ast.BinaryOperator.Add || incrementExpression.Operator == Ast.BinaryOperator.Subtract)) { VariableReferenceExpression incrementVariableExpression = incrementExpression.Left as VariableReferenceExpression; if (incrementVariableExpression != null) { if (incrementVariableExpression.Variable == forVariable) { return true; } } } } return false; }
protected virtual bool CheckTheLoop(WhileStatement theWhile, VariableReference forVariable) { if (theWhile == null || theWhile.Body.Statements.Count < 2) { return false; } VariableFinder variableFinder = new VariableFinder(forVariable); if (!variableFinder.FindVariable(theWhile.Condition)) { return false; } ExpressionStatement incrementCandidate = theWhile.Body.Statements[theWhile.Body.Statements.Count - 1] as ExpressionStatement; VariableReference incrementVariable; if (incrementCandidate == null || !TryGetAssignedVariable(incrementCandidate, out incrementVariable) || forVariable != incrementVariable) { return false; } ContinueFinder continueFinder = new ContinueFinder(); return !continueFinder.FindContinue(theWhile.Body); }
private bool IsForeach(WhileStatement node) { if (node.Condition is UnaryExpression) { UnaryExpression unary = node.Condition as UnaryExpression; if (unary.Operator == UnaryOperator.None && unary.Operand is MethodInvocationExpression) { MethodInvocationExpression expr = unary.Operand as MethodInvocationExpression; return IsMoveNextCall(expr); } } return false; }
public override void VisitWhileStatement(WhileStatement node) { if (foundEnumeratorAssignment && insideTry) { if (IsForeach(node)) { BlockStatement tryParent = theTry.Parent as BlockStatement; if (tryParent == null || tryParent != enumeratorAssignmentStatement.Parent || tryParent.Statements.IndexOf(enumeratorAssignmentStatement) + 1 != tryParent.Statements.IndexOf(theTry)) { ClearState(); base.VisitWhileStatement(node); return; } foreachConditionInstructions = node.Condition.UnderlyingSameMethodInstructions; foundWhile = true; shouldAdd = true; foreach (Statement st in node.Body.Statements) { if (!(st is ExpressionStatement)) { foreachBody.AddStatement(st); //TODO: Must traverse the statement tree, in order to find GetCurrent method and obtain the type of the foreach } else { VisitExpressionStatement(st as ExpressionStatement); } if (foreachVariableType == null) { ForeachElementTypeFinder fet = new ForeachElementTypeFinder(theEnumerator); fet.Visit(st); foreachVariableType = fet.ResultingType; } } if (foreachVariableType != null) { AttachForeach(); if (isEnumeratorUsedInsideForEach) { ClearState(); base.VisitWhileStatement(node); } } else { //this can happen if enumerator.get_Current is not called anywhere in the loop. //in this case there is no foreach. //think of a better way to ClearState(); base.VisitWhileStatement(node); } } else { ClearState(); base.VisitWhileStatement(node); } } else { base.VisitWhileStatement(node); } }
public override void VisitWhileStatement(WhileStatement node) { WriteKeyword(KeyWordWriter.While); WriteSpace(); WriteSpecialBetweenParenthesis(node.Condition); WriteLine(); Visit(node.Body); WriteSpecialEndBlock(KeyWordWriter.While); }
public override void VisitWhileStatement(WhileStatement node) { return; }
private ForStatement CreateForStatement(Statement initializer, WhileStatement theWhile) { int forStatementsCount = theWhile.Body.Statements.Count - 1; string incrementLabel = theWhile.Body.Statements[forStatementsCount].Label; ForStatement result = new ForStatement( (initializer as ExpressionStatement).Expression, theWhile.Condition, (theWhile.Body.Statements[forStatementsCount] as ExpressionStatement).Expression, new BlockStatement()); for (int i = 0; i < forStatementsCount; i++) { result.Body.AddStatement(theWhile.Body.Statements[i]); } if (!string.IsNullOrEmpty(incrementLabel)) { EmptyStatement emptyStatement = new EmptyStatement() { Label = incrementLabel }; result.Body.AddStatement(emptyStatement); } return result; }
public override void VisitWhileStatement(WhileStatement node) { loopStates.Push(StatementState.While); base.VisitWhileStatement(node); loopStates.Pop(); }
public override void VisitWhileStatement(WhileStatement node) { TryProcessConditionStatement(node); states.Push(Step.Expression); Visit(node.Condition); states.Pop(); Visit(node.Body); if (processStep == ProcessStep.Search) { SetVariablesExpressionStatements(node); } }
public virtual void VisitWhileStatement(WhileStatement node) { Visit(node.Condition); Visit(node.Body); }
private void CopyWhileBodyStatements(WhileStatement whileStatement) { statementBody = new BlockStatement(); for (int i = 1; i < whileStatement.Body.Statements.Count - 1; i++) { statementBody.AddStatement(whileStatement.Body.Statements[i]); } }
public override void VisitWhileStatement(WhileStatement node) { TryMergeExpressions(node); base.VisitWhileStatement(node); }