Browse Source

Fix small regressions

pull/976/head
Siegfried Pammer 8 years ago
parent
commit
b3370506ae
  1. 15
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  2. 2
      ICSharpCode.Decompiler/IL/Transforms/HighLevelLoopTransform.cs

15
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -695,6 +695,9 @@ namespace ICSharpCode.Decompiler.CSharp
// Remove the entrypoint label if all jumps to the label were replaced with 'continue;' statements // Remove the entrypoint label if all jumps to the label were replaced with 'continue;' statements
blockStatement.Statements.First().Remove(); blockStatement.Statements.First().Remove();
} }
if (blockStatement.LastOrDefault() is ContinueStatement continueStmt)
continueStmt.Remove();
return new WhileStatement(new PrimitiveExpression(true), blockStatement); return new WhileStatement(new PrimitiveExpression(true), blockStatement);
case ContainerKind.While: case ContainerKind.While:
continueTarget = container.EntryPoint; continueTarget = container.EntryPoint;
@ -714,8 +717,8 @@ namespace ICSharpCode.Decompiler.CSharp
blockStatement.Add(new LabelStatement { Label = container.EntryPoint.Label }); blockStatement.Add(new LabelStatement { Label = container.EntryPoint.Label });
} }
if (blockStatement.LastOrDefault() is ContinueStatement stmt) if (blockStatement.LastOrDefault() is ContinueStatement continueStmt2)
stmt.Remove(); continueStmt2.Remove();
return new WhileStatement(exprBuilder.TranslateCondition(condition), blockStatement); return new WhileStatement(exprBuilder.TranslateCondition(condition), blockStatement);
case ContainerKind.DoWhile: case ContainerKind.DoWhile:
continueTarget = container.Blocks.Last(); continueTarget = container.Blocks.Last();
@ -726,8 +729,8 @@ namespace ICSharpCode.Decompiler.CSharp
// Remove the entrypoint label if all jumps to the label were replaced with 'continue;' statements // Remove the entrypoint label if all jumps to the label were replaced with 'continue;' statements
blockStatement.Statements.First().Remove(); blockStatement.Statements.First().Remove();
} }
if (blockStatement.LastOrDefault() is ContinueStatement continueStmt) if (blockStatement.LastOrDefault() is ContinueStatement continueStmt3)
continueStmt.Remove(); continueStmt3.Remove();
return new DoWhileStatement { return new DoWhileStatement {
EmbeddedStatement = blockStatement, EmbeddedStatement = blockStatement,
Condition = exprBuilder.TranslateCondition(condition) Condition = exprBuilder.TranslateCondition(condition)
@ -746,8 +749,8 @@ namespace ICSharpCode.Decompiler.CSharp
Condition = exprBuilder.TranslateCondition(condition), Condition = exprBuilder.TranslateCondition(condition),
EmbeddedStatement = blockStatement EmbeddedStatement = blockStatement
}; };
if (blockStatement.LastOrDefault() is ContinueStatement continueStmt2) if (blockStatement.LastOrDefault() is ContinueStatement continueStmt4)
continueStmt2.Remove(); continueStmt4.Remove();
for (int i = 0; i < continueTarget.Instructions.Count - 1; i++) { for (int i = 0; i < continueTarget.Instructions.Count - 1; i++) {
forStmt.Iterators.Add(Convert(continueTarget.Instructions[i])); forStmt.Iterators.Add(Convert(continueTarget.Instructions[i]));
} }

2
ICSharpCode.Decompiler/IL/Transforms/HighLevelLoopTransform.cs

@ -88,7 +88,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; return false;
var last = loop.EntryPoint.Instructions.Last(); var last = loop.EntryPoint.Instructions.Last();
var ifInstruction = loop.EntryPoint.Instructions.SecondToLastOrDefault() as IfInstruction; var ifInstruction = loop.EntryPoint.Instructions.SecondToLastOrDefault() as IfInstruction;
if (!ifInstruction.FalseInst.MatchNop()) if (ifInstruction == null || !ifInstruction.FalseInst.MatchNop())
return false; return false;
bool swapBranches = false; bool swapBranches = false;
ILInstruction condition = ifInstruction.Condition; ILInstruction condition = ifInstruction.Condition;

Loading…
Cancel
Save