Browse Source

Fix handling of recombined variables and nested functions in IntroduceNativeIntTypeOnLocals and IntroduceDynamicTypeOnLocals.

pull/2971/head
Siegfried Pammer 2 years ago
parent
commit
29ca38d338
  1. 21
      ICSharpCode.Decompiler/IL/Transforms/IntroduceDynamicTypeOnLocals.cs
  2. 16
      ICSharpCode.Decompiler/IL/Transforms/IntroduceNativeIntTypeOnLocals.cs

21
ICSharpCode.Decompiler/IL/Transforms/IntroduceDynamicTypeOnLocals.cs

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.Decompiler.IL.Transforms;
@ -29,7 +30,10 @@ namespace ICSharpCode.Decompiler.IL @@ -29,7 +30,10 @@ namespace ICSharpCode.Decompiler.IL
{
public void Run(ILFunction function, ILTransformContext context)
{
foreach (var variable in function.Variables)
foreach (var nestedFunction in function.Descendants.OfType<ILFunction>())
{
HashSet<int> dynamicVariables = new();
foreach (var variable in nestedFunction.Variables)
{
if (variable.Kind != VariableKind.Local &&
variable.Kind != VariableKind.StackSlot &&
@ -48,8 +52,23 @@ namespace ICSharpCode.Decompiler.IL @@ -48,8 +52,23 @@ namespace ICSharpCode.Decompiler.IL
if (!argumentInfo.HasFlag(CSharpArgumentInfoFlags.UseCompileTimeType))
{
variable.Type = SpecialType.Dynamic;
if (variable.Index.HasValue && variable.Kind == VariableKind.Local)
{
dynamicVariables.Add(variable.Index.Value);
}
break;
}
}
}
}
foreach (var variable in nestedFunction.Variables)
{
if (variable.Index.HasValue && variable.Kind == VariableKind.Local
&& dynamicVariables.Contains(variable.Index.Value))
{
variable.Type = SpecialType.Dynamic;
continue;
}
}
}
}

16
ICSharpCode.Decompiler/IL/Transforms/IntroduceNativeIntTypeOnLocals.cs

@ -32,7 +32,10 @@ namespace ICSharpCode.Decompiler.IL @@ -32,7 +32,10 @@ namespace ICSharpCode.Decompiler.IL
{
if (!context.Settings.NativeIntegers)
return;
foreach (var variable in function.Variables)
foreach (var nestedFunction in function.Descendants.OfType<ILFunction>())
{
Dictionary<int, IType> variableTypeMapping = new();
foreach (var variable in nestedFunction.Variables)
{
if (variable.Kind != VariableKind.Local &&
variable.Kind != VariableKind.StackSlot &&
@ -49,6 +52,17 @@ namespace ICSharpCode.Decompiler.IL @@ -49,6 +52,17 @@ namespace ICSharpCode.Decompiler.IL
if (isUsedAsNativeInt || isAssignedNativeInt)
{
variable.Type = variable.Type.GetSign() == Sign.Unsigned ? SpecialType.NUInt : SpecialType.NInt;
if (variable.Kind == VariableKind.Local && variable.Index.HasValue)
variableTypeMapping[variable.Index.Value] = variable.Type;
}
}
foreach (var variable in nestedFunction.Variables)
{
if (variable.Kind == VariableKind.Local && variable.Index.HasValue
&& variableTypeMapping.TryGetValue(variable.Index.Value, out var type))
{
variable.Type = type;
}
}
}
}

Loading…
Cancel
Save