Files

245 lines
12 KiB
C#
Raw Permalink Normal View History

2026-08-27 10:56:38 -06:00
using System;
using System.Collections.Generic;
using Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp.Syntax;
public sealed class CompilationUnitSyntax : CSharpSyntaxNode, ICompilationUnitSyntax
{
private SyntaxNode? externs;
private SyntaxNode? usings;
private SyntaxNode? attributeLists;
private SyntaxNode? members;
internal bool HasReferenceDirectives => HasFirstTokenDirective((SyntaxNode n) => n is ReferenceDirectiveTriviaSyntax);
internal bool HasLoadDirectives => HasFirstTokenDirective((SyntaxNode n) => n is LoadDirectiveTriviaSyntax);
public SyntaxList<ExternAliasDirectiveSyntax> Externs => new SyntaxList<ExternAliasDirectiveSyntax>(((SyntaxNode)this).GetRed(ref externs, 0));
public SyntaxList<UsingDirectiveSyntax> Usings => new SyntaxList<UsingDirectiveSyntax>(((SyntaxNode)this).GetRed(ref usings, 1));
public SyntaxList<AttributeListSyntax> AttributeLists => new SyntaxList<AttributeListSyntax>(((SyntaxNode)this).GetRed(ref attributeLists, 2));
public SyntaxList<MemberDeclarationSyntax> Members => new SyntaxList<MemberDeclarationSyntax>(((SyntaxNode)this).GetRed(ref members, 3));
public SyntaxToken EndOfFileToken => new SyntaxToken((SyntaxNode)(object)this, (GreenNode)(object)((Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.CompilationUnitSyntax)(object)((SyntaxNode)this).Green).endOfFileToken, ((SyntaxNode)this).GetChildPosition(4), ((SyntaxNode)this).GetChildIndex(4));
public IList<ReferenceDirectiveTriviaSyntax> GetReferenceDirectives()
{
return GetReferenceDirectives(null);
}
internal IList<ReferenceDirectiveTriviaSyntax> GetReferenceDirectives(Func<ReferenceDirectiveTriviaSyntax, bool>? filter)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
if (!((SyntaxNode)this).ContainsDirectives)
{
return SpecializedCollections.EmptyList<ReferenceDirectiveTriviaSyntax>();
}
SyntaxNodeOrToken val = SyntaxNodeOrToken.op_Implicit(GetFirstToken(includeZeroWidth: true));
return ((SyntaxNodeOrToken)(ref val)).GetDirectives<ReferenceDirectiveTriviaSyntax>(filter);
}
public IList<LoadDirectiveTriviaSyntax> GetLoadDirectives()
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
if (!((SyntaxNode)this).ContainsDirectives)
{
return SpecializedCollections.EmptyList<LoadDirectiveTriviaSyntax>();
}
SyntaxNodeOrToken val = SyntaxNodeOrToken.op_Implicit(GetFirstToken(includeZeroWidth: true));
return ((SyntaxNodeOrToken)(ref val)).GetDirectives<LoadDirectiveTriviaSyntax>((Func<LoadDirectiveTriviaSyntax, bool>)null);
}
private bool HasFirstTokenDirective(Func<SyntaxNode, bool> predicate)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
if (((SyntaxNode)this).ContainsDirectives)
{
SyntaxToken firstToken = GetFirstToken(includeZeroWidth: true);
if (((SyntaxToken)(ref firstToken)).ContainsDirectives)
{
SyntaxTriviaList leadingTrivia = ((SyntaxToken)(ref firstToken)).LeadingTrivia;
Enumerator enumerator = ((SyntaxTriviaList)(ref leadingTrivia)).GetEnumerator();
while (((Enumerator)(ref enumerator)).MoveNext())
{
SyntaxTrivia current = ((Enumerator)(ref enumerator)).Current;
SyntaxNode structure = ((SyntaxTrivia)(ref current)).GetStructure();
if (structure != null && predicate(structure))
{
return true;
}
}
}
}
return false;
}
internal CompilationUnitSyntax(Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax.CSharpSyntaxNode green, SyntaxNode? parent, int position)
: base((GreenNode)(object)green, parent, position)
{
}
internal override SyntaxNode? GetNodeSlot(int index)
{
return (SyntaxNode?)(index switch
{
0 => ((SyntaxNode)this).GetRedAtZero(ref externs),
1 => ((SyntaxNode)this).GetRed(ref usings, 1),
2 => ((SyntaxNode)this).GetRed(ref attributeLists, 2),
3 => ((SyntaxNode)this).GetRed(ref members, 3),
_ => null,
});
}
internal override SyntaxNode? GetCachedSlot(int index)
{
return (SyntaxNode?)(index switch
{
0 => externs,
1 => usings,
2 => attributeLists,
3 => members,
_ => null,
});
}
public override void Accept(CSharpSyntaxVisitor visitor)
{
visitor.VisitCompilationUnit(this);
}
public override TResult? Accept<TResult>(CSharpSyntaxVisitor<TResult> visitor)
{
return visitor.VisitCompilationUnit(this);
}
public CompilationUnitSyntax Update(SyntaxList<ExternAliasDirectiveSyntax> externs, SyntaxList<UsingDirectiveSyntax> usings, SyntaxList<AttributeListSyntax> attributeLists, SyntaxList<MemberDeclarationSyntax> members, SyntaxToken endOfFileToken)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
if (externs != Externs || usings != Usings || attributeLists != AttributeLists || members != Members || endOfFileToken != EndOfFileToken)
{
CompilationUnitSyntax compilationUnitSyntax = SyntaxFactory.CompilationUnit(externs, usings, attributeLists, members, endOfFileToken);
SyntaxAnnotation[] annotations = ((SyntaxNode)this).GetAnnotations();
if (annotations == null || annotations.Length == 0)
{
return compilationUnitSyntax;
}
return compilationUnitSyntax.WithAnnotations(annotations);
}
return this;
}
public CompilationUnitSyntax WithExterns(SyntaxList<ExternAliasDirectiveSyntax> externs)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
return Update(externs, Usings, AttributeLists, Members, EndOfFileToken);
}
public CompilationUnitSyntax WithUsings(SyntaxList<UsingDirectiveSyntax> usings)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
return Update(Externs, usings, AttributeLists, Members, EndOfFileToken);
}
public CompilationUnitSyntax WithAttributeLists(SyntaxList<AttributeListSyntax> attributeLists)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
return Update(Externs, Usings, attributeLists, Members, EndOfFileToken);
}
public CompilationUnitSyntax WithMembers(SyntaxList<MemberDeclarationSyntax> members)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
return Update(Externs, Usings, AttributeLists, members, EndOfFileToken);
}
public CompilationUnitSyntax WithEndOfFileToken(SyntaxToken endOfFileToken)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
return Update(Externs, Usings, AttributeLists, Members, endOfFileToken);
}
public CompilationUnitSyntax AddExterns(params ExternAliasDirectiveSyntax[] items)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
return WithExterns(Externs.AddRange((IEnumerable<ExternAliasDirectiveSyntax>)items));
}
public CompilationUnitSyntax AddUsings(params UsingDirectiveSyntax[] items)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
return WithUsings(Usings.AddRange((IEnumerable<UsingDirectiveSyntax>)items));
}
public CompilationUnitSyntax AddAttributeLists(params AttributeListSyntax[] items)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
return WithAttributeLists(AttributeLists.AddRange((IEnumerable<AttributeListSyntax>)items));
}
public CompilationUnitSyntax AddMembers(params MemberDeclarationSyntax[] items)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
return WithMembers(Members.AddRange((IEnumerable<MemberDeclarationSyntax>)items));
}
}