Support getting type info when writing symbols to symbols

This commit is contained in:
Yoshi Askharoun
2025-09-24 19:21:12 -05:00
parent 2a8aca41c1
commit 5d6dd89f30
2 changed files with 12 additions and 6 deletions
+11 -5
View File
@@ -46,7 +46,7 @@ partial class Decompiler
.Where(i => i.OpCode is OpCode.Jump)
.Select(i => (uint)i.Operands.First().Value));
HashSet<string> scopedLocals = [];
Dictionary<string, TypeSchema> scopedLocals = [];
Stack<object> stack = new();
for (int i = 0; i < methodBody.Length; i++)
@@ -141,11 +141,17 @@ partial class Decompiler
StatementSyntax symbolWriteExpr;
if (symbolRef.Origin is SymbolOrigin.ScopedLocal && !scopedLocals.Contains(symbolRef.Symbol))
if (symbolRef.Origin is SymbolOrigin.ScopedLocal && !scopedLocals.ContainsKey(symbolRef.Symbol))
{
// Scoped locals need to be declared the first time they're assigned
var newSymbolIrisObj = IrisObject.Create(newSymbolValue, null, _context, export);
var typeSchema = newSymbolIrisObj.Type ?? UIXTypes.MapIDToType(UIXTypeID.Object);
TypeSchema typeSchema = null;
if (newSymbolValue is SymbolReference { Origin: SymbolOrigin.ScopedLocal } newSymbolValueRef)
{
scopedLocals.TryGetValue(newSymbolValueRef.Symbol, out typeSchema);
}
var newSymbolIrisObj = IrisObject.Create(newSymbolValue, typeSchema, _context, export);
typeSchema = newSymbolIrisObj.Type ?? UIXTypes.MapIDToType(UIXTypeID.Object);
symbolWriteExpr = LocalDeclarationStatement(VariableDeclaration(
IrisExpression.ToSyntax(typeSchema, _context),
@@ -155,7 +161,7 @@ partial class Decompiler
)
));
scopedLocals.Add(symbolRef.Symbol);
scopedLocals[symbolRef.Symbol] = typeSchema;
}
else
{
+1 -1
View File
@@ -40,7 +40,7 @@ internal record IrisObject(object Object, TypeSchema Type)
type ??= constantInfo.Type;
}
type ??= Disassembler.GuessTypeSchema(obj.GetType(), context.LoadResult);
type ??= Disassembler.TryGuessTypeSchema(obj.GetType(), context.LoadResult);
return new(obj, type);
}