protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { generator.Indent--; generator.Write(TokenType.Keyword, "case "); Value.Generate(generator); generator.WriteLine(TokenType.Punctuation, ':'); generator.Indent++; if (!Fallthrough) { generator.EnterLocalScope(); Statements.ReserveLocals(generator, default(CodeStatementEmitOptions)); } Statements.Generate(generator, default(CodeStatementEmitOptions)); if (!Fallthrough) { bool needsBreak = true; if (Statements.Count > 0) { var lastStatement = Statements[Statements.Count - 1]; needsBreak = !lastStatement.IsTerminator; } if (needsBreak) { generator.Write(TokenType.Keyword, "break"); generator.WriteLine(TokenType.Punctuation, ';'); } generator.ExitLocalScope(); } }
public void WriteStatementEnd(CodeStatementEmitOptions options) { if ((options & CodeStatementEmitOptions.OmitSemiColon) == 0) { WriteLine(TokenType.Punctuation, ';'); } }
protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { generator.WriteBlankLineBeforeEnteringBlock(); generator.EnterLocalScope(); generator.Write(TokenType.Keyword, "foreach"); generator.Write(TokenType.Space, ' '); generator.Write(TokenType.Punctuation, '('); Declaration.Type.Generate(generator); generator.Write(TokenType.Space, ' '); generator.OutputIdentifier(TokenType.Identifier, Declaration.Name); generator.Write(TokenType.Space, ' '); generator.Write(TokenType.Keyword, "in"); generator.Write(TokenType.Space, ' '); Expression.Generate(generator); generator.Write(TokenType.Punctuation, ')'); if (Statements.Count > 0) { generator.WriteOpeningBrace(); generator.Indent++; generator.EnterLocalScope(); Statements.ReserveLocals(generator, default(CodeStatementEmitOptions)); Statements.Generate(generator, default(CodeStatementEmitOptions)); generator.ExitLocalScope(); generator.Indent--; generator.WriteClosingBrace(); } else { generator.WriteEmptyBlock(); } generator.ExitLocalScope(); }
protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { generator.WriteBlankLineBeforeEnteringBlock(); generator.WriteLine(TokenType.Keyword, "do"); if (Statements.Count > 0) { generator.WriteOpeningBrace(); generator.Indent++; generator.EnterLocalScope(); Statements.ReserveLocals(generator, default(CodeStatementEmitOptions)); Statements.Generate(generator, default(CodeStatementEmitOptions)); generator.EnterLocalScope(); generator.Indent--; generator.WriteMiddleClosingBrace(true); } else { generator.WriteEmptyBlock(true); } generator.Write(TokenType.Keyword, "while"); generator.Write(TokenType.Space, ' '); generator.Write(TokenType.Punctuation, '('); Condition.Generate(generator); generator.WriteLine(TokenType.Punctuation, ");"); }
protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { generator.WriteBlankLineBeforeEnteringBlock(); generator.EnterLocalScope(); generator.Write(TokenType.Keyword, "using"); generator.Write(TokenType.Space, ' '); generator.Write(TokenType.Punctuation, '('); InitStatement.Generate(generator, CodeStatementEmitOptions.OmitSemiColon); generator.Write(TokenType.Punctuation, ')'); if (Statements.Count > 0) { generator.WriteOpeningBrace(); generator.Indent++; generator.EnterLocalScope(); Statements.ReserveLocals(generator, default(CodeStatementEmitOptions)); Statements.Generate(generator, default(CodeStatementEmitOptions)); generator.ExitLocalScope(); generator.Indent--; generator.WriteClosingBrace(); } else { generator.WriteEmptyBlock(); } generator.ExitLocalScope(); }
protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { generator.WriteBlankLineIfJustExitedBlock(); generator.Indent--; generator.OutputIdentifier(TokenType.Identifier, Label); generator.Write(TokenType.Punctuation, ':'); generator.Indent++; }
protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { generator.WriteBlankLineIfJustExitedBlock(); generator.Write(TokenType.Keyword, "yield"); generator.Write(TokenType.Space, ' '); generator.Write(TokenType.Keyword, "break"); generator.WriteStatementEnd(emitOptions); }
protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { generator.WriteBlankLineIfJustExitedBlock(); generator.Write(TokenType.Keyword, "goto"); generator.Write(TokenType.Space, ' '); generator.OutputIdentifier(TokenType.Identifier, Label); generator.WriteStatementEnd(emitOptions); }
protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { if (!generator.JustWroteOpeningBrace && generator.JustWroteVariableDeclaration && (emitOptions & CodeStatementEmitOptions.OmitSemiColon) == 0) { generator.WriteLine(); } generator.WriteBlankLineIfJustExitedBlock(); Expression.Generate(generator); generator.WriteStatementEnd(emitOptions); }
public void Generate(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { generator.EnterElement(this); StartDirectives.Generate(generator); GenerateInner(generator, emitOptions); EndDirectives.Generate(generator); generator.ExitElement(); }
protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { generator.WriteBlankLineIfJustExitedBlock(); generator.Write(TokenType.Keyword, "goto"); generator.Write(TokenType.Space, ' '); generator.Write(TokenType.Keyword, "case"); generator.Write(TokenType.Space, ' '); Value.Generate(generator); generator.WriteStatementEnd(emitOptions); }
protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { generator.WriteBlankLineIfJustExitedBlock(); generator.Write(TokenType.Keyword, "return"); if (Expression != null) { generator.Write(TokenType.Space, ' '); Expression.Generate(generator); } generator.WriteStatementEnd(emitOptions); }
protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { generator.WriteBlankLineBeforeEnteringBlock(); generator.Write(TokenType.Keyword, "try"); generator.WriteOpeningBrace(); generator.Indent++; generator.EnterLocalScope(); TryStatements.ReserveLocals(generator, default(CodeStatementEmitOptions)); TryStatements.Generate(generator, default(CodeStatementEmitOptions)); generator.ExitLocalScope(); generator.Indent--; foreach (var catchClause in CatchClauses) { generator.WriteMiddleClosingBrace(); generator.Write(TokenType.Keyword, "catch"); generator.Write(TokenType.Space, ' '); generator.Write(TokenType.Punctuation, '('); catchClause.CatchExceptionType.Generate(generator); generator.Write(TokenType.Space, ' '); generator.OutputIdentifier(TokenType.Identifier, catchClause.LocalName); generator.Write(TokenType.Punctuation, ')'); generator.WriteOpeningBrace(); generator.Indent++; generator.EnterLocalScope(); generator.ReserveLocal(catchClause.LocalName); catchClause.Statements.ReserveLocals(generator, default(CodeStatementEmitOptions)); catchClause.Statements.Generate(generator, default(CodeStatementEmitOptions)); generator.ExitLocalScope(); generator.Indent--; } if (FinallyStatements.Count > 0) { generator.WriteMiddleClosingBrace(); generator.Write(TokenType.Keyword, "finally"); generator.WriteOpeningBrace(); generator.Indent++; generator.EnterLocalScope(); FinallyStatements.ReserveLocals(generator, default(CodeStatementEmitOptions)); FinallyStatements.Generate(generator, default(CodeStatementEmitOptions)); generator.ExitLocalScope(); generator.Indent--; } generator.WriteClosingBrace(); }
protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { if (Statements.Count > 0) { generator.WriteOpeningBrace(); generator.Indent++; generator.EnterLocalScope(); Statements.ReserveLocals(generator, default(CodeStatementEmitOptions)); Statements.Generate(generator, default(CodeStatementEmitOptions)); generator.ExitLocalScope(); generator.Indent--; generator.WriteClosingBrace(); } else { generator.WriteEmptyBlock(); } }
protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { if (!generator.JustWroteOpeningBrace && !generator.JustWroteVariableDeclaration && (emitOptions & CodeStatementEmitOptions.OmitSemiColon) == 0) { generator.WriteLine(); } generator.WriteBlankLineIfJustExitedBlock(); Type.Generate(generator); generator.Write(TokenType.Space, ' '); generator.OutputIdentifier(TokenType.Identifier, Name); if (InitExpression != null) { generator.Write(TokenType.Space, ' '); generator.Write(TokenType.Punctuation, '='); generator.Write(TokenType.Space, ' '); InitExpression.Generate(generator); } generator.WriteStatementEnd(emitOptions); generator.JustWroteVariableDeclaration = true; }
public override void ReserveLocals(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { generator.ReserveLocal(Name); }
public static void Generate(this IEnumerable <CodeStatement> statements, CodeGenerator generator, CodeStatementEmitOptions options) { foreach (var statement in statements) { statement.Generate(generator, options); } }
protected abstract void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions);
public virtual void ReserveLocals(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { }
protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { generator.WriteBlankLineIfJustExitedBlock(); Comment.Generate(generator); generator.WriteLine(); }
protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions) { generator.WriteBlankLineIfJustExitedBlock(); generator.WriteLine(TokenType.Keyword, "continue"); generator.WriteStatementEnd(emitOptions); }