mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
[WIP] Start handling inline expressions
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
using Microsoft.Iris.Markup;
|
||||
|
||||
namespace Microsoft.Iris.DecompXml.Mock;
|
||||
|
||||
internal interface IReturnValueProvider
|
||||
{
|
||||
TypeSchema ReturnType { get; }
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Microsoft.Iris.Markup;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
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 string Decompile(Decompiler decompiler)
|
||||
{
|
||||
if (TypeSchema.IsEnum)
|
||||
return $"{decompiler.GetQualifiedName(TypeSchema)}.{Value}";
|
||||
|
||||
return Value switch
|
||||
{
|
||||
string str => str,
|
||||
IStringEncodable strEnc => strEnc.EncodeString(),
|
||||
_ => Value?.ToString() ?? "null",
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Microsoft.Iris.DecompXml.Mock;
|
||||
|
||||
internal class IrisExpression : Expression
|
||||
{
|
||||
public virtual string Decompile(Decompiler decompiler) => ToString();
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using Microsoft.Iris.Markup;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
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 string Decompile(Decompiler decompiler)
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
|
||||
var qfn = decompiler.GetQualifiedName(Method.Owner);
|
||||
sb.Append(qfn);
|
||||
sb.Append('.');
|
||||
sb.Append(Method.Name);
|
||||
sb.Append('(');
|
||||
|
||||
sb.Append(string.Join(", ", _arguments.Select(exprToString)));
|
||||
|
||||
sb.Append(')');
|
||||
return sb.ToString();
|
||||
|
||||
string exprToString(Expression x)
|
||||
{
|
||||
return x is IrisExpression irisExpr
|
||||
? irisExpr.Decompile(decompiler)
|
||||
: x.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user