public override void VisitDoStatement(IDoStatement stmt, IList <IStatement> body) { if (IsTargetMatch(stmt, CompletionCase.EmptyCompletionBefore)) { body.Add(EmptyCompletionExpression); } var loop = new DoLoop { Condition = _exprVisitor.ToLoopHeaderExpression(stmt.Condition, body) }; body.Add(loop); if (IsTargetMatch(stmt, CompletionCase.InBody)) { loop.Body.Add(EmptyCompletionExpression); } stmt.Body.Accept(this, loop.Body); if (IsTargetMatch(stmt, CompletionCase.EmptyCompletionAfter)) { body.Add(EmptyCompletionExpression); } }
public void DoLoop() { var sst = new DoLoop { Condition = new LoopHeaderBlockExpression { Body = { new ReturnStatement { Expression = new ConstantValueExpression{ Value = "true" } } } }, Body = { new ContinueStatement(), new BreakStatement() } }; AssertPrint( sst, "do", "{", " continue;", " break;", "}", "while (", " {", " return true;", " }", ")"); }
//----------------------------------------------------------- public Type Visit(DoLoop node) { labelStorage.Push(node[0].AnchorToken.Lexeme); if (Visit((Assignment)node[1]) != Type.INTEGER) { throw new SemanticError( "Loop variables can only be integers.", node[1].AnchorToken); } if (Visit((dynamic)node[2]) != Type.INTEGER) { throw new SemanticError( "Loop variables can only be integers.", node[2].AnchorToken); } var loopEval = 3; if (!(node[loopEval] is StatementList)) { if (Visit((dynamic)node[loopEval]) != Type.INTEGER) { throw new SemanticError( "Loop variables can only be integers.", node[loopEval].AnchorToken); } loopEval++; } VisitChildren(node[loopEval]); return(Type.VOID); }
public void Equality_Default() { var a = new DoLoop(); var b = new DoLoop(); Assert.AreEqual(a, b); Assert.AreEqual(a.GetHashCode(), b.GetHashCode()); }
public void CompileDoLoop(DoLoop doLoop) { textWriter.WriteLine("do "); MayBeIndent(doLoop.Body); textWriter.Write("while ("); doLoop.Guard.AcceptCompiler(this); textWriter.WriteLine(");"); }
public void DefaultValues() { var sut = new DoLoop(); Assert.AreEqual(new UnknownExpression(), sut.Condition); Assert.AreEqual(Lists.NewList <IStatement>(), sut.Body); Assert.AreNotEqual(0, sut.GetHashCode()); Assert.AreNotEqual(1, sut.GetHashCode()); }
public void Equality_DifferentCondition() { var a = new DoLoop { Condition = new ConstantValueExpression() }; var b = new DoLoop(); Assert.AreNotEqual(a, b); Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode()); }
public void Equality_DifferentBody() { var a = new DoLoop(); a.Body.Add(new ReturnStatement()); var b = new DoLoop(); Assert.AreNotEqual(a, b); Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode()); }
public void ChildrenIdentity() { var sut = new DoLoop { Condition = new ConstantValueExpression(), Body = { new ReturnStatement() } }; AssertChildren(sut, sut.Condition, sut.Body.First()); }
public void SettingValues() { var sut = new DoLoop { Condition = new ConstantValueExpression(), Body = { new ReturnStatement() } }; Assert.AreEqual(new ConstantValueExpression(), sut.Condition); Assert.AreEqual(Lists.NewList(new ReturnStatement()), sut.Body); }
public void Equality_ReallyTheSame() { var a = new DoLoop { Condition = new ConstantValueExpression() }; a.Body.Add(new ReturnStatement()); var b = new DoLoop { Condition = new ConstantValueExpression() }; b.Body.Add(new ReturnStatement()); Assert.AreEqual(a, b); Assert.AreEqual(a.GetHashCode(), b.GetHashCode()); }
public void CompileDoLoop(DoLoop doLoop) { XmlElement previousElement = currentElement; XmlElement tmpElement = document.CreateElement("DoLoop"); currentElement = document.CreateElement("Guard"); doLoop.Guard.AcceptCompiler(this); tmpElement.AppendChild(currentElement); currentElement = document.CreateElement("Body"); doLoop.Body.AcceptCompiler(this); tmpElement.AppendChild(currentElement); previousElement.AppendChild(tmpElement); currentElement = previousElement; }
protected virtual ICfgNode Build(DoLoop doLoop) { doLoop.Body?.Accept(this); var body = Result; doLoop.Condition.Accept(this); var condition = Result; if (condition == null && body == null) { return(null); } return(Emit.Do( condition ?? doLoop.Condition, body ?? doLoop.Body)); }
/**************************************************************** * Do Loop Node ***************************************************************/ public Node DoLoop() { var loopResult = new DoLoop() { AnchorToken = Expect(TokenCategory.DO) }; loopResult.Add(new Label() { AnchorToken = Expect(TokenCategory.INT_LITERAL) }); loopResult.Add(Assignment()); while (CurrentToken == TokenCategory.COMMA) { Expect(TokenCategory.COMMA); loopResult.Add(Expression()); } loopResult.Add(EvaluateLoopStatements()); return(loopResult); }
public virtual void Visit(DoLoop doLoop) { doLoop.Body?.Accept(this); doLoop.Condition.Accept(this); }
public void VisitorWithReturnIsImplemented() { var sut = new DoLoop(); sut.Accept(23).VerifyWithReturn(v => v.Visit(sut, 23)); }
public void Visit(DoLoop doLoop) => Result = Build(doLoop);