Browse Source

Merge branch 'srm' of github.com:icsharpcode/ILSpy into srm

pull/1198/head
Daniel Grunwald 8 years ago
parent
commit
80fe3d04f8
  1. 30
      ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs
  2. 1
      ILSpy/ILSpy.csproj
  3. 4
      ILSpy/TreeNodes/Analyzer/AnalyzeContextMenuEntry.cs
  4. 47
      ILSpy/TreeNodes/Analyzer/AnalyzedAssemblyTreeNode.cs
  5. 9
      ILSpy/TreeNodes/Analyzer/AnalyzedFieldAccessTreeNode.cs
  6. 4
      ILSpy/TreeNodes/Analyzer/Extensions.cs

30
ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -26,7 +26,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
public static void CollectNamespaces(IEntity entity, DecompilerTypeSystem typeSystem, HashSet<string> namespaces)
public static void CollectNamespaces(IEntity entity, DecompilerTypeSystem typeSystem, HashSet<string> namespaces, bool scanningFullType = false)
{
if (entity == null)
return;
@ -44,23 +44,23 @@ namespace ICSharpCode.Decompiler.CSharp @@ -44,23 +44,23 @@ namespace ICSharpCode.Decompiler.CSharp
}
foreach (var nestedType in td.NestedTypes) {
CollectNamespaces(nestedType, typeSystem, namespaces);
CollectNamespaces(nestedType, typeSystem, namespaces, scanningFullType: true);
}
foreach (var field in td.Fields) {
CollectNamespaces(field, typeSystem, namespaces);
CollectNamespaces(field, typeSystem, namespaces, scanningFullType: true);
}
foreach (var property in td.Properties) {
CollectNamespaces(property, typeSystem, namespaces);
CollectNamespaces(property, typeSystem, namespaces, scanningFullType: true);
}
foreach (var @event in td.Events) {
CollectNamespaces(@event, typeSystem, namespaces);
CollectNamespaces(@event, typeSystem, namespaces, scanningFullType: true);
}
foreach (var method in td.Methods) {
CollectNamespaces(method, typeSystem, namespaces);
CollectNamespaces(method, typeSystem, namespaces, scanningFullType: true);
}
break;
case IField field:
@ -81,7 +81,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -81,7 +81,7 @@ namespace ICSharpCode.Decompiler.CSharp
var reader = typeSystem.ModuleDefinition.Reader;
var methodDef = typeSystem.ModuleDefinition.Metadata.GetMethodDefinition((MethodDefinitionHandle)method.MetadataToken);
var body = reader.GetMethodBody(methodDef.RelativeVirtualAddress);
CollectNamespacesFromMethodBody(body, reader, typeSystem, namespaces);
CollectNamespacesFromMethodBody(body, reader, typeSystem, namespaces, scanningFullType: scanningFullType);
}
break;
case IProperty property:
@ -126,7 +126,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -126,7 +126,11 @@ namespace ICSharpCode.Decompiler.CSharp
public static void CollectNamespaces(EntityHandle entity, DecompilerTypeSystem typeSystem, HashSet<string> namespaces)
{
CollectNamespaces(entity.Kind.IsTypeKind() ? (IEntity)typeSystem.ResolveAsType(entity).GetDefinition() : typeSystem.ResolveAsMember(entity), typeSystem, namespaces);
if (entity.Kind.IsTypeKind()) {
CollectNamespaces(typeSystem.ResolveAsType(entity).GetDefinition(), typeSystem, namespaces);
} else {
CollectNamespaces(typeSystem.ResolveAsMember(entity), typeSystem, namespaces);
}
}
static void HandleAttributes(IEnumerable<IAttribute> attributes, HashSet<string> namespaces)
@ -146,7 +150,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -146,7 +150,7 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
static void CollectNamespacesFromMethodBody(MethodBodyBlock method, PEReader reader, DecompilerTypeSystem typeSystem, HashSet<string> namespaces)
static void CollectNamespacesFromMethodBody(MethodBodyBlock method, PEReader reader, DecompilerTypeSystem typeSystem, HashSet<string> namespaces, bool scanningFullType = false)
{
var instructions = method.GetILReader();
var metadata = reader.GetMetadataReader();
@ -174,7 +178,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -174,7 +178,7 @@ namespace ICSharpCode.Decompiler.CSharp
if (handle.Kind.IsTypeKind())
CollectNamespacesForTypeReference(typeSystem.ResolveAsType(handle), namespaces);
else
CollectNamespacesForMemberReference(typeSystem.ResolveAsMember(handle), typeSystem, namespaces);
CollectNamespacesForMemberReference(typeSystem.ResolveAsMember(handle), typeSystem, namespaces, scanningFullType: scanningFullType);
break;
default:
instructions.SkipOperand(opCode);
@ -183,18 +187,18 @@ namespace ICSharpCode.Decompiler.CSharp @@ -183,18 +187,18 @@ namespace ICSharpCode.Decompiler.CSharp
}
}
static void CollectNamespacesForMemberReference(IMember member, DecompilerTypeSystem typeSystem, HashSet<string> namespaces)
static void CollectNamespacesForMemberReference(IMember member, DecompilerTypeSystem typeSystem, HashSet<string> namespaces, bool scanningFullType = false)
{
switch (member) {
case IField field:
if (field.IsCompilerGeneratedOrIsInCompilerGeneratedClass())
if (!scanningFullType && field.IsCompilerGeneratedOrIsInCompilerGeneratedClass())
CollectNamespaces(field, typeSystem, namespaces);
else
CollectNamespacesForTypeReference(field.DeclaringType, namespaces);
CollectNamespacesForTypeReference(field.ReturnType, namespaces);
break;
case IMethod method:
if (method.IsCompilerGeneratedOrIsInCompilerGeneratedClass())
if (!scanningFullType && method.IsCompilerGeneratedOrIsInCompilerGeneratedClass())
CollectNamespaces(method, typeSystem, namespaces);
else
CollectNamespacesForTypeReference(method.DeclaringType, namespaces);

1
ILSpy/ILSpy.csproj

@ -189,7 +189,6 @@ @@ -189,7 +189,6 @@
<Compile Include="TextView\FoldingCommands.cs" />
<Compile Include="TextView\XmlDocRenderer.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzeContextMenuEntry.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedAssemblyTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedFieldAccessTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedFieldTreeNode.cs" />
<Compile Include="TreeNodes\Analyzer\AnalyzedMethodTreeNode.cs" />

4
ILSpy/TreeNodes/Analyzer/AnalyzeContextMenuEntry.cs

@ -76,8 +76,8 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -76,8 +76,8 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedTypeTreeNode(td));
break;
case FieldDefinition fd:
//if (!fd.IsNil)
// AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedFieldTreeNode(fd));
if (!fd.IsNil)
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedFieldTreeNode(fd.Module, fd.Handle));
break;
case MethodDefinition md:
if (!md.IsNil)

