diff options
author | Mike Krüger <mkrueger@novell.com> | 2011-05-04 10:10:10 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@novell.com> | 2011-05-04 10:10:10 +0400 |
commit | 6ea0f33ae1b67eed3138153120987feca18dec95 (patch) | |
tree | 9b45d937d22f8140c66a4f06d6a8004489f86bc3 /main/src/addins/MonoDevelop.AssemblyBrowser | |
parent | 44edc799f2ebeb5363c266adba909537dc733aab (diff) |
Updated decompiler code.
Diffstat (limited to 'main/src/addins/MonoDevelop.AssemblyBrowser')
8 files changed, 35 insertions, 14 deletions
diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser.csproj b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser.csproj index 9ec1b6b2ad..c7dc5d939c 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser.csproj +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser.csproj @@ -91,16 +91,15 @@ <Project>{07CC7654-27D6-421D-A64C-0FFA40456FA2}</Project> <Name>CSharpBinding</Name> </ProjectReference> - <ProjectReference Include="..\..\..\contrib\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> - <Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project> - <Name>ICSharpCode.NRefactory</Name> - <Private>False</Private> - </ProjectReference> <ProjectReference Include="..\..\..\contrib\ICSharpCode.Decompiler\ICSharpCode.Decompiler.csproj"> <Project>{984CC812-9470-4A13-AFF9-CC44068D666C}</Project> <Name>ICSharpCode.Decompiler</Name> <Private>False</Private> </ProjectReference> + <ProjectReference Include="..\..\..\contrib\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> + <Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project> + <Name>ICSharpCode.NRefactory</Name> + </ProjectReference> </ItemGroup> <ItemGroup> <Compile Include="AssemblyInfo.cs" /> diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyNodeBuilder.cs index 1f4bb6fc14..29e0f724fb 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/AssemblyNodeBuilder.cs @@ -120,13 +120,14 @@ namespace MonoDevelop.AssemblyBrowser result.AppendLine (); return result.ToString (); } - + public List<ReferenceSegment> Disassemble (TextEditorData data, ITreeNavigator navigator) { DomCecilCompilationUnit compilationUnit = (DomCecilCompilationUnit)navigator.DataItem; - return DomMethodNodeBuilder.Decompile (data, null, b => b.AddAssembly (compilationUnit.AssemblyDefinition, true)); + return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), null, b => b.AddAssembly (compilationUnit.AssemblyDefinition, true)); } + public List<ReferenceSegment> Decompile (TextEditorData data, ITreeNavigator navigator) { return Disassemble (data, navigator); diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/ColoredCSharpFormatter.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/ColoredCSharpFormatter.cs index 903cc9694e..cbfaf849b5 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/ColoredCSharpFormatter.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/ColoredCSharpFormatter.cs @@ -68,6 +68,13 @@ namespace MonoDevelop.AssemblyBrowser } #region ITextOutput implementation + int currentLine; + public int CurrentLine { + get { + return currentLine; + } + } + public void Indent () { indent++; @@ -103,6 +110,7 @@ namespace MonoDevelop.AssemblyBrowser { sb.AppendLine (); write_indent = true; + currentLine++; } public void WriteDefinition (string text, object definition) diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomEventNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomEventNodeBuilder.cs index f0e3311b83..6c42d7e6f5 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomEventNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomEventNodeBuilder.cs @@ -112,7 +112,7 @@ namespace MonoDevelop.AssemblyBrowser List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Decompile (TextEditorData data, ITreeNavigator navigator) { var evt = (DomCecilEvent)navigator.DataItem; - return DomMethodNodeBuilder.Decompile (data, ((DomCecilType)evt.DeclaringType).TypeDefinition, b => b.AddEvent (evt.EventDefinition)); + return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), ((DomCecilType)evt.DeclaringType).TypeDefinition, b => b.AddEvent (evt.EventDefinition)); } string IAssemblyBrowserNodeBuilder.GetDocumentationMarkup (ITreeNavigator navigator) diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomFieldNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomFieldNodeBuilder.cs index 55b315e1a1..fb63d8387f 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomFieldNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomFieldNodeBuilder.cs @@ -104,7 +104,7 @@ namespace MonoDevelop.AssemblyBrowser { var field = (DomCecilField)navigator.DataItem; - return DomMethodNodeBuilder.Decompile (data, ((DomCecilType)field.DeclaringType).TypeDefinition, b => b.AddField (field.FieldDefinition)); + return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), ((DomCecilType)field.DeclaringType).TypeDefinition, b => b.AddField (field.FieldDefinition)); } string IAssemblyBrowserNodeBuilder.GetDocumentationMarkup (ITreeNavigator navigator) diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomMethodNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomMethodNodeBuilder.cs index d0cebfdd5a..800a1ffc86 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomMethodNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomMethodNodeBuilder.cs @@ -118,13 +118,26 @@ namespace MonoDevelop.AssemblyBrowser return String.Format ("IL_{0:X4}", instruction.Offset); } - public static List<ReferenceSegment> Decompile (TextEditorData data, TypeDefinition currentType, Action<AstBuilder> setData) + public static ModuleDefinition GetModule (ITreeNavigator navigator) + { + var nav = navigator.Clone (); + while (!(nav.DataItem is DomCecilCompilationUnit.Module) && !(nav.DataItem is DomCecilCompilationUnit)) { + if (!nav.MoveToParent ()) + return ModuleDefinition.CreateModule ("", ModuleKind.Console); + } + if (nav.DataItem is DomCecilCompilationUnit) + return ((DomCecilCompilationUnit)nav.DataItem).AssemblyDefinition.MainModule; + + return ((DomCecilCompilationUnit.Module)nav.DataItem).ModuleDefinition; + } + + public static List<ReferenceSegment> Decompile (TextEditorData data, ModuleDefinition module, TypeDefinition currentType, Action<AstBuilder> setData) { try { var types = DesktopService.GetMimeTypeInheritanceChain (data.Document.MimeType); var codePolicy = MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<MonoDevelop.CSharp.Formatting.CSharpFormattingPolicy> (types); - var context = new DecompilerContext (); + var context = new DecompilerContext (module); var source = new CancellationTokenSource (); context.CancellationToken = source.Token; @@ -172,7 +185,7 @@ namespace MonoDevelop.AssemblyBrowser DomCecilMethod method = navigator.DataItem as DomCecilMethod; if (method == null) return null; - return DomMethodNodeBuilder.Decompile (data, ((DomCecilType)method.DeclaringType).TypeDefinition, b => b.AddMethod (method.MethodDefinition)); + return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), ((DomCecilType)method.DeclaringType).TypeDefinition, b => b.AddMethod (method.MethodDefinition)); } static void AppendLink (StringBuilder sb, string link, string text) diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomPropertyNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomPropertyNodeBuilder.cs index 7045ce6eeb..663a70432e 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomPropertyNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomPropertyNodeBuilder.cs @@ -130,7 +130,7 @@ namespace MonoDevelop.AssemblyBrowser List<ReferenceSegment> IAssemblyBrowserNodeBuilder.Decompile (TextEditorData data, ITreeNavigator navigator) { var property = (DomCecilProperty)navigator.DataItem; - return DomMethodNodeBuilder.Decompile (data, ((DomCecilType)property.DeclaringType).TypeDefinition, b => b.AddProperty (property.PropertyDefinition)); + return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), ((DomCecilType)property.DeclaringType).TypeDefinition, b => b.AddProperty (property.PropertyDefinition)); } string IAssemblyBrowserNodeBuilder.GetDocumentationMarkup (ITreeNavigator navigator) diff --git a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomTypeNodeBuilder.cs b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomTypeNodeBuilder.cs index 568af3999d..473b384f83 100644 --- a/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomTypeNodeBuilder.cs +++ b/main/src/addins/MonoDevelop.AssemblyBrowser/MonoDevelop.AssemblyBrowser/DomTypeNodeBuilder.cs @@ -173,7 +173,7 @@ namespace MonoDevelop.AssemblyBrowser public List<ReferenceSegment> Decompile (TextEditorData data, ITreeNavigator navigator) { var type = (DomCecilType)navigator.DataItem; - return DomMethodNodeBuilder.Decompile (data, type.TypeDefinition, b => b.AddType (type.TypeDefinition)); + return DomMethodNodeBuilder.Decompile (data, DomMethodNodeBuilder.GetModule (navigator), type.TypeDefinition, b => b.AddType (type.TypeDefinition)); } string IAssemblyBrowserNodeBuilder.GetDocumentationMarkup (ITreeNavigator navigator) |