Files
2026-08-27 10:56:38 -06:00

239 lines
8.9 KiB
C#

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.RuntimeMembers;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
internal abstract class MetadataOrSourceAssemblySymbol : NonMissingAssemblySymbol
{
private NamedTypeSymbol[] _lazySpecialTypes;
private TypeConversions _lazyTypeConversions;
private int _cachedSpecialTypes;
private NativeIntegerTypeSymbol[] _lazyNativeIntegerTypes;
private ICollection<string> _lazyTypeNames;
private ICollection<string> _lazyNamespaceNames;
private Symbol[] _lazySpecialTypeMembers;
private ConcurrentDictionary<AssemblySymbol, IVTConclusion> _assembliesToWhichInternalAccessHasBeenAnalyzed;
internal override bool KeepLookingForDeclaredSpecialTypes
{
get
{
if ((object)base.CorLibrary == this)
{
return _cachedSpecialTypes < 46;
}
return false;
}
}
public override ICollection<string> TypeNames
{
get
{
if (_lazyTypeNames == null)
{
Interlocked.CompareExchange(ref _lazyTypeNames, UnionCollection<string>.Create<ModuleSymbol>(Modules, (Func<ModuleSymbol, ICollection<string>>)((ModuleSymbol m) => m.TypeNames)), null);
}
return _lazyTypeNames;
}
}
public override ICollection<string> NamespaceNames
{
get
{
if (_lazyNamespaceNames == null)
{
Interlocked.CompareExchange(ref _lazyNamespaceNames, UnionCollection<string>.Create<ModuleSymbol>(Modules, (Func<ModuleSymbol, ICollection<string>>)((ModuleSymbol m) => m.NamespaceNames)), null);
}
return _lazyNamespaceNames;
}
}
private ConcurrentDictionary<AssemblySymbol, IVTConclusion> AssembliesToWhichInternalAccessHasBeenDetermined
{
get
{
if (_assembliesToWhichInternalAccessHasBeenAnalyzed == null)
{
Interlocked.CompareExchange(ref _assembliesToWhichInternalAccessHasBeenAnalyzed, new ConcurrentDictionary<AssemblySymbol, IVTConclusion>(), null);
}
return _assembliesToWhichInternalAccessHasBeenAnalyzed;
}
}
internal sealed override TypeConversions TypeConversions
{
get
{
if (this != base.CorLibrary)
{
return base.CorLibrary.TypeConversions;
}
if (_lazyTypeConversions == null)
{
Interlocked.CompareExchange(ref _lazyTypeConversions, new TypeConversions(this), null);
}
return _lazyTypeConversions;
}
}
internal sealed override NamedTypeSymbol GetDeclaredSpecialType(SpecialType type)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//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_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Invalid comparison between Unknown and I4
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
if (_lazySpecialTypes == null || (object)_lazySpecialTypes[type] == null)
{
MetadataTypeName emittedName = MetadataTypeName.FromFullName(SpecialTypes.GetMetadataName(type), true, -1);
ModuleSymbol moduleSymbol = Modules[0];
NamedTypeSymbol namedTypeSymbol = moduleSymbol.LookupTopLevelMetadataType(ref emittedName);
if ((object)namedTypeSymbol == null || (int)namedTypeSymbol.DeclaredAccessibility != 6)
{
namedTypeSymbol = new MissingMetadataTypeSymbol.TopLevel(moduleSymbol, ref emittedName, type);
}
RegisterDeclaredSpecialType(namedTypeSymbol);
}
return _lazySpecialTypes[type];
}
internal sealed override void RegisterDeclaredSpecialType(NamedTypeSymbol corType)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
SpecialType specialType = corType.SpecialType;
if (_lazySpecialTypes == null)
{
Interlocked.CompareExchange(ref _lazySpecialTypes, new NamedTypeSymbol[47], null);
}
if ((object)Interlocked.CompareExchange(ref _lazySpecialTypes[specialType], corType, null) == null)
{
Interlocked.Increment(ref _cachedSpecialTypes);
}
}
internal sealed override NamedTypeSymbol GetNativeIntegerType(NamedTypeSymbol underlyingType)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: 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)
//IL_0025: Invalid comparison between Unknown and I4
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Invalid comparison between Unknown and I4
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
if (_lazyNativeIntegerTypes == null)
{
Interlocked.CompareExchange(ref _lazyNativeIntegerTypes, new NativeIntegerTypeSymbol[2], null);
}
SpecialType specialType = underlyingType.SpecialType;
int num;
if ((int)specialType != 21)
{
if ((int)specialType != 22)
{
throw ExceptionUtilities.UnexpectedValue((object)underlyingType.SpecialType);
}
num = 1;
}
else
{
num = 0;
}
int num2 = num;
if ((object)_lazyNativeIntegerTypes[num2] == null)
{
Interlocked.CompareExchange(ref _lazyNativeIntegerTypes[num2], new NativeIntegerTypeSymbol(underlyingType), null);
}
return _lazyNativeIntegerTypes[num2];
}
internal override Symbol GetDeclaredSpecialTypeMember(SpecialMember member)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: 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)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
if (_lazySpecialTypeMembers == null || (object)_lazySpecialTypeMembers[member] == ErrorTypeSymbol.UnknownResultType)
{
if (_lazySpecialTypeMembers == null)
{
Symbol[] array = new Symbol[128];
for (int i = 0; i < array.Length; i++)
{
array[i] = ErrorTypeSymbol.UnknownResultType;
}
Interlocked.CompareExchange(ref _lazySpecialTypeMembers, array, null);
}
MemberDescriptor descriptor = SpecialMembers.GetDescriptor(member);
NamedTypeSymbol declaredSpecialType = GetDeclaredSpecialType((SpecialType)(sbyte)descriptor.DeclaringTypeId);
Symbol value = null;
if (!declaredSpecialType.IsErrorType())
{
value = CSharpCompilation.GetRuntimeMember(declaredSpecialType, in descriptor, (SignatureComparer<MethodSymbol, FieldSymbol, PropertySymbol, TypeSymbol, ParameterSymbol>)(object)CSharpCompilation.SpecialMembersSignatureComparer.Instance, null);
}
Interlocked.CompareExchange(ref _lazySpecialTypeMembers[member], value, ErrorTypeSymbol.UnknownResultType);
}
return _lazySpecialTypeMembers[member];
}
protected IVTConclusion MakeFinalIVTDetermination(AssemblySymbol potentialGiverOfAccess)
{
//IL_0013: 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)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Invalid comparison between Unknown and I4
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
if (AssembliesToWhichInternalAccessHasBeenDetermined.TryGetValue(potentialGiverOfAccess, out var value))
{
return value;
}
value = (IVTConclusion)3;
IEnumerable<ImmutableArray<byte>> internalsVisibleToPublicKeys = potentialGiverOfAccess.GetInternalsVisibleToPublicKeys(Name);
if (internalsVisibleToPublicKeys.Any() && IsNetModule())
{
return (IVTConclusion)0;
}
foreach (ImmutableArray<byte> item in internalsVisibleToPublicKeys)
{
value = ISymbolExtensions.PerformIVTCheck(potentialGiverOfAccess.Identity, PublicKey, item);
if ((int)value == 0 || (int)value == 1)
{
break;
}
}
AssembliesToWhichInternalAccessHasBeenDetermined.TryAdd(potentialGiverOfAccess, value);
return value;
}
internal virtual bool IsNetModule()
{
return false;
}
}