Browse Source

Merge pull request #1039 from icsharpcode/decompileMemberBodies

DecompileMemberBodies setting
pull/1051/head
Siegfried Pammer 7 years ago committed by GitHub
parent
commit
67d6a1d520
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 3
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpFormattingOptions.cs
  3. 19
      ICSharpCode.Decompiler/DecompilerSettings.cs
  4. 44
      ILSpy/Controls/BoolToVisibilityConverter.cs
  5. 1
      ILSpy/ILSpy.csproj
  6. 8
      ILSpy/Options/DecompilerSettingsPanel.xaml
  7. 115
      ILSpy/Options/DecompilerSettingsPanel.xaml.cs

27
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -47,7 +47,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -47,7 +47,7 @@ namespace ICSharpCode.Decompiler.CSharp
{
readonly DecompilerTypeSystem typeSystem;
readonly DecompilerSettings settings;
private SyntaxTree syntaxTree;
SyntaxTree syntaxTree;
List<IILTransform> ilTransforms = GetILTransforms();
@ -761,18 +761,27 @@ namespace ICSharpCode.Decompiler.CSharp @@ -761,18 +761,27 @@ namespace ICSharpCode.Decompiler.CSharp
CancellationToken.ThrowIfCancellationRequested();
transform.Run(function, context);
function.CheckInvariant(ILPhase.Normal);
// When decompiling definitions only, we can cancel decompilation of all steps
// after yield and async detection, because only those are needed to properly set
// IsAsync/IsIterator flags on ILFunction.
if (!settings.DecompileMemberBodies && transform is AsyncAwaitDecompiler)
break;
}
AddDefinesForConditionalAttributes(function);
var statementBuilder = new StatementBuilder(specializingTypeSystem, decompilationContext, function, settings, CancellationToken);
var body = statementBuilder.ConvertAsBlock(function.Body);
var body = BlockStatement.Null;
// Generate C# AST only if bodies should be displayed.
if (settings.DecompileMemberBodies) {
AddDefinesForConditionalAttributes(function);
var statementBuilder = new StatementBuilder(specializingTypeSystem, decompilationContext, function, settings, CancellationToken);
body = statementBuilder.ConvertAsBlock(function.Body);
Comment prev = null;
foreach (string warning in function.Warnings) {
body.InsertChildAfter(prev, prev = new Comment(warning), Roles.Comment);
}
Comment prev = null;
foreach (string warning in function.Warnings) {
body.InsertChildAfter(prev, prev = new Comment(warning), Roles.Comment);
}
entityDecl.AddChild(body, Roles.Body);
entityDecl.AddChild(body, Roles.Body);
}
entityDecl.AddAnnotation(function);
if (function.IsIterator) {

3
ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpFormattingOptions.cs

@ -24,6 +24,8 @@ @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System.ComponentModel;
namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
{
public enum BraceStyle
@ -68,6 +70,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -68,6 +70,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
DoNotIndent
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public class CSharpFormattingOptions
{
public string Name {

19
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -306,7 +306,7 @@ namespace ICSharpCode.Decompiler @@ -306,7 +306,7 @@ namespace ICSharpCode.Decompiler
bool objectCollectionInitializers = true;
/// <summary>
/// Gets/Sets whether to use C# 3.0 object/collection initializers
/// Gets/Sets whether to use C# 3.0 object/collection initializers.
/// </summary>
public bool ObjectOrCollectionInitializers {
get { return objectCollectionInitializers; }
@ -321,7 +321,7 @@ namespace ICSharpCode.Decompiler @@ -321,7 +321,7 @@ namespace ICSharpCode.Decompiler
bool showXmlDocumentation = true;
/// <summary>
/// Gets/Sets whether to include XML documentation comments in the decompiled code
/// Gets/Sets whether to include XML documentation comments in the decompiled code.
/// </summary>
public bool ShowXmlDocumentation {
get { return showXmlDocumentation; }
@ -345,6 +345,21 @@ namespace ICSharpCode.Decompiler @@ -345,6 +345,21 @@ namespace ICSharpCode.Decompiler
}
}
bool decompileMemberBodies = true;
/// <summary>
/// Gets/Sets whether member bodies should be decompiled.
/// </summary>
public bool DecompileMemberBodies {
get { return decompileMemberBodies; }
set {
if (decompileMemberBodies != value) {
decompileMemberBodies = value;
OnPropertyChanged();
}
}
}
#region Options to aid VB decompilation
bool introduceIncrementAndDecrement = true;

44
ILSpy/Controls/BoolToVisibilityConverter.cs

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
// Copyright (c) 2018 Siegfried Pammer
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace ICSharpCode.ILSpy.Controls
{
public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(parameter is Visibility notVisible))
notVisible = Visibility.Collapsed;
if (!(value is bool b))
return notVisible;
return b ? Visibility.Visible : notVisible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(value is Visibility visibility))
return false;
return visibility == Visibility.Visible;
}
}
}

