77 lines
3.1 KiB
C#
77 lines
3.1 KiB
C#
using System.Collections.Immutable;
|
|
using System.Threading;
|
|
using Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp;
|
|
|
|
internal abstract class LockOrUsingBinder : LocalScopeBinder
|
|
{
|
|
private class ExpressionAndDiagnostics
|
|
{
|
|
public readonly BoundExpression Expression;
|
|
|
|
public readonly ImmutableBindingDiagnostic<AssemblySymbol> Diagnostics;
|
|
|
|
public ExpressionAndDiagnostics(BoundExpression expression, ImmutableBindingDiagnostic<AssemblySymbol> diagnostics)
|
|
{
|
|
//IL_000e: 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)
|
|
Expression = expression;
|
|
Diagnostics = diagnostics;
|
|
}
|
|
}
|
|
|
|
private ImmutableHashSet<Symbol> _lazyLockedOrDisposedVariables;
|
|
|
|
private ExpressionAndDiagnostics _lazyExpressionAndDiagnostics;
|
|
|
|
protected abstract ExpressionSyntax TargetExpressionSyntax { get; }
|
|
|
|
internal sealed override ImmutableHashSet<Symbol> LockedOrDisposedVariables
|
|
{
|
|
get
|
|
{
|
|
if (_lazyLockedOrDisposedVariables == null)
|
|
{
|
|
ImmutableHashSet<Symbol> immutableHashSet = base.Next.LockedOrDisposedVariables;
|
|
ExpressionSyntax targetExpressionSyntax = TargetExpressionSyntax;
|
|
if (targetExpressionSyntax != null && targetExpressionSyntax.Kind() == SyntaxKind.IdentifierName)
|
|
{
|
|
BoundExpression boundExpression = BindTargetExpression(null, GetBinder((SyntaxNode)(object)targetExpressionSyntax.Parent));
|
|
switch (boundExpression.Kind)
|
|
{
|
|
case BoundKind.Local:
|
|
immutableHashSet = immutableHashSet.Add(((BoundLocal)boundExpression).LocalSymbol);
|
|
break;
|
|
case BoundKind.Parameter:
|
|
immutableHashSet = immutableHashSet.Add(((BoundParameter)boundExpression).ParameterSymbol);
|
|
break;
|
|
}
|
|
}
|
|
Interlocked.CompareExchange(ref _lazyLockedOrDisposedVariables, immutableHashSet, null);
|
|
}
|
|
return _lazyLockedOrDisposedVariables;
|
|
}
|
|
}
|
|
|
|
internal LockOrUsingBinder(Binder enclosing)
|
|
: base(enclosing)
|
|
{
|
|
}
|
|
|
|
protected BoundExpression BindTargetExpression(BindingDiagnosticBag diagnostics, Binder originalBinder, TypeSymbol targetTypeOpt = null)
|
|
{
|
|
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
|
|
if (_lazyExpressionAndDiagnostics == null)
|
|
{
|
|
BindingDiagnosticBag instance = BindingDiagnosticBag.GetInstance();
|
|
BoundExpression expression = originalBinder.BindValue(TargetExpressionSyntax, instance, BindValueKind.RValueOrMethodGroup);
|
|
Interlocked.CompareExchange(value: new ExpressionAndDiagnostics(((object)targetTypeOpt == null) ? originalBinder.BindToNaturalType(expression, instance) : originalBinder.GenerateConversionForAssignment(targetTypeOpt, expression, instance), ((BindingDiagnosticBag<AssemblySymbol>)(object)instance).ToReadOnlyAndFree()), location1: ref _lazyExpressionAndDiagnostics, comparand: null);
|
|
}
|
|
((BindingDiagnosticBag<AssemblySymbol>)(object)diagnostics)?.AddRange(_lazyExpressionAndDiagnostics.Diagnostics, true);
|
|
return _lazyExpressionAndDiagnostics.Expression;
|
|
}
|
|
}
|