Browse Source

Fix unit tests

pull/887/head
Siegfried Pammer 8 years ago
parent
commit
596fca2b37
  1. 4
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  2. 21
      ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs

4
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -153,7 +153,7 @@ namespace ICSharpCode.Decompiler.CSharp
switch (section.Body) {
case Branch br:
// we can only inline the block, if all branches are in the switchContainer.
if (br.TargetBlock.IsDescendantOf(switchContainer))
if (br.TargetBlock.Parent == switchContainer && switchContainer.Descendants.OfType<Branch>().Where(b => b.TargetBlock == br.TargetBlock).All(b => BlockContainer.FindClosestContainer(b) == switchContainer))
caseLabelMapping.Add(br.TargetBlock, firstValueResolveResult);
break;
default:
@ -167,7 +167,7 @@ namespace ICSharpCode.Decompiler.CSharp
switch (section.Body) {
case Branch br:
// we can only inline the block, if all branches are in the switchContainer.
if (br.TargetBlock.IsDescendantOf(switchContainer))
if (br.TargetBlock.Parent == switchContainer && switchContainer.Descendants.OfType<Branch>().Where(b => b.TargetBlock == br.TargetBlock).All(b => BlockContainer.FindClosestContainer(b) == switchContainer))
ConvertSwitchSectionBody(astSection, br.TargetBlock);
else
ConvertSwitchSectionBody(astSection, section.Body);

21
ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs

@ -66,7 +66,7 @@ namespace ILSpy.BamlDecompiler
function.RunTransforms(CSharpDecompiler.GetILTransforms(), context);
var block = function.Body.Children.OfType<Block>().First();
var ilSwitch = block.Children.OfType<SwitchInstruction>().FirstOrDefault();
var ilSwitch = block.Descendants.OfType<SwitchInstruction>().FirstOrDefault();
if (ilSwitch != null) {
foreach (var section in ilSwitch.Sections) {
@ -92,13 +92,18 @@ namespace ILSpy.BamlDecompiler
{
var events = new List<EventRegistration>();
if (inst is Block) {
foreach (var node in ((Block)inst).Instructions) {
FindEvents(node, events);
}
FindEvents(((Block)inst).FinalInstruction, events);
} else {
FindEvents(inst, events);
switch (inst) {
case Block b:
foreach (var node in ((Block)inst).Instructions) {
FindEvents(node, events);
}
FindEvents(((Block)inst).FinalInstruction, events);
break;
case Branch br:
return FindEvents(br.TargetBlock);
default:
FindEvents(inst, events);
break;
}
return events.ToArray();
}

Loading…
Cancel
Save