157 lines
5.7 KiB
C#
157 lines
5.7 KiB
C#
using System.Collections.Immutable;
|
|||
|
|
|
||
|
|
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
|
||
|
|
|
||
|
|
internal abstract class SourceEventAccessorSymbol : SourceMemberMethodSymbol
|
||
|
|
{
|
||
|
|
private readonly SourceEventSymbol _event;
|
||
|
|
|
||
|
|
private readonly string _name;
|
||
|
|
|
||
|
|
private readonly ImmutableArray<MethodSymbol> _explicitInterfaceImplementations;
|
||
|
|
|
||
|
|
private ImmutableArray<ParameterSymbol> _lazyParameters;
|
||
|
|
|
||
|
|
private TypeWithAnnotations _lazyReturnType;
|
||
|
|
|
||
|
|
public override string Name => _name;
|
||
|
|
|
||
|
|
internal override bool IsExplicitInterfaceImplementation => _event.IsExplicitInterfaceImplementation;
|
||
|
|
|
||
|
|
public override ImmutableArray<MethodSymbol> ExplicitInterfaceImplementations => _explicitInterfaceImplementations;
|
||
|
|
|
||
|
|
public sealed override bool AreLocalsZeroed
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
if (!_event.HasSkipLocalsInitAttribute)
|
||
|
|
{
|
||
|
|
return base.AreLocalsZeroed;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public SourceEventSymbol AssociatedEvent => _event;
|
||
|
|
|
||
|
|
public sealed override Symbol AssociatedSymbol => _event;
|
||
|
|
|
||
|
|
public sealed override bool ReturnsVoid
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
LazyMethodChecks();
|
||
|
|
return base.ReturnsVoid;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public sealed override TypeWithAnnotations ReturnTypeWithAnnotations
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
LazyMethodChecks();
|
||
|
|
return _lazyReturnType;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public sealed override ImmutableArray<CustomModifier> RefCustomModifiers => ImmutableArray<CustomModifier>.Empty;
|
||
|
|
|
||
|
|
public sealed override ImmutableArray<ParameterSymbol> Parameters
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
LazyMethodChecks();
|
||
|
|
return _lazyParameters;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public sealed override ImmutableArray<TypeParameterSymbol> TypeParameters => ImmutableArray<TypeParameterSymbol>.Empty;
|
||
|
|
|
||
|
|
internal Location Location => GetFirstLocation();
|
||
|
|
|
||
|
|
public SourceEventAccessorSymbol(SourceEventSymbol @event, SyntaxReference syntaxReference, Location location, EventSymbol explicitlyImplementedEventOpt, string aliasQualifierOpt, bool isAdder, bool isIterator, bool isNullableAnalysisEnabled, bool isExpressionBodied)
|
||
|
|
: base(@event.containingType, syntaxReference, location, isIterator, (declarationModifiers: @event.Modifiers, flags: SourceMemberMethodSymbol.MakeFlags((MethodKind)(isAdder ? 5 : 7), (RefKind)0, @event.Modifiers, returnsVoid: false, returnsVoidIsSet: false, isExpressionBodied, isExtensionMethod: false, isNullableAnalysisEnabled, isVarArg: false, @event.IsExplicitInterfaceImplementation)))
|
||
|
|
{
|
||
|
|
_event = @event;
|
||
|
|
string text;
|
||
|
|
ImmutableArray<MethodSymbol> explicitInterfaceImplementations;
|
||
|
|
if ((object)explicitlyImplementedEventOpt == null)
|
||
|
|
{
|
||
|
|
text = SourceEventSymbol.GetAccessorName(@event.Name, isAdder);
|
||
|
|
explicitInterfaceImplementations = ImmutableArray<MethodSymbol>.Empty;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
MethodSymbol methodSymbol = (isAdder ? explicitlyImplementedEventOpt.AddMethod : explicitlyImplementedEventOpt.RemoveMethod);
|
||
|
|
text = ExplicitInterfaceHelpers.GetMemberName(((object)methodSymbol != null) ? methodSymbol.Name : SourceEventSymbol.GetAccessorName(explicitlyImplementedEventOpt.Name, isAdder), explicitlyImplementedEventOpt.ContainingType, aliasQualifierOpt);
|
||
|
|
explicitInterfaceImplementations = (((object)methodSymbol == null) ? ImmutableArray<MethodSymbol>.Empty : ImmutableArray.Create(methodSymbol));
|
||
|
|
}
|
||
|
|
_explicitInterfaceImplementations = explicitInterfaceImplementations;
|
||
|
|
_name = GetOverriddenAccessorName(@event, isAdder) ?? text;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected sealed override void MethodChecks(BindingDiagnosticBag diagnostics)
|
||
|
|
{
|
||
|
|
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
|
||
|
|
//IL_0048: Invalid comparison between Unknown and I4
|
||
|
|
if (!_lazyReturnType.IsDefault)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
CSharpCompilation declaringCompilation = DeclaringCompilation;
|
||
|
|
if (_event.IsWindowsRuntimeEvent)
|
||
|
|
{
|
||
|
|
TypeSymbol wellKnownType = declaringCompilation.GetWellKnownType((WellKnownType)184);
|
||
|
|
Binder.ReportUseSite(wellKnownType, diagnostics, Location);
|
||
|
|
if ((int)MethodKind == 5)
|
||
|
|
{
|
||
|
|
_lazyReturnType = TypeWithAnnotations.Create(wellKnownType);
|
||
|
|
SetReturnsVoid(returnsVoid: false);
|
||
|
|
SynthesizedAccessorValueParameterSymbol item = new SynthesizedAccessorValueParameterSymbol(this, _event.TypeWithAnnotations, 0);
|
||
|
|
_lazyParameters = ImmutableArray.Create((ParameterSymbol)item);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
TypeSymbol specialType = declaringCompilation.GetSpecialType((SpecialType)6);
|
||
|
|
Binder.ReportUseSite(specialType, diagnostics, Location);
|
||
|
|
_lazyReturnType = TypeWithAnnotations.Create(specialType);
|
||
|
|
SetReturnsVoid(returnsVoid: true);
|
||
|
|
SynthesizedAccessorValueParameterSymbol item2 = new SynthesizedAccessorValueParameterSymbol(this, TypeWithAnnotations.Create(wellKnownType), 0);
|
||
|
|
_lazyParameters = ImmutableArray.Create((ParameterSymbol)item2);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
TypeSymbol specialType2 = declaringCompilation.GetSpecialType((SpecialType)6);
|
||
|
|
Binder.ReportUseSite(specialType2, diagnostics, Location);
|
||
|
|
_lazyReturnType = TypeWithAnnotations.Create(specialType2);
|
||
|
|
SetReturnsVoid(returnsVoid: true);
|
||
|
|
SynthesizedAccessorValueParameterSymbol item3 = new SynthesizedAccessorValueParameterSymbol(this, _event.TypeWithAnnotations, 0);
|
||
|
|
_lazyParameters = ImmutableArray.Create((ParameterSymbol)item3);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public sealed override ImmutableArray<ImmutableArray<TypeWithAnnotations>> GetTypeParameterConstraintTypes()
|
||
|
|
{
|
||
|
|
return ImmutableArray<ImmutableArray<TypeWithAnnotations>>.Empty;
|
||
|
|
}
|
||
|
|
|
||
|
|
public sealed override ImmutableArray<TypeParameterConstraintKind> GetTypeParameterConstraintKinds()
|
||
|
|
{
|
||
|
|
return ImmutableArray<TypeParameterConstraintKind>.Empty;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected string GetOverriddenAccessorName(SourceEventSymbol @event, bool isAdder)
|
||
|
|
{
|
||
|
|
if (IsOverride)
|
||
|
|
{
|
||
|
|
EventSymbol overriddenEvent = @event.OverriddenEvent;
|
||
|
|
if ((object)overriddenEvent != null)
|
||
|
|
{
|
||
|
|
return overriddenEvent.GetOwnOrInheritedAccessor(isAdder)?.Name;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|