public override object Visit(ForStatement forStatement, object data) { CodeIterationStatement forLoop = new CodeIterationStatement(); if (forStatement.Initializers != null) { if (forStatement.Initializers.Count > 1) { throw new NotSupportedException("CodeDom does not support Multiple For-Loop Initializer Statements"); } foreach (object o in forStatement.Initializers) { if (o is Expression) { forLoop.InitStatement = new CodeExpressionStatement((CodeExpression)((Expression)o).AcceptVisitor(this,data)); } if (o is Statement) { codeStack.Push(NullStmtCollection); forLoop.InitStatement = (CodeStatement)((Statement)o).AcceptVisitor(this, data); codeStack.Pop(); } } } if (forStatement.Condition == null) { forLoop.TestExpression = new CodePrimitiveExpression(true); } else { forLoop.TestExpression = (CodeExpression)forStatement.Condition.AcceptVisitor(this, data); } codeStack.Push(forLoop.Statements); forStatement.EmbeddedStatement.AcceptVisitor(this, data); codeStack.Pop(); if (forStatement.Iterator != null) { if (forStatement.Initializers.Count > 1) { throw new NotSupportedException("CodeDom does not support Multiple For-Loop Iterator Statements"); } foreach (Statement stmt in forStatement.Iterator) { forLoop.IncrementStatement = (CodeStatement)stmt.AcceptVisitor(this, data); } } AddStmt(forLoop); return forLoop; }
public override object Visit(ForStatement forStatement, object data) { DebugOutput(forStatement); if (forStatement.Initializers != null) { foreach (object o in forStatement.Initializers) { if (o is Expression) { Expression expr = (Expression)o; AppendIndentation(); sourceText.Append(expr.AcceptVisitor(this, data).ToString()); AppendNewLine(); } if (o is Statement) { ((Statement)o).AcceptVisitor(this, data); } } } AppendIndentation();sourceText.Append("While "); if (forStatement.Condition == null) { sourceText.Append("True "); } else { sourceText.Append(forStatement.Condition.AcceptVisitor(this, data).ToString()); } AppendNewLine(); ++indentLevel; forStatement.EmbeddedStatement.AcceptVisitor(this, data); if (forStatement.Iterator != null) { foreach (Statement stmt in forStatement.Iterator) { stmt.AcceptVisitor(this, data); } } --indentLevel; AppendIndentation();sourceText.Append("End While"); AppendNewLine(); return null; }
public override object Visit(ForStatement forStatement, object data) { Console.WriteLine(forStatement.ToString()); return forStatement.AcceptChildren(this, data); }
public virtual object Visit(ForStatement forStatement, object data) { object ret = data; if (forStatement.Initializers != null) { foreach(INode n in forStatement.Initializers) { n.AcceptVisitor(this, data); } } if (forStatement.Condition != null) { ret = forStatement.Condition.AcceptVisitor(this, data); } if (forStatement.Iterator != null) { foreach(INode n in forStatement.Iterator) { n.AcceptVisitor(this, data); } } if (forStatement.EmbeddedStatement == null) { return ret; } return forStatement.EmbeddedStatement.AcceptVisitor(this, data); }
void EmbeddedStatement( #line 1564 "cs.ATG" out Statement statement) { #line 1566 "cs.ATG" TypeReference type = null; Expression expr = null; Statement embeddedStatement = null; statement = null; if (la.kind == 14) { Block( #line 1572 "cs.ATG" out statement); } else if (la.kind == 10) { lexer.NextToken(); #line 1574 "cs.ATG" statement = new EmptyStatement(); } else if ( #line 1576 "cs.ATG" IdentIsYield ()) { Expect(1); if (la.kind == 100) { lexer.NextToken(); Expr( #line 1577 "cs.ATG" out expr); } else if (la.kind == 52) { lexer.NextToken(); } else SynErr(169); Expect(10); #line 1577 "cs.ATG" statement = new YieldStatement(expr); } else if ( #line 1579 "cs.ATG" UnCheckedAndLBrace()) { #line 1579 "cs.ATG" Statement block; bool isChecked = true; if (la.kind == 57) { lexer.NextToken(); } else if (la.kind == 117) { lexer.NextToken(); #line 1580 "cs.ATG" isChecked = false; } else SynErr(170); Block( #line 1581 "cs.ATG" out block); #line 1581 "cs.ATG" statement = isChecked ? (Statement)new CheckedStatement(block) : (Statement)new UncheckedStatement(block); } else if (StartOf(4)) { StatementExpr( #line 1583 "cs.ATG" out statement); Expect(10); } else if (la.kind == 78) { lexer.NextToken(); #line 1585 "cs.ATG" Statement elseStatement = null; Expect(18); Expr( #line 1586 "cs.ATG" out expr); Expect(19); EmbeddedStatement( #line 1587 "cs.ATG" out embeddedStatement); if (la.kind == 66) { lexer.NextToken(); EmbeddedStatement( #line 1588 "cs.ATG" out elseStatement); } #line 1589 "cs.ATG" statement = elseStatement != null ? (Statement)new IfElseStatement(expr, embeddedStatement, elseStatement) : (Statement)new IfStatement(expr, embeddedStatement); } else if (la.kind == 109) { lexer.NextToken(); #line 1590 "cs.ATG" ArrayList switchSections = new ArrayList(); Expect(18); Expr( #line 1591 "cs.ATG" out expr); Expect(19); Expect(14); while (la.kind == 54 || la.kind == 62) { SwitchSection( #line 1592 "cs.ATG" out statement); #line 1592 "cs.ATG" switchSections.Add(statement); } Expect(15); #line 1593 "cs.ATG" statement = new SwitchStatement(expr, switchSections); } else if (la.kind == 124) { lexer.NextToken(); Expect(18); Expr( #line 1595 "cs.ATG" out expr); Expect(19); EmbeddedStatement( #line 1596 "cs.ATG" out embeddedStatement); #line 1596 "cs.ATG" statement = new WhileStatement(expr, embeddedStatement); } else if (la.kind == 64) { lexer.NextToken(); EmbeddedStatement( #line 1597 "cs.ATG" out embeddedStatement); Expect(124); Expect(18); Expr( #line 1598 "cs.ATG" out expr); Expect(19); Expect(10); #line 1598 "cs.ATG" statement = new DoWhileStatement(expr, embeddedStatement); } else if (la.kind == 75) { lexer.NextToken(); #line 1599 "cs.ATG" ArrayList initializer = null, iterator = null; Expect(18); if (StartOf(4)) { ForInitializer( #line 1600 "cs.ATG" out initializer); } Expect(10); if (StartOf(4)) { Expr( #line 1601 "cs.ATG" out expr); } Expect(10); if (StartOf(4)) { ForIterator( #line 1602 "cs.ATG" out iterator); } Expect(19); EmbeddedStatement( #line 1603 "cs.ATG" out embeddedStatement); #line 1603 "cs.ATG" statement = new ForStatement(initializer, expr, iterator, embeddedStatement); } else if (la.kind == 76) { lexer.NextToken(); Expect(18); Type( #line 1604 "cs.ATG" out type); Expect(1); #line 1604 "cs.ATG" string varName = t.val; Expect(80); Expr( #line 1605 "cs.ATG" out expr); Expect(19); EmbeddedStatement( #line 1606 "cs.ATG" out embeddedStatement); #line 1606 "cs.ATG" statement = new ForeachStatement(type, varName , expr, embeddedStatement); statement.EndLocation = t.EndLocation; } else if (la.kind == 52) { lexer.NextToken(); Expect(10); #line 1610 "cs.ATG" statement = new BreakStatement(); } else if (la.kind == 60) { lexer.NextToken(); Expect(10); #line 1611 "cs.ATG" statement = new ContinueStatement(); } else if (la.kind == 77) { GotoStatement( #line 1612 "cs.ATG" out statement); } else if (la.kind == 100) { lexer.NextToken(); if (StartOf(4)) { Expr( #line 1613 "cs.ATG" out expr); } Expect(10); #line 1613 "cs.ATG" statement = new ReturnStatement(expr); } else if (la.kind == 111) { lexer.NextToken(); if (StartOf(4)) { Expr( #line 1614 "cs.ATG" out expr); } Expect(10); #line 1614 "cs.ATG" statement = new ThrowStatement(expr); } else if (la.kind == 113) { TryStatement( #line 1617 "cs.ATG" out statement); } else if (la.kind == 85) { lexer.NextToken(); Expect(18); Expr( #line 1619 "cs.ATG" out expr); Expect(19); EmbeddedStatement( #line 1620 "cs.ATG" out embeddedStatement); #line 1620 "cs.ATG" statement = new LockStatement(expr, embeddedStatement); } else if (la.kind == 120) { #line 1622 "cs.ATG" Statement resourceAcquisitionStmt = null; lexer.NextToken(); Expect(18); ResourceAcquisition( #line 1624 "cs.ATG" out resourceAcquisitionStmt); Expect(19); EmbeddedStatement( #line 1625 "cs.ATG" out embeddedStatement); #line 1625 "cs.ATG" statement = new UsingStatement(resourceAcquisitionStmt, embeddedStatement); } else if (la.kind == 118) { lexer.NextToken(); Block( #line 1627 "cs.ATG" out embeddedStatement); #line 1627 "cs.ATG" statement = new UnsafeStatement(embeddedStatement); } else if (la.kind == 73) { lexer.NextToken(); Expect(18); Type( #line 1630 "cs.ATG" out type); #line 1630 "cs.ATG" if (type.PointerNestingLevel == 0) Error("can only fix pointer types"); FixedStatement fxStmt = new FixedStatement(type); string identifier = null; Expect(1); #line 1634 "cs.ATG" identifier = t.val; Expect(3); Expr( #line 1635 "cs.ATG" out expr); #line 1635 "cs.ATG" fxStmt.PointerDeclarators.Add(new VariableDeclaration(identifier, expr)); while (la.kind == 12) { lexer.NextToken(); Expect(1); #line 1637 "cs.ATG" identifier = t.val; Expect(3); Expr( #line 1638 "cs.ATG" out expr); #line 1638 "cs.ATG" fxStmt.PointerDeclarators.Add(new VariableDeclaration(identifier, expr)); } Expect(19); EmbeddedStatement( #line 1640 "cs.ATG" out embeddedStatement); #line 1640 "cs.ATG" fxStmt.EmbeddedStatement = embeddedStatement; statement = fxStmt; } else SynErr(171); }
public override object Visit(ForStatement forStatement, object data) { outputFormatter.Indent(); outputFormatter.PrintToken(Tokens.For); outputFormatter.Space(); outputFormatter.PrintToken(Tokens.OpenParenthesis); outputFormatter.DoIndent = false; outputFormatter.DoNewLine = false; outputFormatter.EmitSemicolon = false; if (forStatement.Initializers != null && forStatement.Initializers.Count > 0) { for (int i = 0; i < forStatement.Initializers.Count; ++i) { INode node = (INode)forStatement.Initializers[i]; node.AcceptVisitor(this, false); if (i + 1 < forStatement.Initializers.Count) { outputFormatter.PrintToken(Tokens.Comma); } } } outputFormatter.EmitSemicolon = true; outputFormatter.PrintToken(Tokens.Semicolon); outputFormatter.EmitSemicolon = false; if (forStatement.Condition != null) { outputFormatter.Space(); forStatement.Condition.AcceptVisitor(this, data); } outputFormatter.EmitSemicolon = true; outputFormatter.PrintToken(Tokens.Semicolon); outputFormatter.EmitSemicolon = false; if (forStatement.Iterator != null && forStatement.Iterator.Count > 0) { outputFormatter.Space(); for (int i = 0; i < forStatement.Iterator.Count; ++i) { INode node = (INode)forStatement.Iterator[i]; node.AcceptVisitor(this, false); if (i + 1 < forStatement.Iterator.Count) { outputFormatter.PrintToken(Tokens.Comma); } } } outputFormatter.PrintToken(Tokens.CloseParenthesis); outputFormatter.EmitSemicolon = true; outputFormatter.DoNewLine = true; outputFormatter.DoIndent = true; if (forStatement.EmbeddedStatement is BlockStatement) { Visit((BlockStatement)forStatement.EmbeddedStatement, false); } else { outputFormatter.NewLine(); forStatement.EmbeddedStatement.AcceptVisitor(this, data); } return null; }