From 0369486be70d4999570d668c50d3437fcfa470ec Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 13 Apr 2012 20:30:02 +0200 Subject: [PATCH] Fixed issue with the patch for #300 when an 'else' block starts with a while loop. --- ICSharpCode.Decompiler/ILAst/LoopsAndConditions.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/ILAst/LoopsAndConditions.cs b/ICSharpCode.Decompiler/ILAst/LoopsAndConditions.cs index 3582d7d96..a310624c0 100644 --- a/ICSharpCode.Decompiler/ILAst/LoopsAndConditions.cs +++ b/ICSharpCode.Decompiler/ILAst/LoopsAndConditions.cs @@ -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 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 content = FindDominatedNodes(scope, falseTarget); scope.ExceptWith(content); ilCond.FalseBlock.Body.AddRange(FindConditions(content, falseTarget)); @@ -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 FindDominatedNodes(HashSet scope, ControlFlowNode head) { HashSet agenda = new HashSet();