Files
MicrosoftIris/UIX/Microsoft/Iris/Markup/MarkupLineNumberTable.cs
T

87 lines
3.2 KiB
C#
Raw Normal View History

2022-03-03 08:14:05 -06:00
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Markup.MarkupLineNumberTable
// Assembly: UIX, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11
// Assembly location: C:\Program Files\Zune\UIX.dll
namespace Microsoft.Iris.Markup
{
2022-10-07 10:29:09 -05:00
public class MarkupLineNumberTable
2022-03-03 08:14:05 -06:00
{
2023-10-11 13:23:33 -05:00
private const ulong OFFSET_MASK = 0x3F_FFFFUL;
private const uint OFFSET_MAX = 0x3F_FFFF;
private const ulong LINE_MASK = 0x7FF_FFC0_0000UL;
2022-03-03 08:14:05 -06:00
private const int LINE_SHIFT = 22;
2023-10-11 13:23:33 -05:00
private const uint LINE_MAX = 0x1F_FFFF;
private const ulong COLUMN_MASK = 0xFFFF_F800_0000_0000UL;
2022-03-03 08:14:05 -06:00
private const int COLUMN_SHIFT = 43;
2023-10-11 13:23:33 -05:00
private const uint COLUMN_MAX = 0x1F_FFFF;
2022-03-03 08:14:05 -06:00
private Vector<ulong> _lookupTable;
private ulong[] _runtimeList;
public MarkupLineNumberTable() => _lookupTable = new Vector<ulong>();
public MarkupLineNumberTable(ulong[] runtimeList) => _runtimeList = runtimeList;
public void AddRecord(uint offset, int line, int column)
{
ulong num = Pack(offset, line, column);
if (_lookupTable.Count > 0 && (int)UnpackOffset(_lookupTable[_lookupTable.Count - 1]) == (int)offset)
_lookupTable[_lookupTable.Count - 1] = num;
else
_lookupTable.Add(num);
}
public void PrepareForRuntimeUse()
{
_runtimeList = new ulong[_lookupTable.Count];
for (int index = 0; index < _lookupTable.Count; ++index)
_runtimeList[index] = _lookupTable[index];
_lookupTable = null;
}
2023-05-23 21:35:58 -05:00
public bool TryLookup(uint offset, out int line, out int column)
2022-03-03 08:14:05 -06:00
{
int length = _runtimeList.Length;
int index = 0;
while (index < length && (offset < UnpackOffset(_runtimeList[index]) || index != length - 1 && offset >= UnpackOffset(_runtimeList[index + 1])))
++index;
if (index < length)
{
line = UnpackLine(_runtimeList[index]);
column = UnpackColumn(_runtimeList[index]);
2023-05-23 21:35:58 -05:00
return true;
2022-03-03 08:14:05 -06:00
}
else
{
line = -1;
column = -1;
2023-05-23 21:35:58 -05:00
return false;
2022-03-03 08:14:05 -06:00
}
}
internal ulong[] PersistList => _runtimeList;
2024-01-20 20:32:30 -06:00
public Debug.Data.MarkupLineNumberEntry[] DumpTable()
2022-03-03 08:14:05 -06:00
{
2024-01-20 20:32:30 -06:00
var knownLines = new Debug.Data.MarkupLineNumberEntry[_runtimeList.Length];
2023-10-11 13:23:33 -05:00
for (int index = 0; index < _runtimeList.Length; ++index)
{
var value = _runtimeList[index];
2024-01-20 20:32:30 -06:00
knownLines[index] = new(UnpackOffset(value), UnpackLine(value), UnpackColumn(value));
2023-10-11 13:23:33 -05:00
}
return knownLines;
2022-03-03 08:14:05 -06:00
}
2023-10-11 13:23:33 -05:00
private static ulong Pack(uint offset, int line, int column) => (ulong)(offset | (long)line << LINE_SHIFT | (long)column << COLUMN_SHIFT);
2022-03-03 08:14:05 -06:00
2023-10-11 13:23:33 -05:00
private static uint UnpackOffset(ulong value) => (uint)(value & OFFSET_MASK);
2022-03-03 08:14:05 -06:00
2023-10-11 13:23:33 -05:00
private static int UnpackLine(ulong value) => (int)((value & LINE_MASK) >> LINE_SHIFT);
2022-03-03 08:14:05 -06:00
2023-10-11 13:23:33 -05:00
private static int UnpackColumn(ulong value) => (int)((value & COLUMN_MASK) >> COLUMN_SHIFT);
2022-03-03 08:14:05 -06:00
}
}