127 lines
4.4 KiB
C#
127 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Roslyn.Utilities;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax;
|
|
|
|
internal sealed class DeclarationPatternSyntax : PatternSyntax
|
|
{
|
|
internal readonly TypeSyntax type;
|
|
|
|
internal readonly VariableDesignationSyntax designation;
|
|
|
|
public TypeSyntax Type => type;
|
|
|
|
public VariableDesignationSyntax Designation => designation;
|
|
|
|
internal DeclarationPatternSyntax(SyntaxKind kind, TypeSyntax type, VariableDesignationSyntax designation, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations)
|
|
: base(kind, diagnostics, annotations)
|
|
{
|
|
((GreenNode)this).SlotCount = 2;
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)type);
|
|
this.type = type;
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)designation);
|
|
this.designation = designation;
|
|
}
|
|
|
|
internal DeclarationPatternSyntax(SyntaxKind kind, TypeSyntax type, VariableDesignationSyntax designation, SyntaxFactoryContext context)
|
|
: base(kind)
|
|
{
|
|
SetFactoryContext(context);
|
|
((GreenNode)this).SlotCount = 2;
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)type);
|
|
this.type = type;
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)designation);
|
|
this.designation = designation;
|
|
}
|
|
|
|
internal DeclarationPatternSyntax(SyntaxKind kind, TypeSyntax type, VariableDesignationSyntax designation)
|
|
: base(kind)
|
|
{
|
|
((GreenNode)this).SlotCount = 2;
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)type);
|
|
this.type = type;
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)designation);
|
|
this.designation = designation;
|
|
}
|
|
|
|
internal override GreenNode? GetSlot(int index)
|
|
{
|
|
return (GreenNode?)(index switch
|
|
{
|
|
0 => type,
|
|
1 => designation,
|
|
_ => null,
|
|
});
|
|
}
|
|
|
|
internal override SyntaxNode CreateRed(SyntaxNode? parent, int position)
|
|
{
|
|
return (SyntaxNode)(object)new Microsoft.CodeAnalysis.CSharp.Syntax.DeclarationPatternSyntax(this, parent, position);
|
|
}
|
|
|
|
public override void Accept(CSharpSyntaxVisitor visitor)
|
|
{
|
|
visitor.VisitDeclarationPattern(this);
|
|
}
|
|
|
|
public override TResult Accept<TResult>(CSharpSyntaxVisitor<TResult> visitor)
|
|
{
|
|
return visitor.VisitDeclarationPattern(this);
|
|
}
|
|
|
|
public DeclarationPatternSyntax Update(TypeSyntax type, VariableDesignationSyntax designation)
|
|
{
|
|
if (type != Type || designation != Designation)
|
|
{
|
|
DeclarationPatternSyntax declarationPatternSyntax = SyntaxFactory.DeclarationPattern(type, designation);
|
|
DiagnosticInfo[] diagnostics = ((GreenNode)this).GetDiagnostics();
|
|
if (diagnostics != null && diagnostics.Length != 0)
|
|
{
|
|
declarationPatternSyntax = GreenNodeExtensions.WithDiagnosticsGreen<DeclarationPatternSyntax>(declarationPatternSyntax, diagnostics);
|
|
}
|
|
SyntaxAnnotation[] annotations = ((GreenNode)this).GetAnnotations();
|
|
if (annotations != null && annotations.Length != 0)
|
|
{
|
|
declarationPatternSyntax = GreenNodeExtensions.WithAnnotationsGreen<DeclarationPatternSyntax>(declarationPatternSyntax, (IEnumerable<SyntaxAnnotation>)annotations);
|
|
}
|
|
return declarationPatternSyntax;
|
|
}
|
|
return this;
|
|
}
|
|
|
|
internal override GreenNode SetDiagnostics(DiagnosticInfo[]? diagnostics)
|
|
{
|
|
return (GreenNode)(object)new DeclarationPatternSyntax(base.Kind, type, designation, diagnostics, ((GreenNode)this).GetAnnotations());
|
|
}
|
|
|
|
internal override GreenNode SetAnnotations(SyntaxAnnotation[]? annotations)
|
|
{
|
|
return (GreenNode)(object)new DeclarationPatternSyntax(base.Kind, type, designation, ((GreenNode)this).GetDiagnostics(), annotations);
|
|
}
|
|
|
|
internal DeclarationPatternSyntax(ObjectReader reader)
|
|
: base(reader)
|
|
{
|
|
((GreenNode)this).SlotCount = 2;
|
|
TypeSyntax typeSyntax = (TypeSyntax)reader.ReadValue();
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)typeSyntax);
|
|
type = typeSyntax;
|
|
VariableDesignationSyntax variableDesignationSyntax = (VariableDesignationSyntax)reader.ReadValue();
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)variableDesignationSyntax);
|
|
designation = variableDesignationSyntax;
|
|
}
|
|
|
|
internal override void WriteTo(ObjectWriter writer)
|
|
{
|
|
((GreenNode)this).WriteTo(writer);
|
|
writer.WriteValue((IObjectWritable)(object)type);
|
|
writer.WriteValue((IObjectWritable)(object)designation);
|
|
}
|
|
|
|
static DeclarationPatternSyntax()
|
|
{
|
|
ObjectBinder.RegisterTypeReader(typeof(DeclarationPatternSyntax), (Func<ObjectReader, IObjectWritable>)((ObjectReader r) => (IObjectWritable)(object)new DeclarationPatternSyntax(r)));
|
|
}
|
|
}
|