Skip to content

Commit

Permalink
Fixed some missing gotos and labels
Browse files Browse the repository at this point in the history
  • Loading branch information
dsrbecky committed Feb 9, 2011
1 parent a420fd6 commit 0d522ba
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
13 changes: 8 additions & 5 deletions ICSharpCode.Decompiler/Ast/AstMetodBodyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,18 @@ public BlockStatement CreateMethodBody()
}
}
}
foreach(Ast.INode inode in TransformNodes(node.Childs)) {
yield return inode;
}
Node fallThroughNode = ((BasicBlock)node).FallThroughBasicBlock;
// If there is default branch and it is not the following node
if (fallThroughNode != null) {
yield return new Ast.GotoStatement(fallThroughNode.Label);
}
} else if (node is AcyclicGraph) {
Ast.BlockStatement blockStatement = new Ast.BlockStatement();
blockStatement.Children.AddRange(TransformNodes(node.Childs));
yield return blockStatement;
foreach(Ast.INode inode in TransformNodes(node.Childs)) {
yield return inode;
}
} else if (node is Loop) {
Ast.BlockStatement blockStatement = new Ast.BlockStatement();
blockStatement.Children.AddRange(TransformNodes(node.Childs));
Expand Down Expand Up @@ -349,7 +352,7 @@ static object TransformByteCode(MethodDefinition methodDef, ILExpression byteCod
if (byteCode.Operand != null) {
args.Insert(0, new IdentifierExpression(FormatByteCodeOperand(byteCode.Operand)));
}
return new Ast.InvocationExpression(new IdentifierExpression("__" + byteCode.OpCode.Name), args);
return new Ast.InvocationExpression(new IdentifierExpression(byteCode.OpCode.Name), args);
}
}

Expand Down Expand Up @@ -391,7 +394,7 @@ static Ast.INode TransformByteCode_Internal(MethodDefinition methodDef, ILExpres
Ast.Expression arg3 = args.Count >= 3 ? args[2] : null;

Ast.Statement branchCommand = null;
if (byteCode.Operand is ILExpression) {
if (byteCode.Operand is ILLabel) {
branchCommand = new Ast.GotoStatement(((ILLabel)byteCode.Operand).Name);
}

Expand Down
16 changes: 16 additions & 0 deletions ICSharpCode.Decompiler/Ast/Transforms/RemoveDeadLabels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ public override object VisitMethodDeclaration(MethodDeclaration methodDeclaratio
return null;
}

public override object VisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data)
{
collectingUsedLabels = true;
base.VisitPropertyGetRegion(propertyGetRegion, data);
collectingUsedLabels = false;
return base.VisitPropertyGetRegion(propertyGetRegion, data);
}

public override object VisitPropertySetRegion(PropertySetRegion propertySetRegion, object data)
{
collectingUsedLabels = true;
base.VisitPropertySetRegion(propertySetRegion, data);
collectingUsedLabels = false;
return base.VisitPropertySetRegion(propertySetRegion, data);
}

public override object VisitGotoStatement(GotoStatement gotoStatement, object data)
{
if (collectingUsedLabels) {
Expand Down
2 changes: 1 addition & 1 deletion ICSharpCode.Decompiler/ILAst/ControlFlow/Nodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ ast[i] is ILTryCatchBlock ||
}
}
if (ast[i] is ILTryCatchBlock) {
nodes.Add(ConvertTryCatch((ILTryCatchBlock)ast[i]));
basicBlock.Childs.Add(ConvertTryCatch((ILTryCatchBlock)ast[i]));
} else {
basicBlock.Body.Add(ast[i]);
}
Expand Down
18 changes: 9 additions & 9 deletions ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Decompiler.Mono.Cecil.Rocks;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
using Cecil = Mono.Cecil;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Decompiler.Mono.Cecil.Rocks;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
using Cecil = Mono.Cecil;

namespace Decompiler
{
Expand Down

0 comments on commit 0d522ba

Please sign in to comment.