Browse Source

Merge branch '3.0.x' of https://github.com/icsharpcode/ILSpy

# Conflicts:
#	ICSharpCode.Decompiler/DecompilerSettings.cs
#	ILSpy/Options/DecompilerSettingsPanel.xaml
#	ILSpy/Options/DecompilerSettingsPanel.xaml.cs
#	ILSpy/Properties/AssemblyInfo.template.cs
pull/1051/head
Siegfried Pammer 8 years ago
parent
commit
4c73a771a1
  1. 27
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 3
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpFormattingOptions.cs
  3. 19
      ICSharpCode.Decompiler/DecompilerSettings.cs
  4. 12
      ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs
  5. 44
      ILSpy/Controls/BoolToVisibilityConverter.cs
  6. 1
      ILSpy/ILSpy.csproj
  7. 8
      ILSpy/Options/DecompilerSettingsPanel.xaml
  8. 112
      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();
@ -763,18 +763,27 @@ namespace ICSharpCode.Decompiler.CSharp @@ -763,18 +763,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; }
@ -336,7 +336,7 @@ namespace ICSharpCode.Decompiler @@ -336,7 +336,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; }
@ -372,6 +372,21 @@ namespace ICSharpCode.Decompiler @@ -372,6 +372,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;

12
ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs

@ -91,11 +91,19 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -91,11 +91,19 @@ namespace ICSharpCode.Decompiler.TypeSystem
entityDict[entity] = mr;
}
MemberReference GetCecil(IUnresolvedEntity member)
/// <summary>
/// Retrieves the Cecil member definition for the specified member.
/// </summary>
/// <remarks>
/// Returns null if the member is not defined in the module being decompiled.
/// </remarks>
public MemberReference GetCecil(IUnresolvedEntity member)
{
if (member == null)
return null;
lock (entityDict) {
MemberReference mr;
if (member != null && entityDict.TryGetValue(member, out mr))
if (entityDict.TryGetValue(member, out mr))
return mr;
return null;
}

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>
@ -19,5 +24,6 @@ @@ -19,5 +24,6 @@
<CheckBox IsChecked="{Binding FullyQualifyAmbiguousTypeNames}">Fully qualify ambiguous type names</CheckBox>
<CheckBox IsChecked="{Binding AlwaysUseBraces}">Always use braces</CheckBox>
<CheckBox IsChecked="{Binding ExpandMemberDefinitions}">Expand member definitions after decompilation</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>

112
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;
@ -96,7 +104,107 @@ namespace ICSharpCode.ILSpy.Options @@ -96,7 +104,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