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 Externs => new SyntaxList(((SyntaxNode)this).GetRed(ref externs, 0)); public SyntaxList Usings => new SyntaxList(((SyntaxNode)this).GetRed(ref usings, 1)); public SyntaxList AttributeLists => new SyntaxList(((SyntaxNode)this).GetRed(ref attributeLists, 2)); public SyntaxList Members => new SyntaxList(((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 GetReferenceDirectives() { return GetReferenceDirectives(null); } internal IList GetReferenceDirectives(Func? 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(); } SyntaxNodeOrToken val = SyntaxNodeOrToken.op_Implicit(GetFirstToken(includeZeroWidth: true)); return ((SyntaxNodeOrToken)(ref val)).GetDirectives(filter); } public IList 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(); } SyntaxNodeOrToken val = SyntaxNodeOrToken.op_Implicit(GetFirstToken(includeZeroWidth: true)); return ((SyntaxNodeOrToken)(ref val)).GetDirectives((Func)null); } private bool HasFirstTokenDirective(Func 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(CSharpSyntaxVisitor visitor) { return visitor.VisitCompilationUnit(this); } public CompilationUnitSyntax Update(SyntaxList externs, SyntaxList usings, SyntaxList attributeLists, SyntaxList 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 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 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 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 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)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)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)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)items)); } }