47
ILSpy/TreeNodes/Analyzer/AnalyzedAssemblyTreeNode.cs

@ -1,47 +0,0 @@ @@ -1,47 +0,0 @@
// 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.Decompiler.Metadata;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{
internal class AnalyzedAssemblyTreeNode : AnalyzerEntityTreeNode
{
private readonly PEFile analyzedAssembly;
public AnalyzedAssemblyTreeNode(PEFile analyzedAssembly)
{
if (analyzedAssembly == null)
throw new ArgumentNullException(nameof(analyzedAssembly));
this.analyzedAssembly = analyzedAssembly;
//this.LazyLoading = true;
}
public override object Icon => Images.Assembly;
public override object Text => analyzedAssembly.Name;
protected override void LoadChildren()
{
//this.Children.Add(new AnalyzedAssemblyReferencedByTreeNode(analyzedAssembly));
}
public override IMetadataEntity Member => null;
}
}

9
ILSpy/TreeNodes/Analyzer/AnalyzedFieldAccessTreeNode.cs

@ -133,14 +133,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer @@ -133,14 +133,9 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
bool IsNewResult(Decompiler.Metadata.MethodDefinition method)
{
var hashtable = foundMethods.Value;
var hashSet = foundMethods.Value;
lock (hashLock) {
if (hashtable.Contains(method)) {
return true;
} else {
hashtable.Add(method);
return false;
}
return hashSet.Add(method);
}
}
}

4
ILSpy/TreeNodes/Analyzer/Extensions.cs

@ -8,8 +8,8 @@ using ICSharpCode.Decompiler; @@ -8,8 +8,8 @@ using ICSharpCode.Decompiler;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{
public static class Extensions
{
public static class Extensions
{
public static TypeDefinitionHandle GetDeclaringType(this MethodDefinitionHandle method, MetadataReader metadata)
{
if (method.IsNil)

Loading…
Cancel
Save