Browse Source

Add ILSpyAddIn.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
8f5f3a7572
  1. 22
      SharpDevelop.sln
  2. 1
      src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlLanguageBinding.cs
  3. 11
      src/AddIns/Debugger/Debugger.AddIn/Pads/BreakPointsPad.cs
  4. 4
      src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs
  5. 6
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs
  6. 1
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
  7. 1
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/EnhancedScrollBar.cs
  8. 3
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs
  9. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ParserFoldingStrategy.cs
  10. 20
      src/AddIns/DisplayBindings/ILSpyAddIn/DebuggerDecompilerService.cs
  11. 8
      src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.addin
  12. 18
      src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.csproj
  13. 76
      src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/ILSpyAssemblyResolver.cs
  14. 37
      src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/ILSpyController.cs
  15. 12
      src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/OpenInILSpyCommand.cs
  16. 21
      src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/SetILSpyPathDialog.resx
  17. 45
      src/AddIns/DisplayBindings/ILSpyAddIn/NavigateToDecompiledEntityService.cs
  18. 209
      src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/CodeView.cs
  19. 67
      src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/DecompiledViewContent.cs
  20. 40
      src/Libraries/ICSharpCode.Decompiler/Ast/AstBuilder.cs
  21. 4
      src/Libraries/ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  22. 6
      src/Libraries/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs
  23. 10
      src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/CombineQueryExpressions.cs
  24. 2
      src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/ExpressionTreeConverter.cs
  25. 2
      src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/IntroduceUsingDeclarations.cs
  26. 5
      src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs
  27. 12
      src/Libraries/ICSharpCode.Decompiler/DecompilerSettings.cs
  28. 3
      src/Libraries/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs
  29. 14
      src/Libraries/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
  30. 32
      src/Libraries/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs
  31. 4
      src/Libraries/ICSharpCode.Decompiler/Properties/AssemblyInfo.cs
  32. 13
      src/Libraries/ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributeSamples.cs
  33. 2
      src/Libraries/ICSharpCode.Decompiler/Tests/DecompilerTestBase.cs
  34. 2
      src/Libraries/ICSharpCode.Decompiler/Tests/IL/ILTests.cs
  35. 2
      src/Libraries/ICSharpCode.Decompiler/Tests/TestRunner.cs
  36. 20
      src/Libraries/ICSharpCode.Decompiler/Tests/UnsafeCode.cs
  37. 8
      src/Libraries/ICSharpCode.Decompiler/Tests/ValueTypes.cs
  38. 2
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  39. 3
      src/Main/Base/Project/Src/Bookmarks/IBookmarkMargin.cs
  40. 30
      src/Main/Base/Project/Src/Editor/DocumentServiceAttribute.cs
  41. 1
      src/Main/Base/Project/Src/Editor/IEditorUIService.cs
  42. 1
      src/Main/Base/Project/Src/Editor/ISyntaxHighlighter.cs
  43. 1
      src/Main/Base/Project/Src/Editor/ITextMarker.cs
  44. 19
      src/Main/Base/Project/Src/Gui/AbstractViewContent.cs
  45. 12
      src/Main/Base/Project/Src/Gui/Pads/OutlinePad.cs
  46. 1
      src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs
  47. 7
      src/Main/Base/Project/Src/Services/NavigationService/NavigationService.cs
  48. 2
      src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs
  49. 18
      src/Main/Base/Project/Src/Services/ViewContentServiceAttribute.cs
  50. 22
      src/Main/Base/Project/Src/Util/ExtensionMethods.cs

22
SharpDevelop.sln

@ -47,6 +47,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Build.Tasks", " @@ -47,6 +47,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Build.Tasks", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.TreeView", "src\Libraries\SharpTreeView\ICSharpCode.TreeView\ICSharpCode.TreeView.csproj", "{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Decompiler", "src\Libraries\ICSharpCode.Decompiler\ICSharpCode.Decompiler.csproj", "{984CC812-9470-4A13-AFF9-CC44068D666C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AddIns", "AddIns", "{39327899-ED91-4F7F-988C-4FE4E17C014D}"
ProjectSection(SolutionItems) = postProject
EndProjectSection
@ -109,6 +111,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlEditor", "src\AddIns\Dis @@ -109,6 +111,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlEditor", "src\AddIns\Dis
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IconEditor", "src\AddIns\DisplayBindings\IconEditor\IconEditor.csproj", "{DFB936AD-90EE-4B4F-941E-4F4A636F0D92}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpyAddIn", "src\AddIns\DisplayBindings\ILSpyAddIn\ILSpyAddIn.csproj", "{8AA421C8-D7AF-4957-9F43-5135328ACB24}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Analysis", "Analysis", "{7019F43E-DFD7-4D1C-8C96-E75D55646DE7}"
ProjectSection(SolutionItems) = postProject
EndProjectSection
@ -445,6 +449,22 @@ Global @@ -445,6 +449,22 @@ Global
{DFB936AD-90EE-4B4F-941E-4F4A636F0D92}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DFB936AD-90EE-4B4F-941E-4F4A636F0D92}.Release|x86.Build.0 = Release|Any CPU
{DFB936AD-90EE-4B4F-941E-4F4A636F0D92}.Release|x86.ActiveCfg = Release|Any CPU
{8AA421C8-D7AF-4957-9F43-5135328ACB24}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8AA421C8-D7AF-4957-9F43-5135328ACB24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8AA421C8-D7AF-4957-9F43-5135328ACB24}.Debug|x86.Build.0 = Debug|Any CPU
{8AA421C8-D7AF-4957-9F43-5135328ACB24}.Debug|x86.ActiveCfg = Debug|Any CPU
{8AA421C8-D7AF-4957-9F43-5135328ACB24}.Release|Any CPU.Build.0 = Release|Any CPU
{8AA421C8-D7AF-4957-9F43-5135328ACB24}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8AA421C8-D7AF-4957-9F43-5135328ACB24}.Release|x86.Build.0 = Release|Any CPU
{8AA421C8-D7AF-4957-9F43-5135328ACB24}.Release|x86.ActiveCfg = Release|Any CPU
{984CC812-9470-4A13-AFF9-CC44068D666C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{984CC812-9470-4A13-AFF9-CC44068D666C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{984CC812-9470-4A13-AFF9-CC44068D666C}.Debug|x86.Build.0 = Debug|Any CPU
{984CC812-9470-4A13-AFF9-CC44068D666C}.Debug|x86.ActiveCfg = Debug|Any CPU
{984CC812-9470-4A13-AFF9-CC44068D666C}.Release|Any CPU.Build.0 = Release|Any CPU
{984CC812-9470-4A13-AFF9-CC44068D666C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{984CC812-9470-4A13-AFF9-CC44068D666C}.Release|x86.Build.0 = Release|Any CPU
{984CC812-9470-4A13-AFF9-CC44068D666C}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -464,6 +484,7 @@ Global @@ -464,6 +484,7 @@ Global
{6C55B776-26D4-4DB3-A6AB-87E783B2F3D1} = {2A232EF1-EB95-41C6-B63A-C106E0C95D3C}
{4139CCF6-FB49-4A9D-B2CF-331E9EA3198D} = {2A232EF1-EB95-41C6-B63A-C106E0C95D3C}
{DDE2A481-8271-4EAC-A330-8FA6A38D13D1} = {2A232EF1-EB95-41C6-B63A-C106E0C95D3C}
{984CC812-9470-4A13-AFF9-CC44068D666C} = {2A232EF1-EB95-41C6-B63A-C106E0C95D3C}
{3B2A5653-EC97-4001-BB9B-D90F1AF2C371} = {E5A0F4D8-37FD-4A30-BEB0-4409DC4E0865}
{53DCA265-3C3C-42F9-B647-F72BA678122B} = {E5A0F4D8-37FD-4A30-BEB0-4409DC4E0865}
{DC393B66-92ED-4CAD-AB25-CFEF23F3D7C6} = {E5A0F4D8-37FD-4A30-BEB0-4409DC4E0865}
@ -493,6 +514,7 @@ Global @@ -493,6 +514,7 @@ Global
{E618A9CD-A39F-4925-A538-E8A3FEF24E54} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F}
{DCA2703D-250A-463E-A68A-07ED105AE6BD} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F}
{DFB936AD-90EE-4B4F-941E-4F4A636F0D92} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F}
{8AA421C8-D7AF-4957-9F43-5135328ACB24} = {11BF9245-88A3-4A0A-9A8A-EC9D98036B0F}
{1F261725-6318-4434-A1B1-6C70CE4CD324} = {7019F43E-DFD7-4D1C-8C96-E75D55646DE7}
{1D18D788-F7EE-4585-A23B-34DC8EC63CB8} = {49CE38B8-0460-46BF-9DFF-5B33A0F9EB5E}
{EC06F96A-AEEC-49D6-B03D-AB87C6EB674C} = {49CE38B8-0460-46BF-9DFF-5B33A0F9EB5E}

1
src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlLanguageBinding.cs

