|
|
@ -18,9 +18,9 @@ |
|
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
using System.Diagnostics; |
|
|
|
using System.Linq; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading; |
|
|
|
|
|
|
|
|
|
|
|
using Mono.Cecil.Cil; |
|
|
|
using Mono.Cecil.Cil; |
|
|
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.Decompiler.FlowAnalysis |
|
|
|
namespace ICSharpCode.Decompiler.FlowAnalysis |
|
|
@ -59,15 +59,7 @@ namespace ICSharpCode.Decompiler.FlowAnalysis |
|
|
|
current.Children.Add(tryBlock); |
|
|
|
current.Children.Add(tryBlock); |
|
|
|
|
|
|
|
|
|
|
|
if (eh.FilterStart != null) { |
|
|
|
if (eh.FilterStart != null) { |
|
|
|
var filterNodes = FindNodes(current, eh.FilterStart, eh.FilterEnd); |
|
|
|
throw new NotSupportedException(); |
|
|
|
current.Nodes.ExceptWith(filterNodes); |
|
|
|
|
|
|
|
ControlStructure filterBlock = new ControlStructure( |
|
|
|
|
|
|
|
filterNodes, |
|
|
|
|
|
|
|
g.Nodes.Single(n => n.Start == eh.HandlerStart), |
|
|
|
|
|
|
|
ControlStructureType.Filter); |
|
|
|
|
|
|
|
filterBlock.ExceptionHandler = eh; |
|
|
|
|
|
|
|
MoveControlStructures(current, filterBlock, eh.FilterStart, eh.FilterEnd); |
|
|
|
|
|
|
|
current.Children.Add(filterBlock); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var handlerNodes = FindNodes(current, eh.HandlerStart, eh.HandlerEnd); |
|
|
|
var handlerNodes = FindNodes(current, eh.HandlerStart, eh.HandlerEnd); |
|
|
@ -77,9 +69,7 @@ namespace ICSharpCode.Decompiler.FlowAnalysis |
|
|
|
handlerNodes.Add(handlerNode.EndFinallyOrFaultNode); |
|
|
|
handlerNodes.Add(handlerNode.EndFinallyOrFaultNode); |
|
|
|
current.Nodes.ExceptWith(handlerNodes); |
|
|
|
current.Nodes.ExceptWith(handlerNodes); |
|
|
|
ControlStructure handlerBlock = new ControlStructure( |
|
|
|
ControlStructure handlerBlock = new ControlStructure( |
|
|
|
handlerNodes, |
|
|
|
handlerNodes, handlerNode, ControlStructureType.Handler); |
|
|
|
g.Nodes.Single(n => n.Start == eh.HandlerStart), |
|
|
|
|
|
|
|
ControlStructureType.Handler); |
|
|
|
|
|
|
|
handlerBlock.ExceptionHandler = eh; |
|
|
|
handlerBlock.ExceptionHandler = eh; |
|
|
|
MoveControlStructures(current, handlerBlock, eh.HandlerStart, eh.HandlerEnd); |
|
|
|
MoveControlStructures(current, handlerBlock, eh.HandlerStart, eh.HandlerEnd); |
|
|
|
current.Children.Add(handlerBlock); |
|
|
|
current.Children.Add(handlerBlock); |
|
|
@ -95,7 +85,7 @@ namespace ICSharpCode.Decompiler.FlowAnalysis |
|
|
|
int start = startInst.Offset; |
|
|
|
int start = startInst.Offset; |
|
|
|
int end = endInst.Offset; |
|
|
|
int end = endInst.Offset; |
|
|
|
foreach (var node in current.Nodes.ToArray()) { |
|
|
|
foreach (var node in current.Nodes.ToArray()) { |
|
|
|
if (node.Start != null && node.Start.Offset >= start && node.Start.Offset < end) { |
|
|
|
if (node.Start != null && start <= node.Start.Offset && node.Start.Offset < end) { |
|
|
|
result.Add(node); |
|
|
|
result.Add(node); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -106,7 +96,7 @@ namespace ICSharpCode.Decompiler.FlowAnalysis |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (int i = 0; i < current.Children.Count; i++) { |
|
|
|
for (int i = 0; i < current.Children.Count; i++) { |
|
|
|
var child = current.Children[i]; |
|
|
|
var child = current.Children[i]; |
|
|
|
if (child.EntryPoint.Start.Offset >= startInst.Offset && child.EntryPoint.Start.Offset <= endInst.Offset) { |
|
|
|
if (startInst.Offset <= child.EntryPoint.Offset && child.EntryPoint.Offset < endInst.Offset) { |
|
|
|
current.Children.RemoveAt(i--); |
|
|
|
current.Children.RemoveAt(i--); |
|
|
|
target.Children.Add(child); |
|
|
|
target.Children.Add(child); |
|
|
|
target.AllNodes.UnionWith(child.AllNodes); |
|
|
|
target.AllNodes.UnionWith(child.AllNodes); |
|
|
@ -128,6 +118,8 @@ namespace ICSharpCode.Decompiler.FlowAnalysis |
|
|
|
|
|
|
|
|
|
|
|
static void DetectLoops(ControlFlowGraph g, ControlStructure current, CancellationToken cancellationToken) |
|
|
|
static void DetectLoops(ControlFlowGraph g, ControlStructure current, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (!current.EntryPoint.IsReachable) |
|
|
|
|
|
|
|
return; |
|
|
|
g.ResetVisited(); |
|
|
|
g.ResetVisited(); |
|
|
|
cancellationToken.ThrowIfCancellationRequested(); |
|
|
|
cancellationToken.ThrowIfCancellationRequested(); |
|
|
|
FindLoops(current, current.EntryPoint); |
|
|
|
FindLoops(current, current.EntryPoint); |
|
|
@ -238,6 +230,8 @@ namespace ICSharpCode.Decompiler.FlowAnalysis |
|
|
|
|
|
|
|
|
|
|
|
public ControlStructure(HashSet<ControlFlowNode> nodes, ControlFlowNode entryPoint, ControlStructureType type) |
|
|
|
public ControlStructure(HashSet<ControlFlowNode> nodes, ControlFlowNode entryPoint, ControlStructureType type) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (nodes == null) |
|
|
|
|
|
|
|
throw new ArgumentNullException("nodes"); |
|
|
|
this.Nodes = nodes; |
|
|
|
this.Nodes = nodes; |
|
|
|
this.EntryPoint = entryPoint; |
|
|
|
this.EntryPoint = entryPoint; |
|
|
|
this.Type = type; |
|
|
|
this.Type = type; |
|
|
|