private Doc PrintDefaultSwitchLabelSyntax(DefaultSwitchLabelSyntax node) { return(Concat( this.PrintSyntaxToken(node.Keyword), this.PrintSyntaxToken(node.ColonToken) )); }
public override string VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) { StringBuilder sb = new StringBuilder(); sb.AppendLine("default:"); return(sb.ToString()); }
private static Task <Document> ConvertSwitchExpressionToSwitchStatement( Document document, SwitchExpressionSyntax switchExpression, CancellationToken cancellationToken) { IEnumerable <SwitchSectionSyntax> sections = switchExpression.Arms.Select((arm, i) => { SyntaxToken separator = switchExpression.Arms.GetSeparator(i); SyntaxToken semicolon = Token(SyntaxKind.SemicolonToken); if (!separator.IsMissing) { semicolon = semicolon.WithTriviaFrom(separator); } PatternSyntax pattern = arm.Pattern; switch (pattern.Kind()) { case SyntaxKind.ConstantPattern: { CaseSwitchLabelSyntax label = CaseSwitchLabel( Token(SyntaxKind.CaseKeyword).WithLeadingTrivia(pattern.GetLeadingTrivia()), ((ConstantPatternSyntax)pattern).Expression.WithoutLeadingTrivia(), Token(SyntaxKind.ColonToken).WithTriviaFrom(arm.EqualsGreaterThanToken)); return(SwitchSection(label, CreateStatement(arm.Expression, semicolon))); } case SyntaxKind.DiscardPattern: { DefaultSwitchLabelSyntax label = DefaultSwitchLabel(Token(SyntaxKind.DefaultKeyword), Token(SyntaxKind.ColonToken)); return(SwitchSection(label, CreateStatement(arm.Expression, semicolon))); } default: { throw new InvalidOperationException(); } } }); var returnStatement = (ReturnStatementSyntax)switchExpression.Parent; SwitchStatementSyntax switchStatement = SwitchStatement( switchExpression.SwitchKeyword.WithTriviaFrom(returnStatement.ReturnKeyword), OpenParenToken(), switchExpression.GoverningExpression, CloseParenToken().WithTrailingTrivia(switchExpression.SwitchKeyword.TrailingTrivia), switchExpression.OpenBraceToken, sections.ToSyntaxList(), switchExpression.CloseBraceToken); switchStatement = switchStatement.WithFormatterAnnotation(); return(document.ReplaceNodeAsync(returnStatement, switchStatement, cancellationToken));
private ImmutableArray<BoundPatternSwitchSection> BindPatternSwitchSections(BoundExpression boundSwitchExpression, SyntaxList<SwitchSectionSyntax> sections, Binder originalBinder, ref DefaultSwitchLabelSyntax defaultLabel, DiagnosticBag diagnostics) { // Bind match sections var boundPatternSwitchSectionsBuilder = ArrayBuilder<BoundPatternSwitchSection>.GetInstance(); foreach (var sectionSyntax in sections) { boundPatternSwitchSectionsBuilder.Add(BindPatternSwitchSection(boundSwitchExpression, sectionSyntax, originalBinder, ref defaultLabel, diagnostics)); } return boundPatternSwitchSectionsBuilder.ToImmutableAndFree(); }
public override void VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) { if (!PreVisit(node)) { return; } base.VisitDefaultSwitchLabel(node); PostVisit(node); }
public override void VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) { if (entryPoint.IsMethodLevel() && node.IsParent <AnonymousFunctionExpressionSyntax>()) { return; } embeddednessNode = node; embeddednessHasBeenIncreased = false; embeddednessHasBeenDecreased = false; base.VisitDefaultSwitchLabel(node); embeddednessNode = null; }
private BoundPatternSwitchStatement BindPatternSwitch(SwitchStatementSyntax node, Binder originalBinder, DiagnosticBag diagnostics) { var boundSwitchExpression = originalBinder.GetBinder(node.Expression).BindValue(node.Expression, diagnostics, BindValueKind.RValue); // TODO: any constraints on a switch expression must be enforced here. For example, // it must have a type (not be target-typed, lambda, null, etc) DefaultSwitchLabelSyntax defaultLabel = null; ImmutableArray <BoundPatternSwitchSection> boundPatternSwitchSections = BindPatternSwitchSections(boundSwitchExpression, node.Sections, originalBinder, ref defaultLabel, diagnostics); return(new BoundPatternSwitchStatement(node, boundSwitchExpression, GetDeclaredLocalsForScope(node), GetDeclaredLocalFunctionsForScope(node), boundPatternSwitchSections, this.BreakLabel)); }
private SwitchSectionSyntax ParseSwitchSection() { // First, parse case label(s) var labels = new List <SwitchLabelSyntax>(); var statements = new List <StatementSyntax>(); do { SyntaxToken specifier; SwitchLabelSyntax label; SyntaxToken colon; if (Current.Kind == SyntaxKind.CaseKeyword) { ExpressionSyntax expression; specifier = NextToken(); if (Current.Kind == SyntaxKind.ColonToken) { expression = CreateMissingIdentifierName(); expression = WithDiagnostic(expression, DiagnosticId.ConstantExpected); } else { expression = ParseExpression(); } colon = Match(SyntaxKind.ColonToken); label = new CaseSwitchLabelSyntax(specifier, expression, colon); } else { Debug.Assert(Current.Kind == SyntaxKind.DefaultKeyword); specifier = Match(SyntaxKind.DefaultKeyword); colon = Match(SyntaxKind.ColonToken); label = new DefaultSwitchLabelSyntax(specifier, colon); } labels.Add(label); }while (IsPossibleSwitchSection()); // Next, parse statement list stopping for new sections ParseStatements(statements, true); return(new SwitchSectionSyntax(labels, statements)); }
private static BoundPatternSwitchSection BindPatternSwitchSection(BoundExpression boundSwitchExpression, SwitchSectionSyntax node, Binder originalBinder, ref DefaultSwitchLabelSyntax defaultLabel, DiagnosticBag diagnostics) { // Bind match section labels var boundLabelsBuilder = ArrayBuilder<BoundPatternSwitchLabel>.GetInstance(); var sectionBinder = originalBinder.GetBinder(node); // this binder can bind pattern variables from the section. Debug.Assert(sectionBinder != null); foreach (var labelSyntax in node.Labels) { BoundPatternSwitchLabel boundLabel = BindPatternSwitchSectionLabel(sectionBinder, boundSwitchExpression, labelSyntax, ref defaultLabel, diagnostics); boundLabelsBuilder.Add(boundLabel); } // Bind switch section statements var boundStatementsBuilder = ArrayBuilder<BoundStatement>.GetInstance(); foreach (var statement in node.Statements) { boundStatementsBuilder.Add(sectionBinder.BindStatement(statement, diagnostics)); } return new BoundPatternSwitchSection(node, sectionBinder.GetDeclaredLocalsForScope(node), boundLabelsBuilder.ToImmutableAndFree(), boundStatementsBuilder.ToImmutableAndFree()); }
private static BoundPatternSwitchLabel BindPatternSwitchSectionLabel(Binder sectionBinder, BoundExpression boundSwitchExpression, SwitchLabelSyntax node, ref DefaultSwitchLabelSyntax defaultLabel, DiagnosticBag diagnostics) { switch (node.Kind()) { case SyntaxKind.CasePatternSwitchLabel: { var matchLabelSyntax = (CasePatternSwitchLabelSyntax)node; var pattern = sectionBinder.BindPattern( matchLabelSyntax.Pattern, boundSwitchExpression, boundSwitchExpression.Type, node.HasErrors, diagnostics, wasSwitchCase: true); return new BoundPatternSwitchLabel(node, pattern, matchLabelSyntax.WhenClause != null ? sectionBinder.BindBooleanExpression(matchLabelSyntax.WhenClause.Condition, diagnostics) : null, node.HasErrors); } case SyntaxKind.CaseSwitchLabel: { var caseLabelSyntax = (CaseSwitchLabelSyntax)node; bool wasExpression; var pattern = sectionBinder.BindConstantPattern( node, boundSwitchExpression, boundSwitchExpression.Type, caseLabelSyntax.Value, node.HasErrors, diagnostics, out wasExpression, wasSwitchCase: true); return new BoundPatternSwitchLabel(node, pattern, null, node.HasErrors); } case SyntaxKind.DefaultSwitchLabel: { var defaultLabelSyntax = (DefaultSwitchLabelSyntax)node; var pattern = new BoundWildcardPattern(node); if (defaultLabel != null) { diagnostics.Add(ErrorCode.ERR_DuplicateCaseLabel, node.Location, "default"); } defaultLabel = defaultLabelSyntax; return new BoundPatternSwitchLabel(node, pattern, null, node.HasErrors); // note that this is semantically last! } default: throw ExceptionUtilities.Unreachable; } }
public override void VisitSwitchSection(SwitchSectionSyntax node) { for (int i = 0; i < node.Labels.Count; i++) { if (node.Labels[i] is CaseSwitchLabelSyntax) { CaseSwitchLabelSyntax switchLabelSyntax = node.Labels[i] as CaseSwitchLabelSyntax; Emit(string.Format("{0} {1}:", switchLabelSyntax.Keyword.Text, switchLabelSyntax.Value)); } else { DefaultSwitchLabelSyntax switchLabelSyntax = node.Labels[i] as DefaultSwitchLabelSyntax; Emit(string.Format("{0}:", switchLabelSyntax.Keyword.Text)); } } using (IndentedBracketScope()) { base.VisitSwitchSection(node); } Emit("break;"); }
public override SyntaxNode VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) { node = (DefaultSwitchLabelSyntax)base.VisitDefaultSwitchLabel(node); Classes.Add(node); return(node); }
public virtual void VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) { DefaultVisit(node); }
public override void VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) { throw new NotImplementedException(); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) { this.OnNodeVisited(node); if (!this.traverseRootOnly) base.VisitDefaultSwitchLabel(node); }
public static void Write(this DefaultSwitchLabelSyntax syntax, IIndentedTextWriterWrapper textWriter, IContext context) { textWriter.Write("true"); }
public override void VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) { LastWhen = new ApexWhenElseClauseSyntax(); }
public override Evaluation VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) { return(base.VisitDefaultSwitchLabel(node)); }
public DefaultSwitchLabelTranslation(DefaultSwitchLabelSyntax syntax, SyntaxTranslation parent) : base(syntax, parent) { }
public override void VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) => base.VisitDefaultSwitchLabel(node);
private static BoundPatternSwitchLabel BindPatternSwitchSectionLabel(Binder sectionBinder, BoundExpression boundSwitchExpression, SwitchLabelSyntax node, ref DefaultSwitchLabelSyntax defaultLabel, DiagnosticBag diagnostics) { switch (node.Kind()) { case SyntaxKind.CasePatternSwitchLabel: { var matchLabelSyntax = (CasePatternSwitchLabelSyntax)node; var pattern = sectionBinder.BindPattern( matchLabelSyntax.Pattern, boundSwitchExpression, boundSwitchExpression.Type, node.HasErrors, diagnostics, wasSwitchCase: true); return(new BoundPatternSwitchLabel(node, pattern, matchLabelSyntax.WhenClause != null ? sectionBinder.BindBooleanExpression(matchLabelSyntax.WhenClause.Condition, diagnostics) : null, node.HasErrors)); } case SyntaxKind.CaseSwitchLabel: { var caseLabelSyntax = (CaseSwitchLabelSyntax)node; bool wasExpression; var pattern = sectionBinder.BindConstantPattern( node, boundSwitchExpression, boundSwitchExpression.Type, caseLabelSyntax.Value, node.HasErrors, diagnostics, out wasExpression, wasSwitchCase: true); return(new BoundPatternSwitchLabel(node, pattern, null, node.HasErrors)); } case SyntaxKind.DefaultSwitchLabel: { var defaultLabelSyntax = (DefaultSwitchLabelSyntax)node; var pattern = new BoundWildcardPattern(node); if (defaultLabel != null) { diagnostics.Add(ErrorCode.ERR_DuplicateCaseLabel, node.Location, "default"); } defaultLabel = defaultLabelSyntax; return(new BoundPatternSwitchLabel(node, pattern, null, node.HasErrors)); // note that this is semantically last! } default: throw ExceptionUtilities.Unreachable; } }
private static BoundPatternSwitchSection BindPatternSwitchSection(BoundExpression boundSwitchExpression, SwitchSectionSyntax node, Binder originalBinder, ref DefaultSwitchLabelSyntax defaultLabel, DiagnosticBag diagnostics) { // Bind match section labels var boundLabelsBuilder = ArrayBuilder <BoundPatternSwitchLabel> .GetInstance(); var sectionBinder = originalBinder.GetBinder(node); // this binder can bind pattern variables from the section. Debug.Assert(sectionBinder != null); foreach (var labelSyntax in node.Labels) { BoundPatternSwitchLabel boundLabel = BindPatternSwitchSectionLabel(sectionBinder, boundSwitchExpression, labelSyntax, ref defaultLabel, diagnostics); boundLabelsBuilder.Add(boundLabel); } // Bind switch section statements var boundStatementsBuilder = ArrayBuilder <BoundStatement> .GetInstance(); foreach (var statement in node.Statements) { boundStatementsBuilder.Add(sectionBinder.BindStatement(statement, diagnostics)); } return(new BoundPatternSwitchSection(node, sectionBinder.GetDeclaredLocalsForScope(node), boundLabelsBuilder.ToImmutableAndFree(), boundStatementsBuilder.ToImmutableAndFree())); }
private ImmutableArray <BoundPatternSwitchSection> BindPatternSwitchSections(BoundExpression boundSwitchExpression, SyntaxList <SwitchSectionSyntax> sections, Binder originalBinder, ref DefaultSwitchLabelSyntax defaultLabel, DiagnosticBag diagnostics) { // Bind match sections var boundPatternSwitchSectionsBuilder = ArrayBuilder <BoundPatternSwitchSection> .GetInstance(); foreach (var sectionSyntax in sections) { boundPatternSwitchSectionsBuilder.Add(BindPatternSwitchSection(boundSwitchExpression, sectionSyntax, originalBinder, ref defaultLabel, diagnostics)); } return(boundPatternSwitchSectionsBuilder.ToImmutableAndFree()); }
private SwitchSectionSyntax ParseSwitchSection() { // First, parse case label(s) var labels = new List<SwitchLabelSyntax>(); var statements = new List<StatementSyntax>(); do { SyntaxToken specifier; SwitchLabelSyntax label; SyntaxToken colon; if (Current.Kind == SyntaxKind.CaseKeyword) { ExpressionSyntax expression; specifier = NextToken(); if (Current.Kind == SyntaxKind.ColonToken) { expression = CreateMissingIdentifierName(); expression = WithDiagnostic(expression, DiagnosticId.ConstantExpected); } else { expression = ParseExpression(); } colon = Match(SyntaxKind.ColonToken); label = new CaseSwitchLabelSyntax(specifier, expression, colon); } else { Debug.Assert(Current.Kind == SyntaxKind.DefaultKeyword); specifier = Match(SyntaxKind.DefaultKeyword); colon = Match(SyntaxKind.ColonToken); label = new DefaultSwitchLabelSyntax(specifier, colon); } labels.Add(label); } while (IsPossibleSwitchSection()); // Next, parse statement list stopping for new sections ParseStatements(statements, true); return new SwitchSectionSyntax(labels, statements); }
public TameDefaultSwitchLabelSyntax(DefaultSwitchLabelSyntax node) { Node = node; AddChildren(); }
public override void VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) { _currentNode = new Literal("default"); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) { this.OnNodeVisited(node, this.type.IsInstanceOfType(node)); base.VisitDefaultSwitchLabel(node); }
public override void VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) { }
public override Ust VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) { return(new IdToken(node.Keyword.Text, node.GetTextSpan())); }
public static Doc Print(DefaultSwitchLabelSyntax node) { return(Doc.Concat(Token.Print(node.Keyword), Token.Print(node.ColonToken))); }
public override UstNode VisitDefaultSwitchLabel(DefaultSwitchLabelSyntax node) { return(null); }