Files

361 lines
14 KiB
C#
Raw Permalink Normal View History

2026-08-27 10:56:38 -06:00
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using Microsoft.Cci;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
internal sealed class LambdaSymbol : SourceMethodSymbolWithAttributes
{
private readonly Binder _binder;
private readonly Symbol _containingSymbol;
private readonly MessageID _messageID;
private readonly SyntaxNode _syntax;
private readonly ImmutableArray<ParameterSymbol> _parameters;
private RefKind _refKind;
private TypeWithAnnotations _returnType;
private readonly bool _isSynthesized;
private readonly bool _isAsync;
private readonly bool _isStatic;
private readonly DiagnosticBag _declarationDiagnostics;
private readonly HashSet<AssemblySymbol> _declarationDependencies;
internal static readonly TypeSymbol ReturnTypeIsBeingInferred = new UnsupportedMetadataTypeSymbol();
internal static readonly TypeSymbol InferenceFailureReturnType = new UnsupportedMetadataTypeSymbol();
public MessageID MessageID => _messageID;
public override MethodKind MethodKind => (MethodKind)0;
public override bool IsExtern => false;
public override bool IsSealed => false;
public override bool IsAbstract => false;
public override bool IsVirtual => false;
public override bool IsOverride => false;
public override bool IsStatic => _isStatic;
public override bool IsAsync => _isAsync;
internal override bool IsMetadataFinal => false;
public override bool IsVararg => false;
internal override bool HasSpecialName => false;
public override bool ReturnsVoid
{
get
{
if (ReturnTypeWithAnnotations.HasType)
{
return base.ReturnType.IsVoidType();
}
return false;
}
}
public override RefKind RefKind => _refKind;
public override TypeWithAnnotations ReturnTypeWithAnnotations => _returnType;
public override ImmutableArray<CustomModifier> RefCustomModifiers => ImmutableArray<CustomModifier>.Empty;
internal override bool IsExplicitInterfaceImplementation => false;
public override ImmutableArray<MethodSymbol> ExplicitInterfaceImplementations => ImmutableArray<MethodSymbol>.Empty;
public override Symbol? AssociatedSymbol => null;
public override ImmutableArray<TypeWithAnnotations> TypeArgumentsWithAnnotations => ImmutableArray<TypeWithAnnotations>.Empty;
public override ImmutableArray<TypeParameterSymbol> TypeParameters => ImmutableArray<TypeParameterSymbol>.Empty;
public override int Arity => 0;
public override ImmutableArray<ParameterSymbol> Parameters => _parameters;
public override Accessibility DeclaredAccessibility => (Accessibility)1;
public override ImmutableArray<Location> Locations => ImmutableArray.Create<Location>(_syntax.Location);
internal Location DiagnosticLocation
{
get
{
//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_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)
SyntaxNode syntax = _syntax;
SyntaxToken val;
if (!(syntax is AnonymousMethodExpressionSyntax anonymousMethodExpressionSyntax))
{
if (syntax is LambdaExpressionSyntax lambdaExpressionSyntax)
{
val = lambdaExpressionSyntax.ArrowToken;
return ((SyntaxToken)(ref val)).GetLocation();
}
return GetFirstLocation();
}
val = anonymousMethodExpressionSyntax.DelegateKeyword;
return ((SyntaxToken)(ref val)).GetLocation();
}
}
private bool HasExplicitReturnType
{
get
{
if (_syntax is ParenthesizedLambdaExpressionSyntax parenthesizedLambdaExpressionSyntax)
{
return parenthesizedLambdaExpressionSyntax.ReturnType != null;
}
return false;
}
}
public override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences => ImmutableArray.Create<SyntaxReference>(syntaxReferenceOpt);
public override Symbol ContainingSymbol => _containingSymbol;
internal override CallingConvention CallingConvention => (CallingConvention)0;
public override bool IsExtensionMethod => false;
internal override Binder OuterBinder => _binder;
internal override Binder WithTypeParametersBinder => _binder;
public override bool IsImplicitlyDeclared => _isSynthesized;
internal override bool GenerateDebugInfo => true;
internal override bool IsDeclaredReadOnly => false;
internal override bool IsInitOnly => false;
public LambdaSymbol(Binder binder, CSharpCompilation compilation, Symbol containingSymbol, UnboundLambda unboundLambda, ImmutableArray<TypeWithAnnotations> parameterTypes, ImmutableArray<RefKind> parameterRefKinds, RefKind refKind, TypeWithAnnotations returnType)
: base(unboundLambda.Syntax.GetReference())
{
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Expected O, but got Unknown
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
_binder = binder;
_containingSymbol = containingSymbol;
_messageID = unboundLambda.Data.MessageID;
_syntax = unboundLambda.Syntax;
if (!unboundLambda.HasExplicitReturnType(out _refKind, out _returnType))
{
_refKind = refKind;
_returnType = ((!returnType.HasType) ? TypeWithAnnotations.Create(ReturnTypeIsBeingInferred) : returnType);
}
_isSynthesized = unboundLambda.WasCompilerGenerated;
_isAsync = unboundLambda.IsAsync;
_isStatic = unboundLambda.IsStatic;
_parameters = MakeParameters(compilation, unboundLambda, parameterTypes, parameterRefKinds);
_declarationDiagnostics = new DiagnosticBag();
_declarationDependencies = new HashSet<AssemblySymbol>();
}
internal sealed override bool IsMetadataNewSlot(bool ignoreInterfaceImplementationChanges = false)
{
return false;
}
internal sealed override bool IsMetadataVirtual(bool ignoreInterfaceImplementationChanges = false)
{
return false;
}
internal void SetInferredReturnType(RefKind refKind, TypeWithAnnotations inferredReturnType)
{
//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)
_refKind = refKind;
_returnType = inferredReturnType;
}
internal override bool TryGetThisParameter(out ParameterSymbol? thisParameter)
{
thisParameter = null;
return true;
}
internal override OneOrMany<SyntaxList<AttributeListSyntax>> GetAttributeDeclarations()
{
//IL_001a: 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_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
if (!(_syntax is LambdaExpressionSyntax lambdaExpressionSyntax))
{
return default(OneOrMany<SyntaxList<AttributeListSyntax>>);
}
return OneOrMany.Create<SyntaxList<AttributeListSyntax>>(lambdaExpressionSyntax.AttributeLists);
}
internal void GetDeclarationDiagnostics(BindingDiagnosticBag addTo)
{
ImmutableArray<ParameterSymbol>.Enumerator enumerator = _parameters.GetEnumerator();
while (enumerator.MoveNext())
{
enumerator.Current.ForceComplete(null, default(CancellationToken));
}
GetAttributes();
GetReturnTypeAttributes();
BindingDiagnosticBag instance = BindingDiagnosticBag.GetInstance();
AsyncMethodChecks(HasExplicitReturnType, DiagnosticLocation, instance);
if (!HasExplicitReturnType && this.HasAsyncMethodBuilderAttribute(out object _))
{
addTo.Add(ErrorCode.ERR_BuilderAttributeDisallowed, DiagnosticLocation);
}
_declarationDiagnostics.AddRange(((BindingDiagnosticBag)instance).DiagnosticBag);
ISetExtensions.AddAll<AssemblySymbol>((ISet<AssemblySymbol>)_declarationDependencies, (IEnumerable<AssemblySymbol>)((BindingDiagnosticBag<AssemblySymbol>)(object)instance).DependenciesBag);
((BindingDiagnosticBag<AssemblySymbol>)(object)instance).Free();
((BindingDiagnosticBag<AssemblySymbol>)(object)addTo).AddRange(_declarationDiagnostics);
((BindingDiagnosticBag<AssemblySymbol>)(object)addTo).AddDependencies((IReadOnlyCollection<AssemblySymbol>)_declarationDependencies);
}
internal override void AddDeclarationDiagnostics(BindingDiagnosticBag diagnostics)
{
DiagnosticBag diagnosticBag = ((BindingDiagnosticBag)diagnostics).DiagnosticBag;
if (diagnosticBag != null)
{
_declarationDiagnostics.AddRange(diagnosticBag);
}
ICollection<AssemblySymbol> dependenciesBag = ((BindingDiagnosticBag<AssemblySymbol>)(object)diagnostics).DependenciesBag;
if (dependenciesBag != null)
{
ISetExtensions.AddAll<AssemblySymbol>((ISet<AssemblySymbol>)_declarationDependencies, (IEnumerable<AssemblySymbol>)dependenciesBag);
}
}
private ImmutableArray<ParameterSymbol> MakeParameters(CSharpCompilation compilation, UnboundLambda unboundLambda, ImmutableArray<TypeWithAnnotations> parameterTypes, ImmutableArray<RefKind> parameterRefKinds)
{
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
if (!unboundLambda.HasSignature || unboundLambda.ParameterCount == 0)
{
return ImmutableArrayExtensions.SelectAsArray<TypeWithAnnotations, (LambdaSymbol, ImmutableArray<RefKind>), ParameterSymbol>(parameterTypes, (Func<TypeWithAnnotations, int, (LambdaSymbol, ImmutableArray<RefKind>), ParameterSymbol>)((TypeWithAnnotations type, int ordinal, (LambdaSymbol owner, ImmutableArray<RefKind> refKinds) arg) => SynthesizedParameterSymbol.Create(arg.owner, type, ordinal, arg.refKinds[ordinal], GeneratedNames.LambdaCopyParameterName(ordinal), (ScopedKind)0)), (this, parameterRefKinds));
}
ArrayBuilder<ParameterSymbol> instance = ArrayBuilder<ParameterSymbol>.GetInstance(unboundLambda.ParameterCount);
bool hasExplicitlyTypedParameterList = unboundLambda.HasExplicitlyTypedParameterList;
int length = parameterTypes.Length;
for (int num = 0; num < unboundLambda.ParameterCount; num++)
{
ParameterSyntax parameterSyntax = null;
TypeWithAnnotations parameterType;
RefKind refKind;
ScopedKind scope;
if (hasExplicitlyTypedParameterList)
{
parameterType = unboundLambda.ParameterTypeWithAnnotations(num);
refKind = unboundLambda.RefKind(num);
scope = unboundLambda.DeclaredScope(num);
parameterSyntax = unboundLambda.ParameterSyntax(num);
}
else if (num < length)
{
parameterType = parameterTypes[num];
refKind = (RefKind)0;
scope = (ScopedKind)0;
}
else
{
parameterType = TypeWithAnnotations.Create(new ExtendedErrorTypeSymbol(compilation, string.Empty, 0, null));
refKind = (RefKind)0;
scope = (ScopedKind)0;
}
SyntaxList<AttributeListSyntax> attributeLists = unboundLambda.ParameterAttributes(num);
string name = unboundLambda.ParameterName(num);
Location location = unboundLambda.ParameterLocation(num);
bool isParams = parameterSyntax != null && ((IEnumerable<SyntaxToken>)(object)parameterSyntax.Modifiers).Any((SyntaxToken m) => m.IsKind(SyntaxKind.ParamsKeyword));
LambdaParameterSymbol lambdaParameterSymbol = new LambdaParameterSymbol(this, parameterSyntax?.GetReference(), attributeLists, parameterType, num, refKind, scope, name, unboundLambda.ParameterIsDiscard(num), isParams, location);
instance.Add((ParameterSymbol)lambdaParameterSymbol);
}
return instance.ToImmutableAndFree();
}
public sealed override bool Equals(Symbol symbol, TypeCompareKind compareKind)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
if ((object)this == symbol)
{
return true;
}
if (symbol is LambdaSymbol lambdaSymbol && lambdaSymbol._syntax == _syntax && lambdaSymbol._refKind == _refKind && TypeSymbol.Equals(lambdaSymbol.ReturnType, base.ReturnType, compareKind) && ImmutableArrayExtensions.SequenceEqual<TypeWithAnnotations, TypeCompareKind>(base.ParameterTypesWithAnnotations, lambdaSymbol.ParameterTypesWithAnnotations, compareKind, (Func<TypeWithAnnotations, TypeWithAnnotations, TypeCompareKind, bool>)((TypeWithAnnotations p1, TypeWithAnnotations p2, TypeCompareKind comparison) => p1.Equals(p2, comparison))))
{
return lambdaSymbol.ContainingSymbol.Equals(ContainingSymbol, compareKind);
}
return false;
}
public override int GetHashCode()
{
return ((object)_syntax).GetHashCode();
}
public override ImmutableArray<ImmutableArray<TypeWithAnnotations>> GetTypeParameterConstraintTypes()
{
return ImmutableArray<ImmutableArray<TypeWithAnnotations>>.Empty;
}
public override ImmutableArray<TypeParameterConstraintKind> GetTypeParameterConstraintKinds()
{
return ImmutableArray<TypeParameterConstraintKind>.Empty;
}
internal override int CalculateLocalSyntaxOffset(int localPosition, SyntaxTree localTree)
{
throw ExceptionUtilities.Unreachable("/_/src/Compilers/CSharp/Portable/Symbols/Source/LambdaSymbol.cs", 433);
}
internal override bool IsNullableAnalysisEnabled()
{
throw ExceptionUtilities.Unreachable("/_/src/Compilers/CSharp/Portable/Symbols/Source/LambdaSymbol.cs", 436);
}
protected override void NoteAttributesComplete(bool forReturnType)
{
}
}