using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.CompilerServices; using Microsoft.CodeAnalysis.Syntax.InternalSyntax; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax; [DebuggerDisplay("{GetDebuggerDisplay(), nq}")] internal abstract class CSharpSyntaxNode : GreenNode { private static readonly ConditionalWeakTable>> s_structuresTable = new ConditionalWeakTable>>(); public override string Language => "C#"; public SyntaxKind Kind => (SyntaxKind)((GreenNode)this).RawKind; public override string KindText => Kind.ToString(); public override int RawContextualKind => ((GreenNode)this).RawKind; public override bool IsSkippedTokensTrivia => Kind == SyntaxKind.SkippedTokensTrivia; public override bool IsDocumentationCommentTrivia => SyntaxFacts.IsDocumentationCommentTrivia(Kind); internal CSharpSyntaxNode(SyntaxKind kind) : base((ushort)kind) { GreenStats.NoteGreen((GreenNode)(object)this); } internal CSharpSyntaxNode(SyntaxKind kind, int fullWidth) : base((ushort)kind, fullWidth) { GreenStats.NoteGreen((GreenNode)(object)this); } internal CSharpSyntaxNode(SyntaxKind kind, DiagnosticInfo[] diagnostics) : base((ushort)kind, diagnostics) { GreenStats.NoteGreen((GreenNode)(object)this); } internal CSharpSyntaxNode(SyntaxKind kind, DiagnosticInfo[] diagnostics, int fullWidth) : base((ushort)kind, diagnostics, fullWidth) { GreenStats.NoteGreen((GreenNode)(object)this); } internal CSharpSyntaxNode(SyntaxKind kind, DiagnosticInfo[] diagnostics, SyntaxAnnotation[] annotations) : base((ushort)kind, diagnostics, annotations) { GreenStats.NoteGreen((GreenNode)(object)this); } internal CSharpSyntaxNode(SyntaxKind kind, DiagnosticInfo[] diagnostics, SyntaxAnnotation[] annotations, int fullWidth) : base((ushort)kind, diagnostics, annotations, fullWidth) { GreenStats.NoteGreen((GreenNode)(object)this); } internal CSharpSyntaxNode(ObjectReader reader) : base(reader) { } public override int GetSlotOffset(int index) { int num = 0; for (int i = 0; i < index; i++) { GreenNode slot = ((GreenNode)this).GetSlot(i); if (slot != null) { num += slot.FullWidth; } } return num; } public SyntaxToken GetFirstToken() { return (SyntaxToken)(object)((GreenNode)this).GetFirstTerminal(); } public SyntaxToken GetLastToken() { return (SyntaxToken)(object)((GreenNode)this).GetLastTerminal(); } public SyntaxToken GetLastNonmissingToken() { return (SyntaxToken)(object)((GreenNode)this).GetLastNonmissingTerminal(); } public virtual GreenNode GetLeadingTrivia() { return null; } public override GreenNode GetLeadingTriviaCore() { return GetLeadingTrivia(); } public virtual GreenNode GetTrailingTrivia() { return null; } public override GreenNode GetTrailingTriviaCore() { return GetTrailingTrivia(); } public abstract TResult Accept(CSharpSyntaxVisitor visitor); public abstract void Accept(CSharpSyntaxVisitor visitor); internal virtual DirectiveStack ApplyDirectives(DirectiveStack stack) { return ApplyDirectives((GreenNode)(object)this, stack); } internal static DirectiveStack ApplyDirectives(GreenNode node, DirectiveStack stack) { if (node.ContainsDirectives) { int i = 0; for (int slotCount = node.SlotCount; i < slotCount; i++) { GreenNode slot = node.GetSlot(i); if (slot != null) { stack = ApplyDirectivesToListOrNode(slot, stack); } } } return stack; } internal static DirectiveStack ApplyDirectivesToListOrNode(GreenNode listOrNode, DirectiveStack stack) { if (listOrNode.RawKind == 1) { return ApplyDirectives(listOrNode, stack); } return ((CSharpSyntaxNode)(object)listOrNode).ApplyDirectives(stack); } internal virtual IList GetDirectives() { //IL_0001: 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) if ((base.flags & 4) != 0) { List list = new List(32); GetDirectives((GreenNode)(object)this, list); return list; } return SpecializedCollections.EmptyList(); } private static void GetDirectives(GreenNode node, List directives) { if (node == null || !node.ContainsDirectives) { return; } if (node is DirectiveTriviaSyntax item) { directives.Add(item); return; } if (node is SyntaxToken syntaxToken) { GetDirectives(syntaxToken.GetLeadingTrivia(), directives); GetDirectives(syntaxToken.GetTrailingTrivia(), directives); return; } int i = 0; for (int slotCount = node.SlotCount; i < slotCount; i++) { GetDirectives(node.GetSlot(i), directives); } } protected void SetFactoryContext(SyntaxFactoryContext context) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0011: 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_0021: 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_002c: Unknown result type (might be due to invalid IL or missing references) if (context.IsInAsync) { base.flags = (NodeFlags)(base.flags | 0x40); } if (context.IsInQuery) { base.flags = (NodeFlags)(base.flags | 0x80); } } internal static NodeFlags SetFactoryContext(NodeFlags flags, SyntaxFactoryContext context) { //IL_0008: 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) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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_001d: Unknown result type (might be due to invalid IL or missing references) if (context.IsInAsync) { flags = (NodeFlags)(flags | 0x40); } if (context.IsInQuery) { flags = (NodeFlags)(flags | 0x80); } return flags; } public override SyntaxToken CreateSeparator(SyntaxNode element) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) return Microsoft.CodeAnalysis.CSharp.SyntaxFactory.Token(SyntaxKind.CommaToken); } public override bool IsTriviaWithEndOfLine() { if (Kind != SyntaxKind.EndOfLineTrivia) { return Kind == SyntaxKind.SingleLineCommentTrivia; } return true; } public override SyntaxNode GetStructure(SyntaxTrivia trivia) { //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_0085: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0045: 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_0066: Unknown result type (might be due to invalid IL or missing references) if (((SyntaxTrivia)(ref trivia)).HasStructure) { SyntaxToken token = ((SyntaxTrivia)(ref trivia)).Token; SyntaxNode parent = ((SyntaxToken)(ref token)).Parent; if (parent != null) { Dictionary> orCreateValue = s_structuresTable.GetOrCreateValue(parent); SyntaxNode target; lock (orCreateValue) { if (!orCreateValue.TryGetValue(trivia, out var value)) { target = (SyntaxNode)(object)Microsoft.CodeAnalysis.CSharp.Syntax.StructuredTriviaSyntax.Create(trivia); orCreateValue.Add(trivia, new WeakReference(target)); } else if (!value.TryGetTarget(out target)) { target = (SyntaxNode)(object)Microsoft.CodeAnalysis.CSharp.Syntax.StructuredTriviaSyntax.Create(trivia); value.SetTarget(target); } } return target; } return (SyntaxNode)(object)Microsoft.CodeAnalysis.CSharp.Syntax.StructuredTriviaSyntax.Create(trivia); } return null; } }