Support method calls on instances

This commit is contained in:
Yoshi Askharoun
2025-07-17 17:52:57 -05:00
parent 8a4b3853b2
commit 64f7a445eb
2 changed files with 22 additions and 14 deletions
+9 -2
View File
@@ -8,7 +8,7 @@ internal class IrisExpression : Expression
{
public virtual string Decompile(DecompileContext context) => ToString();
public static Expression ToExpression(object p)
public static Expression Wrap(object p)
{
return p switch
{
@@ -16,7 +16,14 @@ internal class IrisExpression : Expression
Expression expr => expr,
Disassembler.RawConstantInfo constantInfo => new IrisConstantExpression(constantInfo.Value, constantInfo.Type),
_ => throw new NotImplementedException()
_ => 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();
}
}
@@ -33,22 +33,23 @@ internal class IrisMethodCallExpression : IrisExpression, IArgumentProvider, IRe
{
StringBuilder sb = new();
var qfn = context.GetQualifiedName(Method.Owner);
sb.Append(qfn);
if (Target is null)
{
var qfn = context.GetQualifiedName(Method.Owner);
sb.Append(qfn);
}
else
{
sb.Append(Decompile(Target, context));
}
sb.Append('.');
sb.Append(Method.Name);
sb.Append('(');
sb.Append(string.Join(", ", _arguments.Select(exprToString)));
sb.Append(string.Join(", ", _arguments.Select(x => Decompile(x, context))));
sb.Append(')');
return sb.ToString();
string exprToString(Expression x)
{
return x is IrisExpression irisExpr
? irisExpr.Decompile(context)
: x.ToString();
}
return sb.ToString();
}
}