mirror of https://github.com/icsharpcode/ILSpy.git
5 changed files with 91 additions and 9 deletions
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
using Ast = ICSharpCode.NRefactory.Ast; |
||||
using Decompiler.ControlFlow; |
||||
|
||||
namespace ICSharpCode.NRefactory.Ast |
||||
{ |
||||
public class MyBlockStatement: BlockStatement |
||||
{ |
||||
ChildrenCollection wrapper; |
||||
|
||||
public class ChildrenCollection: System.Collections.ObjectModel.Collection<INode> |
||||
{ |
||||
MyBlockStatement myStmt; |
||||
|
||||
public void AddRange(IEnumerable<INode> items) |
||||
{ |
||||
foreach(INode node in items) { |
||||
Add(node); |
||||
} |
||||
} |
||||
|
||||
protected override void InsertItem(int index, INode item) |
||||
{ |
||||
item.Parent = myStmt; |
||||
base.InsertItem(index, item); |
||||
} |
||||
|
||||
protected override void SetItem(int index, INode item) |
||||
{ |
||||
item.Parent = myStmt; |
||||
base.SetItem(index, item); |
||||
} |
||||
|
||||
public ChildrenCollection(MyBlockStatement myStmt, IList<INode> nodes): base(nodes) |
||||
{ |
||||
this.myStmt = myStmt; |
||||
} |
||||
} |
||||
|
||||
public new ChildrenCollection Children { |
||||
get { |
||||
return wrapper; |
||||
} |
||||
} |
||||
|
||||
public MyBlockStatement() |
||||
{ |
||||
this.wrapper = new ChildrenCollection(this, base.Children); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
using System; |
||||
|
||||
using ICSharpCode.NRefactory.Ast; |
||||
using ICSharpCode.NRefactory.Visitors; |
||||
|
||||
namespace Decompiler.Transforms.Ast |
||||
{ |
||||
public class RemoveGotos: AbstractAstTransformer |
||||
{ |
||||
public override object VisitGotoStatement(GotoStatement gotoStatement, object data) |
||||
{ |
||||
MyGotoStatement myGoto = (MyGotoStatement)gotoStatement; |
||||
if (gotoStatement.Parent == null) return null; |
||||
int index = gotoStatement.Parent.Children.IndexOf(gotoStatement); |
||||
if (index + 1 < gotoStatement.Parent.Children.Count) { |
||||
INode nextStmt = gotoStatement.Parent.Children[index + 1]; |
||||
MyLabelStatement myLabel = nextStmt as MyLabelStatement; |
||||
if (myLabel != null && myLabel.NodeLabel == myGoto.NodeLabel) { |
||||
myGoto.NodeLabel.ReferenceCount--; |
||||
RemoveCurrentNode(); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue