mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Guess expression return types
This commit is contained in:
@@ -74,6 +74,15 @@ internal class DecompileContext
|
||||
|
||||
public TypeSchema GetImportedType(Operand op) => ImportTables.TypeImports[(ushort)op.Value];
|
||||
|
||||
public TypeSchema GetImportedType(QualifiedTypeName typeName)
|
||||
{
|
||||
var uri = MapPrefixToNamespace(typeName.NamespacePrefix);
|
||||
return ImportTables.TypeImports
|
||||
.Where(t => t.Name == typeName.TypeName || t.AlternateName == typeName.TypeName)
|
||||
.OrderBy(t => t.Owner.Uri == uri ? 0 : 1)
|
||||
.First();
|
||||
}
|
||||
|
||||
public MethodSchema GetImportedMethod(Operand op) => ImportTables.MethodImports[(ushort)op.Value];
|
||||
|
||||
public PropertySchema GetImportedProperty(Operand op) => ImportTables.PropertyImports[(ushort)op.Value];
|
||||
@@ -103,6 +112,11 @@ internal class DecompileContext
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public string MapPrefixToNamespace(string prefix)
|
||||
{
|
||||
return _uriAliasMap.First(kvp => kvp.Value == prefix).Key;
|
||||
}
|
||||
|
||||
public QualifiedTypeName GetQualifiedName(TypeSchema schema)
|
||||
{
|
||||
var prefix = MapNamespaceToPrefix(schema.Owner.Uri);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user