Browse Source

Fixed issue with the patch for #300 when an 'else' block starts with a while loop.

pull/348/head
Daniel Grunwald 14 years ago
parent
commit
0369486be7
  1. 9
      ICSharpCode.Decompiler/ILAst/LoopsAndConditions.cs

9
ICSharpCode.Decompiler/ILAst/LoopsAndConditions.cs

@ -364,12 +364,12 @@ namespace ICSharpCode.Decompiler.ILAst @@ -364,12 +364,12 @@ namespace ICSharpCode.Decompiler.ILAst
labelToCfNode.TryGetValue(falseLabel, out falseTarget);
// Pull in the conditional code
if (trueTarget != null && trueTarget.Incoming.Count == 1) {
if (trueTarget != null && HasSingleEdgeEnteringBlock(trueTarget)) {
HashSet<ControlFlowNode> content = FindDominatedNodes(scope, trueTarget);
scope.ExceptWith(content);
ilCond.TrueBlock.Body.AddRange(FindConditions(content, trueTarget));
}
if (falseTarget != null && falseTarget.Incoming.Count == 1) {
if (falseTarget != null && HasSingleEdgeEnteringBlock(falseTarget)) {
HashSet<ControlFlowNode> content = FindDominatedNodes(scope, falseTarget);
scope.ExceptWith(content);
ilCond.FalseBlock.Body.AddRange(FindConditions(content, falseTarget));
@ -398,6 +398,11 @@ namespace ICSharpCode.Decompiler.ILAst @@ -398,6 +398,11 @@ namespace ICSharpCode.Decompiler.ILAst
return result;
}
static bool HasSingleEdgeEnteringBlock(ControlFlowNode node)
{
return node.Incoming.Count(edge => !node.Dominates(edge.Source)) == 1;
}
static HashSet<ControlFlowNode> FindDominatedNodes(HashSet<ControlFlowNode> scope, ControlFlowNode head)
{
HashSet<ControlFlowNode> agenda = new HashSet<ControlFlowNode>();

Loading…
Cancel
Save