149 lines
4.9 KiB
C#
149 lines
4.9 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 VariableDeclarationSyntax : CSharpSyntaxNode
|
|
{
|
|
internal readonly TypeSyntax type;
|
|
|
|
internal readonly GreenNode? variables;
|
|
|
|
public TypeSyntax Type => type;
|
|
|
|
public SeparatedSyntaxList<VariableDeclaratorSyntax> Variables => new SeparatedSyntaxList<VariableDeclaratorSyntax>(SyntaxList<CSharpSyntaxNode>.op_Implicit(new SyntaxList<CSharpSyntaxNode>(variables)));
|
|
|
|
internal VariableDeclarationSyntax(SyntaxKind kind, TypeSyntax type, GreenNode? variables, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations)
|
|
: base(kind, diagnostics, annotations)
|
|
{
|
|
((GreenNode)this).SlotCount = 2;
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)type);
|
|
this.type = type;
|
|
if (variables != null)
|
|
{
|
|
((GreenNode)this).AdjustFlagsAndWidth(variables);
|
|
this.variables = variables;
|
|
}
|
|
}
|
|
|
|
internal VariableDeclarationSyntax(SyntaxKind kind, TypeSyntax type, GreenNode? variables, SyntaxFactoryContext context)
|
|
: base(kind)
|
|
{
|
|
SetFactoryContext(context);
|
|
((GreenNode)this).SlotCount = 2;
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)type);
|
|
this.type = type;
|
|
if (variables != null)
|
|
{
|
|
((GreenNode)this).AdjustFlagsAndWidth(variables);
|
|
this.variables = variables;
|
|
}
|
|
}
|
|
|
|
internal VariableDeclarationSyntax(SyntaxKind kind, TypeSyntax type, GreenNode? variables)
|
|
: base(kind)
|
|
{
|
|
((GreenNode)this).SlotCount = 2;
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)type);
|
|
this.type = type;
|
|
if (variables != null)
|
|
{
|
|
((GreenNode)this).AdjustFlagsAndWidth(variables);
|
|
this.variables = variables;
|
|
}
|
|
}
|
|
|
|
internal override GreenNode? GetSlot(int index)
|
|
{
|
|
return (GreenNode?)(index switch
|
|
{
|
|
0 => type,
|
|
1 => variables,
|
|
_ => null,
|
|
});
|
|
}
|
|
|
|
internal override SyntaxNode CreateRed(SyntaxNode? parent, int position)
|
|
{
|
|
return (SyntaxNode)(object)new Microsoft.CodeAnalysis.CSharp.Syntax.VariableDeclarationSyntax(this, parent, position);
|
|
}
|
|
|
|
public override void Accept(CSharpSyntaxVisitor visitor)
|
|
{
|
|
visitor.VisitVariableDeclaration(this);
|
|
}
|
|
|
|
public override TResult Accept<TResult>(CSharpSyntaxVisitor<TResult> visitor)
|
|
{
|
|
return visitor.VisitVariableDeclaration(this);
|
|
}
|
|
|
|
public VariableDeclarationSyntax Update(TypeSyntax type, SeparatedSyntaxList<VariableDeclaratorSyntax> variables)
|
|
{
|
|
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
|
|
if (type == Type)
|
|
{
|
|
SeparatedSyntaxList<VariableDeclaratorSyntax> val = Variables;
|
|
if (!((ref variables) != (ref val)))
|
|
{
|
|
return this;
|
|
}
|
|
}
|
|
VariableDeclarationSyntax variableDeclarationSyntax = SyntaxFactory.VariableDeclaration(type, variables);
|
|
DiagnosticInfo[] diagnostics = ((GreenNode)this).GetDiagnostics();
|
|
if (diagnostics != null && diagnostics.Length != 0)
|
|
{
|
|
variableDeclarationSyntax = GreenNodeExtensions.WithDiagnosticsGreen<VariableDeclarationSyntax>(variableDeclarationSyntax, diagnostics);
|
|
}
|
|
SyntaxAnnotation[] annotations = ((GreenNode)this).GetAnnotations();
|
|
if (annotations != null && annotations.Length != 0)
|
|
{
|
|
variableDeclarationSyntax = GreenNodeExtensions.WithAnnotationsGreen<VariableDeclarationSyntax>(variableDeclarationSyntax, (IEnumerable<SyntaxAnnotation>)annotations);
|
|
}
|
|
return variableDeclarationSyntax;
|
|
}
|
|
|
|
internal override GreenNode SetDiagnostics(DiagnosticInfo[]? diagnostics)
|
|
{
|
|
return (GreenNode)(object)new VariableDeclarationSyntax(base.Kind, type, variables, diagnostics, ((GreenNode)this).GetAnnotations());
|
|
}
|
|
|
|
internal override GreenNode SetAnnotations(SyntaxAnnotation[]? annotations)
|
|
{
|
|
return (GreenNode)(object)new VariableDeclarationSyntax(base.Kind, type, variables, ((GreenNode)this).GetDiagnostics(), annotations);
|
|
}
|
|
|
|
internal VariableDeclarationSyntax(ObjectReader reader)
|
|
: base(reader)
|
|
{
|
|
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0034: Expected O, but got Unknown
|
|
((GreenNode)this).SlotCount = 2;
|
|
TypeSyntax typeSyntax = (TypeSyntax)reader.ReadValue();
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)typeSyntax);
|
|
type = typeSyntax;
|
|
GreenNode val = (GreenNode)reader.ReadValue();
|
|
if (val != null)
|
|
{
|
|
((GreenNode)this).AdjustFlagsAndWidth(val);
|
|
variables = val;
|
|
}
|
|
}
|
|
|
|
internal override void WriteTo(ObjectWriter writer)
|
|
{
|
|
((GreenNode)this).WriteTo(writer);
|
|
writer.WriteValue((IObjectWritable)(object)type);
|
|
writer.WriteValue((IObjectWritable)(object)variables);
|
|
}
|
|
|
|
static VariableDeclarationSyntax()
|
|
{
|
|
ObjectBinder.RegisterTypeReader(typeof(VariableDeclarationSyntax), (Func<ObjectReader, IObjectWritable>)((ObjectReader r) => (IObjectWritable)(object)new VariableDeclarationSyntax(r)));
|
|
}
|
|
}
|