181 lines
6.2 KiB
C#
181 lines
6.2 KiB
C#
using System;
|
|||
|
|
using System.Collections.Generic;
|
||
|
|
using Roslyn.Utilities;
|
||
|
|
|
||
|
|
namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax;
|
||
|
|
|
||
|
|
internal sealed class CatchClauseSyntax : CSharpSyntaxNode
|
||
|
|
{
|
||
|
|
internal readonly SyntaxToken catchKeyword;
|
||
|
|
|
||
|
|
internal readonly CatchDeclarationSyntax? declaration;
|
||
|
|
|
||
|
|
internal readonly CatchFilterClauseSyntax? filter;
|
||
|
|
|
||
|
|
internal readonly BlockSyntax block;
|
||
|
|
|
||
|
|
public SyntaxToken CatchKeyword => catchKeyword;
|
||
|
|
|
||
|
|
public CatchDeclarationSyntax? Declaration => declaration;
|
||
|
|
|
||
|
|
public CatchFilterClauseSyntax? Filter => filter;
|
||
|
|
|
||
|
|
public BlockSyntax Block => block;
|
||
|
|
|
||
|
|
internal CatchClauseSyntax(SyntaxKind kind, SyntaxToken catchKeyword, CatchDeclarationSyntax? declaration, CatchFilterClauseSyntax? filter, BlockSyntax block, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations)
|
||
|
|
: base(kind, diagnostics, annotations)
|
||
|
|
{
|
||
|
|
((GreenNode)this).SlotCount = 4;
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)catchKeyword);
|
||
|
|
this.catchKeyword = catchKeyword;
|
||
|
|
if (declaration != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)declaration);
|
||
|
|
this.declaration = declaration;
|
||
|
|
}
|
||
|
|
if (filter != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)filter);
|
||
|
|
this.filter = filter;
|
||
|
|
}
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)block);
|
||
|
|
this.block = block;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal CatchClauseSyntax(SyntaxKind kind, SyntaxToken catchKeyword, CatchDeclarationSyntax? declaration, CatchFilterClauseSyntax? filter, BlockSyntax block, SyntaxFactoryContext context)
|
||
|
|
: base(kind)
|
||
|
|
{
|
||
|
|
SetFactoryContext(context);
|
||
|
|
((GreenNode)this).SlotCount = 4;
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)catchKeyword);
|
||
|
|
this.catchKeyword = catchKeyword;
|
||
|
|
if (declaration != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)declaration);
|
||
|
|
this.declaration = declaration;
|
||
|
|
}
|
||
|
|
if (filter != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)filter);
|
||
|
|
this.filter = filter;
|
||
|
|
}
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)block);
|
||
|
|
this.block = block;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal CatchClauseSyntax(SyntaxKind kind, SyntaxToken catchKeyword, CatchDeclarationSyntax? declaration, CatchFilterClauseSyntax? filter, BlockSyntax block)
|
||
|
|
: base(kind)
|
||
|
|
{
|
||
|
|
((GreenNode)this).SlotCount = 4;
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)catchKeyword);
|
||
|
|
this.catchKeyword = catchKeyword;
|
||
|
|
if (declaration != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)declaration);
|
||
|
|
this.declaration = declaration;
|
||
|
|
}
|
||
|
|
if (filter != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)filter);
|
||
|
|
this.filter = filter;
|
||
|
|
}
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)block);
|
||
|
|
this.block = block;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override GreenNode? GetSlot(int index)
|
||
|
|
{
|
||
|
|
return (GreenNode?)(index switch
|
||
|
|
{
|
||
|
|
0 => catchKeyword,
|
||
|
|
1 => declaration,
|
||
|
|
2 => filter,
|
||
|
|
3 => block,
|
||
|
|
_ => null,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override SyntaxNode CreateRed(SyntaxNode? parent, int position)
|
||
|
|
{
|
||
|
|
return (SyntaxNode)(object)new Microsoft.CodeAnalysis.CSharp.Syntax.CatchClauseSyntax(this, parent, position);
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void Accept(CSharpSyntaxVisitor visitor)
|
||
|
|
{
|
||
|
|
visitor.VisitCatchClause(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
public override TResult Accept<TResult>(CSharpSyntaxVisitor<TResult> visitor)
|
||
|
|
{
|
||
|
|
return visitor.VisitCatchClause(this);
|
||
|
|
}
|
||
|
|
|
||
|
|
public CatchClauseSyntax Update(SyntaxToken catchKeyword, CatchDeclarationSyntax declaration, CatchFilterClauseSyntax filter, BlockSyntax block)
|
||
|
|
{
|
||
|
|
if (catchKeyword != CatchKeyword || declaration != Declaration || filter != Filter || block != Block)
|
||
|
|
{
|
||
|
|
CatchClauseSyntax catchClauseSyntax = SyntaxFactory.CatchClause(catchKeyword, declaration, filter, block);
|
||
|
|
DiagnosticInfo[] diagnostics = ((GreenNode)this).GetDiagnostics();
|
||
|
|
if (diagnostics != null && diagnostics.Length != 0)
|
||
|
|
{
|
||
|
|
catchClauseSyntax = GreenNodeExtensions.WithDiagnosticsGreen<CatchClauseSyntax>(catchClauseSyntax, diagnostics);
|
||
|
|
}
|
||
|
|
SyntaxAnnotation[] annotations = ((GreenNode)this).GetAnnotations();
|
||
|
|
if (annotations != null && annotations.Length != 0)
|
||
|
|
{
|
||
|
|
catchClauseSyntax = GreenNodeExtensions.WithAnnotationsGreen<CatchClauseSyntax>(catchClauseSyntax, (IEnumerable<SyntaxAnnotation>)annotations);
|
||
|
|
}
|
||
|
|
return catchClauseSyntax;
|
||
|
|
}
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override GreenNode SetDiagnostics(DiagnosticInfo[]? diagnostics)
|
||
|
|
{
|
||
|
|
return (GreenNode)(object)new CatchClauseSyntax(base.Kind, catchKeyword, declaration, filter, block, diagnostics, ((GreenNode)this).GetAnnotations());
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override GreenNode SetAnnotations(SyntaxAnnotation[]? annotations)
|
||
|
|
{
|
||
|
|
return (GreenNode)(object)new CatchClauseSyntax(base.Kind, catchKeyword, declaration, filter, block, ((GreenNode)this).GetDiagnostics(), annotations);
|
||
|
|
}
|
||
|
|
|
||
|
|
internal CatchClauseSyntax(ObjectReader reader)
|
||
|
|
: base(reader)
|
||
|
|
{
|
||
|
|
((GreenNode)this).SlotCount = 4;
|
||
|
|
SyntaxToken syntaxToken = (SyntaxToken)reader.ReadValue();
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)syntaxToken);
|
||
|
|
catchKeyword = syntaxToken;
|
||
|
|
CatchDeclarationSyntax catchDeclarationSyntax = (CatchDeclarationSyntax)reader.ReadValue();
|
||
|
|
if (catchDeclarationSyntax != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)catchDeclarationSyntax);
|
||
|
|
declaration = catchDeclarationSyntax;
|
||
|
|
}
|
||
|
|
CatchFilterClauseSyntax catchFilterClauseSyntax = (CatchFilterClauseSyntax)reader.ReadValue();
|
||
|
|
if (catchFilterClauseSyntax != null)
|
||
|
|
{
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)catchFilterClauseSyntax);
|
||
|
|
filter = catchFilterClauseSyntax;
|
||
|
|
}
|
||
|
|
BlockSyntax blockSyntax = (BlockSyntax)reader.ReadValue();
|
||
|
|
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)blockSyntax);
|
||
|
|
block = blockSyntax;
|
||
|
|
}
|
||
|
|
|
||
|
|
internal override void WriteTo(ObjectWriter writer)
|
||
|
|
{
|
||
|
|
((GreenNode)this).WriteTo(writer);
|
||
|
|
writer.WriteValue((IObjectWritable)(object)catchKeyword);
|
||
|
|
writer.WriteValue((IObjectWritable)(object)declaration);
|
||
|
|
writer.WriteValue((IObjectWritable)(object)filter);
|
||
|
|
writer.WriteValue((IObjectWritable)(object)block);
|
||
|
|
}
|
||
|
|
|
||
|
|
static CatchClauseSyntax()
|
||
|
|
{
|
||
|
|
ObjectBinder.RegisterTypeReader(typeof(CatchClauseSyntax), (Func<ObjectReader, IObjectWritable>)((ObjectReader r) => (IObjectWritable)(object)new CatchClauseSyntax(r)));
|
||
|
|
}
|
||
|
|
}
|