Browse Source

Move ILAst writing options to DebugSteps pane and implement auto refresh.

pull/923/head
Siegfried Pammer 8 years ago
parent
commit
10cf712135
  1. 9
      ILSpy/DebugSteps.xaml
  2. 28
      ILSpy/DebugSteps.xaml.cs
  3. 63
      ILSpy/Languages/ILAstLanguage.cs

9
ILSpy/DebugSteps.xaml

@ -6,7 +6,12 @@ @@ -6,7 +6,12 @@
xmlns:local="clr-namespace:ICSharpCode.ILSpy"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<DockPanel>
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
<CheckBox Margin="3" Content="UseFieldSugar" IsChecked="{Binding UseFieldSugar, Source={x:Static local:DebugSteps.Options}}" />
<CheckBox Margin="3" Content="UseLogicOperationSugar" IsChecked="{Binding UseLogicOperationSugar, Source={x:Static local:DebugSteps.Options}}" />
<CheckBox Margin="3" Content="ShowILRanges" IsChecked="{Binding ShowILRanges, Source={x:Static local:DebugSteps.Options}}" />
</StackPanel>
<TreeView Name="tree" MouseDoubleClick="ShowStateAfter_Click" KeyDown="tree_KeyDown">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
@ -21,5 +26,5 @@ @@ -21,5 +26,5 @@
</ContextMenu>
</TreeView.ContextMenu>
</TreeView>
</Grid>
</DockPanel>
</UserControl>

