diff --git a/Decompiler.csproj b/Decompiler.csproj index 0e8675aa1..0e5aa019b 100644 --- a/Decompiler.csproj +++ b/Decompiler.csproj @@ -64,6 +64,7 @@ + diff --git a/src/AstBuilder.cs b/src/AstBuilder.cs index 5db7367f4..36bedee71 100644 --- a/src/AstBuilder.cs +++ b/src/AstBuilder.cs @@ -27,6 +27,7 @@ namespace Decompiler astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveGotos(), null); astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveDeadLabels(), null); astCompileUnit.AcceptVisitor(new Transforms.Ast.SimplifyTypeReferences(), null); + astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveEmptyElseBody(), null); astCompileUnit.AcceptVisitor(csOutVisitor, null); diff --git a/src/Transforms/Ast/RemoveEmptyElseBody.cs b/src/Transforms/Ast/RemoveEmptyElseBody.cs new file mode 100644 index 000000000..9463c5afc --- /dev/null +++ b/src/Transforms/Ast/RemoveEmptyElseBody.cs @@ -0,0 +1,23 @@ +using System; + +using Ast = ICSharpCode.NRefactory.Ast; +using ICSharpCode.NRefactory.Ast; +using ICSharpCode.NRefactory.Visitors; + +namespace Decompiler.Transforms.Ast +{ + public class RemoveEmptyElseBody: AbstractAstTransformer + { + public override object VisitIfElseStatement(IfElseStatement ifElseStatement, object data) + { + base.VisitIfElseStatement(ifElseStatement, data); + if (ifElseStatement.FalseStatement.Count == 1 && + ifElseStatement.FalseStatement[0] is MyBlockStatement && + ifElseStatement.FalseStatement[0].Children.Count == 0) + { + ifElseStatement.FalseStatement.Clear(); + } + return null; + } + } +}