Browse Source

Remove empty 'else body' of 'if' statement.

pull/1/head^2
David Srbecký 18 years ago
parent
commit
075c5bebdb
  1. 1
      Decompiler.csproj
  2. 1
      src/AstBuilder.cs
  3. 23
      src/Transforms/Ast/RemoveEmptyElseBody.cs

1
Decompiler.csproj

@ -64,6 +64,7 @@
<Compile Include="src\StackExpression.cs" /> <Compile Include="src\StackExpression.cs" />
<Compile Include="src\StackExpressionCollection.cs" /> <Compile Include="src\StackExpressionCollection.cs" />
<Compile Include="src\Transforms\Ast\RemoveDeadLabels.cs" /> <Compile Include="src\Transforms\Ast\RemoveDeadLabels.cs" />
<Compile Include="src\Transforms\Ast\RemoveEmptyElseBody.cs" />
<Compile Include="src\Transforms\Ast\RemoveGotos.cs" /> <Compile Include="src\Transforms\Ast\RemoveGotos.cs" />
<Compile Include="src\Transforms\Ast\SimplifyTypeReferences.cs" /> <Compile Include="src\Transforms\Ast\SimplifyTypeReferences.cs" />
<Compile Include="src\Util.cs" /> <Compile Include="src\Util.cs" />

1
src/AstBuilder.cs

@ -27,6 +27,7 @@ namespace Decompiler
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveGotos(), null); astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveGotos(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveDeadLabels(), null); astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveDeadLabels(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.SimplifyTypeReferences(), null); astCompileUnit.AcceptVisitor(new Transforms.Ast.SimplifyTypeReferences(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveEmptyElseBody(), null);
astCompileUnit.AcceptVisitor(csOutVisitor, null); astCompileUnit.AcceptVisitor(csOutVisitor, null);

23
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;
}
}
}
Loading…
Cancel
Save