391 lines
14 KiB
C#
391 lines
14 KiB
C#
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using Microsoft.Cci;
|
|
using Microsoft.CodeAnalysis.CSharp.Emit;
|
|
using Microsoft.CodeAnalysis.CSharp.Emit.NoPia;
|
|
using Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel;
|
|
using Microsoft.CodeAnalysis.CodeGen;
|
|
using Microsoft.CodeAnalysis.Emit;
|
|
using Roslyn.Utilities;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
|
|
internal abstract class PropertySymbol : Symbol, IPropertyDefinition, ISignature, ITypeDefinitionMember, ITypeMemberReference, IReference, INamedEntity, IDefinition
|
|
{
|
|
private ParameterSignature _lazyParameterSignature;
|
|
|
|
MetadataConstant IPropertyDefinition.DefaultValue => null;
|
|
|
|
IMethodReference IPropertyDefinition.Getter
|
|
{
|
|
get
|
|
{
|
|
MethodSymbol getMethod = AdaptedPropertySymbol.GetMethod;
|
|
if ((object)getMethod != null || !AdaptedPropertySymbol.IsSealed)
|
|
{
|
|
return (IMethodReference)(object)getMethod?.GetCciAdapter();
|
|
}
|
|
return GetSynthesizedSealedAccessor((MethodKind)11);
|
|
}
|
|
}
|
|
|
|
bool IPropertyDefinition.HasDefaultValue => false;
|
|
|
|
bool IPropertyDefinition.IsRuntimeSpecial => AdaptedPropertySymbol.HasRuntimeSpecialName;
|
|
|
|
bool IPropertyDefinition.IsSpecialName => AdaptedPropertySymbol.HasSpecialName;
|
|
|
|
ImmutableArray<IParameterDefinition> IPropertyDefinition.Parameters => StaticCast<IParameterDefinition>.From<ParameterSymbol>(AdaptedPropertySymbol.Parameters);
|
|
|
|
IMethodReference IPropertyDefinition.Setter
|
|
{
|
|
get
|
|
{
|
|
MethodSymbol setMethod = AdaptedPropertySymbol.SetMethod;
|
|
if ((object)setMethod != null || !AdaptedPropertySymbol.IsSealed)
|
|
{
|
|
return (IMethodReference)(object)setMethod?.GetCciAdapter();
|
|
}
|
|
return GetSynthesizedSealedAccessor((MethodKind)12);
|
|
}
|
|
}
|
|
|
|
CallingConvention ISignature.CallingConvention => AdaptedPropertySymbol.CallingConvention;
|
|
|
|
ushort ISignature.ParameterCount => (ushort)AdaptedPropertySymbol.ParameterCount;
|
|
|
|
ImmutableArray<ICustomModifier> ISignature.ReturnValueCustomModifiers => AdaptedPropertySymbol.TypeWithAnnotations.CustomModifiers.As<ICustomModifier>();
|
|
|
|
ImmutableArray<ICustomModifier> ISignature.RefCustomModifiers => AdaptedPropertySymbol.RefCustomModifiers.As<ICustomModifier>();
|
|
|
|
bool ISignature.ReturnValueIsByRef => AdaptedPropertySymbol.RefKind.IsManagedReference();
|
|
|
|
ITypeDefinition ITypeDefinitionMember.ContainingTypeDefinition => (ITypeDefinition)(object)AdaptedPropertySymbol.ContainingType.GetCciAdapter();
|
|
|
|
TypeMemberVisibility ITypeDefinitionMember.Visibility => PEModuleBuilder.MemberVisibility(AdaptedPropertySymbol);
|
|
|
|
string INamedEntity.Name => AdaptedPropertySymbol.MetadataName;
|
|
|
|
internal PropertySymbol AdaptedPropertySymbol => this;
|
|
|
|
internal virtual bool HasRuntimeSpecialName => false;
|
|
|
|
public new virtual PropertySymbol OriginalDefinition => this;
|
|
|
|
protected sealed override Symbol OriginalSymbolDefinition => OriginalDefinition;
|
|
|
|
internal virtual ImmutableArray<string> NotNullMembers => ImmutableArray<string>.Empty;
|
|
|
|
internal virtual ImmutableArray<string> NotNullWhenTrueMembers => ImmutableArray<string>.Empty;
|
|
|
|
internal virtual ImmutableArray<string> NotNullWhenFalseMembers => ImmutableArray<string>.Empty;
|
|
|
|
public bool ReturnsByRef => (int)RefKind == 1;
|
|
|
|
public bool ReturnsByRefReadonly => (int)RefKind == 3;
|
|
|
|
public abstract RefKind RefKind { get; }
|
|
|
|
public abstract TypeWithAnnotations TypeWithAnnotations { get; }
|
|
|
|
public TypeSymbol Type => TypeWithAnnotations.Type;
|
|
|
|
public abstract ImmutableArray<CustomModifier> RefCustomModifiers { get; }
|
|
|
|
public abstract ImmutableArray<ParameterSymbol> Parameters { get; }
|
|
|
|
internal int ParameterCount => Parameters.Length;
|
|
|
|
internal ImmutableArray<TypeWithAnnotations> ParameterTypesWithAnnotations
|
|
{
|
|
get
|
|
{
|
|
ParameterSignature.PopulateParameterSignature(Parameters, ref _lazyParameterSignature);
|
|
return _lazyParameterSignature.parameterTypesWithAnnotations;
|
|
}
|
|
}
|
|
|
|
internal ImmutableArray<RefKind> ParameterRefKinds
|
|
{
|
|
get
|
|
{
|
|
ParameterSignature.PopulateParameterSignature(Parameters, ref _lazyParameterSignature);
|
|
return _lazyParameterSignature.parameterRefKinds;
|
|
}
|
|
}
|
|
|
|
public virtual bool RequiresInstanceReceiver => !IsStatic;
|
|
|
|
public abstract bool IsIndexer { get; }
|
|
|
|
public virtual bool IsIndexedProperty => false;
|
|
|
|
public bool IsReadOnly => (object)((PropertySymbol)this.GetLeastOverriddenMember(ContainingType)).SetMethod == null;
|
|
|
|
public bool IsWriteOnly => (object)((PropertySymbol)this.GetLeastOverriddenMember(ContainingType)).GetMethod == null;
|
|
|
|
internal abstract bool IsRequired { get; }
|
|
|
|
internal virtual bool IsDirectlyExcludedFromCodeCoverage => false;
|
|
|
|
internal abstract bool HasSpecialName { get; }
|
|
|
|
public abstract MethodSymbol GetMethod { get; }
|
|
|
|
public abstract MethodSymbol SetMethod { get; }
|
|
|
|
internal abstract CallingConvention CallingConvention { get; }
|
|
|
|
internal abstract bool MustCallMethodsDirectly { get; }
|
|
|
|
internal abstract bool HasUnscopedRefAttribute { get; }
|
|
|
|
public PropertySymbol OverriddenProperty
|
|
{
|
|
get
|
|
{
|
|
if (IsOverride)
|
|
{
|
|
if (base.IsDefinition)
|
|
{
|
|
return (PropertySymbol)OverriddenOrHiddenMembers.GetOverriddenMember();
|
|
}
|
|
return (PropertySymbol)OverriddenOrHiddenMembersResult.GetOverriddenMember(this, OriginalDefinition.OverriddenProperty);
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
internal virtual OverriddenOrHiddenMembersResult OverriddenOrHiddenMembers => this.MakeOverriddenOrHiddenMembers();
|
|
|
|
internal bool HidesBasePropertiesByName => (GetMethod ?? SetMethod)?.HidesBaseMethodsByName ?? false;
|
|
|
|
internal virtual bool IsExplicitInterfaceImplementation => ExplicitInterfaceImplementations.Any();
|
|
|
|
public abstract ImmutableArray<PropertySymbol> ExplicitInterfaceImplementations { get; }
|
|
|
|
public sealed override SymbolKind Kind => (SymbolKind)15;
|
|
|
|
public sealed override bool HasUnsupportedMetadata
|
|
{
|
|
get
|
|
{
|
|
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
|
|
DiagnosticInfo diagnosticInfo = GetUseSiteInfo().DiagnosticInfo;
|
|
bool flag = diagnosticInfo != null;
|
|
if (flag)
|
|
{
|
|
int code = diagnosticInfo.Code;
|
|
bool flag2 = ((code == 570 || code == 9041) ? true : false);
|
|
flag = flag2;
|
|
}
|
|
return flag;
|
|
}
|
|
}
|
|
|
|
IEnumerable<IMethodReference> IPropertyDefinition.GetAccessors(EmitContext context)
|
|
{
|
|
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
|
MethodSymbol methodSymbol = AdaptedPropertySymbol.GetMethod?.GetCciAdapter();
|
|
if (methodSymbol != null && Extensions.ShouldInclude((ITypeDefinitionMember)(object)methodSymbol, context))
|
|
{
|
|
yield return (IMethodReference)(object)methodSymbol;
|
|
}
|
|
MethodSymbol methodSymbol2 = AdaptedPropertySymbol.SetMethod?.GetCciAdapter();
|
|
if (methodSymbol2 != null && Extensions.ShouldInclude((ITypeDefinitionMember)(object)methodSymbol2, context))
|
|
{
|
|
yield return (IMethodReference)(object)methodSymbol2;
|
|
}
|
|
if (AdaptedPropertySymbol is SourcePropertySymbolBase sourcePropertySymbolBase && Extensions.ShouldInclude((ITypeDefinitionMember)(object)this, context))
|
|
{
|
|
SynthesizedSealedPropertyAccessor synthesizedSealedAccessorOpt = sourcePropertySymbolBase.SynthesizedSealedAccessorOpt;
|
|
if ((object)synthesizedSealedAccessorOpt != null)
|
|
{
|
|
yield return (IMethodReference)(object)synthesizedSealedAccessorOpt.GetCciAdapter();
|
|
}
|
|
}
|
|
}
|
|
|
|
[Conditional("DEBUG")]
|
|
private void CheckDefinitionInvariantAllowEmbedded()
|
|
{
|
|
}
|
|
|
|
ImmutableArray<IParameterTypeInformation> ISignature.GetParameters(EmitContext context)
|
|
{
|
|
return StaticCast<IParameterTypeInformation>.From<ParameterSymbol>(AdaptedPropertySymbol.Parameters);
|
|
}
|
|
|
|
ITypeReference ISignature.GetType(EmitContext context)
|
|
{
|
|
//IL_0000: 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 ((PEModuleBuilder<CSharpCompilation, SourceModuleSymbol, AssemblySymbol, TypeSymbol, NamedTypeSymbol, MethodSymbol, SyntaxNode, EmbeddedTypesManager, ModuleCompilationState>)(PEModuleBuilder)(object)context.Module).Translate(AdaptedPropertySymbol.Type, (SyntaxNode)(object)(CSharpSyntaxNode)(object)((EmitContext)(ref context)).SyntaxNode, context.Diagnostics);
|
|
}
|
|
|
|
ITypeReference ITypeMemberReference.GetContainingType(EmitContext context)
|
|
{
|
|
return (ITypeReference)(object)AdaptedPropertySymbol.ContainingType.GetCciAdapter();
|
|
}
|
|
|
|
void IReference.Dispatch(MetadataVisitor visitor)
|
|
{
|
|
visitor.Visit((IPropertyDefinition)(object)this);
|
|
}
|
|
|
|
IDefinition IReference.AsDefinition(EmitContext context)
|
|
{
|
|
return (IDefinition)(object)this;
|
|
}
|
|
|
|
private IMethodReference GetSynthesizedSealedAccessor(MethodKind targetMethodKind)
|
|
{
|
|
//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)
|
|
if (AdaptedPropertySymbol is SourcePropertySymbolBase { SynthesizedSealedAccessorOpt: var synthesizedSealedAccessorOpt })
|
|
{
|
|
if ((object)synthesizedSealedAccessorOpt == null || synthesizedSealedAccessorOpt.MethodKind != targetMethodKind)
|
|
{
|
|
return null;
|
|
}
|
|
return (IMethodReference)(object)synthesizedSealedAccessorOpt.GetCciAdapter();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
internal new PropertySymbol GetCciAdapter()
|
|
{
|
|
return this;
|
|
}
|
|
|
|
internal PropertySymbol()
|
|
{
|
|
}
|
|
|
|
internal PropertySymbol GetLeastOverriddenProperty(NamedTypeSymbol accessingTypeOpt)
|
|
{
|
|
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
|
|
accessingTypeOpt = accessingTypeOpt?.OriginalDefinition;
|
|
PropertySymbol propertySymbol = this;
|
|
while (propertySymbol.IsOverride && !propertySymbol.HidesBasePropertiesByName)
|
|
{
|
|
PropertySymbol overriddenProperty = propertySymbol.OverriddenProperty;
|
|
CompoundUseSiteInfo<AssemblySymbol> useSiteInfo = CompoundUseSiteInfo<AssemblySymbol>.Discarded;
|
|
if ((object)overriddenProperty == null || ((object)accessingTypeOpt != null && !AccessCheck.IsSymbolAccessible(overriddenProperty, accessingTypeOpt, ref useSiteInfo)))
|
|
{
|
|
break;
|
|
}
|
|
propertySymbol = overriddenProperty;
|
|
}
|
|
return propertySymbol;
|
|
}
|
|
|
|
internal override TResult Accept<TArgument, TResult>(CSharpSymbolVisitor<TArgument, TResult> visitor, TArgument argument)
|
|
{
|
|
return visitor.VisitProperty(this, argument);
|
|
}
|
|
|
|
public override void Accept(CSharpSymbolVisitor visitor)
|
|
{
|
|
visitor.VisitProperty(this);
|
|
}
|
|
|
|
public override TResult Accept<TResult>(CSharpSymbolVisitor<TResult> visitor)
|
|
{
|
|
return visitor.VisitProperty(this);
|
|
}
|
|
|
|
internal PropertySymbol AsMember(NamedTypeSymbol newOwner)
|
|
{
|
|
if (!newOwner.IsDefinition)
|
|
{
|
|
return new SubstitutedPropertySymbol(newOwner as SubstitutedNamedTypeSymbol, this);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
internal override UseSiteInfo<AssemblySymbol> GetUseSiteInfo()
|
|
{
|
|
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
|
|
if (base.IsDefinition)
|
|
{
|
|
return new UseSiteInfo<AssemblySymbol>(base.PrimaryDependency);
|
|
}
|
|
return OriginalDefinition.GetUseSiteInfo();
|
|
}
|
|
|
|
internal bool CalculateUseSiteDiagnostic(ref UseSiteInfo<AssemblySymbol> result)
|
|
{
|
|
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
|
|
if (DeriveUseSiteInfoFromType(ref result, TypeWithAnnotations, AllowedRequiredModifierType.None) || DeriveUseSiteInfoFromCustomModifiers(ref result, RefCustomModifiers, AllowedRequiredModifierType.System_Runtime_InteropServices_InAttribute) || DeriveUseSiteInfoFromParameters(ref result, Parameters))
|
|
{
|
|
return true;
|
|
}
|
|
if (ContainingModule.HasUnifiedReferences)
|
|
{
|
|
HashSet<TypeSymbol> checkedTypes = null;
|
|
DiagnosticInfo result2 = result.DiagnosticInfo;
|
|
if (TypeWithAnnotations.GetUnificationUseSiteDiagnosticRecursive(ref result2, this, ref checkedTypes) || Symbol.GetUnificationUseSiteDiagnosticRecursive(ref result2, RefCustomModifiers, this, ref checkedTypes) || Symbol.GetUnificationUseSiteDiagnosticRecursive(ref result2, Parameters, this, ref checkedTypes))
|
|
{
|
|
result = result.AdjustDiagnosticInfo(result2);
|
|
return true;
|
|
}
|
|
result = result.AdjustDiagnosticInfo(result2);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
protected sealed override bool IsHighestPriorityUseSiteErrorCode(int code)
|
|
{
|
|
if (code == 570 || code == 9041)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
protected sealed override ISymbol CreateISymbol()
|
|
{
|
|
return (ISymbol)(object)new Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.PropertySymbol(this);
|
|
}
|
|
|
|
public override bool Equals(Symbol symbol, TypeCompareKind compareKind)
|
|
{
|
|
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
|
|
if (!(symbol is PropertySymbol propertySymbol))
|
|
{
|
|
return false;
|
|
}
|
|
if ((object)this == propertySymbol)
|
|
{
|
|
return true;
|
|
}
|
|
if (propertySymbol is NativeIntegerPropertySymbol nativeIntegerPropertySymbol)
|
|
{
|
|
return nativeIntegerPropertySymbol.Equals(this, compareKind);
|
|
}
|
|
if (TypeSymbol.Equals(ContainingType, propertySymbol.ContainingType, compareKind))
|
|
{
|
|
return (object)OriginalDefinition == propertySymbol.OriginalDefinition;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
int num = 1;
|
|
num = Hash.Combine<NamedTypeSymbol>(ContainingType, num);
|
|
num = Hash.Combine<string>(Name, num);
|
|
return Hash.Combine(num, ParameterCount);
|
|
}
|
|
}
|