using System; using System.Collections.Generic; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax; internal sealed class IfDirectiveTriviaSyntax : ConditionalDirectiveTriviaSyntax { internal readonly SyntaxToken hashToken; internal readonly SyntaxToken ifKeyword; internal readonly ExpressionSyntax condition; internal readonly SyntaxToken endOfDirectiveToken; internal readonly bool isActive; internal readonly bool branchTaken; internal readonly bool conditionValue; public override SyntaxToken HashToken => hashToken; public SyntaxToken IfKeyword => ifKeyword; public override ExpressionSyntax Condition => condition; public override SyntaxToken EndOfDirectiveToken => endOfDirectiveToken; public override bool IsActive => isActive; public override bool BranchTaken => branchTaken; public override bool ConditionValue => conditionValue; internal IfDirectiveTriviaSyntax(SyntaxKind kind, SyntaxToken hashToken, SyntaxToken ifKeyword, ExpressionSyntax condition, SyntaxToken endOfDirectiveToken, bool isActive, bool branchTaken, bool conditionValue, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations) : base(kind, diagnostics, annotations) { ((GreenNode)this).SlotCount = 4; ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)hashToken); this.hashToken = hashToken; ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)ifKeyword); this.ifKeyword = ifKeyword; ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)condition); this.condition = condition; ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)endOfDirectiveToken); this.endOfDirectiveToken = endOfDirectiveToken; this.isActive = isActive; this.branchTaken = branchTaken; this.conditionValue = conditionValue; } internal IfDirectiveTriviaSyntax(SyntaxKind kind, SyntaxToken hashToken, SyntaxToken ifKeyword, ExpressionSyntax condition, SyntaxToken endOfDirectiveToken, bool isActive, bool branchTaken, bool conditionValue, SyntaxFactoryContext context) : base(kind) { SetFactoryContext(context); ((GreenNode)this).SlotCount = 4; ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)hashToken); this.hashToken = hashToken; ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)ifKeyword); this.ifKeyword = ifKeyword; ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)condition); this.condition = condition; ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)endOfDirectiveToken); this.endOfDirectiveToken = endOfDirectiveToken; this.isActive = isActive; this.branchTaken = branchTaken; this.conditionValue = conditionValue; } internal IfDirectiveTriviaSyntax(SyntaxKind kind, SyntaxToken hashToken, SyntaxToken ifKeyword, ExpressionSyntax condition, SyntaxToken endOfDirectiveToken, bool isActive, bool branchTaken, bool conditionValue) : base(kind) { ((GreenNode)this).SlotCount = 4; ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)hashToken); this.hashToken = hashToken; ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)ifKeyword); this.ifKeyword = ifKeyword; ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)condition); this.condition = condition; ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)endOfDirectiveToken); this.endOfDirectiveToken = endOfDirectiveToken; this.isActive = isActive; this.branchTaken = branchTaken; this.conditionValue = conditionValue; } internal override GreenNode? GetSlot(int index) { return (GreenNode?)(index switch { 0 => hashToken, 1 => ifKeyword, 2 => condition, 3 => endOfDirectiveToken, _ => null, }); } internal override SyntaxNode CreateRed(SyntaxNode? parent, int position) { return (SyntaxNode)(object)new Microsoft.CodeAnalysis.CSharp.Syntax.IfDirectiveTriviaSyntax(this, parent, position); } public override void Accept(CSharpSyntaxVisitor visitor) { visitor.VisitIfDirectiveTrivia(this); } public override TResult Accept(CSharpSyntaxVisitor visitor) { return visitor.VisitIfDirectiveTrivia(this); } public IfDirectiveTriviaSyntax Update(SyntaxToken hashToken, SyntaxToken ifKeyword, ExpressionSyntax condition, SyntaxToken endOfDirectiveToken, bool isActive, bool branchTaken, bool conditionValue) { if (hashToken != HashToken || ifKeyword != IfKeyword || condition != Condition || endOfDirectiveToken != EndOfDirectiveToken) { IfDirectiveTriviaSyntax ifDirectiveTriviaSyntax = SyntaxFactory.IfDirectiveTrivia(hashToken, ifKeyword, condition, endOfDirectiveToken, isActive, branchTaken, conditionValue); DiagnosticInfo[] diagnostics = ((GreenNode)this).GetDiagnostics(); if (diagnostics != null && diagnostics.Length != 0) { ifDirectiveTriviaSyntax = GreenNodeExtensions.WithDiagnosticsGreen(ifDirectiveTriviaSyntax, diagnostics); } SyntaxAnnotation[] annotations = ((GreenNode)this).GetAnnotations(); if (annotations != null && annotations.Length != 0) { ifDirectiveTriviaSyntax = GreenNodeExtensions.WithAnnotationsGreen(ifDirectiveTriviaSyntax, (IEnumerable)annotations); } return ifDirectiveTriviaSyntax; } return this; } internal override GreenNode SetDiagnostics(DiagnosticInfo[]? diagnostics) { return (GreenNode)(object)new IfDirectiveTriviaSyntax(base.Kind, hashToken, ifKeyword, condition, endOfDirectiveToken, isActive, branchTaken, conditionValue, diagnostics, ((GreenNode)this).GetAnnotations()); } internal override GreenNode SetAnnotations(SyntaxAnnotation[]? annotations) { return (GreenNode)(object)new IfDirectiveTriviaSyntax(base.Kind, hashToken, ifKeyword, condition, endOfDirectiveToken, isActive, branchTaken, conditionValue, ((GreenNode)this).GetDiagnostics(), annotations); } internal IfDirectiveTriviaSyntax(ObjectReader reader) : base(reader) { ((GreenNode)this).SlotCount = 4; SyntaxToken syntaxToken = (SyntaxToken)reader.ReadValue(); ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)syntaxToken); hashToken = syntaxToken; SyntaxToken syntaxToken2 = (SyntaxToken)reader.ReadValue(); ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)syntaxToken2); ifKeyword = syntaxToken2; ExpressionSyntax expressionSyntax = (ExpressionSyntax)reader.ReadValue(); ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)expressionSyntax); condition = expressionSyntax; SyntaxToken syntaxToken3 = (SyntaxToken)reader.ReadValue(); ((GreenNode)this).AdjustFlagsAndWidth((GreenNode)(object)syntaxToken3); endOfDirectiveToken = syntaxToken3; isActive = reader.ReadBoolean(); branchTaken = reader.ReadBoolean(); conditionValue = reader.ReadBoolean(); } internal override void WriteTo(ObjectWriter writer) { ((GreenNode)this).WriteTo(writer); writer.WriteValue((IObjectWritable)(object)hashToken); writer.WriteValue((IObjectWritable)(object)ifKeyword); writer.WriteValue((IObjectWritable)(object)condition); writer.WriteValue((IObjectWritable)(object)endOfDirectiveToken); writer.WriteBoolean(isActive); writer.WriteBoolean(branchTaken); writer.WriteBoolean(conditionValue); } static IfDirectiveTriviaSyntax() { ObjectBinder.RegisterTypeReader(typeof(IfDirectiveTriviaSyntax), (Func)((ObjectReader r) => (IObjectWritable)(object)new IfDirectiveTriviaSyntax(r))); } }