Browse Source

Don't just fall out of case statements.

pull/70/head
David Srbecký 15 years ago
parent
commit
aab0e43a08
  1. 2
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  2. 10
      ICSharpCode.Decompiler/ILAst/GotoRemoval.cs
  3. 8
      ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs
  4. 3
      ICSharpCode.Decompiler/ILAst/ILAstTypes.cs

2
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -130,8 +130,6 @@ namespace ICSharpCode.Decompiler.Ast @@ -130,8 +130,6 @@ namespace ICSharpCode.Decompiler.Ast
switchStmt.SwitchSections.Add(section);
}
yield return switchStmt;
if (ilSwitch.DefaultGoto != null)
yield return (Statement)TransformExpression(ilSwitch.DefaultGoto);
} else if (node is ILTryCatchBlock) {
ILTryCatchBlock tryCatchNode = ((ILTryCatchBlock)node);
var tryCatchStmt = new Ast.TryCatchStatement();

10
ICSharpCode.Decompiler/ILAst/GotoRemoval.cs

@ -76,6 +76,7 @@ namespace ICSharpCode.Decompiler.ILAst @@ -76,6 +76,7 @@ namespace ICSharpCode.Decompiler.ILAst
return true;
}
// TODO: Swich also qualifies for break;
ILWhileLoop loop = null;
ILNode current = gotoExpr;
while(loop == null && current != null) {
@ -184,13 +185,14 @@ namespace ICSharpCode.Decompiler.ILAst @@ -184,13 +185,14 @@ namespace ICSharpCode.Decompiler.ILAst
}
}
if (nodeParent is ILCondition ||
nodeParent is ILTryCatchBlock ||
nodeParent is ILSwitch)
{
if (nodeParent is ILCondition || nodeParent is ILTryCatchBlock) {
return Exit(nodeParent, visitedNodes);
}
if (nodeParent is ILSwitch) {
return null; // Implicit exit from switch is not allowed
}
if (nodeParent is ILWhileLoop) {
return Enter(nodeParent, visitedNodes);
}

8
ICSharpCode.Decompiler/ILAst/ILAstOptimizer.cs

@ -586,13 +586,11 @@ namespace ICSharpCode.Decompiler.ILAst @@ -586,13 +586,11 @@ namespace ICSharpCode.Decompiler.ILAst
// The labels will not be used - kill them
condBranch.Operand = null;
ILSwitch ilSwitch = new ILSwitch() {
Condition = condBranch,
DefaultGoto = block.FallthoughGoto
};
ILSwitch ilSwitch = new ILSwitch() { Condition = condBranch };
result.Add(new ILBasicBlock() {
EntryLabel = block.EntryLabel, // Keep the entry label
Body = { ilSwitch }
Body = { ilSwitch },
FallthoughGoto = block.FallthoughGoto
});
// Remove the item so that it is not picked up as content

3
ICSharpCode.Decompiler/ILAst/ILAstTypes.cs

@ -443,7 +443,6 @@ namespace ICSharpCode.Decompiler.ILAst @@ -443,7 +443,6 @@ namespace ICSharpCode.Decompiler.ILAst
{
public ILExpression Condition;
public List<ILBlock> CaseBlocks = new List<ILBlock>();
public ILExpression DefaultGoto;
public override IEnumerable<ILNode> GetChildren()
{
@ -452,8 +451,6 @@ namespace ICSharpCode.Decompiler.ILAst @@ -452,8 +451,6 @@ namespace ICSharpCode.Decompiler.ILAst
foreach (ILBlock caseBlock in this.CaseBlocks) {
yield return caseBlock;
}
if (this.DefaultGoto != null)
yield return this.DefaultGoto;
}
public override void WriteTo(ITextOutput output)

Loading…
Cancel
Save