Browse Source

Prepare interfaces for decompiler integration.

pull/1/head
Daniel Grunwald 14 years ago
parent
commit
5e3773b588
  1. 5
      ILSpy/AssemblyListTreeNode.cs
  2. 37
      ILSpy/Decompiler/CSharpLanguage.cs
  3. 19
      ILSpy/EventTreeNode.cs
  4. 19
      ILSpy/Fusion.cs
  5. 30
      ILSpy/IDecompilableNode.cs
  6. 4
      ILSpy/ILSpy.csproj
  7. 104
      ILSpy/ITextOutput.cs
  8. 54
      ILSpy/Language.cs
  9. 21
      ILSpy/MainWindow.xaml.cs
  10. 7
      ILSpy/MethodTreeNode.cs
  11. 19
      ILSpy/OpenFromGacDialog.xaml.cs
  12. 19
      ILSpy/PropertyTreeNode.cs
  13. 19
      ILSpy/ReferenceFolderTreeNode.cs

5
ILSpy/AssemblyListTreeNode.cs

@ -54,6 +54,8 @@ namespace ICSharpCode.ILSpy @@ -54,6 +54,8 @@ namespace ICSharpCode.ILSpy
{
if (data.GetDataPresent(AssemblyTreeNode.DataFormat))
return DropEffect.Move;
else if (data.GetDataPresent(DataFormats.FileDrop))
return DropEffect.Move;
else
return DropEffect.None;
}
@ -61,8 +63,11 @@ namespace ICSharpCode.ILSpy @@ -61,8 +63,11 @@ namespace ICSharpCode.ILSpy
public override void Drop(IDataObject data, int index, DropEffect finalEffect)
{
string[] files = data.GetData(AssemblyTreeNode.DataFormat) as string[];
if (files == null)
files = data.GetData(DataFormats.FileDrop) as string[];
if (files != null) {
var nodes = (from file in files
where file != null
select OpenAssembly(file) into node
where node != null
select node).Distinct().ToList();

37
ILSpy/Decompiler/CSharpLanguage.cs

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
// Copyright (c) 2011 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:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.Decompiler
{
/// <summary>
/// Decompiler logic for C#.
/// </summary>
public class CSharpLanguage : Language
{
public override string Name {
get { return "C#"; }
}
public override void Decompile(MethodDefinition methodDefinition, ITextOutput output)
{
}
}
}

19
ILSpy/EventTreeNode.cs

@ -1,5 +1,20 @@ @@ -1,5 +1,20 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
// Copyright (c) 2011 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:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using ICSharpCode.TreeView;

19
ILSpy/Fusion.cs

@ -1,5 +1,20 @@ @@ -1,5 +1,20 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
// Copyright (c) 2011 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:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Runtime.InteropServices;

30
ILSpy/IDecompilableNode.cs

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
// Copyright (c) 2011 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:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
namespace ICSharpCode.ILSpy
{
/// <summary>
/// Interface for decompilable tree nodes.
/// </summary>
public interface IDecompilableNode
{
void Decompile(Language language, ITextOutput output);
}
}

4
ILSpy/ILSpy.csproj

@ -72,11 +72,14 @@ @@ -72,11 +72,14 @@
<Compile Include="AssemblyReferenceTreeNode.cs" />
<Compile Include="AssemblyTreeNode.cs" />
<Compile Include="BaseTypesTreeNode.cs" />
<Compile Include="Decompiler\CSharpLanguage.cs" />
<Compile Include="EventTreeNode.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="FieldTreeNode.cs" />
<Compile Include="Fusion.cs" />
<Compile Include="GacInterop.cs" />
<Compile Include="IDecompilableNode.cs" />
<Compile Include="ITextOutput.cs" />
<Compile Include="Language.cs" />
<Compile Include="Images\Images.cs" />
<Compile Include="MethodTreeNode.cs" />
@ -136,6 +139,7 @@ @@ -136,6 +139,7 @@
<ItemGroup>
<Folder Include="Images" />
<Folder Include="Mono.Cecil.Rocks" />
<Folder Include="Decompiler" />
<Folder Include="themes" />
</ItemGroup>
<ItemGroup>

104
ILSpy/ITextOutput.cs

@ -0,0 +1,104 @@ @@ -0,0 +1,104 @@
// Copyright (c) 2011 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:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Text;
using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.ILSpy
{
public interface ITextOutput
{
void Indent();
void Unindent();
void Write(char ch);
void Write(string text);
void WriteComment(string comment);
void WriteLine();
void WriteDefinition(string text, object definition);
void WriteReference(string text, object definition);
}
sealed class SmartTextOutput : ITextOutput
{
readonly StringBuilder b = new StringBuilder();
int indent;
bool needsIndent;
public override string ToString()
{
return b.ToString();
}
public void Indent()
{
indent++;
}
public void Unindent()
{
indent--;
}
void WriteIndent()
{
if (needsIndent) {
needsIndent = false;
for (int i = 0; i < indent; i++) {
b.Append('\t');
}
}
}
public void Write(char ch)
{
WriteIndent();
b.Append(ch);
}
public void Write(string text)
{
WriteIndent();
b.Append(text);
}
public void WriteComment(string comment)
{
WriteIndent();
b.Append(comment);
}
public void WriteLine()
{
b.AppendLine();
needsIndent = true;
}
public void WriteDefinition(string text, object definition)
{
WriteIndent();
b.Append(text);
}
public void WriteReference(string text, object definition)
{
WriteIndent();
b.Append(text);
}
}
}

54
ILSpy/Language.cs

@ -1,5 +1,20 @@ @@ -1,5 +1,20 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
// Copyright (c) 2011 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:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using Mono.Cecil;
@ -11,20 +26,37 @@ namespace ICSharpCode.ILSpy @@ -11,20 +26,37 @@ namespace ICSharpCode.ILSpy
/// </summary>
public abstract class Language
{
public static readonly Language Current = Languages.IL;
public static readonly Language Current = new Decompiler.CSharpLanguage();
public virtual string TypeToString(TypeReference t)
public abstract string Name { get; }
public virtual ICSharpCode.AvalonEdit.Highlighting.IHighlightingDefinition SyntaxHighlighting {
get { return ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance.GetDefinition(this.Name); }
}
public virtual void Decompile(MethodDefinition method, ITextOutput output)
{
return t.Name;
}
}
public static class Languages
{
public static readonly Language IL = new ILLanguage();
class ILLanguage : Language
public virtual void Decompile(PropertyDefinition property, ITextOutput output)
{
}
public virtual void Decompile(FieldDefinition field, ITextOutput output)
{
}
public virtual void Decompile(EventDefinition ev, ITextOutput output)
{
}
public virtual void Decompile(TypeDefinition type, ITextOutput output)
{
}
public string TypeToString(TypeReference t)
{
return t.Name;
}
}
}

21
ILSpy/MainWindow.xaml.cs

@ -22,7 +22,9 @@ using System.IO; @@ -22,7 +22,9 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using ICSharpCode.TreeView;
using Microsoft.Win32;
@ -67,6 +69,10 @@ namespace ICSharpCode.ILSpy @@ -67,6 +69,10 @@ namespace ICSharpCode.ILSpy
foreach (Assembly asm in initialAssemblies)
assemblyList.OpenAssembly(asm.Location);
string[] args = Environment.GetCommandLineArgs();
for (int i = 1; i < args.Length; i++) {
assemblyList.OpenAssembly(args[i]);
}
}
void OpenCommandExecuted(object sender, ExecutedRoutedEventArgs e)
@ -116,5 +122,20 @@ namespace ICSharpCode.ILSpy @@ -116,5 +122,20 @@ namespace ICSharpCode.ILSpy
OpenFiles(dlg.SelectedFileNames);
}
}
void TreeView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try {
textEditor.SyntaxHighlighting = ILSpy.Language.Current.SyntaxHighlighting;
SmartTextOutput textOutput = new SmartTextOutput();
foreach (var node in treeView.SelectedItems.OfType<IDecompilableNode>()) {
node.Decompile(ILSpy.Language.Current, textOutput);
}
textEditor.Text = textOutput.ToString();
} catch (Exception ex) {
textEditor.SyntaxHighlighting = null;
textEditor.Text = ex.ToString();
}
}
}
}

