180 lines
4.8 KiB
C#
180 lines
4.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using Microsoft.CodeAnalysis.PooledObjects;
|
|
using Roslyn.Utilities;
|
|
|
|
namespace Microsoft.CodeAnalysis.CSharp.Symbols;
|
|
|
|
internal struct RefKindVector : IEquatable<RefKindVector>
|
|
{
|
|
private const int BitsPerRefKind = 3;
|
|
|
|
private BitVector _bits;
|
|
|
|
internal bool IsNull => ((BitVector)(ref _bits)).IsNull;
|
|
|
|
internal int Capacity => ((BitVector)(ref _bits)).Capacity / 3;
|
|
|
|
internal RefKind this[int index]
|
|
{
|
|
get
|
|
{
|
|
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_006b: 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)
|
|
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
|
|
index *= 3;
|
|
(bool, bool, bool) tuple = (((BitVector)(ref _bits))[index + 2], ((BitVector)(ref _bits))[index + 1], ((BitVector)(ref _bits))[index]);
|
|
if (!tuple.Item1)
|
|
{
|
|
if (!tuple.Item2)
|
|
{
|
|
if (!tuple.Item3)
|
|
{
|
|
return (RefKind)0;
|
|
}
|
|
return (RefKind)1;
|
|
}
|
|
if (!tuple.Item3)
|
|
{
|
|
return (RefKind)2;
|
|
}
|
|
return (RefKind)3;
|
|
}
|
|
if (!tuple.Item2 && !tuple.Item3)
|
|
{
|
|
return (RefKind)4;
|
|
}
|
|
throw ExceptionUtilities.UnexpectedValue((object)tuple);
|
|
}
|
|
set
|
|
{
|
|
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0040: Expected I4, but got Unknown
|
|
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
|
|
index *= 3;
|
|
ref BitVector bits = ref _bits;
|
|
int num = index + 2;
|
|
ref BitVector bits2 = ref _bits;
|
|
int num2 = index + 1;
|
|
ref BitVector bits3 = ref _bits;
|
|
int num3 = index;
|
|
(bool, bool, bool) tuple = (int)value switch
|
|
{
|
|
0 => (false, false, false),
|
|
1 => (false, false, true),
|
|
2 => (false, true, false),
|
|
3 => (false, true, true),
|
|
4 => (true, false, false),
|
|
_ => throw ExceptionUtilities.UnexpectedValue((object)value),
|
|
};
|
|
((BitVector)(ref bits))[num] = tuple.Item1;
|
|
((BitVector)(ref bits2))[num2] = tuple.Item2;
|
|
((BitVector)(ref bits3))[num3] = tuple.Item3;
|
|
}
|
|
}
|
|
|
|
internal static RefKindVector Create(int capacity)
|
|
{
|
|
return new RefKindVector(capacity);
|
|
}
|
|
|
|
private RefKindVector(int capacity)
|
|
{
|
|
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
|
|
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
|
|
_bits = BitVector.Create(capacity * 3);
|
|
}
|
|
|
|
private RefKindVector(BitVector bits)
|
|
{
|
|
//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)
|
|
_bits = bits;
|
|
}
|
|
|
|
internal IEnumerable<ulong> Words()
|
|
{
|
|
return ((BitVector)(ref _bits)).Words();
|
|
}
|
|
|
|
public bool Equals(RefKindVector other)
|
|
{
|
|
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
|
|
return ((BitVector)(ref _bits)).Equals(other._bits);
|
|
}
|
|
|
|
public override bool Equals(object? obj)
|
|
{
|
|
if (obj is RefKindVector other)
|
|
{
|
|
return Equals(other);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return ((object)Unsafe.As<BitVector, BitVector>(ref _bits)/*cast due to constrained. prefix*/).GetHashCode();
|
|
}
|
|
|
|
public string ToRefKindString()
|
|
{
|
|
PooledStringBuilder instance = PooledStringBuilder.GetInstance();
|
|
StringBuilder builder = instance.Builder;
|
|
builder.Append("{");
|
|
int num = 0;
|
|
foreach (ulong item in Words())
|
|
{
|
|
if (num > 0)
|
|
{
|
|
builder.Append(",");
|
|
}
|
|
builder.AppendFormat("{0:x8}", item);
|
|
num++;
|
|
}
|
|
builder.Append("}");
|
|
return instance.ToStringAndFree();
|
|
}
|
|
|
|
public static bool TryParse(string refKindString, int capacity, out RefKindVector result)
|
|
{
|
|
//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)
|
|
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
|
|
ulong? num = null;
|
|
ArrayBuilder<ulong> val = null;
|
|
string[] array = refKindString.Split(new char[1] { ',' });
|
|
foreach (string value in array)
|
|
{
|
|
ulong num2;
|
|
try
|
|
{
|
|
num2 = Convert.ToUInt64(value, 16);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
result = default(RefKindVector);
|
|
return false;
|
|
}
|
|
if (!num.HasValue)
|
|
{
|
|
num = num2;
|
|
continue;
|
|
}
|
|
if (val == null)
|
|
{
|
|
val = ArrayBuilder<ulong>.GetInstance();
|
|
}
|
|
val.Add(num2);
|
|
}
|
|
BitVector bits = BitVector.FromWords(num.Value, val?.ToArrayAndFree() ?? Array.Empty<ulong>(), capacity * 3);
|
|
result = new RefKindVector(bits);
|
|
return true;
|
|
}
|
|
}
|