Browse Source

Remove GraphViz from ICSharpCode.Decompiler.

pull/100/head
Daniel Grunwald 14 years ago
parent
commit
68b07e2828
  1. 4
      ICSharpCode.Decompiler/FlowAnalysis/ControlFlowGraph.cs
  2. 1
      ICSharpCode.Decompiler/FlowAnalysis/SsaForm.cs
  3. 197
      ICSharpCode.Decompiler/GraphVizGraph.cs
  4. 1
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
  5. 2
      ILSpy/MainWindow.xaml.cs

4
ICSharpCode.Decompiler/FlowAnalysis/ControlFlowGraph.cs

@ -23,6 +23,8 @@ using System.Diagnostics; @@ -23,6 +23,8 @@ using System.Diagnostics;
using System.Linq;
using System.Threading;
using ICSharpCode.NRefactory.Utils;
namespace ICSharpCode.Decompiler.FlowAnalysis
{
/// <summary>
@ -57,7 +59,6 @@ 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 @@ -87,7 +88,6 @@ namespace ICSharpCode.Decompiler.FlowAnalysis
}
return graph;
}
#endif
/// <summary>
/// Resets "Visited" to false for all nodes in this graph.

1
ICSharpCode.Decompiler/FlowAnalysis/SsaForm.cs

@ -22,6 +22,7 @@ using System.Collections.ObjectModel; @@ -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;

197
ICSharpCode.Decompiler/GraphVizGraph.cs

@ -1,197 +0,0 @@ @@ -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
{
/// <summary>
/// GraphViz graph.
/// </summary>
public sealed class GraphVizGraph
{
List<GraphVizNode> nodes = new List<GraphVizNode>();
List<GraphVizEdge> edges = new List<GraphVizEdge>();
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;
/// <summary>edge stroke color</summary>
public string color;
/// <summary>use edge to affect node ranking</summary>
public bool? constraint;
public string label;
public string style;
/// <summary>point size of label</summary>
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;
/// <summary>point size of label</summary>
public int? fontsize;
/// <summary>minimum height in inches</summary>
public double? height;
/// <summary>space around label</summary>
public string margin;
/// <summary>node shape</summary>
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("];");
}
}
}

1
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -85,7 +85,6 @@ @@ -85,7 +85,6 @@
<Compile Include="FlowAnalysis\SsaOptimization.cs" />
<Compile Include="FlowAnalysis\SsaVariable.cs" />
<Compile Include="FlowAnalysis\TransformToSsa.cs" />
<Compile Include="GraphVizGraph.cs" />
<Compile Include="ILAst\InitializerPeepholeTransforms.cs" />
<Compile Include="ILAst\DefaultDictionary.cs" />
<Compile Include="ILAst\GotoRemoval.cs" />

2
ILSpy/MainWindow.xaml.cs

@ -273,7 +273,7 @@ namespace ICSharpCode.ILSpy @@ -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)

Loading…
Cancel
Save