7
ILSpy/MethodTreeNode.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.ILSpy @@ -26,7 +26,7 @@ namespace ICSharpCode.ILSpy
/// <summary>
/// Tree Node representing a field, method, property, or event.
/// </summary>
public sealed class MethodTreeNode : SharpTreeNode
sealed class MethodTreeNode : SharpTreeNode, IDecompilableNode
{
MethodDefinition method;
@ -65,5 +65,10 @@ namespace ICSharpCode.ILSpy @@ -65,5 +65,10 @@ namespace ICSharpCode.ILSpy
return Images.Method;
}
}
public void Decompile(Language language, ITextOutput output)
{
language.Decompile(method, output);
}
}
}

19
ILSpy/OpenFromGacDialog.xaml.cs

@ -1,5 +1,20 @@ @@ -1,5 +1,20 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
// Copyright (c) 2011 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:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;

19
ILSpy/PropertyTreeNode.cs

@ -1,5 +1,20 @@ @@ -1,5 +1,20 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
// Copyright (c) 2011 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:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using ICSharpCode.TreeView;

19
ILSpy/ReferenceFolderTreeNode.cs

@ -1,5 +1,20 @@ @@ -1,5 +1,20 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
// Copyright (c) 2011 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:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using ICSharpCode.TreeView;

Loading…
Cancel
Save