Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into newdecompiler.
Browse files Browse the repository at this point in the history
Note: due to massive conflicts, this merge effectively reverts Christoph's ILSpy.AddIn commits from 2017-03-05.
  • Loading branch information
dgrunwald committed Sep 12, 2017
2 parents 3ecacd1 + 9be9b0b commit f54c621
Show file tree
Hide file tree
Showing 29 changed files with 309 additions and 25 deletions.
3 changes: 2 additions & 1 deletion ICSharpCode.Decompiler/Output/TextTokenWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ object GetCurrentDefinition()

public override void WriteKeyword(Role role, string keyword)
{
if (keyword == "this" || keyword == "base") {
//To make reference for 'this' and 'base' keywords in the ClassName():this() expression
if (role == ConstructorInitializer.ThisKeywordRole || role == ConstructorInitializer.BaseKeywordRole) {
if (nodeStack.Peek() is ConstructorInitializer initializer && initializer.GetSymbol() is IMember member) {
var cecil = typeSystem.GetCecil(member);
if (cecil != null) {
Expand Down
2 changes: 1 addition & 1 deletion ILSpy.AddIn/license.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ The following MIT license applies to ILSpy, NRefactory and ICSharpCode.Decompile

MIT license:

Copyright (c) 2011-2016 AlphaSierraPapa for the SharpDevelop team
Copyright (c) 2011-2017 AlphaSierraPapa for the SharpDevelop team

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:

Expand Down
2 changes: 2 additions & 0 deletions ILSpy/ContextMenuEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public class ExportContextMenuEntryAttribute : ExportAttribute, IContextMenuEntr
public ExportContextMenuEntryAttribute()
: base(typeof(IContextMenuEntry))
{
// entries default to end of menu unless given specific order position
Order = double.MaxValue;
}

public string Icon { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions ILSpy/ILSpy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
<Compile Include="TreeNodes\Analyzer\Helpers.cs" />
<Compile Include="TreeNodes\Analyzer\ScopedWhereUsedAnalyzer.cs" />
<Compile Include="TreeNodes\BaseTypesEntryNode.cs" />
<Compile Include="TreeNodes\CopyFullyQualifiedTypeNameContextMenuEntry.cs" />
<Compile Include="TreeNodes\DerivedTypesEntryNode.cs" />
<Compile Include="TreeNodes\FilterResult.cs" />
<Compile Include="TreeNodes\IMemberTreeNode.cs" />
Expand Down Expand Up @@ -348,6 +349,8 @@

<ItemGroup>
<Resource Include="Images\Sort.png" />
<Resource Include="Images\SearchMsdn.png" />
<Resource Include="Images\Copy.png" />
</ItemGroup>

<ItemGroup>
Expand Down
Binary file added ILSpy/Images/Copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ILSpy/Images/Library.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ILSpy/Images/OverlayStatic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ILSpy/Images/SearchMsdn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 14 additions & 3 deletions ILSpy/Languages/CSharpLanguage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ protected override IEnumerable<Tuple<string, string>> WriteResourceToFile(string
return base.WriteResourceToFile(fileName, resourceName, entryStream);
}
}

/*
AstBuilder CreateAstBuilder(DecompilationOptions options, ModuleDefinition currentModule = null, TypeDefinition currentType = null, bool isSingleMember = false)
{
Expand Down Expand Up @@ -421,10 +421,12 @@ string TypeToString(ConvertTypeOptions options, TypeReference type, ICustomAttri
((ComposedType)astType).PointerRank--;
}
astType.AcceptVisitor(new CSharpOutputVisitor(w, FormattingOptionsFactory.CreateAllman()));
astType.AcceptVisitor(new CSharpOutputVisitor(w, TypeToStringFormattingOptions));
return w.ToString();
}
*/
static readonly CSharpFormattingOptions TypeToStringFormattingOptions = FormattingOptionsFactory.CreateEmpty();
*/

public override string FormatPropertyName(PropertyDefinition property, bool? isIndexer)
{
if (property == null)
Expand Down Expand Up @@ -455,6 +457,15 @@ public override string FormatPropertyName(PropertyDefinition property, bool? isI
} else
return property.Name;
}

public override string FormatMethodName(MethodDefinition method)
{
if (method == null)
throw new ArgumentNullException("method");

return (method.IsConstructor) ? method.DeclaringType.Name : method.Name;
}

/*
public override string FormatTypeName(TypeDefinition type)
{
Expand Down
9 changes: 8 additions & 1 deletion ILSpy/Languages/Language.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,14 @@ public virtual string FormatPropertyName(PropertyDefinition property, bool? isIn
throw new ArgumentNullException(nameof(property));
return property.Name;
}


public virtual string FormatMethodName(MethodDefinition method)
{
if (method == null)
throw new ArgumentNullException("method");
return method.Name;
}

public virtual string FormatTypeName(TypeDefinition type)
{
if (type == null)
Expand Down
14 changes: 14 additions & 0 deletions ILSpy/LoadedAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ ModuleDefinition LoadAssembly(object state)

private void LoadSymbols(ModuleDefinition module)
{
if (!module.HasDebugHeader) {
return;
}
byte[] headerBytes;
var debugHeader = module.GetDebugHeader(out headerBytes);
if (debugHeader.Type != 2) {
// the debug type is not IMAGE_DEBUG_TYPE_CODEVIEW
return;
}
if (debugHeader.MajorVersion != 0 || debugHeader.MinorVersion != 0) {
// the PDB type is not compatible with PdbReaderProvider. It is probably a Portable PDB
return;
}

// search for pdb in same directory as dll
string pdbName = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + ".pdb");
if (File.Exists(pdbName)) {
Expand Down
11 changes: 7 additions & 4 deletions ILSpy/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</Window.TaskbarItemInfo>
<DockPanel>
<!-- Main menu -->
<Menu DockPanel.Dock="Top" Name="mainMenu" Height="23">
<Menu DockPanel.Dock="Top" Name="mainMenu" Height="23" KeyboardNavigation.TabNavigation="None">
<MenuItem Header="_File" /> <!-- contents of file menu are added using MEF -->
<MenuItem Header="_View">
<MenuItem Header="Show _internal types and members" IsCheckable="True" IsChecked="{Binding FilterSettings.ShowInternalApi}">
Expand All @@ -57,7 +57,7 @@
<!-- ToolBar -->
<ToolBar
Name="toolBar"
DockPanel.Dock="Top" ToolBarTray.IsLocked="True">
DockPanel.Dock="Top" ToolBarTray.IsLocked="True" KeyboardNavigation.TabNavigation="None">
<ToolBar.Resources>
<!-- Make images transparent if menu command is disabled -->
<Style TargetType="{x:Type Image}">
Expand Down Expand Up @@ -113,6 +113,7 @@
<!-- Left pane: Tree View of assemblies and classes -->
<tv:SharpTreeView
Name="treeView"
AutomationProperties.Name="Assemblies and Classes"
SelectionChanged="TreeView_SelectionChanged"
ShowRoot="False"
AllowDropOrder="True"
Expand Down Expand Up @@ -142,7 +143,7 @@
<RowDefinition Height="0" Name="bottomPaneRow" />
</Grid.RowDefinitions>
<Border BorderBrush="Black" BorderThickness="1" Name="updatePanel" Visibility="Collapsed">
<DockPanel>
<DockPanel KeyboardNavigation.TabNavigation="Contained">
<Button DockPanel.Dock="Right" Click="updatePanelCloseButtonClick" MinWidth="0">X</Button>
<StackPanel Orientation="Horizontal">
<TextBlock Name="updatePanelMessage" Margin="4,0" VerticalAlignment="Center">A new ILSpy version is available.</TextBlock>
Expand All @@ -152,6 +153,7 @@
</Border>

<controls:DockedPane x:Name="topPane" Grid.Row="1" Title="Top" Visibility="Collapsed"
AutomationProperties.Name="Close top pane"
CloseButtonClicked="TopPane_CloseButtonClicked" Margin="0,0,0,3"
BorderThickness="1,1,0,1" />

Expand Down Expand Up @@ -181,8 +183,9 @@
Visibility="{Binding Visibility, ElementName=bottomPane}" />

<controls:DockedPane x:Name="bottomPane" Grid.Row="5" Title="Bottom" Visibility="Collapsed"
AutomationProperties.Name="Close"
CloseButtonClicked="BottomPane_CloseButtonClicked" Margin="0,3,0,0" BorderThickness="1,1,0,1"/>
</Grid>
</Grid>
</DockPanel>
</Window>
</Window>
35 changes: 34 additions & 1 deletion ILSpy/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ protected override void OnClosing(CancelEventArgs e)
sessionSettings.WindowBounds = this.RestoreBounds;
sessionSettings.SplitterPosition = leftColumn.Width.Value / (leftColumn.Width.Value + rightColumn.Width.Value);
if (topPane.Visibility == Visibility.Visible)
sessionSettings.BottomPaneSplitterPosition = topPaneRow.Height.Value / (topPaneRow.Height.Value + textViewRow.Height.Value);
sessionSettings.TopPaneSplitterPosition = topPaneRow.Height.Value / (topPaneRow.Height.Value + textViewRow.Height.Value);
if (bottomPane.Visibility == Visibility.Visible)
sessionSettings.BottomPaneSplitterPosition = bottomPaneRow.Height.Value / (bottomPaneRow.Height.Value + textViewRow.Height.Value);
sessionSettings.Save();
Expand All @@ -873,10 +873,40 @@ private string GetAutoLoadedAssemblyNode(SharpTreeNode node)
}

#region Top/Bottom Pane management

/// <summary>
/// When grid is resized using splitter, row height value could become greater than 1.
/// As result, when a new pane is shown, both textView and pane could become very small.
/// This method normalizes two rows and ensures that height is less then 1.
/// </summary>
void NormalizePaneRowHeightValues(RowDefinition pane1Row, RowDefinition pane2Row)
{
var pane1Height = pane1Row.Height;
var pane2Height = pane2Row.Height;

//only star height values are normalized.
if (!pane1Height.IsStar || !pane2Height.IsStar)
{
return;
}

var totalHeight = pane1Height.Value + pane2Height.Value;
if (totalHeight == 0)
{
return;
}

pane1Row.Height = new GridLength(pane1Height.Value / totalHeight, GridUnitType.Star);
pane2Row.Height = new GridLength(pane2Height.Value / totalHeight, GridUnitType.Star);
}

public void ShowInTopPane(string title, object content)
{
topPaneRow.MinHeight = 100;
if (sessionSettings.TopPaneSplitterPosition > 0 && sessionSettings.TopPaneSplitterPosition < 1) {
//Ensure all 3 blocks are in fair conditions
NormalizePaneRowHeightValues(bottomPaneRow, textViewRow);

textViewRow.Height = new GridLength(1 - sessionSettings.TopPaneSplitterPosition, GridUnitType.Star);
topPaneRow.Height = new GridLength(sessionSettings.TopPaneSplitterPosition, GridUnitType.Star);
}
Expand Down Expand Up @@ -907,6 +937,9 @@ public void ShowInBottomPane(string title, object content)
{
bottomPaneRow.MinHeight = 100;
if (sessionSettings.BottomPaneSplitterPosition > 0 && sessionSettings.BottomPaneSplitterPosition < 1) {
//Ensure all 3 blocks are in fair conditions
NormalizePaneRowHeightValues(topPaneRow, textViewRow);

textViewRow.Height = new GridLength(1 - sessionSettings.BottomPaneSplitterPosition, GridUnitType.Star);
bottomPaneRow.Height = new GridLength(sessionSettings.BottomPaneSplitterPosition, GridUnitType.Star);
}
Expand Down
1 change: 1 addition & 0 deletions ILSpy/SearchPane.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal">
<Label Margin="0,-1" Target="searchModeComboBox">_Search for:</Label>
<ComboBox Width="100" Name="searchModeComboBox" Margin="1"
TextSearch.TextPath="Name"
SelectionChanged="SearchModeComboBox_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
Expand Down
17 changes: 16 additions & 1 deletion ILSpy/TextView/DecompilerTextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
Expand Down Expand Up @@ -99,6 +100,10 @@ public DecompilerTextView()
textEditor.SetBinding(Control.FontSizeProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFontSize") });
textEditor.SetBinding(TextEditor.WordWrapProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("EnableWordWrap") });

// disable Tab editing command (useless for read-only editor); allow using tab for focus navigation instead
RemoveEditCommand(EditingCommands.TabForward);
RemoveEditCommand(EditingCommands.TabBackward);

textMarkerService = new TextMarkerService(textEditor.TextArea.TextView);
textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
Expand All @@ -115,7 +120,17 @@ public DecompilerTextView()
textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
}


void RemoveEditCommand(RoutedUICommand command)
{
var handler = textEditor.TextArea.DefaultInputHandler.Editing;
var inputBinding = handler.InputBindings.FirstOrDefault(b => b.Command == command);
if (inputBinding != null)
handler.InputBindings.Remove(inputBinding);
var commandBinding = handler.CommandBindings.FirstOrDefault(b => b.Command == command);
if (commandBinding != null)
handler.CommandBindings.Remove(commandBinding);
}
#endregion

#region Line margin
Expand Down
2 changes: 1 addition & 1 deletion ILSpy/TextView/DecompilerTextView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Grid>
<Border BorderThickness="1,1,0,1" BorderBrush="#FF828790">
<Grid>
<ae:TextEditor Name="textEditor" FontFamily="Consolas" FontSize="10pt" IsReadOnly="True"
<ae:TextEditor Name="textEditor" AutomationProperties.Name="Decompilation" FontFamily="Consolas" FontSize="10pt" IsReadOnly="True"
Background="{DynamicResource {x:Static SystemColors.InfoBrushKey}}"
Foreground="{DynamicResource {x:Static SystemColors.InfoTextBrushKey}}">
<ae:TextEditor.Resources>
Expand Down
2 changes: 1 addition & 1 deletion ILSpy/TreeNodes/Analyzer/AnalyzeContextMenuEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{
[ExportContextMenuEntryAttribute(Header = "Analyze", Icon = "images/Search.png")]
[ExportContextMenuEntry(Header = "Analyze", Icon = "images/Search.png", Category = "Analyze", Order = 100)]
internal sealed class AnalyzeContextMenuEntry : IContextMenuEntry
{
public bool IsVisible(TextViewContext context)
Expand Down
2 changes: 1 addition & 1 deletion ILSpy/TreeNodes/Analyzer/RemoveAnalyzeContextMenuEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{
[ExportContextMenuEntryAttribute(Header = "Remove", Icon = "images/Delete.png")]
[ExportContextMenuEntry(Header = "Remove", Icon = "images/Delete.png", Category = "Analyze", Order = 200)]
internal sealed class RemoveAnalyzeContextMenuEntry : IContextMenuEntry
{
public bool IsVisible(TextViewContext context)
Expand Down
6 changes: 3 additions & 3 deletions ILSpy/TreeNodes/AssemblyTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public override bool Save(DecompilerTextView textView)
}
}

[ExportContextMenuEntryAttribute(Header = "_Remove", Icon = "images/Delete.png")]
[ExportContextMenuEntry(Header = "_Remove", Icon = "images/Delete.png")]
sealed class RemoveAssembly : IContextMenuEntry
{
public bool IsVisible(TextViewContext context)
Expand Down Expand Up @@ -352,7 +352,7 @@ public void Execute(TextViewContext context)
}
}

[ExportContextMenuEntry(Header = "_Load Dependencies")]
[ExportContextMenuEntry(Header = "_Load Dependencies", Category = "Dependencies")]
sealed class LoadDependencies : IContextMenuEntry
{
public bool IsVisible(TextViewContext context)
Expand Down Expand Up @@ -383,7 +383,7 @@ public void Execute(TextViewContext context)
}
}

[ExportContextMenuEntry(Header = "_Add To Main List")]
[ExportContextMenuEntry(Header = "_Add To Main List", Category = "Dependencies")]
sealed class AddToMainList : IContextMenuEntry
{
public bool IsVisible(TextViewContext context)
Expand Down
42 changes: 42 additions & 0 deletions ILSpy/TreeNodes/CopyFullyQualifiedTypeNameContextMenuEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Windows;
using Mono.Cecil;

namespace ICSharpCode.ILSpy.TreeNodes
{
[ExportContextMenuEntry(Header = "Copy FQ Name", Icon = "images/Copy.png", Order = 9999)]
public class CopyFullyQualifiedTypeNameContextMenuEntry : IContextMenuEntry
{
public bool IsVisible(TextViewContext context)
{
return GetTypeNodeFromContext(context) != null;
}

public bool IsEnabled(TextViewContext context) => true;

public void Execute(TextViewContext context)
{
var typeDefinition = GetTypeNodeFromContext(context)?.TypeDefinition;
if (typeDefinition == null) return;

Clipboard.SetText(GetFullyQualifiedName(typeDefinition));
}

private TypeTreeNode GetTypeNodeFromContext(TextViewContext context)
{
return context.SelectedTreeNodes?.Length == 1 ? context.SelectedTreeNodes[0] as TypeTreeNode : null;
}

/// <summary>
/// Resolve full type name using .NET type representation for nested types.
/// </summary>
private string GetFullyQualifiedName(TypeDefinition typeDefinition)
{
if (typeDefinition.IsNested)
{
return $"{GetFullyQualifiedName(typeDefinition.DeclaringType)}+{typeDefinition.Name}";
}

return $"{typeDefinition.Namespace}.{typeDefinition.Name}";
}
}
}
4 changes: 2 additions & 2 deletions ILSpy/TreeNodes/MethodTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static object GetText(MethodDefinition method, Language language)
b.Append(") : ");
b.Append(language.TypeToString(method.ReturnType, false, method.MethodReturnType));
b.Append(method.MetadataToken.ToSuffixString());
return HighlightSearchMatch(method.Name, b.ToString());
return HighlightSearchMatch(language.FormatMethodName(method), b.ToString());
}

public override object Icon
Expand All @@ -95,7 +95,7 @@ public static ImageSource GetIcon(MethodDefinition method)

if (method.IsSpecialName &&
(method.Name == ".ctor" || method.Name == ".cctor")) {
return Images.GetIcon(MemberIcon.Constructor, GetOverlayIcon(method.Attributes), false);
return Images.GetIcon(MemberIcon.Constructor, GetOverlayIcon(method.Attributes), method.IsStatic);
}

if (method.HasPInvokeInfo)
Expand Down
Loading

0 comments on commit f54c621

Please sign in to comment.