@ -12,6 +12,7 @@ namespace ICSharpCode.XamlBinding @@ -12,6 +12,7 @@ namespace ICSharpCode.XamlBinding
/// <summary>
/// Description of XamlLanguageBinding.
/// </summary>
[TextEditorService]
public class XamlLanguageBinding : XmlEditor.XmlLanguageBinding
{
// XamlColorizer colorizer;

11
src/AddIns/Debugger/Debugger.AddIn/Pads/BreakPointsPad.cs

@ -37,11 +37,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads @@ -37,11 +37,12 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads
protected override void OnItemActivated(SDBookmark bookmark)
{
if (bookmark is DecompiledBreakpointBookmark) {
// get information from breakpoint and navigate to the decompiled type
string assemblyFile, typeName;
if (DecompiledBreakpointBookmark.GetAssemblyAndType(bookmark.FileName, out assemblyFile, out typeName)) {
NavigationService.NavigateTo(assemblyFile, typeName, string.Empty, bookmark.LineNumber, false);
}
// // get information from breakpoint and navigate to the decompiled type
// string assemblyFile, typeName;
// if (DecompiledBreakpointBookmark.GetAssemblyAndType(bookmark.FileName, out assemblyFile, out typeName)) {
// NavigationService.NavigateTo(assemblyFile, typeName, string.Empty, bookmark.LineNumber, false);
// }
throw new NotImplementedException();
} else {
base.OnItemActivated(bookmark);
}

4
src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs

@ -358,9 +358,7 @@ namespace ICSharpCode.SharpDevelop.Services @@ -358,9 +358,7 @@ namespace ICSharpCode.SharpDevelop.Services
public void InitializeService()
{
// get decompiler service
var items = AddInTree.BuildItems<IDebuggerDecompilerService>("/SharpDevelop/Services/DebuggerDecompilerService", null, false);
if (items.Count > 0)
debuggerDecompilerService = items[0];
debuggerDecompilerService = SD.GetService<IDebuggerDecompilerService>();
// init NDebugger
CurrentDebugger = new NDebugger();

6
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.ComponentModel.Design;
using System.IO;
using System.Linq;
using System.Text;
@ -34,6 +35,11 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -34,6 +35,11 @@ namespace ICSharpCode.AvalonEdit.AddIn
public AvalonEditViewContent(OpenedFile file, Encoding fixedEncodingForLoading = null)
{
// Use common service container for view content and primary text editor.
// This makes all text editor services available as view content services and vice versa.
// (with the exception of the interfaces implemented directly by this class,
// those are available as view-content services only)
this.Services = codeEditor.PrimaryTextEditor.GetRequiredService<IServiceContainer>();
if (fixedEncodingForLoading != null) {
codeEditor.UseFixedEncoding = true;
codeEditor.PrimaryTextEditor.Encoding = fixedEncodingForLoading;

1
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs

@ -37,6 +37,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -37,6 +37,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// Integrates AvalonEdit with SharpDevelop.
/// Also provides support for Split-View (showing two AvalonEdit instances using the same TextDocument)
/// </summary>
[TextEditorService]
public class CodeEditor : Grid, IDisposable
{
const string contextMenuPath = "/SharpDevelop/ViewContent/AvalonEdit/ContextMenu";

1
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/EnhancedScrollBar.cs

@ -21,6 +21,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -21,6 +21,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// <summary>
/// Scrollbar that shows markers.
/// </summary>
[TextEditorService]
public class EnhancedScrollBar : IDisposable
{
readonly TextEditor editor;

3
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Options/HighlightingOptions.xaml.cs

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Globalization;
using System.IO;
using System.Linq;
@ -43,7 +44,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options @@ -43,7 +44,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.Options
textMarkerService = new TextMarkerService(textEditor.Document);
textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
textEditor.TextArea.TextView.Services.AddService(typeof(ITextMarkerService), textMarkerService);
textEditor.Document.GetRequiredService<IServiceContainer>().AddService(typeof(ITextMarkerService), textMarkerService);
}
BracketHighlightRenderer bracketHighlighter;

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ParserFoldingStrategy.cs

@ -8,6 +8,7 @@ using System.Linq; @@ -8,6 +8,7 @@ using System.Linq;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Folding;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Parser;
namespace ICSharpCode.AvalonEdit.AddIn
@ -15,6 +16,7 @@ namespace ICSharpCode.AvalonEdit.AddIn @@ -15,6 +16,7 @@ namespace ICSharpCode.AvalonEdit.AddIn
/// <summary>
/// Uses the NRefactory type system to create parsing information.
/// </summary>
[TextEditorService]
public class ParserFoldingStrategy : IDisposable
{
readonly FoldingManager foldingManager;

20
src/AddIns/DisplayBindings/ILSpyAddIn/DebuggerDecompilerService.cs

@ -15,6 +15,7 @@ using Mono.Cecil; @@ -15,6 +15,7 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpyAddIn
{
/*
// Dummy class to avoid the build errors after updating the ICSharpCode.Decompiler version.
// TODO: get rid of this & fix debugging decompiled files
public class DecompileInformation {
@ -83,15 +84,15 @@ namespace ICSharpCode.ILSpyAddIn @@ -83,15 +84,15 @@ namespace ICSharpCode.ILSpyAddIn
DebuggerTextOutput output = new DebuggerTextOutput(new PlainTextOutput());
astBuilder.GenerateCode(output);
/*int token = type.MetadataToken.ToInt32();
var info = new DecompileInformation {
CodeMappings = astBuilder.CodeMappings,
LocalVariables = astBuilder.LocalVariables,
DecompiledMemberReferences = astBuilder.DecompiledMemberReferences
};
// save the data
DebugInformation.AddOrUpdate(token, info, (k, v) => info);*/
// int token = type.MetadataToken.ToInt32();
// var info = new DecompileInformation {
// CodeMappings = astBuilder.CodeMappings,
// LocalVariables = astBuilder.LocalVariables,
// DecompiledMemberReferences = astBuilder.DecompiledMemberReferences
// };
//
// // save the data
// DebugInformation.AddOrUpdate(token, info, (k, v) => info);
} catch {
return;
}
@ -199,4 +200,5 @@ namespace ICSharpCode.ILSpyAddIn @@ -199,4 +200,5 @@ namespace ICSharpCode.ILSpyAddIn
return resolver;
}
}
*/
}

8
src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.addin

@ -16,12 +16,8 @@ @@ -16,12 +16,8 @@
<Class id="ILSpy" class="ICSharpCode.ILSpyAddIn.NavigateToDecompiledEntityService"/>
</Path>
<Path name="/SharpDevelop/Services/DebuggerDecompilerService">
<Class id="DebuggerDecompilerService" class="ICSharpCode.ILSpyAddIn.DebuggerDecompilerService"/>
</Path>
<!-- Text editor context menu: Launch ILSpy command -->
<!--
<Path name = "/SharpDevelop/ViewContent/DefaultTextEditor/ClassMemberContextMenu">
<MenuItem id="ILSpy" icon="ILSpy" type="Item" label="${res:ILSpyAddIn.OpenILSpyCommand}" class="ICSharpCode.ILSpyAddIn.TextEditorContextMenuCommand"/>
</Path>
@ -37,5 +33,5 @@ @@ -37,5 +33,5 @@
<Path name = "/SharpDevelop/Pads/ClassBrowser/ClassContextMenu">
<MenuItem id="ILSpy" icon="ILSpy" type="Item" label="${res:ILSpyAddIn.OpenILSpyCommand}" class="ICSharpCode.ILSpyAddIn.TextEditorContextMenuCommand"/>
</Path>
-->
</AddIn>

18
src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyAddIn.csproj

@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
<OutputType>Library</OutputType>
<RootNamespace>ICSharpCode.ILSpyAddIn</RootNamespace>
<AssemblyName>ILSpyAddIn</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<AppDesignerFolder>Properties</AppDesignerFolder>
<OutputPath>..\..\..\..\AddIns\DisplayBindings\Decompiler\</OutputPath>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
@ -74,7 +74,7 @@ @@ -74,7 +74,7 @@
<Compile Include="LaunchILSpy\SetILSpyPathDialog.Designer.cs">
<DependentUpon>SetILSpyPathDialog.cs</DependentUpon>
</Compile>
<Compile Include="LaunchILSpy\TextEditorContextMenuCommand.cs" />
<Compile Include="LaunchILSpy\OpenInILSpyCommand.cs" />
<Compile Include="ViewContent\CodeView.cs" />
<Compile Include="ViewContent\DecompiledViewContent.cs" />
<EmbeddedResource Include="LaunchILSpy\SetILSpyPathDialog.resx">
@ -99,17 +99,14 @@ @@ -99,17 +99,14 @@
<Name>Mono.Cecil</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\Libraries\NewNRefactory\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj">
<ProjectReference Include="..\..\..\Libraries\NRefactory\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj">
<Project>{53DCA265-3C3C-42F9-B647-F72BA678122B}</Project>
<Name>ICSharpCode.NRefactory.CSharp</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\Libraries\NewNRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<ProjectReference Include="..\..\..\Libraries\NRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Libraries\NRefactory\Project\NRefactory.csproj">
<Project>{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}</Project>
<Name>NRefactory</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj">
@ -122,11 +119,6 @@ @@ -122,11 +119,6 @@
<Name>ICSharpCode.Core</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\Main\ICSharpCode.SharpDevelop.Dom\Project\ICSharpCode.SharpDevelop.Dom.csproj">
<Project>{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}</Project>
<Name>ICSharpCode.SharpDevelop.Dom</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\AvalonEdit.AddIn\AvalonEdit.AddIn.csproj">
<Project>{0162E499-42D0-409B-AA25-EED21F75336B}</Project>
<Name>AvalonEdit.AddIn</Name>

76
src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/ILSpyAssemblyResolver.cs

@ -6,9 +6,9 @@ using System.Collections.Generic; @@ -6,9 +6,9 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Parser;
using Mono.Cecil;
namespace ICSharpCode.ILSpyAddIn.LaunchILSpy
@ -61,7 +61,7 @@ namespace ICSharpCode.ILSpyAddIn.LaunchILSpy @@ -61,7 +61,7 @@ namespace ICSharpCode.ILSpyAddIn.LaunchILSpy
if (assembly == null) {
// search using ILSpy's GacInterop.FindAssemblyInNetGac()
string fileInGac = FindAssemblyInNetGac(name);
string fileInGac = SD.GlobalAssemblyCache.FindAssemblyInNetGac(new DomAssemblyName(name.FullName));
if (!string.IsNullOrEmpty(fileInGac)) {
assembly = AssemblyDefinition.ReadAssembly(fileInGac, parameters);
}
@ -103,75 +103,5 @@ namespace ICSharpCode.ILSpyAddIn.LaunchILSpy @@ -103,75 +103,5 @@ namespace ICSharpCode.ILSpyAddIn.LaunchILSpy
}
}
}
#region FindAssemblyInGac
// This region is based on code from Mono.Cecil:
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2010 Jb Evain
//
// 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.
//
static readonly string[] gac_paths = { GacInterop.GacRootPathV2, GacInterop.GacRootPathV4 };
static readonly string[] gacs = { "GAC_MSIL", "GAC_32", "GAC" };
static readonly string[] prefixes = { string.Empty, "v4.0_" };
/// <summary>
/// Gets the file name for an assembly stored in the GAC.
/// </summary>
public static string FindAssemblyInNetGac (AssemblyNameReference reference)
{
// without public key, it can't be in the GAC
if (reference.PublicKeyToken == null)
return null;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < gacs.Length; j++) {
var gac = Path.Combine (gac_paths [i], gacs [j]);
var file = GetAssemblyFile (reference, prefixes [i], gac);
if (File.Exists (file))
return file;
}
}
return null;
}
static string GetAssemblyFile (AssemblyNameReference reference, string prefix, string gac)
{
var gac_folder = new StringBuilder ()
.Append (prefix)
.Append (reference.Version)
.Append ("__");
for (int i = 0; i < reference.PublicKeyToken.Length; i++)
gac_folder.Append (reference.PublicKeyToken [i].ToString ("x2"));
return Path.Combine (
Path.Combine (
Path.Combine (gac, reference.Name), gac_folder.ToString ()),
reference.Name + ".dll");
}
#endregion
}
}