28
ILSpy/DebugSteps.xaml.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.IL.Transforms;
namespace ICSharpCode.ILSpy
@ -12,6 +13,13 @@ namespace ICSharpCode.ILSpy @@ -12,6 +13,13 @@ namespace ICSharpCode.ILSpy
/// </summary>
public partial class DebugSteps : UserControl, IPane
{
static readonly ILAstWritingOptions writingOptions = new ILAstWritingOptions {
UseFieldSugar = true,
UseLogicOperationSugar = true
};
public static ILAstWritingOptions Options => writingOptions;
#if DEBUG
ILAstLanguage language;
#endif
@ -23,6 +31,7 @@ namespace ICSharpCode.ILSpy @@ -23,6 +31,7 @@ namespace ICSharpCode.ILSpy
#if DEBUG
MainWindow.Instance.SessionSettings.FilterSettings.PropertyChanged += FilterSettings_PropertyChanged;
MainWindow.Instance.SelectionChanged += SelectionChanged;
writingOptions.PropertyChanged += WritingOptions_PropertyChanged;
if (MainWindow.Instance.CurrentLanguage is ILAstLanguage l) {
l.StepperUpdated += ILAstStepperUpdated;
@ -32,9 +41,17 @@ namespace ICSharpCode.ILSpy @@ -32,9 +41,17 @@ namespace ICSharpCode.ILSpy
#endif
}
private void WritingOptions_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
DecompileAsync(lastSelectedStep);
}
private void SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Dispatcher.Invoke(() => tree.ItemsSource = null);
Dispatcher.Invoke(() => {
tree.ItemsSource = null;
lastSelectedStep = int.MaxValue;
});
}
private void FilterSettings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
@ -57,7 +74,10 @@ namespace ICSharpCode.ILSpy @@ -57,7 +74,10 @@ namespace ICSharpCode.ILSpy
{
#if DEBUG
if (language == null) return;
Dispatcher.Invoke(() => tree.ItemsSource = language.Stepper.Steps);
Dispatcher.Invoke(() => {
tree.ItemsSource = language.Stepper.Steps;
lastSelectedStep = int.MaxValue;
});
#endif
}
@ -71,6 +91,7 @@ namespace ICSharpCode.ILSpy @@ -71,6 +91,7 @@ namespace ICSharpCode.ILSpy
#if DEBUG
MainWindow.Instance.SessionSettings.FilterSettings.PropertyChanged -= FilterSettings_PropertyChanged;
MainWindow.Instance.SelectionChanged -= SelectionChanged;
writingOptions.PropertyChanged -= WritingOptions_PropertyChanged;
if (language != null) {
language.StepperUpdated -= ILAstStepperUpdated;
}
@ -98,8 +119,11 @@ namespace ICSharpCode.ILSpy @@ -98,8 +119,11 @@ namespace ICSharpCode.ILSpy
DecompileAsync(n.BeginStep, true);
}
int lastSelectedStep = int.MaxValue;
void DecompileAsync(int step, bool isDebug = false)
{
lastSelectedStep = step;
var window = MainWindow.Instance;
var state = window.TextView.GetState();
window.TextView.DecompileAsync(window.CurrentLanguage, window.SelectedNodes,

63
ILSpy/Languages/ILAstLanguage.cs

@ -53,47 +53,6 @@ namespace ICSharpCode.ILSpy @@ -53,47 +53,6 @@ namespace ICSharpCode.ILSpy
}
public override string Name { get { return name; } }
/*
public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
{
if (!method.HasBody) {
return;
}
ILAstBuilder astBuilder = new ILAstBuilder();
ILBlock ilMethod = new ILBlock();
DecompilerContext context = new DecompilerContext(method.Module) { CurrentType = method.DeclaringType, CurrentMethod = method };
ilMethod.Body = astBuilder.Build(method, inlineVariables, context);
if (abortBeforeStep != null) {
new ILAstOptimizer().Optimize(context, ilMethod, abortBeforeStep.Value);
}
if (context.CurrentMethodIsAsync)
output.WriteLine("async/await");
var allVariables = ilMethod.GetSelfAndChildrenRecursive<ILExpression>().Select(e => e.Operand as ILVariable)
.Where(v => v != null && !v.IsParameter).Distinct();
foreach (ILVariable v in allVariables) {
output.WriteDefinition(v.Name, v);
if (v.Type != null) {
output.Write(" : ");
if (v.IsPinned)
output.Write("pinned ");
v.Type.WriteTo(output, ILNameSyntax.ShortTypeName);
}
if (v.IsGenerated) {
output.Write(" [generated]");
}
output.WriteLine();
}
output.WriteLine();
foreach (ILNode node in ilMethod.Body) {
node.WriteTo(output);
output.WriteLine();
}
}*/
internal static IEnumerable<ILAstLanguage> GetDebugLanguages()
{
@ -141,10 +100,6 @@ namespace ICSharpCode.ILSpy @@ -141,10 +100,6 @@ namespace ICSharpCode.ILSpy
class BlockIL : ILAstLanguage
{
readonly IReadOnlyList<IILTransform> transforms;
readonly ILAstWritingOptions writingOptions = new ILAstWritingOptions {
UseFieldSugar = true,
UseLogicOperationSugar = true
};
public BlockIL(IReadOnlyList<IILTransform> transforms) : base("ILAst")
{
@ -180,27 +135,11 @@ namespace ICSharpCode.ILSpy @@ -180,27 +135,11 @@ namespace ICSharpCode.ILSpy
OnStepperUpdated(new EventArgs());
}
}
(output as ISmartTextOutput)?.AddUIElement(OptionsCheckBox(nameof(writingOptions.UseFieldSugar)));
output.WriteLine();
(output as ISmartTextOutput)?.AddUIElement(OptionsCheckBox(nameof(writingOptions.UseLogicOperationSugar)));
output.WriteLine();
(output as ISmartTextOutput)?.AddButton(Images.ViewCode, "Show Steps", delegate {
DebugSteps.Show();
});
output.WriteLine();
il.WriteTo(output, writingOptions);
}
Func<System.Windows.UIElement> OptionsCheckBox(string propertyName)
{
return () => {
var checkBox = new System.Windows.Controls.CheckBox();
checkBox.Content = propertyName;
checkBox.Cursor = System.Windows.Input.Cursors.Arrow;
checkBox.SetBinding(System.Windows.Controls.CheckBox.IsCheckedProperty,
new System.Windows.Data.Binding(propertyName) { Source = writingOptions });
return checkBox;
};
il.WriteTo(output, DebugSteps.Options);
}
}
}

Loading…
Cancel
Save