Browse Source

Move local variables into a property of AstBuilder

pull/191/merge
Eusebiu Marcu 15 years ago
parent
commit
65be04d18e
  1. 8
      Debugger/ILSpy.Debugger/DebuggedData.cs
  2. 7
      Debugger/ILSpy.Debugger/Models/TreeModel/ExpressionNode.cs
  3. 20
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  4. 22
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  5. 5
      ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs
  6. 1
      ILSpy/CSharpLanguage.cs

8
Debugger/ILSpy.Debugger/DebuggedData.cs

@ -2,8 +2,11 @@ @@ -2,8 +2,11 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.ILAst;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.Debugger
@ -53,6 +56,11 @@ namespace ICSharpCode.ILSpy.Debugger @@ -53,6 +56,11 @@ namespace ICSharpCode.ILSpy.Debugger
/// </summary>
public static Tuple<string, List<MemberMapping>> CodeMappings { get; set; }
/// <summary>
/// Gets or sets the local variables of the current decompiled type, method, etc.
/// </summary>
public static ConcurrentDictionary<int, IEnumerable<ILVariable>> LocalVariables { get; set; }
/// <summary>
/// Gets or sets the old code mappings.
/// </summary>

7
Debugger/ILSpy.Debugger/Models/TreeModel/ExpressionNode.cs

