Browse Source

Port AddXmlDocumentationTransform to SRM

pull/1198/head
Siegfried Pammer 8 years ago
parent
commit
2571018c8a
  1. 20
      ICSharpCode.Decompiler/CSharp/Transforms/AddXmlDocumentationTransform.cs
  2. 9
      ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs
  3. 37
      ICSharpCode.Decompiler/Metadata/Dom.cs

20
ICSharpCode.Decompiler/CSharp/Transforms/AddXmlDocumentationTransform.cs

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection.Metadata;
using System.Xml;
using ICSharpCode.Decompiler.CSharp.Syntax;
using ICSharpCode.Decompiler.Documentation;
@ -40,24 +41,13 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -40,24 +41,13 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
if (xmldoc == null)
return;
foreach (var entity in rootNode.DescendantsAndSelf.OfType<EntityDeclaration>()) {
var symbol = entity.GetSymbol();
#warning TODO : replace with SRM
/*switch (symbol) {
case IMember member:
mr = context.TypeSystem.GetCecil(member);
break;
case IType type:
mr = context.TypeSystem.GetCecil(type.GetDefinition());
break;
default:
continue;
}
if (mr == null)
var handle = ((entity.GetSymbol() as IEntity)?.MetadataToken).Value;
if (handle.IsNil)
continue;
string doc = xmldoc.GetDocumentation(XmlDocKeyProvider.GetKey(mr));
string doc = xmldoc.GetDocumentation(XmlDocKeyProvider.GetKey(context.TypeSystem.GetMetadata(), handle));
if (doc != null) {
InsertXmlDocumentation(entity, new StringReader(doc));
}*/
}
}
} catch (XmlException ex) {
string[] msg = (" Exception while reading XmlDoc: " + ex).Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

9
ICSharpCode.Decompiler/Documentation/XmlDocLoader.cs

@ -20,8 +20,7 @@ using System; @@ -20,8 +20,7 @@ using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using ICSharpCode.Decompiler.Documentation;
using Mono.Cecil;
using ICSharpCode.Decompiler.Metadata;
namespace ICSharpCode.Decompiler.Documentation
{
@ -31,7 +30,7 @@ namespace ICSharpCode.Decompiler.Documentation @@ -31,7 +30,7 @@ namespace ICSharpCode.Decompiler.Documentation
public static class XmlDocLoader
{
static readonly Lazy<XmlDocumentationProvider> mscorlibDocumentation = new Lazy<XmlDocumentationProvider>(LoadMscorlibDocumentation);
static readonly ConditionalWeakTable<ModuleDefinition, XmlDocumentationProvider> cache = new ConditionalWeakTable<ModuleDefinition, XmlDocumentationProvider>();
static readonly ConditionalWeakTable<PEFile, XmlDocumentationProvider> cache = new ConditionalWeakTable<PEFile, XmlDocumentationProvider>();
static XmlDocumentationProvider LoadMscorlibDocumentation()
{
@ -47,7 +46,7 @@ namespace ICSharpCode.Decompiler.Documentation @@ -47,7 +46,7 @@ namespace ICSharpCode.Decompiler.Documentation
get { return mscorlibDocumentation.Value; }
}
public static XmlDocumentationProvider LoadDocumentation(ModuleDefinition module)
public static XmlDocumentationProvider LoadDocumentation(PEFile module)
{
if (module == null)
throw new ArgumentNullException(nameof(module));
@ -56,7 +55,7 @@ namespace ICSharpCode.Decompiler.Documentation @@ -56,7 +55,7 @@ namespace ICSharpCode.Decompiler.Documentation
if (!cache.TryGetValue(module, out xmlDoc)) {
string xmlDocFile = LookupLocalizedXmlDoc(module.FileName);
if (xmlDocFile == null) {
xmlDocFile = FindXmlDocumentation(Path.GetFileName(module.FileName), module.Runtime);
xmlDocFile = FindXmlDocumentation(Path.GetFileName(module.FileName), module.GetRuntime());
}
if (xmlDocFile != null) {
xmlDoc = new XmlDocumentationProvider(xmlDocFile);

37
ICSharpCode.Decompiler/Metadata/Dom.cs

@ -74,9 +74,17 @@ namespace ICSharpCode.Decompiler.Metadata @@ -74,9 +74,17 @@ namespace ICSharpCode.Decompiler.Metadata
public interface IDebugInfoProvider
{
IList<SequencePoint> GetSequencePoints(MethodDefinition method);
IList<Variable> GetVariables(MethodDefinition method);
bool TryGetName(MethodDefinition method, int index, out string name);
IList<SequencePoint> GetSequencePoints(MethodDefinitionHandle method);
IList<Variable> GetVariables(MethodDefinitionHandle method);
bool TryGetName(MethodDefinitionHandle method, int index, out string name);
}
public enum TargetRuntime
{
Net_1_0,
Net_1_1,
Net_2_0,
Net_4_0
}
public class PEFile
@ -98,6 +106,25 @@ namespace ICSharpCode.Decompiler.Metadata @@ -98,6 +106,25 @@ namespace ICSharpCode.Decompiler.Metadata
public string Name => GetName();
public string FullName => IsAssembly ? GetMetadataReader().GetFullAssemblyName() : Name;
public TargetRuntime GetRuntime()
{
string version = GetMetadataReader().MetadataVersion;
switch (version[1]) {
case '1':
if (version[3] == 1)
return TargetRuntime.Net_1_0;
else
return TargetRuntime.Net_1_1;
case '2':
return TargetRuntime.Net_2_0;
case '4':
return TargetRuntime.Net_4_0;
default:
throw new NotSupportedException($"metadata version {version} is not supported!");
}
}
public MetadataReader GetMetadataReader() => Reader.GetMetadataReader();
string GetName()
@ -497,12 +524,12 @@ namespace ICSharpCode.Decompiler.Metadata @@ -497,12 +524,12 @@ namespace ICSharpCode.Decompiler.Metadata
public IList<SequencePoint> GetSequencePoints()
{
return Module.DebugInfo?.GetSequencePoints(this);
return Module.DebugInfo?.GetSequencePoints(Handle);
}
public IList<Variable> GetVariables()
{
return Module.DebugInfo?.GetVariables(this);
return Module.DebugInfo?.GetVariables(Handle);
}
}

Loading…
Cancel
Save