Guess expression return types

This commit is contained in:
Yoshi Askharoun
2025-08-02 21:37:15 -05:00
parent 3a6dfd9f49
commit f82630c6c1
3 changed files with 49 additions and 1 deletions
+27 -1
View File
@@ -1,4 +1,7 @@
using Microsoft.Iris.Asm;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.Iris.Asm;
using Microsoft.Iris.Asm.Models;
using Microsoft.Iris.Markup;
namespace Microsoft.Iris.DecompXml.Mock;
@@ -19,6 +22,10 @@ internal record IrisObject(object Object, TypeSchema Type)
{
type ??= UIXTypes.MapIDToType(UIXTypeID.Null);
}
else if (objIn is ExpressionSyntax expr)
{
type ??= GuessExpressionReturnType(expr, context);
}
if (objIn is Disassembler.RawConstantInfo constantInfo)
{
@@ -30,4 +37,23 @@ internal record IrisObject(object Object, TypeSchema Type)
return new(obj, type);
}
private static TypeSchema GuessExpressionReturnType(ExpressionSyntax expr, DecompileContext ctx)
{
if (expr is MemberAccessExpressionSyntax memberAccessExpression)
{
// TODO: Handle member access on instance methods
var sourceExpr = (IdentifierNameSyntax)memberAccessExpression.Expression;
var sourceTypeName = QualifiedTypeName.Parse(sourceExpr.ToString());
var sourceType = ctx.GetImportedType(sourceTypeName);
var memberName = memberAccessExpression.TryGetInferredMemberName();
var property = sourceType.FindPropertyDeep(memberName);
if (property is not null)
return property.PropertyType;
}
return null;
}
}