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) { switch (section.Body) {
case Branch br: case Branch br:
// we can only inline the block, if all branches are in the switchContainer. // 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); caseLabelMapping.Add(br.TargetBlock, firstValueResolveResult);
break; break;
default: default:
@ -167,7 +167,7 @@ namespace ICSharpCode.Decompiler.CSharp
switch (section.Body) { switch (section.Body) {
case Branch br: case Branch br:
// we can only inline the block, if all branches are in the switchContainer. // 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); ConvertSwitchSectionBody(astSection, br.TargetBlock);
else else
ConvertSwitchSectionBody(astSection, section.Body); ConvertSwitchSectionBody(astSection, section.Body);

21
ILSpy.BamlDecompiler/ConnectMethodDecompiler.cs

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

Loading…
Cancel
Save