2023-05-25 01:01:57 -05:00
|
|
|
using System;
|
2023-10-08 23:54:01 -05:00
|
|
|
using System.Text;
|
2023-05-25 01:01:57 -05:00
|
|
|
|
|
|
|
|
namespace Microsoft.Iris.Debug.Data;
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
2023-05-25 02:20:01 -05:00
|
|
|
public class InterpreterObject
|
2023-05-25 01:01:57 -05:00
|
|
|
{
|
2023-08-22 02:04:19 -05:00
|
|
|
private object _value;
|
|
|
|
|
|
2023-05-25 01:01:57 -05:00
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
public Type Type { get; set; }
|
|
|
|
|
|
2023-08-22 02:04:19 -05:00
|
|
|
public object Value
|
|
|
|
|
{
|
|
|
|
|
get => _value;
|
|
|
|
|
set
|
|
|
|
|
{
|
2023-08-25 14:38:51 -05:00
|
|
|
if (value is byte[] bytes)
|
|
|
|
|
{
|
|
|
|
|
if (Type == typeof(uint))
|
|
|
|
|
_value = BitConverter.ToUInt32(bytes, 0);
|
|
|
|
|
else if (Type == typeof(ulong))
|
|
|
|
|
_value = BitConverter.ToUInt64(bytes, 0);
|
|
|
|
|
}
|
2023-08-22 02:04:19 -05:00
|
|
|
else
|
2023-08-25 14:38:51 -05:00
|
|
|
{
|
2023-08-22 02:04:19 -05:00
|
|
|
_value = value;
|
2023-08-25 14:38:51 -05:00
|
|
|
}
|
2023-08-22 02:04:19 -05:00
|
|
|
}
|
|
|
|
|
}
|
2023-05-25 01:01:57 -05:00
|
|
|
|
|
|
|
|
public InstructionObjectSource Source { get; set; }
|
|
|
|
|
|
|
|
|
|
public int TableIndex { get; set; } = -1;
|
|
|
|
|
|
|
|
|
|
public InterpreterObject(string name, Type type, object value, InstructionObjectSource source, int tableIndex = -1)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
Type = type;
|
|
|
|
|
Value = value;
|
|
|
|
|
Source = source;
|
|
|
|
|
TableIndex = tableIndex;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-25 21:01:48 -05:00
|
|
|
public InterpreterObject(object value) : this(null, value?.GetType(), value, InstructionObjectSource.Dynamic)
|
2023-05-25 01:01:57 -05:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-25 21:01:48 -05:00
|
|
|
public InterpreterObject() { }
|
|
|
|
|
|
2023-10-08 23:54:01 -05:00
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new();
|
|
|
|
|
ToString(sb, true);
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 13:23:18 -05:00
|
|
|
public void ToString(StringBuilder sb, bool includeType = false, bool includeSource = false)
|
2023-10-08 23:54:01 -05:00
|
|
|
{
|
|
|
|
|
if (includeType)
|
|
|
|
|
{
|
|
|
|
|
sb.Append(Type?.Name);
|
|
|
|
|
sb.Append(' ');
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 13:23:18 -05:00
|
|
|
if (includeSource)
|
2023-10-08 23:54:01 -05:00
|
|
|
{
|
2023-10-11 13:23:18 -05:00
|
|
|
if (Source == InstructionObjectSource.Inline)
|
|
|
|
|
sb.Append(Value ?? "NULL");
|
|
|
|
|
else
|
|
|
|
|
sb.Append(Source);
|
|
|
|
|
|
|
|
|
|
if (TableIndex != -1)
|
|
|
|
|
{
|
|
|
|
|
sb.Append('[');
|
|
|
|
|
sb.Append(TableIndex);
|
|
|
|
|
sb.Append(']');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sb.Append(Value ?? "NULL");
|
2023-10-08 23:54:01 -05:00
|
|
|
}
|
|
|
|
|
}
|
2023-05-25 01:01:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates where the argument value came from.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public enum InstructionObjectSource : byte
|
|
|
|
|
{
|
|
|
|
|
Dynamic,
|
|
|
|
|
Stack,
|
|
|
|
|
Inline,
|
|
|
|
|
Exports,
|
|
|
|
|
Alias,
|
|
|
|
|
DataMappings,
|
|
|
|
|
BinaryData,
|
|
|
|
|
Constants,
|
|
|
|
|
SymbolReference,
|
|
|
|
|
|
|
|
|
|
Imports = 1 << 4,
|
|
|
|
|
TypeImports = Imports | 1,
|
|
|
|
|
ConstructorImports = Imports | 2,
|
|
|
|
|
PropertyImports = Imports | 3,
|
|
|
|
|
MethodImports = Imports | 4,
|
|
|
|
|
EventImports = Imports | 5,
|
|
|
|
|
}
|