101 lines
4.4 KiB
C#
101 lines
4.4 KiB
C#
using System.Threading;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp;
|
|
|
|
internal class SpeculativeSyntaxTreeSemanticModel : SyntaxTreeSemanticModel
|
|
{
|
|
private readonly SyntaxTreeSemanticModel _parentSemanticModel;
|
|
|
|
private readonly CSharpSyntaxNode _root;
|
|
|
|
private readonly Binder _rootBinder;
|
|
|
|
private readonly int _position;
|
|
|
|
private readonly SpeculativeBindingOption _bindingOption;
|
|
|
|
public override bool IsSpeculativeSemanticModel => true;
|
|
|
|
public override int OriginalPositionForSpeculation => _position;
|
|
|
|
public override CSharpSemanticModel ParentModel => _parentSemanticModel;
|
|
|
|
internal override CSharpSyntaxNode Root => _root;
|
|
|
|
public static SpeculativeSyntaxTreeSemanticModel Create(SyntaxTreeSemanticModel parentSemanticModel, TypeSyntax root, Binder rootBinder, int position, SpeculativeBindingOption bindingOption)
|
|
{
|
|
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
|
|
return CreateCore(parentSemanticModel, root, rootBinder, position, bindingOption);
|
|
}
|
|
|
|
public static SpeculativeSyntaxTreeSemanticModel Create(SyntaxTreeSemanticModel parentSemanticModel, CrefSyntax root, Binder rootBinder, int position)
|
|
{
|
|
return CreateCore(parentSemanticModel, root, rootBinder, position, (SpeculativeBindingOption)1);
|
|
}
|
|
|
|
private static SpeculativeSyntaxTreeSemanticModel CreateCore(SyntaxTreeSemanticModel parentSemanticModel, CSharpSyntaxNode root, Binder rootBinder, int position, SpeculativeBindingOption bindingOption)
|
|
{
|
|
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
|
|
return new SpeculativeSyntaxTreeSemanticModel(parentSemanticModel, root, rootBinder, position, bindingOption);
|
|
}
|
|
|
|
private SpeculativeSyntaxTreeSemanticModel(SyntaxTreeSemanticModel parentSemanticModel, CSharpSyntaxNode root, Binder rootBinder, int position, SpeculativeBindingOption bindingOption)
|
|
: base(parentSemanticModel.Compilation, parentSemanticModel.SyntaxTree, root.SyntaxTree, ((SemanticModel)parentSemanticModel).IgnoresAccessibility)
|
|
{
|
|
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
|
|
_parentSemanticModel = parentSemanticModel;
|
|
_root = root;
|
|
_rootBinder = rootBinder;
|
|
_position = position;
|
|
_bindingOption = bindingOption;
|
|
}
|
|
|
|
internal override BoundNode Bind(Binder binder, CSharpSyntaxNode node, BindingDiagnosticBag diagnostics)
|
|
{
|
|
return _parentSemanticModel.Bind(binder, node, diagnostics);
|
|
}
|
|
|
|
internal override Binder GetEnclosingBinderInternal(int position)
|
|
{
|
|
return _rootBinder;
|
|
}
|
|
|
|
private SpeculativeBindingOption GetSpeculativeBindingOption(ExpressionSyntax node)
|
|
{
|
|
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
|
if (SyntaxFacts.IsInNamespaceOrTypeContext(node))
|
|
{
|
|
return (SpeculativeBindingOption)1;
|
|
}
|
|
return _bindingOption;
|
|
}
|
|
|
|
internal override SymbolInfo GetSymbolInfoWorker(CSharpSyntaxNode node, SymbolInfoOptions options, CancellationToken cancellationToken = default(CancellationToken))
|
|
{
|
|
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_005d: 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_0043: Unknown result type (might be due to invalid IL or missing references)
|
|
if (node is CrefSyntax cref)
|
|
{
|
|
return _parentSemanticModel.GetSpeculativeSymbolInfo(_position, cref, options);
|
|
}
|
|
ExpressionSyntax expressionSyntax = (ExpressionSyntax)node;
|
|
if ((options & SymbolInfoOptions.PreserveAliases) != 0)
|
|
{
|
|
return new SymbolInfo((ISymbol)(object)((SemanticModel)_parentSemanticModel).GetSpeculativeAliasInfo(_position, (SyntaxNode)(object)expressionSyntax, GetSpeculativeBindingOption(expressionSyntax)));
|
|
}
|
|
return _parentSemanticModel.GetSpeculativeSymbolInfo(_position, expressionSyntax, GetSpeculativeBindingOption(expressionSyntax));
|
|
}
|
|
|
|
internal override CSharpTypeInfo GetTypeInfoWorker(CSharpSyntaxNode node, CancellationToken cancellationToken = default(CancellationToken))
|
|
{
|
|
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
|
|
ExpressionSyntax expressionSyntax = (ExpressionSyntax)node;
|
|
return _parentSemanticModel.GetSpeculativeTypeInfoWorker(_position, expressionSyntax, GetSpeculativeBindingOption(expressionSyntax));
|
|
}
|
|
}
|