Browse Source

Fixed some missing gotos and labels

pull/1/head^2
David Srbecký 15 years ago
parent
commit
0d522ba136
  1. 13
      ICSharpCode.Decompiler/Ast/AstMetodBodyBuilder.cs
  2. 16
      ICSharpCode.Decompiler/Ast/Transforms/RemoveDeadLabels.cs
  3. 2
      ICSharpCode.Decompiler/ILAst/ControlFlow/Nodes.cs
  4. 18
      ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs

13
ICSharpCode.Decompiler/Ast/AstMetodBodyBuilder.cs

@ -135,15 +135,18 @@ namespace Decompiler
} }
} }
} }
foreach(Ast.INode inode in TransformNodes(node.Childs)) {
yield return inode;
}
Node fallThroughNode = ((BasicBlock)node).FallThroughBasicBlock; Node fallThroughNode = ((BasicBlock)node).FallThroughBasicBlock;
// If there is default branch and it is not the following node // If there is default branch and it is not the following node
if (fallThroughNode != null) { if (fallThroughNode != null) {
yield return new Ast.GotoStatement(fallThroughNode.Label); yield return new Ast.GotoStatement(fallThroughNode.Label);
} }
} else if (node is AcyclicGraph) { } else if (node is AcyclicGraph) {
Ast.BlockStatement blockStatement = new Ast.BlockStatement(); foreach(Ast.INode inode in TransformNodes(node.Childs)) {
blockStatement.Children.AddRange(TransformNodes(node.Childs)); yield return inode;
yield return blockStatement; }
} else if (node is Loop) { } else if (node is Loop) {
Ast.BlockStatement blockStatement = new Ast.BlockStatement(); Ast.BlockStatement blockStatement = new Ast.BlockStatement();
blockStatement.Children.AddRange(TransformNodes(node.Childs)); blockStatement.Children.AddRange(TransformNodes(node.Childs));
@ -349,7 +352,7 @@ namespace Decompiler
if (byteCode.Operand != null) { if (byteCode.Operand != null) {
args.Insert(0, new IdentifierExpression(FormatByteCodeOperand(byteCode.Operand))); 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);
} }
} }
@ -391,7 +394,7 @@ namespace Decompiler
Ast.Expression arg3 = args.Count >= 3 ? args[2] : null; Ast.Expression arg3 = args.Count >= 3 ? args[2] : null;
Ast.Statement branchCommand = null; Ast.Statement branchCommand = null;
if (byteCode.Operand is ILExpression) { if (byteCode.Operand is ILLabel) {
branchCommand = new Ast.GotoStatement(((ILLabel)byteCode.Operand).Name); branchCommand = new Ast.GotoStatement(((ILLabel)byteCode.Operand).Name);
} }

16
ICSharpCode.Decompiler/Ast/Transforms/RemoveDeadLabels.cs

@ -29,6 +29,22 @@ namespace Decompiler.Transforms.Ast
return null; 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) public override object VisitGotoStatement(GotoStatement gotoStatement, object data)
{ {
if (collectingUsedLabels) { if (collectingUsedLabels) {

2
ICSharpCode.Decompiler/ILAst/ControlFlow/Nodes.cs

@ -170,7 +170,7 @@ namespace Decompiler.ControlFlow
} }
} }
if (ast[i] is ILTryCatchBlock) { if (ast[i] is ILTryCatchBlock) {
nodes.Add(ConvertTryCatch((ILTryCatchBlock)ast[i])); basicBlock.Childs.Add(ConvertTryCatch((ILTryCatchBlock)ast[i]));
} else { } else {
basicBlock.Body.Add(ast[i]); basicBlock.Body.Add(ast[i]);
} }

18
ICSharpCode.Decompiler/ILAst/ILAstBuilder.cs

@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Decompiler.Mono.Cecil.Rocks; using Decompiler.Mono.Cecil.Rocks;
using Mono.Cecil; using Mono.Cecil;
using Mono.Cecil.Cil; using Mono.Cecil.Cil;
using Mono.Cecil.Rocks; using Mono.Cecil.Rocks;
using Cecil = Mono.Cecil; using Cecil = Mono.Cecil;
namespace Decompiler namespace Decompiler
{ {

Loading…
Cancel
Save