@ -11,11 +11,12 @@ using System.Windows.Media; @@ -11,11 +11,12 @@ using System.Windows.Media;
using Debugger;
using Debugger.MetaData;
using ICSharpCode.Decompiler.Ast;
using ICSharpCode.Decompiler.ILAst;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.ILSpy.Debugger.Services;
using ICSharpCode.ILSpy.Debugger.Services.Debugger;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.CSharp;
namespace ICSharpCode.ILSpy.Debugger.Models.TreeModel
{
@ -161,7 +162,7 @@ namespace ICSharpCode.ILSpy.Debugger.Models.TreeModel @@ -161,7 +162,7 @@ namespace ICSharpCode.ILSpy.Debugger.Models.TreeModel
// get local variable index
IEnumerable<ILVariable> list;
if (ILAstBuilder.MemberLocalVariables.TryGetValue(token, out list)) {
if (DebugData.LocalVariables.TryGetValue(token, out list)) {
var variable = list.FirstOrDefault(v => v.Name == targetName);
if (variable != null && variable.OriginalVariable != null) {
if (expression is MemberReferenceExpression) {

20
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
@ -7,6 +8,7 @@ using System.Linq; @@ -7,6 +8,7 @@ using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Ast.Transforms;
using ICSharpCode.Decompiler.ILAst;
@ -42,6 +44,8 @@ namespace ICSharpCode.Decompiler.Ast @@ -42,6 +44,8 @@ namespace ICSharpCode.Decompiler.Ast
throw new ArgumentNullException("context");
this.context = context;
this.DecompileMethodBodies = true;
this.LocalVariables = new ConcurrentDictionary<int, IEnumerable<ILVariable>>();
}
public static bool MemberIsHidden(MemberReference member, DecompilerSettings settings)
@ -872,7 +876,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -872,7 +876,7 @@ namespace ICSharpCode.Decompiler.Ast
BlockStatement CreateMethodBody(MethodDefinition method, IEnumerable<ParameterDeclaration> parameters = null)
{
if (DecompileMethodBodies)
return AstMethodBodyBuilder.CreateMethodBody(method, context, parameters);
return AstMethodBodyBuilder.CreateMethodBody(method, context, parameters, LocalVariables);
else
return null;
}
@ -1340,9 +1344,15 @@ namespace ICSharpCode.Decompiler.Ast @@ -1340,9 +1344,15 @@ namespace ICSharpCode.Decompiler.Ast
return type.CustomAttributes.Any(attr => attr.AttributeType.FullName == "System.FlagsAttribute");
}
public Tuple<string, List<MemberMapping>> CodeMappings {
get;
private set;
}
/// <summary>
/// <inheritdoc/>
/// </summary>
public Tuple<string, List<MemberMapping>> CodeMappings { get; private set; }
/// <summary>
/// Gets the local variables for the current decompiled type, method, etc.
/// <remarks>The key is the metadata token.</remarks>
/// </summary>
public ConcurrentDictionary<int, IEnumerable<ILVariable>> LocalVariables { get; private set; }
}
}

22
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -32,9 +32,16 @@ namespace ICSharpCode.Decompiler.Ast @@ -32,9 +32,16 @@ namespace ICSharpCode.Decompiler.Ast
/// <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>
/// <param name="localVariables">Local variables storage that will be filled/updated with the local variables.</param>
/// <returns>Block for the method body</returns>
public static BlockStatement CreateMethodBody(MethodDefinition methodDef, DecompilerContext context, IEnumerable<ParameterDeclaration> parameters = null)
public static BlockStatement CreateMethodBody(MethodDefinition methodDef,
DecompilerContext context,
IEnumerable<ParameterDeclaration> parameters = null,
ConcurrentDictionary<int, IEnumerable<ILVariable>> localVariables = null)
{
if (localVariables == null)
localVariables = new ConcurrentDictionary<int, IEnumerable<ILVariable>>();
MethodDefinition oldCurrentMethod = context.CurrentMethod;
Debug.Assert(oldCurrentMethod == null || oldCurrentMethod == methodDef);
context.CurrentMethod = methodDef;
@ -44,10 +51,10 @@ namespace ICSharpCode.Decompiler.Ast @@ -44,10 +51,10 @@ namespace ICSharpCode.Decompiler.Ast
builder.context = context;
builder.typeSystem = methodDef.Module.TypeSystem;
if (Debugger.IsAttached) {
return builder.CreateMethodBody(parameters);
return builder.CreateMethodBody(parameters, localVariables);
} else {
try {
return builder.CreateMethodBody(parameters);
return builder.CreateMethodBody(parameters, localVariables);
} catch (OperationCanceledException) {
throw;
} catch (Exception ex) {
@ -59,10 +66,14 @@ namespace ICSharpCode.Decompiler.Ast @@ -59,10 +66,14 @@ namespace ICSharpCode.Decompiler.Ast
}
}
public BlockStatement CreateMethodBody(IEnumerable<ParameterDeclaration> parameters)
public BlockStatement CreateMethodBody(IEnumerable<ParameterDeclaration> parameters,
ConcurrentDictionary<int, IEnumerable<ILVariable>> localVariables)
{
if (methodDef.Body == null) return null;
if (localVariables == null)
throw new ArgumentException("localVariables must be instantiated");
context.CancellationToken.ThrowIfCancellationRequested();
ILBlock ilMethod = new ILBlock();
ILAstBuilder astBuilder = new ILAstBuilder();
@ -104,8 +115,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -104,8 +115,7 @@ namespace ICSharpCode.Decompiler.Ast
// store the variables - used for debugger
int token = methodDef.MetadataToken.ToInt32();
ILAstBuilder.MemberLocalVariables.AddOrUpdate(
token, allVariables, (key, oldValue) => allVariables);
localVariables.AddOrUpdate(token, allVariables, (key, oldValue) => allVariables);
return astBlock;
}

5
ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs

@ -12,11 +12,6 @@ namespace ICSharpCode.Decompiler.ILAst @@ -12,11 +12,6 @@ namespace ICSharpCode.Decompiler.ILAst
{
public class ILAstBuilder
{
/// <summary>
///
/// </summary>
public static ConcurrentDictionary<int, IEnumerable<ILVariable>> MemberLocalVariables = new ConcurrentDictionary<int, IEnumerable<ILVariable>>();
static ByteCode[] EmptyByteCodeArray = new ByteCode[] {};
/// <summary> Immutable </summary>

1
ILSpy/CSharpLanguage.cs

@ -129,6 +129,7 @@ namespace ICSharpCode.ILSpy @@ -129,6 +129,7 @@ namespace ICSharpCode.ILSpy
codeDomBuilder.RunTransformations(transformAbortCondition);
codeDomBuilder.GenerateCode(output);
DebugData.CodeMappings = codeDomBuilder.CodeMappings;
DebugData.LocalVariables = codeDomBuilder.LocalVariables;
}
public override void DecompileAssembly(AssemblyDefinition assembly, string fileName, ITextOutput output, DecompilationOptions options)

Loading…
Cancel
Save