Files
2026-08-27 10:56:38 -06:00

928 lines
37 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Syntax;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp;
public abstract class CSharpSyntaxTree : SyntaxTree
{
private sealed class DebuggerSyntaxTree : ParsedSyntaxTree
{
internal override bool SupportsLocations => true;
public DebuggerSyntaxTree(CSharpSyntaxNode root, SourceText text, CSharpParseOptions options)
: base(text, text.Encoding, text.ChecksumAlgorithm, "", options, root, DirectiveStack.Empty, null, cloneRoot: true)
{
}//IL_0009: Unknown result type (might be due to invalid IL or missing references)
}
internal sealed class DummySyntaxTree : CSharpSyntaxTree
{
private const SourceHashAlgorithm ChecksumAlgorithm = (SourceHashAlgorithm)1;
private readonly Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax _node;
public override Encoding Encoding => System.Text.Encoding.UTF8;
public override int Length => 0;
public override CSharpParseOptions Options => CSharpParseOptions.Default;
[Obsolete("Obsolete due to performance problems, use CompilationOptions.SyntaxTreeOptionsProvider instead", false)]
public override ImmutableDictionary<string, ReportDiagnostic> DiagnosticOptions
{
get
{
throw ExceptionUtilities.Unreachable("/_/src/Compilers/CSharp/Portable/Syntax/CSharpSyntaxTree.Dummy.cs", 61);
}
}
public override string FilePath => string.Empty;
public override bool HasCompilationUnitRoot => true;
public DummySyntaxTree()
{
_node = CloneNodeAsRoot(SyntaxFactory.ParseCompilationUnit(string.Empty));
}
public override string ToString()
{
return string.Empty;
}
public override SourceText GetText(CancellationToken cancellationToken)
{
return SourceText.From(string.Empty, ((SyntaxTree)this).Encoding, (SourceHashAlgorithm)1);
}
public override bool TryGetText(out SourceText text)
{
text = SourceText.From(string.Empty, ((SyntaxTree)this).Encoding, (SourceHashAlgorithm)1);
return true;
}
public override SyntaxReference GetReference(SyntaxNode node)
{
return (SyntaxReference)(object)new SimpleSyntaxReference(node);
}
public override CSharpSyntaxNode GetRoot(CancellationToken cancellationToken)
{
return _node;
}
public override bool TryGetRoot(out CSharpSyntaxNode root)
{
root = _node;
return true;
}
public override FileLinePositionSpan GetLineSpan(TextSpan span, CancellationToken cancellationToken = default(CancellationToken))
{
//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)
return default(FileLinePositionSpan);
}
public override SyntaxTree WithRootAndOptions(SyntaxNode root, ParseOptions options)
{
return Create((CSharpSyntaxNode)(object)root, (CSharpParseOptions)(object)options, ((SyntaxTree)this).FilePath, ((SyntaxTree)this).Encoding, (SourceHashAlgorithm)1);
}
public override SyntaxTree WithFilePath(string path)
{
return Create(_node, Options, path, ((SyntaxTree)this).Encoding, (SourceHashAlgorithm)1);
}
}
private sealed class LazySyntaxTree : CSharpSyntaxTree
{
private readonly SourceText _text;
private readonly CSharpParseOptions _options;
private readonly string _path;
private readonly ImmutableDictionary<string, ReportDiagnostic> _diagnosticOptions;
private CSharpSyntaxNode? _lazyRoot;
public override string FilePath => _path;
public override Encoding? Encoding => _text.Encoding;
public override int Length => _text.Length;
public override bool HasCompilationUnitRoot => true;
public override CSharpParseOptions Options => _options;
[Obsolete("Obsolete due to performance problems, use CompilationOptions.SyntaxTreeOptionsProvider instead", false)]
public override ImmutableDictionary<string, ReportDiagnostic> DiagnosticOptions => _diagnosticOptions;
internal LazySyntaxTree(SourceText text, CSharpParseOptions options, string path, ImmutableDictionary<string, ReportDiagnostic>? diagnosticOptions)
{
_text = text;
_options = options;
_path = path ?? string.Empty;
_diagnosticOptions = diagnosticOptions ?? SyntaxTree.EmptyDiagnosticOptions;
}
public override SourceText GetText(CancellationToken cancellationToken)
{
return _text;
}
public override bool TryGetText([NotNullWhen(true)] out SourceText? text)
{
text = _text;
return true;
}
public override CSharpSyntaxNode GetRoot(CancellationToken cancellationToken)
{
if (_lazyRoot == null)
{
SyntaxTree val = SyntaxFactory.ParseSyntaxTree(_text, (ParseOptions?)(object)_options, _path, cancellationToken);
CSharpSyntaxNode value = CloneNodeAsRoot((CSharpSyntaxNode)(object)val.GetRoot(cancellationToken));
Interlocked.CompareExchange(ref _lazyRoot, value, null);
}
return _lazyRoot;
}
public override bool TryGetRoot([NotNullWhen(true)] out CSharpSyntaxNode? root)
{
root = _lazyRoot;
return root != null;
}
public override SyntaxReference GetReference(SyntaxNode node)
{
return (SyntaxReference)(object)new SimpleSyntaxReference(node);
}
public override SyntaxTree WithRootAndOptions(SyntaxNode root, ParseOptions options)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
if ((object)_lazyRoot == root && (object)_options == options)
{
return (SyntaxTree)(object)this;
}
return (SyntaxTree)(object)new ParsedSyntaxTree(null, _text.Encoding, _text.ChecksumAlgorithm, _path, (CSharpParseOptions)(object)options, (CSharpSyntaxNode)(object)root, _lazyDirectives, _diagnosticOptions, cloneRoot: true);
}
public override SyntaxTree WithFilePath(string path)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
if (_path == path)
{
return (SyntaxTree)(object)this;
}
if (TryGetRoot(out CSharpSyntaxNode root))
{
return (SyntaxTree)(object)new ParsedSyntaxTree(_text, _text.Encoding, _text.ChecksumAlgorithm, path, _options, root, default(DirectiveStack), _diagnosticOptions, cloneRoot: true);
}
return (SyntaxTree)(object)new LazySyntaxTree(_text, _options, path, _diagnosticOptions);
}
[Obsolete("Obsolete due to performance problems, use CompilationOptions.SyntaxTreeOptionsProvider instead", false)]
public override SyntaxTree WithDiagnosticOptions(ImmutableDictionary<string, ReportDiagnostic> options)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
if (options == null)
{
options = SyntaxTree.EmptyDiagnosticOptions;
}
if (_diagnosticOptions == options)
{
return (SyntaxTree)(object)this;
}
if (TryGetRoot(out CSharpSyntaxNode root))
{
return (SyntaxTree)(object)new ParsedSyntaxTree(_text, _text.Encoding, _text.ChecksumAlgorithm, _path, _options, root, default(DirectiveStack), options, cloneRoot: true);
}
return (SyntaxTree)(object)new LazySyntaxTree(_text, _options, _path, options);
}
}
private class ParsedSyntaxTree : CSharpSyntaxTree
{
private readonly CSharpParseOptions _options;
private readonly string _path;
private readonly CSharpSyntaxNode _root;
private readonly bool _hasCompilationUnitRoot;
private readonly Encoding? _encodingOpt;
private readonly SourceHashAlgorithm _checksumAlgorithm;
private readonly ImmutableDictionary<string, ReportDiagnostic> _diagnosticOptions;
private SourceText? _lazyText;
public override string FilePath => _path;
public override Encoding? Encoding => _encodingOpt;
public override int Length
{
get
{
//IL_0006: 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)
TextSpan fullSpan = ((SyntaxNode)_root).FullSpan;
return ((TextSpan)(ref fullSpan)).Length;
}
}
public override bool HasCompilationUnitRoot => _hasCompilationUnitRoot;
public override CSharpParseOptions Options => _options;
[Obsolete("Obsolete due to performance problems, use CompilationOptions.SyntaxTreeOptionsProvider instead", false)]
public override ImmutableDictionary<string, ReportDiagnostic> DiagnosticOptions => _diagnosticOptions;
internal ParsedSyntaxTree(SourceText? textOpt, Encoding? encodingOpt, SourceHashAlgorithm checksumAlgorithm, string? path, CSharpParseOptions options, CSharpSyntaxNode root, DirectiveStack directives, ImmutableDictionary<string, ReportDiagnostic>? diagnosticOptions, bool cloneRoot)
: base(directives)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
_lazyText = textOpt;
_encodingOpt = encodingOpt ?? ((textOpt != null) ? textOpt.Encoding : null);
_checksumAlgorithm = checksumAlgorithm;
_options = options;
_path = path ?? string.Empty;
_root = (cloneRoot ? CloneNodeAsRoot(root) : root);
_hasCompilationUnitRoot = root.Kind() == SyntaxKind.CompilationUnit;
_diagnosticOptions = diagnosticOptions ?? SyntaxTree.EmptyDiagnosticOptions;
}
public override SourceText GetText(CancellationToken cancellationToken)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
if (_lazyText == null)
{
Interlocked.CompareExchange(ref _lazyText, ((SyntaxNode)GetRoot(cancellationToken)).GetText(_encodingOpt, _checksumAlgorithm), null);
}
return _lazyText;
}
public override bool TryGetText([NotNullWhen(true)] out SourceText? text)
{
text = _lazyText;
return text != null;
}
public override CSharpSyntaxNode GetRoot(CancellationToken cancellationToken)
{
return _root;
}
public override bool TryGetRoot(out CSharpSyntaxNode root)
{
root = _root;
return true;
}
public override SyntaxReference GetReference(SyntaxNode node)
{
return (SyntaxReference)(object)new SimpleSyntaxReference(node);
}
public override SyntaxTree WithRootAndOptions(SyntaxNode root, ParseOptions options)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
if ((object)_root == root && (object)_options == options)
{
return (SyntaxTree)(object)this;
}
return (SyntaxTree)(object)new ParsedSyntaxTree(null, _encodingOpt, _checksumAlgorithm, _path, (CSharpParseOptions)(object)options, (CSharpSyntaxNode)(object)root, ((object)_root == root) ? _lazyDirectives : default(DirectiveStack), _diagnosticOptions, cloneRoot: true);
}
public override SyntaxTree WithFilePath(string path)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
if (_path == path)
{
return (SyntaxTree)(object)this;
}
return (SyntaxTree)(object)new ParsedSyntaxTree(_lazyText, _encodingOpt, _checksumAlgorithm, path, _options, _root, _lazyDirectives, _diagnosticOptions, cloneRoot: true);
}
[Obsolete("Obsolete due to performance problems, use CompilationOptions.SyntaxTreeOptionsProvider instead", false)]
public override SyntaxTree WithDiagnosticOptions(ImmutableDictionary<string, ReportDiagnostic> options)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
if (options == null)
{
options = SyntaxTree.EmptyDiagnosticOptions;
}
if (_diagnosticOptions == options)
{
return (SyntaxTree)(object)this;
}
return (SyntaxTree)(object)new ParsedSyntaxTree(_lazyText, _encodingOpt, _checksumAlgorithm, _path, _options, _root, _lazyDirectives, options, cloneRoot: true);
}
}
internal static readonly SyntaxTree Dummy = (SyntaxTree)(object)new DummySyntaxTree();
private DirectiveStack _lazyDirectives;
private ImmutableArray<int> _preprocessorStateChangePositions;
private ImmutableArray<DirectiveStack> _preprocessorStates;
private CSharpLineDirectiveMap? _lazyLineDirectiveMap;
private CSharpPragmaWarningStateMap? _lazyPragmaWarningStateMap;
private StrongBox<NullableContextStateMap>? _lazyNullableContextStateMap;
private GeneratedKind _lazyIsGeneratedCode;
public abstract CSharpParseOptions Options { get; }
internal bool HasReferenceDirectives
{
get
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Invalid comparison between Unknown and I4
if ((int)((ParseOptions)Options).Kind == 1)
{
return GetCompilationUnitRoot().HasReferenceDirectives;
}
return false;
}
}
internal bool HasReferenceOrLoadDirectives
{
get
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Invalid comparison between Unknown and I4
if ((int)((ParseOptions)Options).Kind == 1)
{
Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax compilationUnitRoot = GetCompilationUnitRoot();
if (!compilationUnitRoot.HasReferenceDirectives)
{
return compilationUnitRoot.HasLoadDirectives;
}
return true;
}
return false;
}
}
protected override ParseOptions OptionsCore => (ParseOptions)(object)Options;
public CSharpSyntaxTree()
: this(default(DirectiveStack))
{
}
internal CSharpSyntaxTree(DirectiveStack directives)
{
_lazyDirectives = directives;
}
protected T CloneNodeAsRoot<T>(T node) where T : CSharpSyntaxNode
{
return SyntaxNode.CloneNodeAsRoot<T>(node, (SyntaxTree)(object)this);
}
public abstract CSharpSyntaxNode GetRoot(CancellationToken cancellationToken = default(CancellationToken));
public abstract bool TryGetRoot([NotNullWhen(true)] out CSharpSyntaxNode? root);
public virtual Task<CSharpSyntaxNode> GetRootAsync(CancellationToken cancellationToken = default(CancellationToken))
{
CSharpSyntaxNode root;
return Task.FromResult(TryGetRoot(out root) ? root : GetRoot(cancellationToken));
}
public Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax GetCompilationUnitRoot(CancellationToken cancellationToken = default(CancellationToken))
{
return (Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax)GetRoot(cancellationToken);
}
public override bool IsEquivalentTo(SyntaxTree tree, bool topLevel = false)
{
return SyntaxFactory.AreEquivalent((SyntaxTree?)(object)this, tree, topLevel);
}
internal DirectiveStack GetDirectives()
{
if (_lazyDirectives.IsNull)
{
DirectiveStack.InterlockedInitialize(ref _lazyDirectives, GetRoot().CsGreen.ApplyDirectives(DirectiveStack.Empty));
}
return _lazyDirectives;
}
internal bool IsAnyPreprocessorSymbolDefined(ImmutableArray<string> conditionalSymbols)
{
DirectiveStack directives = GetDirectives();
ImmutableArray<string>.Enumerator enumerator = conditionalSymbols.GetEnumerator();
while (enumerator.MoveNext())
{
string current = enumerator.Current;
if (IsPreprocessorSymbolDefined(directives, current))
{
return true;
}
}
return false;
}
private bool IsPreprocessorSymbolDefined(DirectiveStack directives, string symbolName)
{
return directives.IsDefined(symbolName) switch
{
DefineState.Defined => true,
DefineState.Undefined => false,
_ => Options.PreprocessorSymbols.Contains(symbolName),
};
}
internal bool IsPreprocessorSymbolDefined(string symbolName, int position)
{
if (_preprocessorStateChangePositions.IsDefault)
{
BuildPreprocessorStateChangeMap();
}
int num = _preprocessorStateChangePositions.BinarySearch(position);
DirectiveStack directives;
if (num < 0)
{
num = ~num - 1;
directives = ((num < 0) ? DirectiveStack.Empty : _preprocessorStates[num]);
}
else
{
directives = _preprocessorStates[num];
}
return IsPreprocessorSymbolDefined(directives, symbolName);
}
private void BuildPreprocessorStateChangeMap()
{
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
DirectiveStack directiveStack = DirectiveStack.Empty;
ArrayBuilder<int> instance = ArrayBuilder<int>.GetInstance();
ArrayBuilder<DirectiveStack> instance2 = ArrayBuilder<DirectiveStack>.GetInstance();
foreach (Microsoft.CodeAnalysis.CSharp.Syntax.DirectiveTriviaSyntax directive in GetRoot().GetDirectives(delegate(Microsoft.CodeAnalysis.CSharp.Syntax.DirectiveTriviaSyntax d)
{
SyntaxKind syntaxKind = d.Kind();
return (syntaxKind - 8548 <= (SyntaxKind)3 || syntaxKind - 8554 <= SyntaxKind.List) ? true : false;
}))
{
directiveStack = ((SyntaxNode)(object)directive).ApplyDirectives(directiveStack);
SyntaxToken val;
switch (directive.Kind())
{
case SyntaxKind.ElifDirectiveTrivia:
instance2.Add(directiveStack);
val = ((Microsoft.CodeAnalysis.CSharp.Syntax.ElifDirectiveTriviaSyntax)directive).ElifKeyword;
instance.Add(((SyntaxToken)(ref val)).SpanStart);
break;
case SyntaxKind.ElseDirectiveTrivia:
instance2.Add(directiveStack);
val = ((Microsoft.CodeAnalysis.CSharp.Syntax.ElseDirectiveTriviaSyntax)directive).ElseKeyword;
instance.Add(((SyntaxToken)(ref val)).SpanStart);
break;
case SyntaxKind.EndIfDirectiveTrivia:
instance2.Add(directiveStack);
val = ((Microsoft.CodeAnalysis.CSharp.Syntax.EndIfDirectiveTriviaSyntax)directive).EndIfKeyword;
instance.Add(((SyntaxToken)(ref val)).SpanStart);
break;
case SyntaxKind.DefineDirectiveTrivia:
instance2.Add(directiveStack);
val = ((Microsoft.CodeAnalysis.CSharp.Syntax.DefineDirectiveTriviaSyntax)directive).Name;
instance.Add(((SyntaxToken)(ref val)).SpanStart);
break;
case SyntaxKind.UndefDirectiveTrivia:
instance2.Add(directiveStack);
val = ((Microsoft.CodeAnalysis.CSharp.Syntax.UndefDirectiveTriviaSyntax)directive).Name;
instance.Add(((SyntaxToken)(ref val)).SpanStart);
break;
default:
throw ExceptionUtilities.UnexpectedValue((object)directive.Kind());
case SyntaxKind.IfDirectiveTrivia:
break;
}
}
ImmutableInterlocked.InterlockedInitialize(ref _preprocessorStates, instance2.ToImmutableAndFree());
ImmutableInterlocked.InterlockedInitialize(ref _preprocessorStateChangePositions, instance.ToImmutableAndFree());
}
public static SyntaxTree Create(CSharpSyntaxNode root, CSharpParseOptions? options = null, string? path = "", Encoding? encoding = null)
{
return Create(root, options, path, encoding, (ImmutableDictionary<string, ReportDiagnostic>?)null);
}
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("The diagnosticOptions and isGeneratedCode parameters are obsolete due to performance problems, if you are using them use CompilationOptions.SyntaxTreeOptionsProvider instead", false)]
public static SyntaxTree Create(CSharpSyntaxNode root, CSharpParseOptions? options, string? path, Encoding? encoding, ImmutableDictionary<string, ReportDiagnostic>? diagnosticOptions, bool? isGeneratedCode)
{
if (root == null)
{
throw new ArgumentNullException("root");
}
return (SyntaxTree)(object)new ParsedSyntaxTree(null, encoding, (SourceHashAlgorithm)1, path, options ?? CSharpParseOptions.Default, root, default(DirectiveStack), diagnosticOptions, cloneRoot: true);
}
internal static SyntaxTree Create(CSharpSyntaxNode root, CSharpParseOptions options, string? path, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return (SyntaxTree)(object)new ParsedSyntaxTree(null, encoding, checksumAlgorithm, path, options, root, default(DirectiveStack), null, cloneRoot: true);
}
internal static SyntaxTree CreateForDebugger(CSharpSyntaxNode root, SourceText text, CSharpParseOptions options)
{
return (SyntaxTree)(object)new DebuggerSyntaxTree(root, text, options);
}
internal static SyntaxTree CreateWithoutClone(CSharpSyntaxNode root)
{
return (SyntaxTree)(object)new ParsedSyntaxTree(null, null, (SourceHashAlgorithm)1, "", CSharpParseOptions.Default, root, default(DirectiveStack), null, cloneRoot: false);
}
internal static SyntaxTree ParseTextLazy(SourceText text, CSharpParseOptions? options = null, string path = "")
{
return (SyntaxTree)(object)new LazySyntaxTree(text, options ?? CSharpParseOptions.Default, path, null);
}
public static SyntaxTree ParseText(string text, CSharpParseOptions? options = null, string path = "", Encoding? encoding = null, CancellationToken cancellationToken = default(CancellationToken))
{
return ParseText(text, options, path, encoding, null, cancellationToken);
}
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("The diagnosticOptions and isGeneratedCode parameters are obsolete due to performance problems, if you are using them use CompilationOptions.SyntaxTreeOptionsProvider instead", false)]
public static SyntaxTree ParseText(string text, CSharpParseOptions? options, string path, Encoding? encoding, ImmutableDictionary<string, ReportDiagnostic>? diagnosticOptions, bool? isGeneratedCode, CancellationToken cancellationToken)
{
return ParseText(SourceText.From(text, encoding, (SourceHashAlgorithm)1), options, path, diagnosticOptions, isGeneratedCode, cancellationToken);
}
public static SyntaxTree ParseText(SourceText text, CSharpParseOptions? options = null, string path = "", CancellationToken cancellationToken = default(CancellationToken))
{
return ParseText(text, options, path, null, cancellationToken);
}
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("The diagnosticOptions and isGeneratedCode parameters are obsolete due to performance problems, if you are using them use CompilationOptions.SyntaxTreeOptionsProvider instead", false)]
public static SyntaxTree ParseText(SourceText text, CSharpParseOptions? options, string path, ImmutableDictionary<string, ReportDiagnostic>? diagnosticOptions, bool? isGeneratedCode, CancellationToken cancellationToken)
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
if (text == null)
{
throw new ArgumentNullException("text");
}
options = options ?? CSharpParseOptions.Default;
using Lexer lexer = new Lexer(text, options);
using LanguageParser languageParser = new LanguageParser(lexer, null, null, LexerMode.Syntax, cancellationToken);
Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax root = (Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax)(object)((GreenNode)languageParser.ParseCompilationUnit()).CreateRed();
return (SyntaxTree)(object)new ParsedSyntaxTree(text, text.Encoding, text.ChecksumAlgorithm, path, options, root, languageParser.Directives, diagnosticOptions, cloneRoot: true);
}
public override SyntaxTree WithChangedText(SourceText newText)
{
//IL_003a: 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_004a: Unknown result type (might be due to invalid IL or missing references)
SourceText val = default(SourceText);
if (((SyntaxTree)this).TryGetText(ref val))
{
IReadOnlyList<TextChangeRange> changeRanges = newText.GetChangeRanges(val);
if (changeRanges.Count == 0 && newText == val)
{
return (SyntaxTree)(object)this;
}
return WithChanges(newText, changeRanges);
}
return WithChanges(newText, (IReadOnlyList<TextChangeRange>)(object)new TextChangeRange[1]
{
new TextChangeRange(new TextSpan(0, ((SyntaxTree)this).Length), newText.Length)
});
}
private SyntaxTree WithChanges(SourceText newText, IReadOnlyList<TextChangeRange> changes)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: 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_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
if (changes == null)
{
throw new ArgumentNullException("changes");
}
IReadOnlyList<TextChangeRange> readOnlyList = changes;
CSharpSyntaxTree cSharpSyntaxTree = this;
if (readOnlyList.Count == 1)
{
TextChangeRange val = readOnlyList[0];
if (((TextChangeRange)(ref val)).Span == new TextSpan(0, ((SyntaxTree)this).Length))
{
val = readOnlyList[0];
if (((TextChangeRange)(ref val)).NewLength == newText.Length)
{
readOnlyList = null;
cSharpSyntaxTree = null;
}
}
}
using Lexer lexer = new Lexer(newText, Options);
using LanguageParser languageParser = new LanguageParser(lexer, cSharpSyntaxTree?.GetRoot(), readOnlyList);
Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax root = (Microsoft.CodeAnalysis.CSharp.Syntax.CompilationUnitSyntax)(object)((GreenNode)languageParser.ParseCompilationUnit()).CreateRed();
return (SyntaxTree)(object)new ParsedSyntaxTree(newText, newText.Encoding, newText.ChecksumAlgorithm, ((SyntaxTree)this).FilePath, Options, root, languageParser.Directives, ((SyntaxTree)this).DiagnosticOptions, cloneRoot: true);
}
public override IList<TextSpan> GetChangedSpans(SyntaxTree oldTree)
{
if (oldTree == null)
{
throw new ArgumentNullException("oldTree");
}
return SyntaxDiffer.GetPossiblyDifferentTextSpans(oldTree, (SyntaxTree)(object)this);
}
public override IList<TextChange> GetChanges(SyntaxTree oldTree)
{
if (oldTree == null)
{
throw new ArgumentNullException("oldTree");
}
return SyntaxDiffer.GetTextChanges(oldTree, (SyntaxTree)(object)this);
}
private CSharpLineDirectiveMap GetDirectiveMap()
{
if (_lazyLineDirectiveMap == null)
{
Interlocked.CompareExchange(ref _lazyLineDirectiveMap, new CSharpLineDirectiveMap((SyntaxTree)(object)this), null);
}
return _lazyLineDirectiveMap;
}
public override FileLinePositionSpan GetLineSpan(TextSpan span, CancellationToken cancellationToken = default(CancellationToken))
{
//IL_000f: 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)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
return new FileLinePositionSpan(((SyntaxTree)this).FilePath, GetLinePosition(((TextSpan)(ref span)).Start, cancellationToken), GetLinePosition(((TextSpan)(ref span)).End, cancellationToken));
}
public override FileLinePositionSpan GetMappedLineSpan(TextSpan span, CancellationToken cancellationToken = default(CancellationToken))
{
//IL_0013: 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)
return ((LineDirectiveMap<Microsoft.CodeAnalysis.CSharp.Syntax.DirectiveTriviaSyntax>)(object)GetDirectiveMap()).TranslateSpan(((SyntaxTree)this).GetText(cancellationToken), ((SyntaxTree)this).FilePath, span);
}
public override LineVisibility GetLineVisibility(int position, CancellationToken cancellationToken = default(CancellationToken))
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
return ((LineDirectiveMap<Microsoft.CodeAnalysis.CSharp.Syntax.DirectiveTriviaSyntax>)(object)GetDirectiveMap()).GetLineVisibility(((SyntaxTree)this).GetText(cancellationToken), position);
}
public override IEnumerable<LineMapping> GetLineMappings(CancellationToken cancellationToken = default(CancellationToken))
{
CSharpLineDirectiveMap directiveMap = GetDirectiveMap();
if (((LineDirectiveMap<Microsoft.CodeAnalysis.CSharp.Syntax.DirectiveTriviaSyntax>)(object)directiveMap).Entries.Length != 1)
{
return ((LineDirectiveMap<Microsoft.CodeAnalysis.CSharp.Syntax.DirectiveTriviaSyntax>)(object)directiveMap).GetLineMappings(((SyntaxTree)this).GetText(cancellationToken).Lines);
}
return Array.Empty<LineMapping>();
}
internal override FileLinePositionSpan GetMappedLineSpanAndVisibility(TextSpan span, out bool isHiddenPosition)
{
//IL_001b: 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)
return ((LineDirectiveMap<Microsoft.CodeAnalysis.CSharp.Syntax.DirectiveTriviaSyntax>)(object)GetDirectiveMap()).TranslateSpanAndVisibility(((SyntaxTree)this).GetText(default(CancellationToken)), ((SyntaxTree)this).FilePath, span, ref isHiddenPosition);
}
public override bool HasHiddenRegions()
{
return ((LineDirectiveMap<Microsoft.CodeAnalysis.CSharp.Syntax.DirectiveTriviaSyntax>)(object)GetDirectiveMap()).HasAnyHiddenRegions();
}
internal PragmaWarningState GetPragmaDirectiveWarningState(string id, int position)
{
if (_lazyPragmaWarningStateMap == null)
{
Interlocked.CompareExchange(ref _lazyPragmaWarningStateMap, new CSharpPragmaWarningStateMap((SyntaxTree)(object)this), null);
}
return ((AbstractWarningStateMap<PragmaWarningState>)_lazyPragmaWarningStateMap).GetWarningState(id, position);
}
private NullableContextStateMap GetNullableContextStateMap()
{
if (_lazyNullableContextStateMap == null)
{
Interlocked.CompareExchange(ref _lazyNullableContextStateMap, new StrongBox<NullableContextStateMap>(NullableContextStateMap.Create((SyntaxTree)(object)this)), null);
}
return _lazyNullableContextStateMap.Value;
}
internal NullableContextState GetNullableContextState(int position)
{
return GetNullableContextStateMap().GetContextState(position);
}
internal bool? IsNullableAnalysisEnabled(TextSpan span)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
return GetNullableContextStateMap().IsNullableAnalysisEnabled(span);
}
internal bool IsGeneratedCode(SyntaxTreeOptionsProvider? provider, CancellationToken cancellationToken)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: 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)
//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_003b: Invalid comparison between Unknown and I4
GeneratedKind? val = ((provider != null) ? new GeneratedKind?(provider.IsGenerated((SyntaxTree)(object)this, cancellationToken)) : ((GeneratedKind?)null));
if (val.HasValue)
{
GeneratedKind valueOrDefault = val.GetValueOrDefault();
if ((int)valueOrDefault != 0)
{
return (int)valueOrDefault != 1;
}
}
return isGeneratedHeuristic();
bool isGeneratedHeuristic()
{
//IL_0001: 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_004b: Invalid comparison between Unknown and I4
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
if ((int)_lazyIsGeneratedCode == 0)
{
bool flag = GeneratedCodeUtilities.IsGeneratedCode((SyntaxTree)(object)this, (Func<SyntaxTrivia, bool>)((SyntaxTrivia trivia) => trivia.Kind() == SyntaxKind.SingleLineCommentTrivia || trivia.Kind() == SyntaxKind.MultiLineCommentTrivia), default(CancellationToken));
_lazyIsGeneratedCode = (GeneratedKind)((!flag) ? 1 : 2);
}
return (int)_lazyIsGeneratedCode == 2;
}
}
private LinePosition GetLinePosition(int position, CancellationToken cancellationToken)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
return ((SyntaxTree)this).GetText(cancellationToken).Lines.GetLinePosition(position);
}
public override Location GetLocation(TextSpan span)
{
//IL_0001: 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_0008: Expected O, but got Unknown
return (Location)new SourceLocation((SyntaxTree)(object)this, span);
}
public override IEnumerable<Diagnostic> GetDiagnostics(SyntaxNode node)
{
if (node == null)
{
throw new ArgumentNullException("node");
}
return GetDiagnostics(node.Green, node.Position);
}
private IEnumerable<Diagnostic> GetDiagnostics(GreenNode greenNode, int position)
{
if (greenNode == null)
{
throw new InvalidOperationException();
}
if (greenNode.ContainsDiagnostics)
{
return EnumerateDiagnostics(greenNode, position);
}
return SpecializedCollections.EmptyEnumerable<Diagnostic>();
}
private IEnumerable<Diagnostic> EnumerateDiagnostics(GreenNode node, int position)
{
SyntaxTreeDiagnosticEnumerator enumerator = new SyntaxTreeDiagnosticEnumerator((SyntaxTree)(object)this, node, position);
while (enumerator.MoveNext())
{
yield return enumerator.Current;
}
}
public override IEnumerable<Diagnostic> GetDiagnostics(SyntaxToken token)
{
if (((SyntaxToken)(ref token)).Node == null)
{
throw new InvalidOperationException();
}
return GetDiagnostics(((SyntaxToken)(ref token)).Node, ((SyntaxToken)(ref token)).Position);
}
public override IEnumerable<Diagnostic> GetDiagnostics(SyntaxTrivia trivia)
{
if (((SyntaxTrivia)(ref trivia)).UnderlyingNode == null)
{
throw new InvalidOperationException();
}
return GetDiagnostics(((SyntaxTrivia)(ref trivia)).UnderlyingNode, ((SyntaxTrivia)(ref trivia)).Position);
}
public override IEnumerable<Diagnostic> GetDiagnostics(SyntaxNodeOrToken nodeOrToken)
{
if (((SyntaxNodeOrToken)(ref nodeOrToken)).UnderlyingNode == null)
{
throw new InvalidOperationException();
}
return GetDiagnostics(((SyntaxNodeOrToken)(ref nodeOrToken)).UnderlyingNode, ((SyntaxNodeOrToken)(ref nodeOrToken)).Position);
}
public override IEnumerable<Diagnostic> GetDiagnostics(CancellationToken cancellationToken = default(CancellationToken))
{
return ((SyntaxTree)this).GetDiagnostics((SyntaxNode)(object)GetRoot(cancellationToken));
}
protected override SyntaxNode GetRootCore(CancellationToken cancellationToken)
{
return (SyntaxNode)(object)GetRoot(cancellationToken);
}
protected override async Task<SyntaxNode> GetRootAsyncCore(CancellationToken cancellationToken)
{
return (SyntaxNode)(object)(await GetRootAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false));
}
protected override bool TryGetRootCore([NotNullWhen(true)] out SyntaxNode? root)
{
if (TryGetRoot(out CSharpSyntaxNode root2))
{
root = (SyntaxNode?)(object)root2;
return true;
}
root = null;
return false;
}
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("The diagnosticOptions parameter is obsolete due to performance problems, if you are passing non-null use CompilationOptions.SyntaxTreeOptionsProvider instead", false)]
public static SyntaxTree ParseText(SourceText text, CSharpParseOptions? options, string path, ImmutableDictionary<string, ReportDiagnostic>? diagnosticOptions, CancellationToken cancellationToken)
{
return ParseText(text, options, path, diagnosticOptions, null, cancellationToken);
}
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("The diagnosticOptions parameter is obsolete due to performance problems, if you are passing non-null use CompilationOptions.SyntaxTreeOptionsProvider instead", false)]
public static SyntaxTree ParseText(string text, CSharpParseOptions? options, string path, Encoding? encoding, ImmutableDictionary<string, ReportDiagnostic>? diagnosticOptions, CancellationToken cancellationToken)
{
return ParseText(SourceText.From(text, encoding, (SourceHashAlgorithm)1), options, path, diagnosticOptions, null, cancellationToken);
}
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("The diagnosticOptions parameter is obsolete due to performance problems, if you are passing non-null use CompilationOptions.SyntaxTreeOptionsProvider instead", false)]
public static SyntaxTree Create(CSharpSyntaxNode root, CSharpParseOptions? options, string? path, Encoding? encoding, ImmutableDictionary<string, ReportDiagnostic>? diagnosticOptions)
{
return Create(root, options, path, encoding, diagnosticOptions, null);
}
internal string Dump()
{
return GetRoot().Dump();
}
}