diff options
author | Michal Strehovský <MichalStrehovsky@users.noreply.github.com> | 2017-03-01 00:47:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-01 00:47:52 +0300 |
commit | dfc3656f109e52676d8ee85eca6384702b4da2fe (patch) | |
tree | 5e34ab5d46723ab5c11d23c7562d64b581e7503c /src/ILCompiler.DependencyAnalysisFramework | |
parent | 82b4ca49acfe611d905bc2f7b1c9b8a4e4d76096 (diff) |
Make DgmlWriter call GetName instead of ToString (#2845)
We agreed in the past that `ToString` is allowed to return
debugger-friendly strings and doesn't need to be the symbolic name.
Disentangle pieces of `DgmlWriter` so that it can call the right method
instead of `ToString`.
This is a step towards getting rid of the static name mangler. In the
next step, `GetName` will be updated to accept a `DependencyContextType`
parameter (`NodeFactory` in the `ILCompiler` world) so that it can get
to the `NameMangler` associated with the factory and we can get rid of
the static that makes everything non-unit testable (two different name
manglers can't coexist in a single process right now), limiting what we
can test in xunit.
Diffstat (limited to 'src/ILCompiler.DependencyAnalysisFramework')
-rw-r--r-- | src/ILCompiler.DependencyAnalysisFramework/src/DependencyNode.cs | 2 | ||||
-rw-r--r-- | src/ILCompiler.DependencyAnalysisFramework/src/DgmlWriter.cs | 43 |
2 files changed, 29 insertions, 16 deletions
diff --git a/src/ILCompiler.DependencyAnalysisFramework/src/DependencyNode.cs b/src/ILCompiler.DependencyAnalysisFramework/src/DependencyNode.cs index 75d87e4cf..6167b6963 100644 --- a/src/ILCompiler.DependencyAnalysisFramework/src/DependencyNode.cs +++ b/src/ILCompiler.DependencyAnalysisFramework/src/DependencyNode.cs @@ -40,7 +40,7 @@ namespace ILCompiler.DependencyAnalysisFramework } // Force all non-abstract nodes to provide a name - protected abstract string GetName(); + protected internal abstract string GetName(); public override string ToString() { diff --git a/src/ILCompiler.DependencyAnalysisFramework/src/DgmlWriter.cs b/src/ILCompiler.DependencyAnalysisFramework/src/DgmlWriter.cs index 5f9d80edf..58addb9e8 100644 --- a/src/ILCompiler.DependencyAnalysisFramework/src/DgmlWriter.cs +++ b/src/ILCompiler.DependencyAnalysisFramework/src/DgmlWriter.cs @@ -4,16 +4,21 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Xml; using System.IO; using System.Diagnostics; namespace ILCompiler.DependencyAnalysisFramework { - public class DgmlWriter : IDisposable, IDependencyAnalyzerLogEdgeVisitor, IDependencyAnalyzerLogNodeVisitor + public class DgmlWriter + { + public static void WriteDependencyGraphToStream<DependencyContextType>(Stream stream, DependencyAnalyzerBase<DependencyContextType> analysis) + { + DgmlWriter<DependencyContextType>.WriteDependencyGraphToStream(stream, analysis); + } + } + + internal class DgmlWriter<DependencyContextType> : IDisposable, IDependencyAnalyzerLogEdgeVisitor, IDependencyAnalyzerLogNodeVisitor { private XmlWriter _xmlWrite; private bool _done = false; @@ -24,22 +29,22 @@ namespace ILCompiler.DependencyAnalysisFramework _xmlWrite.WriteStartElement("DirectedGraph", "http://schemas.microsoft.com/vs/2009/dgml"); } - public void WriteNodesAndEdges(Action<Action<object>> nodeWriter, Action<Action<object, object, string>> edgeWriter) + public void WriteNodesAndEdges(Action nodeWriter, Action edgeWriter) { _xmlWrite.WriteStartElement("Nodes"); { - nodeWriter(AddNode); + nodeWriter(); } _xmlWrite.WriteEndElement(); _xmlWrite.WriteStartElement("Links"); { - edgeWriter(AddReason); + edgeWriter(); } _xmlWrite.WriteEndElement(); } - public static void WriteDependencyGraphToStream<DependencyContextType>(Stream stream, DependencyAnalyzerBase<DependencyContextType> analysis) + public static void WriteDependencyGraphToStream(Stream stream, DependencyAnalyzerBase<DependencyContextType> analysis) { XmlWriterSettings writerSettings = new XmlWriterSettings(); writerSettings.Indent = true; @@ -47,13 +52,13 @@ namespace ILCompiler.DependencyAnalysisFramework using (XmlWriter xmlWriter = XmlWriter.Create(stream, writerSettings)) { - using (DgmlWriter dgmlWriter = new DgmlWriter(xmlWriter)) + using (var dgmlWriter = new DgmlWriter<DependencyContextType>(xmlWriter)) { - dgmlWriter.WriteNodesAndEdges((Action<Object> writeNode) => + dgmlWriter.WriteNodesAndEdges(() => { analysis.VisitLogNodes(dgmlWriter); }, - (Action<object, object, string> writeEdge) => + () => { analysis.VisitLogEdges(dgmlWriter); } @@ -96,7 +101,12 @@ namespace ILCompiler.DependencyAnalysisFramework private Dictionary<object, int> _nodeMappings = new Dictionary<object, int>(); private int _nodeNextId = 0; - private void AddNode(object node) + private void AddNode(DependencyNode node) + { + AddNode(node, node.GetName()); + } + + private void AddNode(object node, string label) { int nodeId = _nodeNextId++; Debug.Assert(!_nodeMappings.ContainsKey(node)); @@ -105,7 +115,7 @@ namespace ILCompiler.DependencyAnalysisFramework _xmlWrite.WriteStartElement("Node"); _xmlWrite.WriteAttributeString("Id", nodeId.ToString()); - _xmlWrite.WriteAttributeString("Label", node.ToString()); + _xmlWrite.WriteAttributeString("Label", label); _xmlWrite.WriteEndElement(); } @@ -135,7 +145,10 @@ namespace ILCompiler.DependencyAnalysisFramework void IDependencyAnalyzerLogNodeVisitor.VisitCombinedNode(Tuple<DependencyNode, DependencyNode> node) { - AddNode(node); + string label1 = node.Item1.GetName(); + string label2 = node.Item2.GetName(); + + AddNode(node, string.Concat("(", label1, ", ", label2, ")")); } private HashSet<Tuple<DependencyNode, DependencyNode>> _combinedNodesEdgeVisited = new HashSet<Tuple<DependencyNode, DependencyNode>>(); @@ -177,7 +190,7 @@ namespace ILCompiler.DependencyAnalysisFramework void IDependencyAnalyzerLogNodeVisitor.VisitRootNode(string rootName) { - AddNode(rootName); + AddNode(rootName, rootName); } } } |