Browse Source

Create a decompile finished event.

pull/191/merge
Eusebiu Marcu 15 years ago
parent
commit
d6c7c065d8
  1. 5
      ILSpy/CSharpLanguage.cs
  2. 4
      ILSpy/ILLanguage.cs
  3. 31
      ILSpy/Language.cs
  4. 5
      ILSpy/TextView/DecompilerTextView.cs
  5. 1
      ILSpy/TreeNodes/TypeTreeNode.cs

5
ILSpy/CSharpLanguage.cs

@ -123,13 +123,12 @@ namespace ICSharpCode.ILSpy @@ -123,13 +123,12 @@ namespace ICSharpCode.ILSpy
public override void DecompileType(TypeDefinition type, ITextOutput output, DecompilationOptions options)
{
DebugData.OldCodeMappings = DebugData.CodeMappings;
AstBuilder codeDomBuilder = CreateAstBuilder(options, currentType: type);
codeDomBuilder.AddType(type);
codeDomBuilder.RunTransformations(transformAbortCondition);
codeDomBuilder.GenerateCode(output);
DebugData.CodeMappings = codeDomBuilder.CodeMappings;
DebugData.LocalVariables = codeDomBuilder.LocalVariables;
OnDecompilationFinished(new DecompileEventArgs { CodeMappings = codeDomBuilder.CodeMappings, LocalVariables = codeDomBuilder.LocalVariables });
}
public override void DecompileAssembly(AssemblyDefinition assembly, string fileName, ITextOutput output, DecompilationOptions options)

4
ILSpy/ILLanguage.cs

@ -73,10 +73,10 @@ namespace ICSharpCode.ILSpy @@ -73,10 +73,10 @@ namespace ICSharpCode.ILSpy
public override void DecompileType(TypeDefinition type, ITextOutput output, DecompilationOptions options)
{
DebugData.OldCodeMappings = DebugData.CodeMappings;
var dis = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken);
dis.DisassembleType(type);
DebugData.CodeMappings = dis.CodeMappings;
OnDecompilationFinished(new DecompileEventArgs { CodeMappings = dis.CodeMappings });
}
public override void DecompileNamespace(string nameSpace, IEnumerable<TypeDefinition> types, ITextOutput output, DecompilationOptions options)

31
ILSpy/Language.cs

@ -17,20 +17,44 @@ @@ -17,20 +17,44 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.ILAst;
using Mono.Cecil;
namespace ICSharpCode.ILSpy
{
/// <summary>
/// Decompilation event arguments.
/// </summary>
public sealed class DecompileEventArgs : EventArgs
{
/// <summary>
/// Gets ot sets the code mappings
/// </summary>
public Tuple<string, List<MemberMapping>> CodeMappings { get; set; }
/// <summary>
/// Gets or sets the local variables.
/// </summary>
public ConcurrentDictionary<int, IEnumerable<ILVariable>> LocalVariables { get; set; }
}
/// <summary>
/// Base class for language-specific decompiler implementations.
/// </summary>
public abstract class Language
{
/// <summary>
/// Decompile finished event.
/// </summary>
public event EventHandler<DecompileEventArgs> DecompileFinished;
/// <summary>
/// Gets the name of the language (as shown in the UI)
/// </summary>
@ -137,6 +161,13 @@ namespace ICSharpCode.ILSpy @@ -137,6 +161,13 @@ namespace ICSharpCode.ILSpy
{
return true;
}
protected virtual void OnDecompilationFinished(DecompileEventArgs e)
{
if (DecompileFinished != null) {
DecompileFinished(this, e);
}
}
}
public static class Languages

5
ILSpy/TextView/DecompilerTextView.cs

@ -336,6 +336,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -336,6 +336,7 @@ namespace ICSharpCode.ILSpy.TextView
{
// reset type
DebugData.CurrentMemberReference = null;
DebugData.OldCodeMappings = DebugData.CodeMappings;
TextEditorListener.Instance.ClosePopup();
RunWithCancellation(
@ -452,6 +453,10 @@ namespace ICSharpCode.ILSpy.TextView @@ -452,6 +453,10 @@ namespace ICSharpCode.ILSpy.TextView
if (i > 0)
textOutput.WriteLine();
context.Language.DecompileFinished += (s, e) => { DebugData.CodeMappings = e.CodeMappings; DebugData.LocalVariables = e.LocalVariables; };
if (nodes[i] is IMemberTreeNode) {
DebugData.CurrentMemberReference = (nodes[i] as IMemberTreeNode).Member;
}
context.Options.CancellationToken.ThrowIfCancellationRequested();
nodes[i].Decompile(context.Language, textOutput, context.Options);
}

1
ILSpy/TreeNodes/TypeTreeNode.cs

@ -121,7 +121,6 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -121,7 +121,6 @@ namespace ICSharpCode.ILSpy.TreeNodes
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
DebugData.CurrentMemberReference = type;
language.DecompileType(type, output, options);
}

Loading…
Cancel
Save