Files

151 lines
5.7 KiB
C#
Raw Permalink Normal View History

2026-08-27 10:56:38 -06:00
using System;
using System.Collections.Generic;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax;
internal sealed class BadDirectiveTriviaSyntax : DirectiveTriviaSyntax
{
internal readonly SyntaxToken hashToken;
internal readonly SyntaxToken identifier;
internal readonly SyntaxToken endOfDirectiveToken;
internal readonly bool isActive;
public override SyntaxToken HashToken => hashToken;
public SyntaxToken Identifier => identifier;
public override SyntaxToken EndOfDirectiveToken => endOfDirectiveToken;
public override bool IsActive => isActive;
internal BadDirectiveTriviaSyntax(SyntaxKind kind, SyntaxToken hashToken, SyntaxToken identifier, SyntaxToken endOfDirectiveToken, bool isActive, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations)
: base(kind, diagnostics, annotations)
{
((GreenNode)this).SlotCount = 3;
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)hashToken);
this.hashToken = hashToken;
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)identifier);
this.identifier = identifier;
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)endOfDirectiveToken);
this.endOfDirectiveToken = endOfDirectiveToken;
this.isActive = isActive;
}
internal BadDirectiveTriviaSyntax(SyntaxKind kind, SyntaxToken hashToken, SyntaxToken identifier, SyntaxToken endOfDirectiveToken, bool isActive, SyntaxFactoryContext context)
: base(kind)
{
SetFactoryContext(context);
((GreenNode)this).SlotCount = 3;
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)hashToken);
this.hashToken = hashToken;
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)identifier);
this.identifier = identifier;
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)endOfDirectiveToken);
this.endOfDirectiveToken = endOfDirectiveToken;
this.isActive = isActive;
}
internal BadDirectiveTriviaSyntax(SyntaxKind kind, SyntaxToken hashToken, SyntaxToken identifier, SyntaxToken endOfDirectiveToken, bool isActive)
: base(kind)
{
((GreenNode)this).SlotCount = 3;
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)hashToken);
this.hashToken = hashToken;
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)identifier);
this.identifier = identifier;
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)endOfDirectiveToken);
this.endOfDirectiveToken = endOfDirectiveToken;
this.isActive = isActive;
}
internal override GreenNode? GetSlot(int index)
{
return (GreenNode?)(index switch
{
0 => hashToken,
1 => identifier,
2 => endOfDirectiveToken,
_ => null,
});
}
internal override SyntaxNode CreateRed(SyntaxNode? parent, int position)
{
return (SyntaxNode)(object)new Microsoft.CodeAnalysis.CSharp.Syntax.BadDirectiveTriviaSyntax(this, parent, position);
}
public override void Accept(CSharpSyntaxVisitor visitor)
{
visitor.VisitBadDirectiveTrivia(this);
}
public override TResult Accept<TResult>(CSharpSyntaxVisitor<TResult> visitor)
{
return visitor.VisitBadDirectiveTrivia(this);
}
public BadDirectiveTriviaSyntax Update(SyntaxToken hashToken, SyntaxToken identifier, SyntaxToken endOfDirectiveToken, bool isActive)
{
if (hashToken != HashToken || identifier != Identifier || endOfDirectiveToken != EndOfDirectiveToken)
{
BadDirectiveTriviaSyntax badDirectiveTriviaSyntax = SyntaxFactory.BadDirectiveTrivia(hashToken, identifier, endOfDirectiveToken, isActive);
DiagnosticInfo[] diagnostics = ((GreenNode)this).GetDiagnostics();
if (diagnostics != null && diagnostics.Length != 0)
{
badDirectiveTriviaSyntax = GreenNodeExtensions.WithDiagnosticsGreen<BadDirectiveTriviaSyntax>(badDirectiveTriviaSyntax, diagnostics);
}
SyntaxAnnotation[] annotations = ((GreenNode)this).GetAnnotations();
if (annotations != null && annotations.Length != 0)
{
badDirectiveTriviaSyntax = GreenNodeExtensions.WithAnnotationsGreen<BadDirectiveTriviaSyntax>(badDirectiveTriviaSyntax, (IEnumerable<SyntaxAnnotation>)annotations);
}
return badDirectiveTriviaSyntax;
}
return this;
}
internal override GreenNode SetDiagnostics(DiagnosticInfo[]? diagnostics)
{
return (GreenNode)(object)new BadDirectiveTriviaSyntax(base.Kind, hashToken, identifier, endOfDirectiveToken, isActive, diagnostics, ((GreenNode)this).GetAnnotations());
}
internal override GreenNode SetAnnotations(SyntaxAnnotation[]? annotations)
{
return (GreenNode)(object)new BadDirectiveTriviaSyntax(base.Kind, hashToken, identifier, endOfDirectiveToken, isActive, ((GreenNode)this).GetDiagnostics(), annotations);
}
internal BadDirectiveTriviaSyntax(ObjectReader reader)
: base(reader)
{
((GreenNode)this).SlotCount = 3;
SyntaxToken syntaxToken = (SyntaxToken)reader.ReadValue();
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)syntaxToken);
hashToken = syntaxToken;
SyntaxToken syntaxToken2 = (SyntaxToken)reader.ReadValue();
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)syntaxToken2);
identifier = syntaxToken2;
SyntaxToken syntaxToken3 = (SyntaxToken)reader.ReadValue();
((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)syntaxToken3);
endOfDirectiveToken = syntaxToken3;
isActive = reader.ReadBoolean();
}
internal override void WriteTo(ObjectWriter writer)
{
((GreenNode)this).WriteTo(writer);
writer.WriteValue((IObjectWritable)(object)hashToken);
writer.WriteValue((IObjectWritable)(object)identifier);
writer.WriteValue((IObjectWritable)(object)endOfDirectiveToken);
writer.WriteBoolean(isActive);
}
static BadDirectiveTriviaSyntax()
{
ObjectBinder.RegisterTypeReader(typeof(BadDirectiveTriviaSyntax), (Func<ObjectReader, IObjectWritable>)((ObjectReader r) => (IObjectWritable)(object)new BadDirectiveTriviaSyntax(r)));
}
}