1
ILSpy/ILSpy.csproj

@ -84,6 +84,7 @@ @@ -84,6 +84,7 @@
<Compile Include="Commands\OpenListCommand.cs" />
<Compile Include="Commands\ShowDebugSteps.cs" />
<Compile Include="Commands\SortAssemblyListCommand.cs" />
<Compile Include="Controls\BoolToVisibilityConverter.cs" />
<Compile Include="Controls\CustomDialog.cs">
<SubType>Form</SubType>
</Compile>

8
ILSpy/Options/DecompilerSettingsPanel.xaml

@ -1,7 +1,12 @@ @@ -1,7 +1,12 @@
<UserControl x:Class="ICSharpCode.ILSpy.Options.DecompilerSettingsPanel"
x:ClassModifier="internal"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:options="clr-namespace:ICSharpCode.ILSpy.Options"
xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls">
<UserControl.Resources>
<controls:BoolToVisibilityConverter x:Key="boolConv" />
</UserControl.Resources>
<StackPanel Margin="10">
<CheckBox IsChecked="{Binding AnonymousMethods}">Decompile anonymous methods/lambdas</CheckBox>
<CheckBox IsChecked="{Binding AnonymousTypes}">Decompile anonymous types</CheckBox>
@ -18,5 +23,6 @@ @@ -18,5 +23,6 @@
<CheckBox IsChecked="{Binding UsingDeclarations}">Insert using declarations</CheckBox>
<CheckBox IsChecked="{Binding FullyQualifyAmbiguousTypeNames}">Fully qualify ambiguous type names</CheckBox>
<CheckBox IsChecked="{Binding AlwaysUseBraces}">Always use braces</CheckBox>
<Button Content="Advanced" Click="AdvancedOptions_Click" Visibility="{Binding Source={x:Static options:DecompilerSettingsPanel.IsDebug}, Converter={StaticResource boolConv}, ConverterParameter={x:Static Visibility.Collapsed}}" />
</StackPanel>
</UserControl>

115
ILSpy/Options/DecompilerSettingsPanel.xaml.cs

