From 68b07e28288d79a9ddcc7ff59894dce08337ec2e Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 13 Mar 2011 17:09:07 +0100 Subject: [PATCH] Remove GraphViz from ICSharpCode.Decompiler. --- .../FlowAnalysis/ControlFlowGraph.cs | 4 +- .../FlowAnalysis/SsaForm.cs | 1 + ICSharpCode.Decompiler/GraphVizGraph.cs | 197 ------------------ .../ICSharpCode.Decompiler.csproj | 1 - ILSpy/MainWindow.xaml.cs | 2 +- 5 files changed, 4 insertions(+), 201 deletions(-) delete mode 100644 ICSharpCode.Decompiler/GraphVizGraph.cs diff --git a/ICSharpCode.Decompiler/FlowAnalysis/ControlFlowGraph.cs b/ICSharpCode.Decompiler/FlowAnalysis/ControlFlowGraph.cs index 89cd6fcf2..64b866c54 100644 --- a/ICSharpCode.Decompiler/FlowAnalysis/ControlFlowGraph.cs +++ b/ICSharpCode.Decompiler/FlowAnalysis/ControlFlowGraph.cs @@ -23,6 +23,8 @@ using System.Diagnostics; using System.Linq; using System.Threading; +using ICSharpCode.NRefactory.Utils; + namespace ICSharpCode.Decompiler.FlowAnalysis { /// @@ -57,7 +59,6 @@ namespace ICSharpCode.Decompiler.FlowAnalysis Debug.Assert(ExceptionalExit.NodeType == ControlFlowNodeType.ExceptionalExit); } - #if DEBUG public GraphVizGraph ExportGraph() { GraphVizGraph graph = new GraphVizGraph(); @@ -87,7 +88,6 @@ namespace ICSharpCode.Decompiler.FlowAnalysis } return graph; } - #endif /// /// Resets "Visited" to false for all nodes in this graph. diff --git a/ICSharpCode.Decompiler/FlowAnalysis/SsaForm.cs b/ICSharpCode.Decompiler/FlowAnalysis/SsaForm.cs index ed4e2892c..1a85e76a7 100644 --- a/ICSharpCode.Decompiler/FlowAnalysis/SsaForm.cs +++ b/ICSharpCode.Decompiler/FlowAnalysis/SsaForm.cs @@ -22,6 +22,7 @@ using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; +using ICSharpCode.NRefactory.Utils; using Mono.Cecil; using Mono.Cecil.Cil; diff --git a/ICSharpCode.Decompiler/GraphVizGraph.cs b/ICSharpCode.Decompiler/GraphVizGraph.cs deleted file mode 100644 index 62b957f25..000000000 --- a/ICSharpCode.Decompiler/GraphVizGraph.cs +++ /dev/null @@ -1,197 +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 System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Text.RegularExpressions; - -namespace ICSharpCode.Decompiler -{ - /// - /// GraphViz graph. - /// - public sealed class GraphVizGraph - { - List nodes = new List(); - List edges = new List(); - - public string rankdir; - - public void AddEdge(GraphVizEdge edge) - { - edges.Add(edge); - } - - public void AddNode(GraphVizNode node) - { - nodes.Add(node); - } - - public void Save(string fileName) - { - using (StreamWriter writer = new StreamWriter(fileName)) - Save(writer); - } - - static string Escape(string text) - { - if (Regex.IsMatch(text, @"^[\w\d]+$")) { - return text; - } else { - return "\"" + text.Replace("\\", "\\\\").Replace("\r", "").Replace("\n", "\\n").Replace("\"", "\\\"") + "\""; - } - } - - static void WriteGraphAttribute(TextWriter writer, string name, string value) - { - if (value != null) - writer.WriteLine("{0}={1};", name, Escape(value)); - } - - internal static void WriteAttribute(TextWriter writer, string name, double? value, ref bool isFirst) - { - if (value != null) { - WriteAttribute(writer, name, value.Value.ToString(CultureInfo.InvariantCulture), ref isFirst); - } - } - - internal static void WriteAttribute(TextWriter writer, string name, bool? value, ref bool isFirst) - { - if (value != null) { - WriteAttribute(writer, name, value.Value ? "true" : "false", ref isFirst); - } - } - - internal static void WriteAttribute(TextWriter writer, string name, string value, ref bool isFirst) - { - if (value != null) { - if (isFirst) - isFirst = false; - else - writer.Write(','); - writer.Write("{0}={1}", name, Escape(value)); - } - } - - public void Save(TextWriter writer) - { - writer.WriteLine("digraph G {"); - writer.WriteLine("node [fontsize = 16];"); - WriteGraphAttribute(writer, "rankdir", rankdir); - foreach (GraphVizNode node in nodes) { - node.Save(writer); - } - foreach (GraphVizEdge edge in edges) { - edge.Save(writer); - } - writer.WriteLine("}"); - } - } - - public sealed class GraphVizEdge - { - public readonly string Source, Target; - - /// edge stroke color - public string color; - /// use edge to affect node ranking - public bool? constraint; - - public string label; - - public string style; - - /// point size of label - public int? fontsize; - - public GraphVizEdge(string source, string target) - { - if (source == null) - throw new ArgumentNullException("source"); - if (target == null) - throw new ArgumentNullException("target"); - this.Source = source; - this.Target = target; - } - - public GraphVizEdge(int source, int target) - { - this.Source = source.ToString(CultureInfo.InvariantCulture); - this.Target = target.ToString(CultureInfo.InvariantCulture); - } - - public void Save(TextWriter writer) - { - writer.Write("{0} -> {1} [", Source, Target); - bool isFirst = true; - GraphVizGraph.WriteAttribute(writer, "label", label, ref isFirst); - GraphVizGraph.WriteAttribute(writer, "style", style, ref isFirst); - GraphVizGraph.WriteAttribute(writer, "fontsize", fontsize, ref isFirst); - GraphVizGraph.WriteAttribute(writer, "color", color, ref isFirst); - GraphVizGraph.WriteAttribute(writer, "constraint", constraint, ref isFirst); - writer.WriteLine("];"); - } - } - - public sealed class GraphVizNode - { - public readonly string ID; - public string label; - - public string labelloc; - - /// point size of label - public int? fontsize; - - /// minimum height in inches - public double? height; - - /// space around label - public string margin; - - /// node shape - public string shape; - - public GraphVizNode(string id) - { - if (id == null) - throw new ArgumentNullException("id"); - this.ID = id; - } - - public GraphVizNode(int id) - { - this.ID = id.ToString(CultureInfo.InvariantCulture); - } - - public void Save(TextWriter writer) - { - writer.Write(ID); - writer.Write(" ["); - bool isFirst = true; - GraphVizGraph.WriteAttribute(writer, "label", label, ref isFirst); - GraphVizGraph.WriteAttribute(writer, "labelloc", labelloc, ref isFirst); - GraphVizGraph.WriteAttribute(writer, "fontsize", fontsize, ref isFirst); - GraphVizGraph.WriteAttribute(writer, "margin", margin, ref isFirst); - GraphVizGraph.WriteAttribute(writer, "shape", shape, ref isFirst); - writer.WriteLine("];"); - } - } -} diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index 1dee46ee2..d0e482afb 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -85,7 +85,6 @@ - diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs index 88b28ff1a..25d4103ea 100644 --- a/ILSpy/MainWindow.xaml.cs +++ b/ILSpy/MainWindow.xaml.cs @@ -273,7 +273,7 @@ namespace ICSharpCode.ILSpy typeof(ICSharpCode.TreeView.SharpTreeView).Assembly, typeof(Mono.Cecil.AssemblyDefinition).Assembly, typeof(ICSharpCode.AvalonEdit.TextEditor).Assembly, - typeof(ICSharpCode.Decompiler.GraphVizGraph).Assembly, + typeof(ICSharpCode.Decompiler.Ast.AstBuilder).Assembly, typeof(MainWindow).Assembly }; foreach (System.Reflection.Assembly asm in initialAssemblies)