Browse Source

Rename Idioms to ReplaceMethodCallsWithOperators.

pull/10/head
Daniel Grunwald 15 years ago
parent
commit
c6aa812609
  1. 5
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 21
      ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs
  3. 2
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

5
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -26,19 +26,20 @@ namespace Decompiler
//astCompileUnit.AcceptVisitor(new Transforms.Ast.RestoreLoop(), null); //astCompileUnit.AcceptVisitor(new Transforms.Ast.RestoreLoop(), null);
} }
if (Options.ReduceAstOther) { if (Options.ReduceAstOther) {
astCompileUnit.AcceptVisitor(new Transforms.Ast.Idioms(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveEmptyElseBody(), null); astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveEmptyElseBody(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.PushNegation(), null); astCompileUnit.AcceptVisitor(new Transforms.Ast.PushNegation(), null);
} }
} }
if (Options.ReduceAstOther) { if (Options.ReduceAstOther) {
astCompileUnit.AcceptVisitor(new Transforms.Ast.SimplifyTypeReferences(), null); astCompileUnit.AcceptVisitor(new Transforms.Ast.SimplifyTypeReferences(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.Idioms(), null);
} }
if (Options.ReduceAstLoops) { if (Options.ReduceAstLoops) {
//astCompileUnit.AcceptVisitor(new Transforms.Ast.RestoreLoop(), null); //astCompileUnit.AcceptVisitor(new Transforms.Ast.RestoreLoop(), null);
} }
// Run ReplaceMethodCallsWithOperators at the end only - this step transforms custom operator calls
// into operator expressions, and we don't want other simplification steps to change those later on.
astCompileUnit.AcceptVisitor(new Transforms.Ast.ReplaceMethodCallsWithOperators(), null);
astCompileUnit.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }, null); astCompileUnit.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }, null);
var outputFormatter = new TextOutputFormatter(output); var outputFormatter = new TextOutputFormatter(output);

21
ICSharpCode.Decompiler/Ast/Transforms/Idioms.cs → ICSharpCode.Decompiler/Ast/Transforms/ReplaceMethodCallsWithOperators.cs

@ -7,7 +7,11 @@ using ICSharpCode.NRefactory.CSharp;
namespace Decompiler.Transforms.Ast namespace Decompiler.Transforms.Ast
{ {
public class Idioms: DepthFirstAstVisitor<object, object> /// <summary>
/// Replaces method calls with the appropriate operator expressions.
/// Also simplifies "x = x op y" into "x op= y" where possible.
/// </summary>
public class ReplaceMethodCallsWithOperators : DepthFirstAstVisitor<object, object>
{ {
public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data) public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
{ {
@ -162,7 +166,7 @@ namespace Decompiler.Transforms.Ast
break; break;
} }
if (assignment.Operator != AssignmentOperatorType.Assign) { if (assignment.Operator != AssignmentOperatorType.Assign) {
// If we found a shorter operators, get rid of the BinaryOperatorExpression: // If we found a shorter operator, get rid of the BinaryOperatorExpression:
assignment.Right = binary.Right; assignment.Right = binary.Right;
} }
} }
@ -174,18 +178,5 @@ namespace Decompiler.Transforms.Ast
{ {
return left is IdentifierExpression; // TODO return left is IdentifierExpression; // TODO
} }
/*
public override object VisitCastExpression(CastExpression castExpression, object data)
{
MethodReference typeRef = invocationExpression.Annotation<TypeReference>();
if (typeRef.FullName == Constants.Int32 &&
castExpression.Expression is MemberReferenceExpression &&
(castExpression.Expression as MemberReferenceExpression).MemberName == "Length") {
ReplaceCurrentNode(castExpression.Expression);
return null;
}
return base.VisitCastExpression(castExpression, data);
}*/
} }
} }

2
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -54,7 +54,7 @@
<Compile Include="Ast\CommentStatement.cs" /> <Compile Include="Ast\CommentStatement.cs" />
<Compile Include="Ast\NRefactoryExtensions.cs" /> <Compile Include="Ast\NRefactoryExtensions.cs" />
<Compile Include="Ast\TextOutputFormatter.cs" /> <Compile Include="Ast\TextOutputFormatter.cs" />
<Compile Include="Ast\Transforms\Idioms.cs" /> <Compile Include="Ast\Transforms\ReplaceMethodCallsWithOperators.cs" />
<Compile Include="Ast\Transforms\PushNegation.cs" /> <Compile Include="Ast\Transforms\PushNegation.cs" />
<Compile Include="Ast\Transforms\RemoveEmptyElseBody.cs" /> <Compile Include="Ast\Transforms\RemoveEmptyElseBody.cs" />
<Compile Include="Ast\Transforms\RemoveGotos.cs" /> <Compile Include="Ast\Transforms\RemoveGotos.cs" />

Loading…
Cancel
Save