@ -16,9 +16,11 @@ @@ -16,9 +16,11 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System.Windows;
using System.Windows.Controls;
using System.Xml.Linq;
using ICSharpCode.Decompiler;
using WinForms = System.Windows.Forms;
namespace ICSharpCode.ILSpy.Options
{
@ -28,6 +30,12 @@ namespace ICSharpCode.ILSpy.Options @@ -28,6 +30,12 @@ namespace ICSharpCode.ILSpy.Options
[ExportOptionPage(Title = "Decompiler", Order = 0)]
partial class DecompilerSettingsPanel : UserControl, IOptionPage
{
#if DEBUG
public const bool IsDebug = true;
#else
public const bool IsDebug = false;
#endif
public DecompilerSettingsPanel()
{
InitializeComponent();
@ -35,7 +43,7 @@ namespace ICSharpCode.ILSpy.Options @@ -35,7 +43,7 @@ namespace ICSharpCode.ILSpy.Options
public void Load(ILSpySettings settings)
{
this.DataContext = LoadDecompilerSettings(settings);
this.DataContext = currentDecompilerSettings ?? LoadDecompilerSettings(settings);
}
static DecompilerSettings currentDecompilerSettings;
@ -61,6 +69,7 @@ namespace ICSharpCode.ILSpy.Options @@ -61,6 +69,7 @@ namespace ICSharpCode.ILSpy.Options
s.ShowDebugInfo = (bool?)e.Attribute("showDebugInfo") ?? s.ShowDebugInfo;
s.ShowXmlDocumentation = (bool?)e.Attribute("xmlDoc") ?? s.ShowXmlDocumentation;
s.FoldBraces = (bool?)e.Attribute("foldBraces") ?? s.FoldBraces;
s.RemoveDeadCode = (bool?)e.Attribute("removeDeadCode") ?? s.RemoveDeadCode;
s.UsingDeclarations = (bool?)e.Attribute("usingDeclarations") ?? s.UsingDeclarations;
s.FullyQualifyAmbiguousTypeNames = (bool?)e.Attribute("fullyQualifyAmbiguousTypeNames") ?? s.FullyQualifyAmbiguousTypeNames;
s.AlwaysUseBraces = (bool?)e.Attribute("alwaysUseBraces") ?? s.AlwaysUseBraces;
@ -82,7 +91,7 @@ namespace ICSharpCode.ILSpy.Options @@ -82,7 +91,7 @@ namespace ICSharpCode.ILSpy.Options
section.SetAttributeValue("showDebugInfo", s.ShowDebugInfo);
section.SetAttributeValue("xmlDoc", s.ShowXmlDocumentation);
section.SetAttributeValue("foldBraces", s.FoldBraces);
section.SetAttributeValue("foldBraces", s.RemoveDeadCode);
section.SetAttributeValue("removeDeadCode", s.RemoveDeadCode);
section.SetAttributeValue("usingDeclarations", s.UsingDeclarations);
section.SetAttributeValue("fullyQualifyAmbiguousTypeNames", s.FullyQualifyAmbiguousTypeNames);
section.SetAttributeValue("alwaysUseBraces", s.AlwaysUseBraces);
@ -93,7 +102,107 @@ namespace ICSharpCode.ILSpy.Options @@ -93,7 +102,107 @@ namespace ICSharpCode.ILSpy.Options
else
root.Add(section);
currentDecompilerSettings = null; // invalidate cached settings
currentDecompilerSettings = s; // update cached settings
}
void AdvancedOptions_Click(object sender, RoutedEventArgs e)
{
#if DEBUG
// I know this is crazy, but WindowsFormsHost is too buggy in this scenario...
using (var wnd = new PropertyGridHost(((DecompilerSettings)DataContext).Clone())) {
if (wnd.ShowDialog() == WinForms.DialogResult.OK) {
this.DataContext = wnd.Settings;
}
}
#endif
}
#if DEBUG
class PropertyGridHost : WinForms.Form
{
private WinForms.PropertyGrid propertyGrid;
private WinForms.Button cancelButton;
private WinForms.Button okButton;
public DecompilerSettings Settings { get; }
public PropertyGridHost(DecompilerSettings settings)
{
InitializeComponent();
this.propertyGrid.SelectedObject = Settings = settings;
}
private void InitializeComponent()
{
this.propertyGrid = new System.Windows.Forms.PropertyGrid();
this.cancelButton = new System.Windows.Forms.Button();
this.okButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// propertyGrid
//
this.propertyGrid.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Left
| System.Windows.Forms.AnchorStyles.Right;
this.propertyGrid.Location = new System.Drawing.Point(0, 0);
this.propertyGrid.Name = "propertyGrid";
this.propertyGrid.Size = new System.Drawing.Size(468, 369);
this.propertyGrid.TabIndex = 0;
//
// cancelButton
//
this.cancelButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(365, 375);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(91, 23);
this.cancelButton.TabIndex = 1;
this.cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true;
this.cancelButton.Click += CancelButton_Click;
//
// okButton
//
this.okButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
this.okButton.Location = new System.Drawing.Point(267, 375);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(92, 23);
this.okButton.TabIndex = 2;
this.okButton.Text = "OK";
this.okButton.UseVisualStyleBackColor = true;
this.okButton.Click += OkButton_Click;
//
// Form1
//
this.AcceptButton = this.okButton;
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(468, 410);
this.Controls.Add(this.okButton);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.propertyGrid);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.Text = "Advanced Decompiler Options";
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.ResumeLayout(false);
}
private void OkButton_Click(object sender, System.EventArgs e)
{
DialogResult = WinForms.DialogResult.OK;
Close();
}
private void CancelButton_Click(object sender, System.EventArgs e)
{
DialogResult = WinForms.DialogResult.Cancel;
Close();
}
}
#endif
}
}
Loading…
Cancel
Save