162 lines
5.1 KiB
C#
162 lines
5.1 KiB
C#
using System;
|
|||
|
|
using System.Collections.Generic;
|
||
|
|
using Microsoft.CodeAnalysis.Syntax.InternalSyntax;
|
||
|
|
using Roslyn.Utilities;
|
||
|
|
|
||
|
|
namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax;
|
||
|
|
|
||
|
|
internal sealed class SwitchSectionSyntax : CSharpSyntaxNode
|
||
|
|
{
|
||
|
|
internal readonly GreenNode? labels;
|
||
|
|
|
||
|
|
internal readonly GreenNode? statements;
|
||
|
|
|
||
|
|
public SyntaxList<SwitchLabelSyntax> Labels => new SyntaxList<SwitchLabelSyntax>(labels);
|
||
|
|
|
||
|
|
public SyntaxList<StatementSyntax> Statements => new SyntaxList<StatementSyntax>(statements);
|
||
|
|
|
||
|
|
internal SwitchSectionSyntax(SyntaxKind kind, GreenNode? labels, GreenNode? statements, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations)
|
||
|
|
: base(kind, diagnostics, annotations)
|
||
|
|
{
|
||
|
|
((GreenNode)this).SlotCount = 2;
|
||
|
|
if (labels != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth(labels);
|
||
|
|
this.labels = labels;
|
||
|
|
}
|
||
|
|
if (statements != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth(statements);
|
||
|
|
this.statements = statements;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
internal SwitchSectionSyntax(SyntaxKind kind, GreenNode? labels, GreenNode? statements, SyntaxFactoryContext context)
|
||
|
|
: base(kind)
|
||
|
|
{
|
||
|
|
SetFactoryContext(context);
|
||
|
|
((GreenNode)this).SlotCount = 2;
|
||
|
|
if (labels != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth(labels);
|
||
|
|
this.labels = labels;
|
||
|
|
}
|
||
|
|
if (statements != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth(statements);
|
||
|
|
this.statements = statements;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
internal SwitchSectionSyntax(SyntaxKind kind, GreenNode? labels, GreenNode? statements)
|
||
|
|
: base(kind)
|
||
|
|
{
|
||
|
|
((GreenNode)this).SlotCount = 2;
|
||
|
|
if (labels != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth(labels);
|
||
|
|
this.labels = labels;
|
||
|
|
}
|
||
|
|
if (statements != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth(statements);
|
||
|
|
this.statements = statements;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override GreenNode? GetSlot(int index)
|
||
|
|
{
|
||
|
|
return (GreenNode?)(index switch
|
||
|
|
{
|
||
|
|
0 => labels,
|
||
|
|
1 => statements,
|
||
|
|
_ => null,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override SyntaxNode CreateRed(SyntaxNode? parent, int position)
|
||
|
|
{
|
||
|
|
return (SyntaxNode)(object)new Microsoft.CodeAnalysis.CSharp.Syntax.SwitchSectionSyntax(this, parent, position);
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void Accept(CSharpSyntaxVisitor visitor)
|
||
|
|
{
|
||
|
|
visitor.VisitSwitchSection(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
public override TResult Accept<TResult>(CSharpSyntaxVisitor<TResult> visitor)
|
||
|
|
{
|
||
|
|
return visitor.VisitSwitchSection(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
public SwitchSectionSyntax Update(SyntaxList<SwitchLabelSyntax> labels, SyntaxList<StatementSyntax> statements)
|
||
|
|
{
|
||
|
|
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
if (labels != Labels || statements != Statements)
|
||
|
|
{
|
||
|
|
SwitchSectionSyntax switchSectionSyntax = SyntaxFactory.SwitchSection(labels, statements);
|
||
|
|
DiagnosticInfo[] diagnostics = ((GreenNode)this).GetDiagnostics();
|
||
|
|
if (diagnostics != null && diagnostics.Length != 0)
|
||
|
|
{
|
||
|
|
switchSectionSyntax = GreenNodeExtensions.WithDiagnosticsGreen<SwitchSectionSyntax>(switchSectionSyntax, diagnostics);
|
||
|
|
}
|
||
|
|
SyntaxAnnotation[] annotations = ((GreenNode)this).GetAnnotations();
|
||
|
|
if (annotations != null && annotations.Length != 0)
|
||
|
|
{
|
||
|
|
switchSectionSyntax = GreenNodeExtensions.WithAnnotationsGreen<SwitchSectionSyntax>(switchSectionSyntax, (IEnumerable<SyntaxAnnotation>)annotations);
|
||
|
|
}
|
||
|
|
return switchSectionSyntax;
|
||
|
|
}
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override GreenNode SetDiagnostics(DiagnosticInfo[]? diagnostics)
|
||
|
|
{
|
||
|
|
return (GreenNode)(object)new SwitchSectionSyntax(base.Kind, labels, statements, diagnostics, ((GreenNode)this).GetAnnotations());
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override GreenNode SetAnnotations(SyntaxAnnotation[]? annotations)
|
||
|
|
{
|
||
|
|
return (GreenNode)(object)new SwitchSectionSyntax(base.Kind, labels, statements, ((GreenNode)this).GetDiagnostics(), annotations);
|
||
|
|
}
|
||
|
|
|
||
|
|
internal SwitchSectionSyntax(ObjectReader reader)
|
||
|
|
: base(reader)
|
||
|
|
{
|
||
|
|
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_001a: Expected O, but got Unknown
|
||
|
|
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0037: Expected O, but got Unknown
|
||
|
|
((GreenNode)this).SlotCount = 2;
|
||
|
|
GreenNode val = (GreenNode)reader.ReadValue();
|
||
|
|
if (val != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth(val);
|
||
|
|
labels = val;
|
||
|
|
}
|
||
|
|
GreenNode val2 = (GreenNode)reader.ReadValue();
|
||
|
|
if (val2 != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth(val2);
|
||
|
|
statements = val2;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override void WriteTo(ObjectWriter writer)
|
||
|
|
{
|
||
|
|
((GreenNode)this).WriteTo(writer);
|
||
|
|
writer.WriteValue((IObjectWritable)(object)labels);
|
||
|
|
writer.WriteValue((IObjectWritable)(object)statements);
|
||
|
|
}
|
||
|
|
|
||
|
|
static SwitchSectionSyntax()
|
||
|
|
{
|
||
|
|
ObjectBinder.RegisterTypeReader(typeof(SwitchSectionSyntax), (Func<ObjectReader, IObjectWritable>)((ObjectReader r) => (IObjectWritable)(object)new SwitchSectionSyntax(r)));
|
||
|
|
}
|
||
|
|
}
|