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