|
|
|
@ -24,7 +24,15 @@ namespace ICSharpCode.Decompiler.Ast
@@ -24,7 +24,15 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
HashSet<ILVariable> localVariablesToDefine = new HashSet<ILVariable>(); // local variables that are missing a definition
|
|
|
|
|
HashSet<ILVariable> implicitlyDefinedVariables = new HashSet<ILVariable>(); // local variables that are implicitly defined (e.g. catch handler)
|
|
|
|
|
|
|
|
|
|
public static BlockStatement CreateMethodBody(MethodDefinition methodDef, DecompilerContext context) |
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates the body for the method definition.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="methodDef">Method definition to decompile.</param>
|
|
|
|
|
/// <param name="context">Decompilation context.</param>
|
|
|
|
|
/// <param name="parameters">Parameter declarations of the method being decompiled.
|
|
|
|
|
/// These are used to update the parameter names when the decompiler generates names for the parameters.</param>
|
|
|
|
|
/// <returns>Block for the method body</returns>
|
|
|
|
|
public static BlockStatement CreateMethodBody(MethodDefinition methodDef, DecompilerContext context, IEnumerable<ParameterDeclaration> parameters = null) |
|
|
|
|
{ |
|
|
|
|
MethodDefinition oldCurrentMethod = context.CurrentMethod; |
|
|
|
|
Debug.Assert(oldCurrentMethod == null || oldCurrentMethod == methodDef); |
|
|
|
@ -35,10 +43,10 @@ namespace ICSharpCode.Decompiler.Ast
@@ -35,10 +43,10 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
builder.context = context; |
|
|
|
|
builder.typeSystem = methodDef.Module.TypeSystem; |
|
|
|
|
if (Debugger.IsAttached) { |
|
|
|
|
return builder.CreateMethodBody(); |
|
|
|
|
return builder.CreateMethodBody(parameters); |
|
|
|
|
} else { |
|
|
|
|
try { |
|
|
|
|
return builder.CreateMethodBody(); |
|
|
|
|
return builder.CreateMethodBody(parameters); |
|
|
|
|
} catch (OperationCanceledException) { |
|
|
|
|
throw; |
|
|
|
|
} catch (Exception ex) { |
|
|
|
@ -50,7 +58,7 @@ namespace ICSharpCode.Decompiler.Ast
@@ -50,7 +58,7 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public BlockStatement CreateMethodBody() |
|
|
|
|
public BlockStatement CreateMethodBody(IEnumerable<ParameterDeclaration> parameters) |
|
|
|
|
{ |
|
|
|
|
if (methodDef.Body == null) return null; |
|
|
|
|
|
|
|
|
@ -69,6 +77,15 @@ namespace ICSharpCode.Decompiler.Ast
@@ -69,6 +77,15 @@ namespace ICSharpCode.Decompiler.Ast
|
|
|
|
|
Debug.Assert(context.CurrentMethod == methodDef); |
|
|
|
|
NameVariables.AssignNamesToVariables(context, astBuilder.Parameters, allVariables, ilMethod); |
|
|
|
|
|
|
|
|
|
if (parameters != null) { |
|
|
|
|
foreach (var pair in (from p in parameters |
|
|
|
|
join v in astBuilder.Parameters on p.Annotation<ParameterDefinition>() equals v.OriginalParameter |
|
|
|
|
select new { p, v.Name })) |
|
|
|
|
{ |
|
|
|
|
pair.p.Name = pair.Name; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
context.CancellationToken.ThrowIfCancellationRequested(); |
|
|
|
|
Ast.BlockStatement astBlock = TransformBlock(ilMethod); |
|
|
|
|
CommentStatement.ReplaceAll(astBlock); // convert CommentStatements to Comments
|
|
|
|
|