public override SyntaxList <StatementSyntax> VisitBreakStatement(CSS.BreakStatementSyntax node) { var statementKind = SyntaxKind.None; var keywordKind = SyntaxKind.None; foreach (var stmt in node.GetAncestors <CSS.StatementSyntax>()) { if (stmt is CSS.DoStatementSyntax) { statementKind = SyntaxKind.ExitDoStatement; keywordKind = SyntaxKind.DoKeyword; break; } if (stmt is CSS.WhileStatementSyntax) { statementKind = SyntaxKind.ExitWhileStatement; keywordKind = SyntaxKind.WhileKeyword; break; } if (stmt is CSS.ForStatementSyntax || stmt is CSS.ForEachStatementSyntax) { statementKind = SyntaxKind.ExitForStatement; keywordKind = SyntaxKind.ForKeyword; break; } if (stmt is CSS.SwitchStatementSyntax) { statementKind = SyntaxKind.ExitSelectStatement; keywordKind = SyntaxKind.SelectKeyword; break; } } return(SyntaxFactory.SingletonList <StatementSyntax>(SyntaxFactory.ExitStatement(statementKind, SyntaxFactory.Token(keywordKind)))); }
public override SyntaxList <StatementSyntax> VisitBreakStatement(CSS.BreakStatementSyntax node) { var statementKind = SyntaxKind.None; var keywordKind = SyntaxKind.None; foreach (var stmt in node.GetAncestors <CSS.StatementSyntax>()) { if (stmt is CSS.DoStatementSyntax) { statementKind = SyntaxKind.ExitDoStatement; keywordKind = SyntaxKind.DoKeyword; break; } if (stmt is CSS.WhileStatementSyntax) { statementKind = SyntaxKind.ExitWhileStatement; keywordKind = SyntaxKind.WhileKeyword; break; } if (stmt is CSS.ForEachStatementSyntax) { statementKind = SyntaxKind.ExitForStatement; keywordKind = SyntaxKind.ForKeyword; break; } if (stmt is CSS.ForStatementSyntax fs) { bool isFor = ConvertForToSimpleForNextWithoutStatements(fs, out _); statementKind = isFor ? SyntaxKind.ExitForStatement : SyntaxKind.ExitWhileStatement; keywordKind = isFor ? SyntaxKind.ForKeyword : SyntaxKind.WhileKeyword; break; } if (stmt is CSS.SwitchStatementSyntax) { statementKind = SyntaxKind.ExitSelectStatement; keywordKind = SyntaxKind.SelectKeyword; break; } } return(SyntaxFactory.SingletonList <StatementSyntax>(SyntaxFactory.ExitStatement(statementKind, SyntaxFactory.Token(keywordKind)))); }
private VB.Syntax.StatementSyntax VisitBreakStatementWorker(CS.Syntax.BreakStatementSyntax node) { foreach (SyntaxNode parent in node.GetAncestorsOrThis <SyntaxNode>()) { if (parent.IsBreakableConstruct()) { switch (parent.Kind()) { case CS.SyntaxKind.DoStatement: return(VB.SyntaxFactory.ExitDoStatement()); case CS.SyntaxKind.WhileStatement: return(VB.SyntaxFactory.ExitWhileStatement()); case CS.SyntaxKind.SwitchStatement: // If the 'break' is the last statement of a switch block, then we // don't need to translate it into VB (as it is implied). SwitchSectionSyntax outerSection = node.FirstAncestorOrSelf <CS.Syntax.SwitchSectionSyntax>(); if (outerSection != null && outerSection.Statements.Count > 0) { if (node == outerSection.Statements.Last()) { return(VB.SyntaxFactory.EmptyStatement()); } } return(VB.SyntaxFactory.ExitSelectStatement()); case CS.SyntaxKind.ForStatement: case CS.SyntaxKind.ForEachStatement: return(VB.SyntaxFactory.ExitForStatement()); } } } return(CreateBadStatement(node, nodeVisitor)); }
public override SyntaxList <VB.Syntax.StatementSyntax> VisitBreakStatement(CS.Syntax.BreakStatementSyntax node) { return(List(VisitBreakStatementWorker(node))); }