Browse Source

Add annotations on local function parameter declarations

pull/2333/head
Siegfried Pammer 5 years ago
parent
commit
8fc64669c2
  1. 23
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 1
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

23
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -1473,15 +1473,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1473,15 +1473,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (entityDecl != null)
{
int i = 0;
var parameters = function.Variables.Where(v => v.Kind == VariableKind.Parameter).ToDictionary(v => v.Index);
foreach (var parameter in entityDecl.GetChildrenByRole(Roles.Parameter))
{
if (parameters.TryGetValue(i, out var v))
parameter.AddAnnotation(new ILVariableResolveResult(v, method.Parameters[i].Type));
i++;
}
entityDecl.AddAnnotation(function);
AddAnnotationsToDeclaration(method, entityDecl, function);
}
var localSettings = settings.Clone();
@ -1541,6 +1533,19 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1541,6 +1533,19 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
internal static void AddAnnotationsToDeclaration(IMethod method, EntityDeclaration entityDecl, ILFunction function)
{
int i = 0;
var parameters = function.Variables.Where(v => v.Kind == VariableKind.Parameter).ToDictionary(v => v.Index);
foreach (var parameter in entityDecl.GetChildrenByRole(Roles.Parameter))
{
if (parameters.TryGetValue(i, out var v))
parameter.AddAnnotation(new ILVariableResolveResult(v, method.Parameters[i].Type));
i++;
}
entityDecl.AddAnnotation(function);
}
internal static void CleanUpMethodDeclaration(EntityDeclaration entityDecl, BlockStatement body, ILFunction function, bool decompileBody = true)
{
if (function.IsIterator)

1
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -1368,6 +1368,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1368,6 +1368,7 @@ namespace ICSharpCode.Decompiler.CSharp
method.Modifiers |= Modifiers.Extern;
}
CSharpDecompiler.AddAnnotationsToDeclaration(function.ReducedMethod, method, function);
CSharpDecompiler.CleanUpMethodDeclaration(method, method.Body, function, function.Method.HasBody);
CSharpDecompiler.RemoveAttribute(method, KnownAttribute.CompilerGenerated);
var stmt = new LocalFunctionDeclarationStatement(method);

Loading…
Cancel
Save