37
src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/ILSpyController.cs

@ -8,7 +8,9 @@ using System.IO; @@ -8,7 +8,9 @@ using System.IO;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.NRefactory.Documentation;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
@ -19,29 +21,20 @@ namespace ICSharpCode.ILSpyAddIn @@ -19,29 +21,20 @@ namespace ICSharpCode.ILSpyAddIn
/// </summary>
public static class ILSpyController
{
public static void TryGoTo(AbstractEntity entity)
public static void OpenInILSpy(IEntity entity)
{
if (entity == null)
throw new ArgumentNullException("entity");
while ((entity is IMember) && ((IMember)entity).GenericMember is AbstractEntity)
entity = (AbstractEntity)((IMember)entity).GenericMember;
// Get the underlying entity for generic instance members
if (entity is IMember)
entity = ((IMember)entity).MemberDefinition;
// Try to find the assembly which contains the resolved type
IProjectContent pc = entity.ProjectContent;
ReflectionProjectContent rpc = pc as ReflectionProjectContent;
string assemblyLocation = null;
if (rpc != null) {
assemblyLocation = GetAssemblyLocation(rpc);
} else {
IProject project = pc.Project as IProject;
if (project != null) {
assemblyLocation = project.OutputAssemblyFullPath;
}
}
var assemblyLocation = entity.ParentAssembly.GetRuntimeAssemblyLocation();
if (string.IsNullOrEmpty(assemblyLocation)) {
MessageService.ShowWarning("ILSpy AddIn: Could not determine the assembly location for " + entity.FullyQualifiedName + ".");
MessageService.ShowWarning("ILSpy AddIn: Could not determine the assembly location for " + entity.ParentAssembly.AssemblyName + ".");
return;
}
@ -49,19 +42,11 @@ namespace ICSharpCode.ILSpyAddIn @@ -49,19 +42,11 @@ namespace ICSharpCode.ILSpyAddIn
if (string.IsNullOrEmpty(ilspyPath))
return;
string commandLine = "/singleInstance \"" + assemblyLocation + "\" \"/navigateTo:" + entity.DocumentationTag + "\"";
string commandLine = "/singleInstance \"" + assemblyLocation + "\" \"/navigateTo:" + IdStringProvider.GetIdString(entity) + "\"";
LoggingService.Debug(ilspyPath + " " + commandLine);
Process.Start(ilspyPath, commandLine);
}
public static string GetAssemblyLocation(ReflectionProjectContent rpc)
{
if (rpc == null)
throw new ArgumentNullException("rpc");
// prefer GAC assemblies over reference assemblies:
return rpc.RealAssemblyLocation;
}
#region Find ILSpy
internal const string ILSpyExePathPropertyName = "ILSpyAddIn.ILSpyExePath";
@ -73,7 +58,7 @@ namespace ICSharpCode.ILSpyAddIn @@ -73,7 +58,7 @@ namespace ICSharpCode.ILSpyAddIn
/// <returns>The full path of ILSpy.exe, or <c>null</c> if the path was unknown and the user cancelled the path selection dialog.</returns>
internal static string GetILSpyExeFullPathInteractive()
{
string path = PropertyService.Get(ILSpyExePathPropertyName);
string path = PropertyService.Get(ILSpyExePathPropertyName, "");
string askReason = null;
if (String.IsNullOrEmpty(path)) {

12
src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/TextEditorContextMenuCommand.cs → src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/OpenInILSpyCommand.cs

@ -4,8 +4,6 @@ @@ -4,8 +4,6 @@
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Bookmarks;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui.ClassBrowser;
namespace ICSharpCode.ILSpyAddIn
{
@ -13,11 +11,13 @@ namespace ICSharpCode.ILSpyAddIn @@ -13,11 +11,13 @@ namespace ICSharpCode.ILSpyAddIn
/// Implements a menu command to position .NET ILSpy on a class
/// or class member.
/// </summary>
public sealed class TextEditorContextMenuCommand : AbstractMenuCommand
public sealed class OpenInILSpyCommand : AbstractMenuCommand
{
public override void Run()
{
IClass c;
throw new NotImplementedException();
#warning implement OpenInILSpyCommand
/*IClass c;
IMember m;
MemberNode mn = this.Owner as MemberNode;
@ -56,8 +56,8 @@ namespace ICSharpCode.ILSpyAddIn @@ -56,8 +56,8 @@ namespace ICSharpCode.ILSpyAddIn
if (entity == null)
entity = c as AbstractEntity;
if (entity != null) {
ILSpyController.TryGoTo(entity);
}
ILSpyController.OpenInILSpy(entity);
}*/
}
}
}

21
src/AddIns/DisplayBindings/ILSpyAddIn/LaunchILSpy/SetILSpyPathDialog.resx

@ -117,19 +117,20 @@ @@ -117,19 +117,20 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="pshOK.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="pshOK.GenerateMember" type="System.Boolean, mscorlib">
<value>False</value>
</metadata>
<metadata name="pshCancel.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
</data>
<data name="pshCancel.GenerateMember" type="System.Boolean, mscorlib">
<value>False</value>
</metadata>
<metadata name="txtILSpyExplanation.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
</data>
<data name="txtILSpyExplanation.GenerateMember" type="System.Boolean, mscorlib">
<value>False</value>
</metadata>
<metadata name="grpPath.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
</data>
<data name="grpPath.GenerateMember" type="System.Boolean, mscorlib">
<value>False</value>
</metadata>
<metadata name="pshBrowse.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
</data>
<data name="pshBrowse.GenerateMember" type="System.Boolean, mscorlib">
<value>False</value>
</metadata>
</data>
</root>

45
src/AddIns/DisplayBindings/ILSpyAddIn/NavigateToDecompiledEntityService.cs

@ -4,14 +4,15 @@ @@ -4,14 +4,15 @@
using System;
using System.IO;
using System.Linq;
using ICSharpCode.Core;
using ICSharpCode.NRefactory.Documentation;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Dom;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.ILSpyAddIn
{
public class NavigateToDecompiledEntityService : INavigateToEntityService, INavigateToMemberService
public class NavigateToDecompiledEntityService : INavigateToEntityService
{
public bool NavigateToEntity(IEntity entity)
{
@ -19,46 +20,43 @@ namespace ICSharpCode.ILSpyAddIn @@ -19,46 +20,43 @@ namespace ICSharpCode.ILSpyAddIn
throw new ArgumentNullException("entity");
// Get the underlying entity for generic instance members
while ((entity is IMember) && ((IMember)entity).GenericMember != null)
entity = ((IMember)entity).GenericMember;
if (entity is IMember)
entity = ((IMember)entity).MemberDefinition;
IClass declaringType = (entity as IClass) ?? entity.DeclaringType;
ITypeDefinition declaringType = (entity as ITypeDefinition) ?? entity.DeclaringTypeDefinition;
if (declaringType == null)
return false;
// get the top-level type
while (declaringType.DeclaringType != null)
declaringType = declaringType.DeclaringType;
while (declaringType.DeclaringTypeDefinition != null)
declaringType = declaringType.DeclaringTypeDefinition;
ReflectionProjectContent rpc = entity.ProjectContent as ReflectionProjectContent;
if (rpc != null) {
string assemblyLocation = ILSpyController.GetAssemblyLocation(rpc);
if (!string.IsNullOrEmpty(assemblyLocation) && File.Exists(assemblyLocation)) {
NavigateTo(assemblyLocation, declaringType.DotNetName, ((AbstractEntity)entity).DocumentationTag);
return true;
}
FileName assemblyLocation = declaringType.ParentAssembly.GetRuntimeAssemblyLocation();
if (assemblyLocation != null && File.Exists(assemblyLocation)) {
NavigateTo(assemblyLocation, declaringType.ReflectionName, IdStringProvider.GetIdString(entity));
return true;
}
return false;
}
public static void NavigateTo(string assemblyFile, string typeName, string entityTag)
public static void NavigateTo(FileName assemblyFile, string typeName, string entityIdString)
{
if (string.IsNullOrEmpty(assemblyFile))
throw new ArgumentException("assemblyFile is null or empty");
if (assemblyFile == null)
throw new ArgumentNullException("assemblyFile");
if (string.IsNullOrEmpty(typeName))
throw new ArgumentException("typeName is null or empty");
foreach (var viewContent in WorkbenchSingleton.Workbench.ViewContentCollection.OfType<DecompiledViewContent>()) {
if (string.Equals(viewContent.AssemblyFile, assemblyFile, StringComparison.OrdinalIgnoreCase) && typeName == viewContent.FullTypeName) {
if (viewContent.AssemblyFile == assemblyFile && typeName == viewContent.FullTypeName) {
viewContent.WorkbenchWindow.SelectWindow();
viewContent.JumpToEntity(entityTag);
viewContent.JumpToEntity(entityIdString);
return;
}
}
WorkbenchSingleton.Workbench.ShowView(new DecompiledViewContent(assemblyFile, typeName, entityTag));
WorkbenchSingleton.Workbench.ShowView(new DecompiledViewContent(assemblyFile, typeName, entityIdString));
}
public bool NavigateToMember(string assemblyFile, string typeName, string entityTag, int lineNumber, bool updateMarker)
/*
public bool NavigateToMember(FileName assemblyFile, string typeName, string entityTag, int lineNumber, bool updateMarker)
{
if (string.IsNullOrEmpty(assemblyFile))
throw new ArgumentException("assemblyFile is null or empty");
@ -95,5 +93,6 @@ namespace ICSharpCode.ILSpyAddIn @@ -95,5 +93,6 @@ namespace ICSharpCode.ILSpyAddIn
WorkbenchSingleton.Workbench.ShowView(decompiledView);
return true;
}
*/
}
}

209
src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/CodeView.cs

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
@ -13,6 +14,8 @@ using ICSharpCode.AvalonEdit.Document; @@ -13,6 +14,8 @@ using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.AvalonEdit.Search;
using ICSharpCode.Core;
using ICSharpCode.NRefactory.Editor;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Bookmarks;
using ICSharpCode.SharpDevelop.Editor;
@ -21,180 +24,44 @@ using ICSharpCode.SharpDevelop.Gui; @@ -21,180 +24,44 @@ using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.ILSpyAddIn.ViewContent
{
class DecompiledTextEditorAdapter : AvalonEditTextEditorAdapter
{
public DecompiledTextEditorAdapter(TextEditor textEditor) : base(textEditor)
{}
public string DecompiledFileName { get; set; }
public override ICSharpCode.Core.FileName FileName {
get { return ICSharpCode.Core.FileName.Create(DecompiledFileName); }
}
}
/// <summary>
/// Equivalent to AE.AddIn CodeEditor, but without editing capabilities.
/// </summary>
class CodeView : Grid, IDisposable, IPositionable
{
public event EventHandler DocumentChanged;
readonly DecompiledTextEditorAdapter adapter;
readonly SharpDevelopTextEditor textEditor;
readonly IconBarManager iconBarManager;
readonly IconBarMargin iconMargin;
readonly TextMarkerService textMarkerService;
readonly AvalonEditTextEditorAdapter adapter;
public CodeView(string decompiledFileName)
public CodeView()
{
this.adapter = new DecompiledTextEditorAdapter(new SharpDevelopTextEditor { IsReadOnly = true }) {
DecompiledFileName = decompiledFileName
};
this.Children.Add(adapter.TextEditor);
adapter.TextEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");
textEditor = new SharpDevelopTextEditor();
textEditor.IsReadOnly = true;
this.Children.Add(textEditor);
adapter = new AvalonEditTextEditorAdapter(textEditor);
textEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");
// add margin
this.iconMargin = new IconBarMargin(iconBarManager = new IconBarManager());
this.adapter.TextEditor.TextArea.LeftMargins.Insert(0, iconMargin);
this.adapter.TextEditor.TextArea.TextView.VisualLinesChanged += delegate { iconMargin.InvalidateVisual(); };
textEditor.TextArea.LeftMargins.Insert(0, iconMargin);
textEditor.TextArea.TextView.VisualLinesChanged += delegate { iconMargin.InvalidateVisual(); };
// add marker service
this.textMarkerService = new TextMarkerService(adapter.TextEditor.Document);
this.adapter.TextEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
this.adapter.TextEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
this.adapter.TextEditor.TextArea.TextView.Services.AddService(typeof(ITextMarkerService), textMarkerService);
this.adapter.TextEditor.TextArea.TextView.Services.AddService(typeof(IBookmarkMargin), iconBarManager);
// DON'T add the editor in textview ervices - will mess the setting of breakpoints
// add events
this.adapter.TextEditor.MouseHover += TextEditorMouseHover;
this.adapter.TextEditor.MouseHoverStopped += TextEditorMouseHoverStopped;
this.adapter.TextEditor.MouseLeave += TextEditorMouseLeave;
this.adapter.TextEditor.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(this.adapter.TextEditor.TextArea));
}
#region Popup
ToolTip toolTip;
Popup popupToolTip;
void TextEditorMouseHover(object sender, MouseEventArgs e)
{
ToolTipRequestEventArgs args = new ToolTipRequestEventArgs(this.adapter);
var pos = adapter.TextEditor.GetPositionFromPoint(e.GetPosition(this));
args.InDocument = pos.HasValue;
if (pos.HasValue) {
args.LogicalPosition = AvalonEditDocumentAdapter.ToLocation(pos.Value.Location);
}
if (!args.Handled) {
// if request wasn't handled by a marker, pass it to the ToolTipRequestService
ToolTipRequestService.RequestToolTip(args);
}
if (!TryCloseExistingPopup(false)) {
return;
}
if (args.ContentToShow != null) {
popupToolTip = args.ContentToShow as Popup;
if (popupToolTip != null) {
var popupPosition = GetPopupPosition(e);
popupToolTip.HorizontalOffset = popupPosition.X;
popupToolTip.VerticalOffset = popupPosition.Y;
popupToolTip.IsOpen = true;
popupToolTip.StaysOpen = true; // We will close it ourselves
e.Handled = true;
} else {
if (toolTip == null) {
toolTip = new ToolTip();
toolTip.Closed += delegate { toolTip = null; };
}
toolTip.PlacementTarget = this.adapter.TextEditor; // required for property inheritance
this.textMarkerService = new TextMarkerService(textEditor.Document);
textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
var documentServiceContainer = textEditor.Document.GetRequiredService<ServiceContainer>();
documentServiceContainer.AddService(typeof(ITextMarkerService), textMarkerService);
documentServiceContainer.AddService(typeof(IBookmarkMargin), iconBarManager);
if(args.ContentToShow is string) {
toolTip.Content = new TextBlock
{
Text = args.ContentToShow as string,
TextWrapping = TextWrapping.Wrap
};
}
else
toolTip.Content = args.ContentToShow;
toolTip.IsOpen = true;
e.Handled = true;
}
}
textEditor.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(textEditor.TextArea));
}
bool TryCloseExistingPopup(bool mouseClick)
{
if (popupToolTip != null) {
if (popupToolTip.IsOpen && !mouseClick && popupToolTip is ITooltip && !((ITooltip)popupToolTip).CloseOnHoverEnd) {
return false; // Popup does not want to be closed yet
}
popupToolTip.IsOpen = false;
popupToolTip = null;
}
return true;
}
/// <summary> Returns Popup position based on mouse position, in device independent units </summary>
Point GetPopupPosition(MouseEventArgs mouseArgs)
{
Point mousePos = mouseArgs.GetPosition(this);
Point positionInPixels;
// align Popup with line bottom
TextViewPosition? logicalPos = adapter.TextEditor.GetPositionFromPoint(mousePos);
if (logicalPos.HasValue) {
var textView = adapter.TextEditor.TextArea.TextView;
positionInPixels =
textView.PointToScreen(
textView.GetVisualPosition(logicalPos.Value, VisualYPosition.LineBottom) - textView.ScrollOffset);
positionInPixels.X -= 4;
} else {
positionInPixels = PointToScreen(mousePos + new Vector(-4, 6));
}
// use device independent units, because Popup Left/Top are in independent units
return positionInPixels.TransformFromDevice(this);
}
void TextEditorMouseHoverStopped(object sender, MouseEventArgs e)
{
if (toolTip != null) {
toolTip.IsOpen = false;
e.Handled = true;
}
TextEditorMouseLeave(sender, e);
}
void TextEditorMouseLeave(object sender, MouseEventArgs e)
{
if (popupToolTip != null && !popupToolTip.IsMouseOver) {
// do not close popup if mouse moved from editor to popup
TryCloseExistingPopup(false);
}
}
#endregion
public TextDocument Document {
get { return adapter.TextEditor.Document; }
set {
adapter.TextEditor.Document = value;
if (DocumentChanged != null) {
DocumentChanged(value, EventArgs.Empty);
}
}
}
public ITextEditor TextEditor {
get {
return adapter;
}
get { return textEditor.Document; }
}
public IconBarManager IconBarManager {
@ -205,47 +72,21 @@ namespace ICSharpCode.ILSpyAddIn.ViewContent @@ -205,47 +72,21 @@ namespace ICSharpCode.ILSpyAddIn.ViewContent
{
}
public void UnfoldAndScroll(int lineNumber)
{
if (lineNumber <= 0 || lineNumber > adapter.Document.TotalNumberOfLines)
return;
// var line = adapter.TextEditor.Document.GetLineByNumber(lineNumber);
// // unfold
// var foldings = foldingManager.GetFoldingsContaining(line.Offset);
// if (foldings != null) {
// foreach (var folding in foldings) {
// if (folding.IsFolded) {
// folding.IsFolded = false;
// }
// }
// }
// scroll to
adapter.TextEditor.ScrollTo(lineNumber, 0);
}
public void Redraw(ISegment segment, System.Windows.Threading.DispatcherPriority priority)
{
this.adapter.TextEditor.TextArea.TextView.Redraw(segment, priority);
}
public int Line {
get {
return this.adapter.Caret.Line;
return textEditor.TextArea.Caret.Line;
}
}
public int Column {
get {
return this.adapter.Caret.Column;
return textEditor.TextArea.Caret.Column;
}
}
public void JumpTo(int line, int column)
{
this.adapter.JumpTo(line, column);
adapter.JumpTo(line, column);
}
}
}

67
src/AddIns/DisplayBindings/ILSpyAddIn/ViewContent/DecompiledViewContent.cs

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.IO;
using System.Linq;
using System.Threading;
@ -27,56 +28,52 @@ namespace ICSharpCode.ILSpyAddIn @@ -27,56 +28,52 @@ namespace ICSharpCode.ILSpyAddIn
/// </summary>
class DecompiledViewContent : AbstractViewContentWithoutFile
{
readonly string assemblyFile;
readonly FileName assemblyFile;
readonly string fullTypeName;
readonly string tempFileName;
readonly string uri;
/// <summary>
/// Entity to jump to once decompilation has finished.
/// </summary>
string jumpToEntityTagWhenDecompilationFinished;
string jumpToEntityIdStringWhenDecompilationFinished;
bool decompilationFinished;
readonly CodeView codeView;
readonly CancellationTokenSource cancellation = new CancellationTokenSource();
MemberReference decompiledType;
Dictionary<string, TextLocation> memberLocations;
#region Constructor
public DecompiledViewContent(string assemblyFile, string fullTypeName, string entityTag)
public DecompiledViewContent(FileName assemblyFile, string fullTypeName, string entityTag)
{
// TODO: create options for decompiling in a specific language
this.tempFileName = string.Format("{0}{1}{2}.cs", assemblyFile, DecompiledBreakpointBookmark.SEPARATOR, fullTypeName);
this.codeView = new CodeView(tempFileName);
this.uri = string.Format("ilspy://{0}|{1}", assemblyFile, fullTypeName);
this.codeView = new CodeView();
this.assemblyFile = assemblyFile;
this.fullTypeName = fullTypeName;
this.jumpToEntityTagWhenDecompilationFinished = entityTag;
this.jumpToEntityIdStringWhenDecompilationFinished = entityTag;
string shortTypeName = fullTypeName.Substring(fullTypeName.LastIndexOf('.') + 1);
this.TitleName = "[" + shortTypeName + "]";
this.InfoTip = tempFileName;
Thread thread = new Thread(DecompilationThread);
thread.Name = "Decompiler (" + shortTypeName + ")";
thread.Start();
BookmarkManager.Removed += BookmarkManager_Removed;
BookmarkManager.Added += BookmarkManager_Added;
// add services
this.Services.AddService(typeof(ITextEditor), this.codeView.TextEditor);
}
#endregion
#region Properties
public string AssemblyFile {
public FileName AssemblyFile {
get { return assemblyFile; }
}
/// <summary>
/// The reflection name of the top-level type displayed in this view content.
/// </summary>
public string FullTypeName {
get { return fullTypeName; }
}
@ -98,11 +95,8 @@ namespace ICSharpCode.ILSpyAddIn @@ -98,11 +95,8 @@ namespace ICSharpCode.ILSpyAddIn
codeView.Dispose();
BookmarkManager.Added -= BookmarkManager_Added;
BookmarkManager.Removed -= BookmarkManager_Removed;
if (decompiledType != null) {
DecompileInformation data;
DebuggerDecompilerService.DebugInformation.TryRemove(decompiledType.MetadataToken.ToInt32(), out data);
data = null;
}
// DecompileInformation data;
// DebuggerDecompilerService.DebugInformation.TryRemove(decompiledType.MetadataToken.ToInt32(), out data);
base.Dispose();
}
#endregion
@ -122,14 +116,14 @@ namespace ICSharpCode.ILSpyAddIn @@ -122,14 +116,14 @@ namespace ICSharpCode.ILSpyAddIn
#endregion
#region JumpToEntity
public void JumpToEntity(string entityTag)
public void JumpToEntity(string entityIdString)
{
if (!decompilationFinished) {
this.jumpToEntityTagWhenDecompilationFinished = entityTag;
this.jumpToEntityIdStringWhenDecompilationFinished = entityIdString;
return;
}
TextLocation location;
if (memberLocations != null && memberLocations.TryGetValue(entityTag, out location))
if (memberLocations != null && memberLocations.TryGetValue(entityIdString, out location))
codeView.JumpTo(location.Line, location.Column);
}
#endregion
@ -150,7 +144,7 @@ namespace ICSharpCode.ILSpyAddIn @@ -150,7 +144,7 @@ namespace ICSharpCode.ILSpyAddIn
MessageService.ShowException(ex);
return;
}
AnalyticsMonitorService.TrackException(ex);
SD.AnalyticsMonitor.TrackException(ex);
StringWriter writer = new StringWriter();
writer.WriteLine(string.Format("Exception while decompiling {0} ({1})", fullTypeName, assemblyFile));
@ -178,7 +172,6 @@ namespace ICSharpCode.ILSpyAddIn @@ -178,7 +172,6 @@ namespace ICSharpCode.ILSpyAddIn
astBuilder.GenerateCode(textOutput);
// save decompilation data
decompiledType = typeDefinition;
memberLocations = textOutput.MemberLocations;
}
@ -190,10 +183,10 @@ namespace ICSharpCode.ILSpyAddIn @@ -190,10 +183,10 @@ namespace ICSharpCode.ILSpyAddIn
codeView.Document.UndoStack.ClearAll();
this.decompilationFinished = true;
JumpToEntity(this.jumpToEntityTagWhenDecompilationFinished);
JumpToEntity(this.jumpToEntityIdStringWhenDecompilationFinished);
// update UI
UpdateIconMargin();
//UpdateIconMargin();
// fire events
OnDecompilationFinished(EventArgs.Empty);
@ -201,6 +194,7 @@ namespace ICSharpCode.ILSpyAddIn @@ -201,6 +194,7 @@ namespace ICSharpCode.ILSpyAddIn
#endregion
#region Update UI
/*
void UpdateIconMargin()
{
codeView.IconBarManager.UpdateClassMemberBookmarks(
@ -250,30 +244,19 @@ namespace ICSharpCode.ILSpyAddIn @@ -250,30 +244,19 @@ namespace ICSharpCode.ILSpyAddIn
this.JumpToLineNumber(line);
}
public void JumpToLineNumber(int lineNumber)
{
if (codeView == null || codeView.Document == null)
return;
if (lineNumber <= 0 || lineNumber > codeView.Document.LineCount)
return;
codeView.UnfoldAndScroll(lineNumber);
}
void UpdateCurrentLineBookmark(int lineNumber)
{
if (lineNumber <= 0)
return;
CurrentLineBookmark.SetPosition(codeView.TextEditor.FileName, codeView.TextEditor.Document, lineNumber, 0, lineNumber, 0);
CurrentLineBookmark.SetPosition(uri, codeView.Document, lineNumber, 0, lineNumber, 0);
var currentLineBookmark = BookmarkManager.Bookmarks.OfType<CurrentLineBookmark>().FirstOrDefault();
if (currentLineBookmark != null) {
// update bookmark & marker
codeView.IconBarManager.Bookmarks.Add(currentLineBookmark);
currentLineBookmark.Document = this.codeView.TextEditor.Document;
}
}
}*/
#endregion
@ -290,9 +273,9 @@ namespace ICSharpCode.ILSpyAddIn @@ -290,9 +273,9 @@ namespace ICSharpCode.ILSpyAddIn
void BookmarkManager_Added(object sender, BookmarkEventArgs e)
{
var mark = e.Bookmark;
if (mark != null && mark is BreakpointBookmark && mark.FileName == this.codeView.TextEditor.FileName) {
if (mark != null && mark is BreakpointBookmark && mark.FileName == uri) {
codeView.IconBarManager.Bookmarks.Add(mark);
mark.Document = this.codeView.TextEditor.Document;
mark.Document = this.codeView.Document;
}
}
#endregion

40
src/Libraries/ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -52,7 +52,7 @@ namespace ICSharpCode.Decompiler.Ast
public class AstBuilder
{
DecompilerContext context;
CompilationUnit astCompileUnit = new CompilationUnit();
SyntaxTree syntaxTree = new SyntaxTree();
Dictionary<string, NamespaceDeclaration> astNamespaces = new Dictionary<string, NamespaceDeclaration>();
bool transformationsHaveRun;
@ -139,15 +139,15 @@ namespace ICSharpCode.Decompiler.Ast @@ -139,15 +139,15 @@ namespace ICSharpCode.Decompiler.Ast
public void RunTransformations(Predicate<IAstTransform> transformAbortCondition)
{
TransformationPipeline.RunTransformationsUntil(astCompileUnit, transformAbortCondition, context);
TransformationPipeline.RunTransformationsUntil(syntaxTree, transformAbortCondition, context);
transformationsHaveRun = true;
}
/// <summary>
/// Gets the abstract source tree.
/// </summary>
public CompilationUnit CompilationUnit {
get { return astCompileUnit; }
public SyntaxTree SyntaxTree {
get { return syntaxTree; }
}
/// <summary>
@ -159,16 +159,16 @@ namespace ICSharpCode.Decompiler.Ast @@ -159,16 +159,16 @@ namespace ICSharpCode.Decompiler.Ast
if (!transformationsHaveRun)
RunTransformations();
astCompileUnit.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true });
var outputFormatter = new TextOutputFormatter(output);
syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true });
var outputFormatter = new TextOutputFormatter(output) { FoldBraces = context.Settings.FoldBraces };
var formattingPolicy = context.Settings.CSharpFormattingOptions;
astCompileUnit.AcceptVisitor(new CSharpOutputVisitor(outputFormatter, formattingPolicy));
syntaxTree.AcceptVisitor(new CSharpOutputVisitor(outputFormatter, formattingPolicy));
}
public void AddAssembly(AssemblyDefinition assemblyDefinition, bool onlyAssemblyLevel = false)
{
if (assemblyDefinition.Name.Version != null) {
astCompileUnit.AddChild(
syntaxTree.AddChild(
new AttributeSection {
AttributeTarget = "assembly",
Attributes = {
@ -185,10 +185,10 @@ namespace ICSharpCode.Decompiler.Ast @@ -185,10 +185,10 @@ namespace ICSharpCode.Decompiler.Ast
}, EntityDeclaration.AttributeRole);
}
ConvertCustomAttributes(astCompileUnit, assemblyDefinition, "assembly");
ConvertSecurityAttributes(astCompileUnit, assemblyDefinition, "assembly");
ConvertCustomAttributes(astCompileUnit, assemblyDefinition.MainModule, "module");
AddTypeForwarderAttributes(astCompileUnit, assemblyDefinition.MainModule, "assembly");
ConvertCustomAttributes(syntaxTree, assemblyDefinition, "assembly");
ConvertSecurityAttributes(syntaxTree, assemblyDefinition, "assembly");
ConvertCustomAttributes(syntaxTree, assemblyDefinition.MainModule, "module");
AddTypeForwarderAttributes(syntaxTree, assemblyDefinition.MainModule, "assembly");
if (!onlyAssemblyLevel) {
foreach (TypeDefinition typeDef in assemblyDefinition.MainModule.Types) {
@ -203,7 +203,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -203,7 +203,7 @@ namespace ICSharpCode.Decompiler.Ast
}
}
void AddTypeForwarderAttributes(CompilationUnit astCompileUnit, ModuleDefinition module, string target)
void AddTypeForwarderAttributes(SyntaxTree astCompileUnit, ModuleDefinition module, string target)
{
if (!module.HasExportedTypes)
return;
@ -237,7 +237,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -237,7 +237,7 @@ namespace ICSharpCode.Decompiler.Ast
} else {
// Create the namespace
NamespaceDeclaration astNamespace = new NamespaceDeclaration { Name = name };
astCompileUnit.AddChild(astNamespace, CompilationUnit.MemberRole);
syntaxTree.Members.Add(astNamespace);
astNamespaces[name] = astNamespace;
return astNamespace;
}
@ -248,31 +248,31 @@ namespace ICSharpCode.Decompiler.Ast @@ -248,31 +248,31 @@ namespace ICSharpCode.Decompiler.Ast
var astType = CreateType(typeDef);
NamespaceDeclaration astNS = GetCodeNamespace(typeDef.Namespace);
if (astNS != null) {
astNS.AddChild(astType, NamespaceDeclaration.MemberRole);
astNS.Members.Add(astType);
} else {
astCompileUnit.AddChild(astType, CompilationUnit.MemberRole);
syntaxTree.Members.Add(astType);
}
}
public void AddMethod(MethodDefinition method)
{
AstNode node = method.IsConstructor ? (AstNode)CreateConstructor(method) : CreateMethod(method);
astCompileUnit.AddChild(node, CompilationUnit.MemberRole);
syntaxTree.Members.Add(node);
}
public void AddProperty(PropertyDefinition property)
{
astCompileUnit.AddChild(CreateProperty(property), CompilationUnit.MemberRole);
syntaxTree.Members.Add(CreateProperty(property));
}
public void AddField(FieldDefinition field)
{
astCompileUnit.AddChild(CreateField(field), CompilationUnit.MemberRole);
syntaxTree.Members.Add(CreateField(field));
}
public void AddEvent(EventDefinition ev)
{
astCompileUnit.AddChild(CreateEvent(ev), CompilationUnit.MemberRole);
syntaxTree.Members.Add(CreateEvent(ev));
}
/// <summary>

4
src/Libraries/ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -755,7 +755,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -755,7 +755,7 @@ namespace ICSharpCode.Decompiler.Ast
for (int i = 0; i < args.Count; i++) {
atce.Initializers.Add(
new NamedExpression {
Identifier = ctor.Parameters[i].Name,
Name = ctor.Parameters[i].Name,
Expression = args[i]
});
}
@ -805,7 +805,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -805,7 +805,7 @@ namespace ICSharpCode.Decompiler.Ast
MemberReferenceExpression mre = m.Get<MemberReferenceExpression>("left").Single();
initializer.Elements.Add(
new NamedExpression {
Identifier = mre.MemberName,
Name = mre.MemberName,
Expression = m.Get<Expression>("right").Single().Detach()
}.CopyAnnotationsFrom(mre));
} else {

6
src/Libraries/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs

@ -36,6 +36,8 @@ namespace ICSharpCode.Decompiler.Ast @@ -36,6 +36,8 @@ namespace ICSharpCode.Decompiler.Ast
bool firstUsingDeclaration;
bool lastUsingDeclaration;
public bool FoldBraces = false;
public TextOutputFormatter(ITextOutput output)
{
if (output == null)
@ -183,7 +185,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -183,7 +185,7 @@ namespace ICSharpCode.Decompiler.Ast
{
if (braceLevelWithinType >= 0 || nodeStack.Peek() is TypeDeclaration)
braceLevelWithinType++;
if (nodeStack.OfType<BlockStatement>().Count() <= 1) {
if (nodeStack.OfType<BlockStatement>().Count() <= 1 || FoldBraces) {
output.MarkFoldStart(defaultCollapsed: braceLevelWithinType == 1);
}
output.WriteLine();
@ -195,7 +197,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -195,7 +197,7 @@ namespace ICSharpCode.Decompiler.Ast
{
output.Unindent();
output.Write('}');
if (nodeStack.OfType<BlockStatement>().Count() <= 1)
if (nodeStack.OfType<BlockStatement>().Count() <= 1 || FoldBraces)
output.MarkFoldEnd();
if (braceLevelWithinType >= 0)
braceLevelWithinType--;

10
src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/CombineQueryExpressions.cs

@ -82,11 +82,11 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -82,11 +82,11 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
new AnonymousTypeCreateExpression {
Initializers = {
new NamedExpression {
Identifier = Pattern.AnyString,
Name = Pattern.AnyString,
Expression = new IdentifierExpression(Pattern.AnyString)
}.WithName("nae1"),
new NamedExpression {
Identifier = Pattern.AnyString,
Name = Pattern.AnyString,
Expression = new AnyNode("nae2Expr")
}.WithName("nae2")
}
@ -114,11 +114,11 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -114,11 +114,11 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
QuerySelectClause selectClause = (QuerySelectClause)innerQuery.Clauses.Last();
NamedExpression nae1 = match.Get<NamedExpression>("nae1").SingleOrDefault();
NamedExpression nae2 = match.Get<NamedExpression>("nae2").SingleOrDefault();
if (nae1 != null && nae1.Identifier != ((IdentifierExpression)nae1.Expression).Identifier)
if (nae1 != null && nae1.Name != ((IdentifierExpression)nae1.Expression).Identifier)
return false;
Expression nae2Expr = match.Get<Expression>("nae2Expr").Single();
IdentifierExpression nae2IdentExpr = nae2Expr as IdentifierExpression;
if (nae2IdentExpr != null && (nae2 == null || nae2.Identifier == nae2IdentExpr.Identifier)) {
if (nae2IdentExpr != null && (nae2 == null || nae2.Name == nae2IdentExpr.Identifier)) {
// from * in (from x in ... select new { x = x, y = y }) ...
// =>
// from x in ... ...
@ -142,7 +142,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -142,7 +142,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
}
string ident;
if (nae2 != null)
ident = nae2.Identifier;
ident = nae2.Name;
else if (nae2Expr is IdentifierExpression)
ident = ((IdentifierExpression)nae2Expr).Identifier;
else if (nae2Expr is MemberReferenceExpression)

2
src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/ExpressionTreeConverter.cs

@ -567,7 +567,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -567,7 +567,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
for (int i = 0; i < resolvedCtor.Parameters.Count; i++) {
atce.Initializers.Add(
new NamedExpression {
Identifier = resolvedCtor.Parameters[i].Name,
Name = resolvedCtor.Parameters[i].Name,
Expression = arguments[i].Detach()
});
}

2
src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/IntroduceUsingDeclarations.cs

@ -55,7 +55,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -55,7 +55,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
for (int i = 1; i < parts.Length; i++) {
nsType = new MemberType { Target = nsType, MemberName = parts[i] };
}
compilationUnit.InsertChildAfter(null, new UsingDeclaration { Import = nsType }, CompilationUnit.MemberRole);
compilationUnit.InsertChildAfter(null, new UsingDeclaration { Import = nsType }, SyntaxTree.MemberRole);
}
if (!context.Settings.FullyQualifyAmbiguousTypeNames)

5
src/Libraries/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs

@ -897,6 +897,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -897,6 +897,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
#region Automatic Events
static readonly Accessor automaticEventPatternV4 = new Accessor {
Attributes = { new Repeat(new AnyNode()) },
Body = new BlockStatement {
new VariableDeclarationStatement { Type = new AnyNode("type"), Variables = { new AnyNode() } },
new VariableDeclarationStatement { Type = new Backreference("type"), Variables = { new AnyNode() } },
@ -965,6 +966,10 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -965,6 +966,10 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
return null;
EventDeclaration ed = new EventDeclaration();
ev.Attributes.MoveTo(ed.Attributes);
foreach (var attr in ev.AddAccessor.Attributes) {
attr.AttributeTarget = "method";
ed.Attributes.Add(attr.Detach());
}
ed.ReturnType = ev.ReturnType.Detach();
ed.Modifiers = ev.Modifiers;
ed.Variables.Add(new VariableInitializer(ev.Name));

12
src/Libraries/ICSharpCode.Decompiler/DecompilerSettings.cs

@ -255,6 +255,18 @@ namespace ICSharpCode.Decompiler @@ -255,6 +255,18 @@ namespace ICSharpCode.Decompiler
}
}
bool foldBraces = false;
public bool FoldBraces {
get { return foldBraces; }
set {
if (foldBraces != value) {
foldBraces = value;
OnPropertyChanged("FoldBraces");
}
}
}
#region Options to aid VB decompilation
bool introduceIncrementAndDecrement = true;

3
src/Libraries/ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs

@ -674,6 +674,9 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -674,6 +674,9 @@ namespace ICSharpCode.Decompiler.Disassembler
public void DisassembleField(FieldDefinition field)
{
output.WriteDefinition(".field ", field);
if (field.HasLayoutInfo) {
output.Write("[" + field.Offset + "] ");
}
WriteEnum(field.Attributes & FieldAttributes.FieldAccessMask, fieldVisibility);
const FieldAttributes hasXAttributes = FieldAttributes.HasDefault | FieldAttributes.HasFieldMarshal | FieldAttributes.HasFieldRVA;
WriteFlags(field.Attributes & ~(FieldAttributes.FieldAccessMask | hasXAttributes), fieldAttributes);

14
src/Libraries/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -7,15 +7,16 @@ @@ -7,15 +7,16 @@
<OutputType>Library</OutputType>
<RootNamespace>ICSharpCode.Decompiler</RootNamespace>
<AssemblyName>ICSharpCode.Decompiler</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<AppDesignerFolder>Properties</AppDesignerFolder>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\NewNRefactory\ICSharpCode.NRefactory.snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>..\NRefactory\ICSharpCode.NRefactory.snk</AssemblyOriginatorKeyFile>
<DelaySign>False</DelaySign>
<AssemblyOriginatorKeyMode>File</AssemblyOriginatorKeyMode>
</PropertyGroup>
@ -131,14 +132,17 @@ @@ -131,14 +132,17 @@
<ProjectReference Include="..\Mono.Cecil\Mono.Cecil.csproj">
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
<Name>Mono.Cecil</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\NewNRefactory\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj">
<ProjectReference Include="..\NRefactory\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj">
<Project>{53DCA265-3C3C-42F9-B647-F72BA678122B}</Project>
<Name>ICSharpCode.NRefactory.CSharp</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\NewNRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<ProjectReference Include="..\NRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup />

32
src/Libraries/ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

@ -303,7 +303,13 @@ namespace ICSharpCode.Decompiler.ILAst @@ -303,7 +303,13 @@ namespace ICSharpCode.Decompiler.ILAst
return v.Type;
}
case ILCode.Ldloca:
return new ByReferenceType(((ILVariable)expr.Operand).Type);
{
ILVariable v = (ILVariable)expr.Operand;
if (v.Type != null)
return new ByReferenceType(v.Type);
else
return null;
}
#endregion
#region Call / NewObj
case ILCode.Call:
@ -385,23 +391,29 @@ namespace ICSharpCode.Decompiler.ILAst @@ -385,23 +391,29 @@ namespace ICSharpCode.Decompiler.ILAst
case ILCode.Ldobj:
{
TypeReference type = (TypeReference)expr.Operand;
if (expectedType != null) {
int infoAmount = GetInformationAmount(expectedType);
var argType = InferTypeForExpression(expr.Arguments[0], null);
if (argType is PointerType || argType is ByReferenceType) {
var elementType = ((TypeSpecification)argType).ElementType;
int infoAmount = GetInformationAmount(elementType);
if (infoAmount == 1 && GetInformationAmount(type) == 8) {
// A bool can be loaded from both bytes and sbytes.
type = expectedType;
type = elementType;
}
if (infoAmount >= 8 && infoAmount <= 64 && infoAmount == GetInformationAmount(type)) {
// An integer can be loaded as another integer of the same size.
// For integers smaller than 32 bit, the signs must match (as loading performs sign extension)
if (infoAmount >= 32 || IsSigned(expectedType) == IsSigned(type))
type = expectedType;
bool? elementTypeIsSigned = IsSigned(elementType);
bool? typeIsSigned = IsSigned(type);
if (elementTypeIsSigned != null && typeIsSigned != null) {
if (infoAmount >= 32 || elementTypeIsSigned == typeIsSigned)
type = elementType;
}
}
}
if (forceInferChildren) {
if (InferTypeForExpression(expr.Arguments[0], new ByReferenceType(type)) is PointerType)
InferTypeForExpression(expr.Arguments[0], new PointerType(type));
}
if (argType is PointerType)
InferTypeForExpression(expr.Arguments[0], new PointerType(type));
else
InferTypeForExpression(expr.Arguments[0], new ByReferenceType(type));
return type;
}
case ILCode.Stobj:

4
src/Libraries/ICSharpCode.Decompiler/Properties/AssemblyInfo.cs

@ -19,8 +19,8 @@ using System.Runtime.InteropServices; @@ -19,8 +19,8 @@ using System.Runtime.InteropServices;
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("2.1.0.1603")]
[assembly: AssemblyInformationalVersion("2.1.0.1603-1170e2f8")]
[assembly: AssemblyVersion("2.1.0.1619")]
[assembly: AssemblyInformationalVersion("2.1.0.1619-214c1f73")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2243:AttributeStringLiteralsShouldParseCorrectly",

13
src/Libraries/ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributeSamples.cs

@ -69,6 +69,19 @@ namespace AppliedToEvent @@ -69,6 +69,19 @@ namespace AppliedToEvent
public event EventHandler MyEvent;
}
}
//$$ AppliedToEventMethods
namespace AppliedToEventMethods
{
[AttributeUsage(AttributeTargets.Method)]
public class MyAttributeAttribute : Attribute
{
}
public class TestClass
{
[method: MyAttribute]
public event EventHandler MyEvent;
}
}
//$$ AppliedToField
namespace AppliedToField
{

2
src/Libraries/ICSharpCode.Decompiler/Tests/DecompilerTestBase.cs

@ -58,7 +58,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -58,7 +58,7 @@ namespace ICSharpCode.Decompiler.Tests
AssemblyDefinition assembly = Compile(code);
AstBuilder decompiler = new AstBuilder(new DecompilerContext(assembly.MainModule) { Settings = settings });
decompiler.AddAssembly(assembly);
new Helpers.RemoveCompilerAttribute().Run(decompiler.CompilationUnit);
new Helpers.RemoveCompilerAttribute().Run(decompiler.SyntaxTree);
StringWriter output = new StringWriter();
decompiler.GenerateCode(new PlainTextOutput(output));
return output.ToString();

2
src/Libraries/ICSharpCode.Decompiler/Tests/IL/ILTests.cs

@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.Tests
var assembly = AssemblyDefinition.ReadAssembly(Path.Combine(path, compiledFile));
AstBuilder decompiler = new AstBuilder(new DecompilerContext(assembly.MainModule));
decompiler.AddAssembly(assembly);
new Helpers.RemoveCompilerAttribute().Run(decompiler.CompilationUnit);
new Helpers.RemoveCompilerAttribute().Run(decompiler.SyntaxTree);
StringWriter output = new StringWriter();
decompiler.GenerateCode(new PlainTextOutput(output));
CodeAssert.AreEqual(expectedOutput, output.ToString());

2
src/Libraries/ICSharpCode.Decompiler/Tests/TestRunner.cs

@ -184,7 +184,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -184,7 +184,7 @@ namespace ICSharpCode.Decompiler.Tests
AssemblyDefinition assembly = Compile(code, optimize, useDebug);
AstBuilder decompiler = new AstBuilder(new DecompilerContext(assembly.MainModule));
decompiler.AddAssembly(assembly);
new Helpers.RemoveCompilerAttribute().Run(decompiler.CompilationUnit);
new Helpers.RemoveCompilerAttribute().Run(decompiler.SyntaxTree);
StringWriter output = new StringWriter();
decompiler.GenerateCode(new PlainTextOutput(output));
CodeAssert.AreEqual(code, output.ToString());

20
src/Libraries/ICSharpCode.Decompiler/Tests/UnsafeCode.cs

@ -33,6 +33,21 @@ public class UnsafeCode @@ -33,6 +33,21 @@ public class UnsafeCode
return *(long*)(&d);
}
public unsafe double ConvertLongToDouble(long d)
{
return *(double*)(&d);
}
public unsafe int ConvertFloatToInt(float d)
{
return *(int*)(&d);
}
public unsafe float ConvertIntToFloat(int d)
{
return *(float*)(&d);
}
public unsafe void PassRefParameterAsPointer(ref int p)
{
fixed (int* ptr = &p)
@ -48,7 +63,8 @@ public class UnsafeCode @@ -48,7 +63,8 @@ public class UnsafeCode
public unsafe void AddressInMultiDimensionalArray(double[,] matrix)
{
fixed (double* ptr = &matrix[1, 2]) {
fixed (double* ptr = &matrix[1, 2])
{
this.PointerReferenceExpression(ptr);
}
}
@ -58,7 +74,7 @@ public class UnsafeCode @@ -58,7 +74,7 @@ public class UnsafeCode
fixed (char* ptr = text)
{
char* ptr2 = ptr;
while (*ptr2 != 0)
while (*ptr2 != '\0')
{
*ptr2 = 'A';
ptr2++;

8
src/Libraries/ICSharpCode.Decompiler/Tests/ValueTypes.cs

@ -160,4 +160,12 @@ public static class ValueTypes @@ -160,4 +160,12 @@ public static class ValueTypes
s.SetField();
return p;
}
public static void UseRefBoolInCondition(ref bool x)
{
if (x)
{
Console.WriteLine("true");
}
}
}

2
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -112,6 +112,7 @@ @@ -112,6 +112,7 @@
<Compile Include="Src\Editor\Commands\FindReferencesCommand.cs" />
<Compile Include="Src\Editor\Commands\GotoLineNumber.cs" />
<Compile Include="Src\Editor\Commands\SymbolUnderCaretMenuCommand.cs" />
<Compile Include="Src\Editor\DocumentServiceAttribute.cs" />
<Compile Include="Src\Editor\IDocumentBaseVersionProvider.cs" />
<Compile Include="Src\Editor\IEditorControlService.cs" />
<Compile Include="Src\Editor\IEditorUIService.cs" />
@ -740,6 +741,7 @@ @@ -740,6 +741,7 @@
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\AsyncDiscoveryState.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\DiscoveryNetworkCredential.cs" />
<Compile Include="Src\Services\ProjectService\ProjectLoader.cs" />
<Compile Include="Src\Services\ViewContentServiceAttribute.cs" />
<Compile Include="Src\Util\AtomicBoolean.cs" />
<Compile Include="Src\Util\DotnetDetection.cs" />
<Compile Include="Src\Util\FakeXmlViewContent.cs" />

3
src/Main/Base/Project/Src/Bookmarks/IBookmarkMargin.cs

@ -5,11 +5,14 @@ using System; @@ -5,11 +5,14 @@ using System;
using System.Collections.Generic;
using System.Windows.Input;
using ICSharpCode.SharpDevelop.Editor;
namespace ICSharpCode.SharpDevelop.Bookmarks
{
/// <summary>
/// The bookmark margin.
/// </summary>
[DocumentService]
public interface IBookmarkMargin
{
/// <summary>

30
src/Main/Base/Project/Src/Editor/DocumentServiceAttribute.cs

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.SharpDevelop.Editor
{
/// <summary>
/// Specifies that the given interface is a service that can be retrieved using an <see cref="IDocument"/> or
/// an <see cref="ITextEditor"/> as service provider.
/// </summary>
/// <remarks>
/// This attribute is intended to be used as documentation, it does not have any effect at runtime.
/// </remarks>
[AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class)]
public class DocumentServiceAttribute : Attribute
{
}
/// <summary>
/// Specifies that the given interface is a service that can be retrieved using an <see cref="ITextEditor"/> as service provider.
/// </summary>
/// <remarks>
/// This attribute is intended to be used as documentation, it does not have any effect at runtime.
/// </remarks>
[AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class)]
public class TextEditorServiceAttribute : Attribute
{
}
}

1
src/Main/Base/Project/Src/Editor/IEditorUIService.cs

@ -8,6 +8,7 @@ using ICSharpCode.NRefactory.Editor; @@ -8,6 +8,7 @@ using ICSharpCode.NRefactory.Editor;
namespace ICSharpCode.SharpDevelop.Editor
{
[TextEditorService]
public interface IEditorUIService
{
IInlineUIElement CreateInlineUIElement(ITextAnchor position, UIElement element);

1
src/Main/Base/Project/Src/Editor/ISyntaxHighlighter.cs

@ -12,6 +12,7 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -12,6 +12,7 @@ namespace ICSharpCode.SharpDevelop.Editor
/// <summary>
/// Represents the syntax highlighter inside the text editor.
/// </summary>
[TextEditorService]
public interface ISyntaxHighlighter
{
/// <summary>

1
src/Main/Base/Project/Src/Editor/ITextMarker.cs

@ -107,6 +107,7 @@ namespace ICSharpCode.SharpDevelop.Editor @@ -107,6 +107,7 @@ namespace ICSharpCode.SharpDevelop.Editor
CircleInScrollBar = 0x1000
}
[DocumentService]
public interface ITextMarkerService
{
/// <summary>

19
src/Main/Base/Project/Src/Gui/AbstractViewContent.cs

@ -577,20 +577,25 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -577,20 +577,25 @@ namespace ICSharpCode.SharpDevelop.Gui
#endregion
#region IServiceProvider
ServiceContainer services = new ServiceContainer();
IServiceContainer services = new ServiceContainer();
public object GetService(Type serviceType)
{
object obj = services.GetService(serviceType);
if (obj == null) {
if (serviceType.IsInstanceOfType(this))
return this;
}
return obj;
if (obj != null)
return obj;
if (serviceType.IsInstanceOfType(this))
return this;
return null;
}
public ServiceContainer Services {
public IServiceContainer Services {
get { return services; }
protected set {
if (value == null)
throw new ArgumentNullException();
services = value;
}
}
#endregion

12
src/Main/Base/Project/Src/Gui/Pads/OutlinePad.cs

@ -11,6 +11,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -11,6 +11,7 @@ namespace ICSharpCode.SharpDevelop.Gui
/// <summary>
/// Implement this interface to make a view content display tools in the outline pad.
/// </summary>
[ViewContentService]
public interface IOutlineContentHost
{
/// <summary>
@ -41,17 +42,8 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -41,17 +42,8 @@ namespace ICSharpCode.SharpDevelop.Gui
void WorkbenchActiveContentChanged(object sender, EventArgs e)
{
IViewContent view = WorkbenchSingleton.Workbench.ActiveViewContent;
if(view!=null){
if (view!=null) {
IOutlineContentHost content = view.GetService(typeof(IOutlineContentHost)) as IOutlineContentHost;
if(content!=null){
contentControl.SetContent(content.OutlineContent, content);
return ;
}
}
ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider;
if (provider != null) {
IOutlineContentHost content = provider.TextEditor.GetService(typeof(IOutlineContentHost)) as IOutlineContentHost;
if (content != null) {
contentControl.SetContent(content.OutlineContent, content);
return;

1
src/Main/Base/Project/Src/Services/Debugger/DebuggerService.cs

@ -313,6 +313,7 @@ namespace ICSharpCode.SharpDevelop.Debugging @@ -313,6 +313,7 @@ namespace ICSharpCode.SharpDevelop.Debugging
/// <summary>
/// Interface for common debugger-decompiler mapping operations.
/// </summary>
[SDService]
public interface IDebuggerDecompilerService
{
/// <summary>

7
src/Main/Base/Project/Src/Services/NavigationService/NavigationService.cs

@ -468,7 +468,7 @@ namespace ICSharpCode.SharpDevelop @@ -468,7 +468,7 @@ namespace ICSharpCode.SharpDevelop
#endregion
#region Navigate to Member
/* Part of Eusebiu's debugger/decompiler implementation
public static bool NavigateTo(string assemblyFile, string typeName, string entityTag, int lineNumber = 0, bool updateMarker = true)
{
if (string.IsNullOrEmpty(assemblyFile))
@ -483,7 +483,7 @@ namespace ICSharpCode.SharpDevelop @@ -483,7 +483,7 @@ namespace ICSharpCode.SharpDevelop
}
return false;
}
*/
#endregion
}
@ -497,7 +497,7 @@ namespace ICSharpCode.SharpDevelop @@ -497,7 +497,7 @@ namespace ICSharpCode.SharpDevelop
{
bool NavigateToEntity(IEntity entity);
}
/* Part of Eusebiu's debugger/decompiler implementation
/// <summary>
/// Called by <see cref="NavigationService.NavigateTo"/> when the member reference is not defined in source code.
/// </summary>
@ -508,4 +508,5 @@ namespace ICSharpCode.SharpDevelop @@ -508,4 +508,5 @@ namespace ICSharpCode.SharpDevelop
{
bool NavigateToMember(string assemblyFile, string typeName, string entityTag, int lineNumber, bool updateMarker);
}
*/
}

2
src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs

@ -154,7 +154,7 @@ namespace ICSharpCode.SharpDevelop.Parser @@ -154,7 +154,7 @@ namespace ICSharpCode.SharpDevelop.Parser
try {
using (FileStream fs = new FileStream(cacheFileName, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete, 4096, FileOptions.SequentialScan)) {
using (BinaryReader reader = new BinaryReaderWith7BitEncodedInts(fs)) {
if (reader.ReadByte() != cacheMagicNumber) {
if (reader.ReadInt32() != cacheMagicNumber) {
LoggingService.Warn("Incorrect magic number");
return null;
}

18
src/Main/Base/Project/Src/Services/ViewContentServiceAttribute.cs

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.SharpDevelop
{
/// <summary>
/// Specifies that the given interface is a service that can be retrieved using an <see cref="IViewContent"/> as service provider.
/// </summary>
/// <remarks>
/// This attribute is intended to be used as documentation, it does not have any effect at runtime.
/// </remarks>
[AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class)]
public class ViewContentServiceAttribute : Attribute
{
}
}

22
src/Main/Base/Project/Src/Util/ExtensionMethods.cs

@ -15,6 +15,7 @@ using System.Windows.Forms; @@ -15,6 +15,7 @@ using System.Windows.Forms;
using System.Windows.Media;
using System.Xml;
using System.Xml.Linq;
using ICSharpCode.Core;
using ICSharpCode.Core.Presentation;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.Editor;
@ -182,6 +183,27 @@ namespace ICSharpCode.SharpDevelop @@ -182,6 +183,27 @@ namespace ICSharpCode.SharpDevelop
return snapshot.GetProject(assembly.UnresolvedAssembly as IProjectContent);
}
/// <summary>
/// Gets the location of the assembly on disk.
/// </summary>
public static FileName GetReferenceAssemblyLocation(this IAssembly assembly)
{
return FileName.Create(assembly.UnresolvedAssembly.Location);
}
/// <summary>
/// Gets the location of the assembly on disk.
/// If the specified assembly is a reference assembly, this method the location of the actual runtime assembly instead.
/// </summary>
/// <remarks>
/// May return null if the assembly has no location.
/// </remarks>
public static FileName GetRuntimeAssemblyLocation(this IAssembly assembly)
{
#warning Find and use GAC assembly if possible
return FileName.Create(assembly.UnresolvedAssembly.Location);
}
/// <summary>
/// Creates an array containing a part of the array (similar to string.Substring).
/// </summary>

Loading…
Cancel
Save