Remove unused classes

This commit is contained in:
Yoshi Askharoun
2025-07-20 10:24:49 -05:00
parent 14505cd006
commit 05d00fcdea
8 changed files with 17 additions and 260 deletions
-3
View File
@@ -349,15 +349,12 @@ public partial class Decompiler
obj = irisObj.Object; obj = irisObj.Object;
} }
return obj switch return obj switch
{ {
string str => str, string str => str,
null => "{null}", null => "{null}",
bool b => b ? "true" : "false", bool b => b ? "true" : "false",
IStringEncodable strEnc => strEnc.EncodeString(), IStringEncodable strEnc => strEnc.EncodeString(),
IrisExpression expr => '{' + expr.Decompile(_context) + '}',
ExpressionSyntax expr => FormatInlineExpression(expr), ExpressionSyntax expr => FormatInlineExpression(expr),
SymbolReference symRef => '{' + symRef.Symbol + '}', SymbolReference symRef => '{' + symRef.Symbol + '}',
IFormattable formattable => formattable.ToString(null, CultureInfo.InvariantCulture), IFormattable formattable => formattable.ToString(null, CultureInfo.InvariantCulture),
@@ -1,8 +0,0 @@
using Microsoft.Iris.Markup;
namespace Microsoft.Iris.DecompXml.Mock;
internal interface IReturnValueProvider
{
TypeSchema ReturnType { get; }
}
@@ -1,40 +0,0 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Iris.Markup;
using System;
using System.Linq.Expressions;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace Microsoft.Iris.DecompXml.Mock;
internal class IrisConstantExpression : IrisExpression, IReturnValueProvider
{
public IrisConstantExpression(object value, TypeSchema typeSchema)
{
Value = value;
TypeSchema = typeSchema;
}
public sealed override ExpressionType NodeType => ExpressionType.Constant;
public object Value { get; }
public TypeSchema TypeSchema { get; }
public TypeSchema ReturnType => TypeSchema;
public override ExpressionSyntax ToSyntax(DecompileContext context)
{
return Value switch
{
Enum enumValue => MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName(context.GetQualifiedName(TypeSchema).ToString()),
IdentifierName(Value.ToString())
),
_ => ToSyntax(Value, context)
};
}
}
+17 -29
View File
@@ -3,38 +3,13 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Iris.Asm; using Microsoft.Iris.Asm;
using Microsoft.Iris.Markup; using Microsoft.Iris.Markup;
using System; using System;
using System.Linq.Expressions;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace Microsoft.Iris.DecompXml.Mock; namespace Microsoft.Iris.DecompXml.Mock;
internal abstract class IrisExpression : Expression internal static class IrisExpression
{ {
public virtual string Decompile(DecompileContext context) => ToSyntax(context).ToString();
public abstract ExpressionSyntax ToSyntax(DecompileContext context);
public static Expression Wrap(object p)
{
return p switch
{
null => Constant(null),
Expression expr => expr,
Disassembler.RawConstantInfo constantInfo => new IrisConstantExpression(constantInfo.Value, constantInfo.Type),
SymbolReference symbolRef => Constant(symbolRef),
_ => throw new NotImplementedException($"Unable to wrap '{p}' in an expression")
};
}
public static string Decompile(Expression expr, DecompileContext context)
{
return expr is IrisExpression irisExpr
? irisExpr.Decompile(context)
: expr.ToString();
}
public static ExpressionSyntax ToSyntax(object obj, DecompileContext context) public static ExpressionSyntax ToSyntax(object obj, DecompileContext context)
{ {
return obj switch return obj switch
@@ -45,12 +20,11 @@ internal abstract class IrisExpression : Expression
string strValue => LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(strValue)), string strValue => LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(strValue)),
IStringEncodable strEnc => ParseExpression(strEnc.EncodeString()), IStringEncodable strEnc => ParseExpression(strEnc.EncodeString()),
Disassembler.RawConstantInfo constantInfo => new IrisConstantExpression(constantInfo.Value, constantInfo.Type).ToSyntax(context), Disassembler.RawConstantInfo constantInfo => ToSyntax(constantInfo.Value, constantInfo.Type, context),
IrisObject irisObj => ToSyntax(irisObj.Object, irisObj.Type, context),
SymbolReference symbolRef => ToSyntax(symbolRef), SymbolReference symbolRef => ToSyntax(symbolRef),
TypeSchema typeSchema => ToSyntax(typeSchema, context), TypeSchema typeSchema => ToSyntax(typeSchema, context),
IrisExpression irisExpr => irisExpr.ToSyntax(context),
Expression expr => ParseExpression(expr.ToString()),
ExpressionSyntax exprSyn => exprSyn, ExpressionSyntax exprSyn => exprSyn,
_ => IdentifierName(obj.ToString()) _ => IdentifierName(obj.ToString())
@@ -62,4 +36,18 @@ internal abstract class IrisExpression : Expression
public static IdentifierNameSyntax ToSyntax(SymbolReference symbolRef) => public static IdentifierNameSyntax ToSyntax(SymbolReference symbolRef) =>
IdentifierName(symbolRef.Symbol); IdentifierName(symbolRef.Symbol);
public static ExpressionSyntax ToSyntax(object obj, TypeSchema type, DecompileContext context)
{
return obj switch
{
Enum _ => MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName(context.GetQualifiedName(type).ToString()),
IdentifierName(obj.ToString())
),
_ => ToSyntax(obj, context),
};
}
} }
@@ -1,52 +0,0 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Iris.Markup;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace Microsoft.Iris.DecompXml.Mock;
internal class IrisMethodCallExpression : IrisExpression, IArgumentProvider, IReturnValueProvider
{
private readonly Expression[] _arguments;
public IrisMethodCallExpression(MethodSchema method, Expression? target, IEnumerable<Expression> arguments)
{
Method = method;
Target = target;
_arguments = arguments.ToArray();
}
public MethodSchema Method { get; }
public sealed override ExpressionType NodeType => ExpressionType.Call;
public Expression? Target { get; }
public int ArgumentCount => _arguments.Length;
public TypeSchema ReturnType => Method.ReturnType;
public Expression GetArgument(int index) => _arguments[index];
public override ExpressionSyntax ToSyntax(DecompileContext context)
{
var targetExpression = Target switch
{
null => IdentifierName(context.GetQualifiedName(Method.Owner).ToString()),
IrisExpression irisExpr => irisExpr.ToSyntax(context),
_ => IdentifierName(Target.ToString())
};
var methodExpression = MemberAccessExpression(CodeAnalysis.CSharp.SyntaxKind.SimpleMemberAccessExpression,
targetExpression, IdentifierName(Method.Name));
var argumentExpressions = _arguments
.Select(expr => ToSyntax(expr, context))
.Select(Argument);
return InvocationExpression(methodExpression, ArgumentList([..argumentExpressions]));
}
}
-5
View File
@@ -26,11 +26,6 @@ internal record IrisObject(object Object, TypeSchema Type)
type ??= constantInfo.Type; type ??= constantInfo.Type;
} }
if (objIn is IReturnValueProvider hasReturnValue)
{
type ??= hasReturnValue.ReturnType;
}
type ??= Disassembler.GuessTypeSchema(obj.GetType(), context.LoadResult); type ??= Disassembler.GuessTypeSchema(obj.GetType(), context.LoadResult);
return new(obj, type); return new(obj, type);
@@ -1,39 +0,0 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Iris.Markup;
using System.Linq.Expressions;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace Microsoft.Iris.DecompXml.Mock;
internal class IrisPropertyExpression : IrisExpression, IReturnValueProvider
{
public IrisPropertyExpression(PropertySchema property, Expression? target)
{
Property = property;
Target = target;
}
public new PropertySchema Property { get; }
public sealed override ExpressionType NodeType => ExpressionType.MemberAccess;
public Expression? Target { get; }
public TypeSchema ReturnType => Property.PropertyType;
public override ExpressionSyntax ToSyntax(DecompileContext context)
{
var targetExpression = Target switch
{
null => IdentifierName(context.GetQualifiedName(Property.Owner).ToString()),
IrisExpression irisExpr => irisExpr.ToSyntax(context),
_ => IdentifierName(Target.ToString())
};
var propertyAccessExpression = MemberAccessExpression(CodeAnalysis.CSharp.SyntaxKind.SimpleMemberAccessExpression,
targetExpression, IdentifierName(Property.Name));
return propertyAccessExpression;
}
}
-84
View File
@@ -1,84 +0,0 @@
using Microsoft.Iris.Library;
using Microsoft.Iris.Markup;
using Microsoft.Iris.Session;
using System;
using System.Collections.Generic;
namespace Microsoft.Iris.DecompXml.Mock;
internal class MockMarkupType : IMarkupTypeBase
{
private static readonly DeferredHandler s_executePendingScriptsHandler = ExecutePendingScripts;
private readonly Dictionary<string, object> _propertyStorage = [];
private readonly Dictionary<SymbolReference, object> _symbolStorage = [];
private readonly MarkupTypeSchema _typeSchema;
private List<IDisposableObject> _disposables = null;
private ScriptRunScheduler _scriptRunScheduler = new();
public MockMarkupType(MarkupTypeSchema typeSchema)
{
_typeSchema = typeSchema;
}
public TypeSchema TypeSchema => _typeSchema;
public MarkupListeners Listeners { get; set; }
public bool ScriptEnabled => true;
public Dictionary<object, object> Storage { get; } = [];
public IReadOnlyDictionary<string, object> Properties => _propertyStorage;
public IReadOnlyDictionary<SymbolReference, object> SymbolReferences => _symbolStorage;
public object GetProperty(string name) => _propertyStorage[name];
public void SetProperty(string name, object value) => _propertyStorage[name] = value;
public void NotifyInitialized() { }
public void NotifyScriptErrors() { }
public object ReadSymbol(SymbolReference symbolRef) => _symbolStorage[symbolRef];
public void WriteSymbol(SymbolReference symbolRef, object value) => _symbolStorage[symbolRef] = value;
public object RunScript(uint scriptId, bool ignoreErrors, ParameterContext parameterContext) => _typeSchema.Run(this, scriptId, ignoreErrors, parameterContext);
public void ScheduleScriptRun(uint scriptId, bool ignoreErrors)
{
if (!_scriptRunScheduler.Pending)
DeferredCall.Post(DispatchPriority.Script, s_executePendingScriptsHandler, this);
_scriptRunScheduler.ScheduleRun(scriptId, ignoreErrors);
}
private static void ExecutePendingScripts(object args)
{
var mockType = (MockMarkupType)args;
mockType._scriptRunScheduler.Execute(mockType);
}
public void RegisterDisposable(IDisposableObject disposable)
{
_disposables ??= [];
_disposables.Add(disposable);
}
public bool UnregisterDisposable(ref IDisposableObject disposable)
{
if (_disposables != null)
{
int index = _disposables.IndexOf(disposable);
if (index != -1)
{
disposable = _disposables[index];
_disposables.RemoveAt(index);
return true;
}
}
return false;
}
}