Browse Source

Fix #3258: Move GraphVizGraph and friends to ILSpy and remove InternalsVisibleTo.

pull/3265/head
Siegfried Pammer 12 months ago
parent
commit
6cee0cdc4b
  1. 37
      ICSharpCode.Decompiler/FlowAnalysis/ControlFlowNode.cs
  2. 1
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
  3. 9
      ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowGraph.cs
  4. 4
      ICSharpCode.Decompiler/Properties/AssemblyInfo.cs
  5. 39
      ILSpy/Commands/ShowCFGContextMenuEntry.cs
  6. 2
      ILSpy/Util/GraphVizGraph.cs

37
ICSharpCode.Decompiler/FlowAnalysis/ControlFlowNode.cs

@ -129,42 +129,5 @@ namespace ICSharpCode.Decompiler.FlowAnalysis @@ -129,42 +129,5 @@ namespace ICSharpCode.Decompiler.FlowAnalysis
}
return false;
}
#if DEBUG
internal static GraphVizGraph ExportGraph(IReadOnlyList<ControlFlowNode> nodes, Func<ControlFlowNode, string> labelFunc = null)
{
if (labelFunc == null)
{
labelFunc = node => {
var block = node.UserData as IL.Block;
return block != null ? block.Label : node.UserData?.ToString();
};
}
GraphVizGraph g = new GraphVizGraph();
GraphVizNode[] n = new GraphVizNode[nodes.Count];
for (int i = 0; i < n.Length; i++)
{
n[i] = new GraphVizNode(nodes[i].UserIndex);
n[i].shape = "box";
n[i].label = labelFunc(nodes[i]);
g.AddNode(n[i]);
}
foreach (var source in nodes)
{
foreach (var target in source.Successors)
{
g.AddEdge(new GraphVizEdge(source.UserIndex, target.UserIndex));
}
if (source.ImmediateDominator != null)
{
g.AddEdge(
new GraphVizEdge(source.ImmediateDominator.UserIndex, source.UserIndex) {
color = "green"
});
}
}
return g;
}
#endif
}
}

1
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -475,7 +475,6 @@ @@ -475,7 +475,6 @@
<Compile Include="TypeSystem\TupleType.cs" />
<Compile Include="TypeSystem\TypeProvider.cs" />
<Compile Include="Util\FileUtility.cs" />
<Compile Include="Util\GraphVizGraph.cs" />
<Compile Include="Util\KeyComparer.cs" />
<Compile Include="Util\LongDict.cs" />
<Compile Include="Util\ResourcesFile.cs" />

9
ICSharpCode.Decompiler/IL/ControlFlow/ControlFlowGraph.cs

@ -1,10 +1,6 @@ @@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ICSharpCode.Decompiler.FlowAnalysis;
using ICSharpCode.Decompiler.Util;
@ -36,6 +32,9 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -36,6 +32,9 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
/// </summary>
internal readonly ControlFlowNode[] cfg;
/// <inheritdoc cref="cfg"/>
public IReadOnlyList<ControlFlowNode> Nodes => cfg;
/// <summary>
/// Dictionary from Block to ControlFlowNode.
/// Unlike the cfg array, this can be used to discover control flow nodes even after

4
ICSharpCode.Decompiler/Properties/AssemblyInfo.cs

@ -19,10 +19,6 @@ using System.Runtime.InteropServices; @@ -19,10 +19,6 @@ using System.Runtime.InteropServices;
[assembly: InternalsVisibleTo("ICSharpCode.Decompiler.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001004dcf3979c4e902efa4dd2163a039701ed5822e6f1134d77737296abbb97bf0803083cfb2117b4f5446a217782f5c7c634f9fe1fc60b4c11d62c5b3d33545036706296d31903ddcf750875db38a8ac379512f51620bb948c94d0831125fbc5fe63707cbb93f48c1459c4d1749eb7ac5e681a2f0d6d7c60fa527a3c0b8f92b02bf")]
#if DEBUG
[assembly: InternalsVisibleTo("ILSpy, PublicKey=00240000048000009400000006020000002400005253413100040000010001004dcf3979c4e902efa4dd2163a039701ed5822e6f1134d77737296abbb97bf0803083cfb2117b4f5446a217782f5c7c634f9fe1fc60b4c11d62c5b3d33545036706296d31903ddcf750875db38a8ac379512f51620bb948c94d0831125fbc5fe63707cbb93f48c1459c4d1749eb7ac5e681a2f0d6d7c60fa527a3c0b8f92b02bf")]
#endif
[assembly: SuppressMessage("Microsoft.Usage", "CA2243:AttributeStringLiteralsShouldParseCorrectly",
Justification = "AssemblyInformationalVersion does not need to be a parsable version")]

39
ILSpy/Commands/ShowCFGContextMenuEntry.cs

@ -1,9 +1,11 @@ @@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Windows;
using ICSharpCode.Decompiler.FlowAnalysis;
using ICSharpCode.Decompiler.IL;
using ICSharpCode.Decompiler.IL.ControlFlow;
using ICSharpCode.ILSpy.Util;
namespace ICSharpCode.ILSpy.Commands
{
@ -17,7 +19,7 @@ namespace ICSharpCode.ILSpy.Commands @@ -17,7 +19,7 @@ namespace ICSharpCode.ILSpy.Commands
{
var container = (BlockContainer)context.Reference.Reference;
var cfg = new ControlFlowGraph(container);
ControlFlowNode.ExportGraph(cfg.cfg).Show();
ExportGraph(cfg.Nodes).Show();
}
catch (Exception ex)
{
@ -34,6 +36,41 @@ namespace ICSharpCode.ILSpy.Commands @@ -34,6 +36,41 @@ namespace ICSharpCode.ILSpy.Commands
{
return context.Reference?.Reference is BlockContainer;
}
internal static GraphVizGraph ExportGraph(IReadOnlyList<ControlFlowNode> nodes, Func<ControlFlowNode, string> labelFunc = null)
{
if (labelFunc == null)
{
labelFunc = node => {
var block = node.UserData as Block;
return block != null ? block.Label : node.UserData?.ToString();
};
}
GraphVizGraph g = new GraphVizGraph();
GraphVizNode[] n = new GraphVizNode[nodes.Count];
for (int i = 0; i < n.Length; i++)
{
n[i] = new GraphVizNode(nodes[i].UserIndex);
n[i].shape = "box";
n[i].label = labelFunc(nodes[i]);
g.AddNode(n[i]);
}
foreach (var source in nodes)
{
foreach (var target in source.Successors)
{
g.AddEdge(new GraphVizEdge(source.UserIndex, target.UserIndex));
}
if (source.ImmediateDominator != null)
{
g.AddEdge(
new GraphVizEdge(source.ImmediateDominator.UserIndex, source.UserIndex) {
color = "green"
});
}
}
return g;
}
}
#endif
}

2
ICSharpCode.Decompiler/Util/GraphVizGraph.cs → ILSpy/Util/GraphVizGraph.cs

@ -25,7 +25,7 @@ using System.Globalization; @@ -25,7 +25,7 @@ using System.Globalization;
using System.IO;
using System.Text.RegularExpressions;
namespace ICSharpCode.Decompiler.Util
namespace ICSharpCode.ILSpy.Util
{
#if DEBUG
/// <summary>
Loading…
Cancel
Save