diff --git a/bin/Debug/output.cs b/bin/Debug/output.cs index fb9388ced..3dd5fbc78 100644 --- a/bin/Debug/output.cs +++ b/bin/Debug/output.cs @@ -33,41 +33,41 @@ namespace Reversi { for (int i = 0; i < 8; i = i + 1) { for (int j = 0; j < 8; j = j + 1) { - @this.squares.Set(i, j, IL__ldsfld(Empty)); - @this.safeDiscs.Set(i, j, 0); + squares.Set(i, j, IL__ldsfld(Empty)); + safeDiscs.Set(i, j, 0); } } - @this.squares.Set(3, 3, IL__ldsfld(White)); - @this.squares.Set(3, 4, IL__ldsfld(Black)); - @this.squares.Set(4, 3, IL__ldsfld(Black)); - @this.squares.Set(4, 4, IL__ldsfld(White)); - @this.UpdateCounts(); + squares.Set(3, 3, IL__ldsfld(White)); + squares.Set(3, 4, IL__ldsfld(Black)); + squares.Set(4, 3, IL__ldsfld(Black)); + squares.Set(4, 4, IL__ldsfld(White)); + UpdateCounts(); } public int GetSquareContents(int row, int col) { - return (@this.squares.Get(row, col)); + return (squares.Get(row, col)); } public void MakeMove(int color, int row, int col) { - @this.squares.Set(row, col, color); + squares.Set(row, col, color); for (int i = -1; i <= 1; i = i + 1) { for (int j = -1; j <= 1; j = j + 1) { - if ((i || j) && @this.IsOutflanking(color, row, col, i, j)) { + if ((i || j) && IsOutflanking(color, row, col, i, j)) { int k = row + i; - for (int l = col + j; @this.squares.Get(k, l) == -color; l = l + j) { - @this.squares.Set(k, l, color); + for (int l = col + j; squares.Get(k, l) == -color; l = l + j) { + squares.Set(k, l, color); k = k + i; } } } } - @this.UpdateCounts(); + UpdateCounts(); } public bool HasAnyValidMove(int color) { for (int i = 0; i < 8; i = i + 1) { for (int j = 0; j < 8; j = j + 1) { - if (@this.IsValidMove(color, i, j)) { + if (IsValidMove(color, i, j)) { return 1; } } @@ -76,12 +76,12 @@ namespace Reversi } public bool IsValidMove(int color, int row, int col) { - if (!(@this.squares.Get(row, col) == IL__ldsfld(Empty))) { + if (!(squares.Get(row, col) == IL__ldsfld(Empty))) { return 0; } for (int i = -1; i <= 1; i = i + 1) { for (int j = -1; j <= 1; j = j + 1) { - if ((i || j) && @this.IsOutflanking(color, row, col, i, j)) { + if ((i || j) && IsOutflanking(color, row, col, i, j)) { return 1; } } @@ -93,7 +93,7 @@ namespace Reversi int i = 0; for (int j = 0; j < 8; j = j + 1) { for (int k = 0; k < 8; k = k + 1) { - if (@this.IsValidMove(color, j, k)) { + if (IsValidMove(color, j, k)) { i = i + 1; } } @@ -103,29 +103,29 @@ namespace Reversi private bool IsOutflanking(int color, int row, int col, int dr, int dc) { int i = row + dr; - for (int j = col + dc; i >= 0 && i < 8 && j >= 0 && j < 8 && @this.squares.Get(i, j) == -color; j = j + dc) { + for (int j = col + dc; i >= 0 && i < 8 && j >= 0 && j < 8 && squares.Get(i, j) == -color; j = j + dc) { i = i + dr; } - if (i < 0 || i > 7 || j < 0 || j > 7 || i - dr == row && j - dc == col || @this.squares.Get(i, j) != color) { + if (i < 0 || i > 7 || j < 0 || j > 7 || i - dr == row && j - dc == col || squares.Get(i, j) != color) { return 0; } return 1; } private void UpdateCounts() { - @this.blackCount = 0; - @this.whiteCount = 0; - @this.emptyCount = 0; - @this.blackFrontierCount = 0; - @this.whiteFrontierCount = 0; - @this.whiteSafeCount = 0; - @this.blackSafeCount = 0; + blackCount = 0; + whiteCount = 0; + emptyCount = 0; + blackFrontierCount = 0; + whiteFrontierCount = 0; + whiteSafeCount = 0; + blackSafeCount = 0; for (bool V_2 = 1; V_2;) { V_2 = 0; for (int i = 0; i < 8; i = i + 1) { for (int j = 0; j < 8; j = j + 1) { - if (!(@this.squares.Get(i, j) == IL__ldsfld(Empty)) && !@this.safeDiscs.Get(i, j) && !@this.IsOutflankable(i, j)) { - @this.safeDiscs.Set(i, j, 1); + if (!(squares.Get(i, j) == IL__ldsfld(Empty)) && !safeDiscs.Get(i, j) && !IsOutflankable(i, j)) { + safeDiscs.Set(i, j, 1); V_2 = 1; } } @@ -136,47 +136,47 @@ namespace Reversi j = 0; for (; j < 8; j = j + 1) { bool V_5 = 0; - if (!(@this.squares.Get(i, j) == IL__ldsfld(Empty))) { + if (!(squares.Get(i, j) == IL__ldsfld(Empty))) { for (int k = -1; k <= 1; k = k + 1) { for (int l = -1; l <= 1; l = l + 1) { - if ((k || l) && i + k >= 0 && i + k < 8 && j + l >= 0 && j + l < 8 && !(@this.squares.Get((i + k), (j + l)) != IL__ldsfld(Empty))) { + if ((k || l) && i + k >= 0 && i + k < 8 && j + l >= 0 && j + l < 8 && !(squares.Get((i + k), (j + l)) != IL__ldsfld(Empty))) { V_5 = 1; } } } } - if (!(@this.squares.Get(i, j) != IL__ldsfld(Black))) { - IL__dup(@this); + if (!(squares.Get(i, j) != IL__ldsfld(Black))) { + IL__dup(this); object expr123 = expr122.blackCount; int expr129 = expr123 + 1; expr122.blackCount = expr129; if (V_5) { - IL__dup(@this); + IL__dup(this); object expr135 = expr134.blackFrontierCount; int expr13B = expr135 + 1; expr134.blackFrontierCount = expr13B; } - if (@this.safeDiscs.Get(i, j)) { - IL__dup(@this); + if (safeDiscs.Get(i, j)) { + IL__dup(this); object expr152 = expr151.blackSafeCount; int expr158 = expr152 + 1; expr151.blackSafeCount = expr158; } } else { - if (!(@this.squares.Get(i, j) != IL__ldsfld(White))) { - IL__dup(@this); + if (!(squares.Get(i, j) != IL__ldsfld(White))) { + IL__dup(this); object expr176 = expr175.whiteCount; int expr17C = expr176 + 1; expr175.whiteCount = expr17C; if (V_5) { - IL__dup(@this); + IL__dup(this); object expr188 = expr187.whiteFrontierCount; int expr18E = expr188 + 1; expr187.whiteFrontierCount = expr18E; } - if (@this.safeDiscs.Get(i, j)) { - IL__dup(@this); + if (safeDiscs.Get(i, j)) { + IL__dup(this); object expr1A5 = expr1A4.whiteSafeCount; int expr1AB = expr1A5 + 1; expr1A4.whiteSafeCount = expr1AB; @@ -186,7 +186,7 @@ namespace Reversi goto BasicBlock_313; } } - IL__dup(@this); + IL__dup(this); object expr1B5 = expr1B4.emptyCount; int expr1BB = expr1B5 + 1; expr1B4.emptyCount = expr1BB; @@ -197,28 +197,28 @@ namespace Reversi } private bool IsOutflankable(int row, int col) { - int i = @this.squares.Get(row, col); + int i = squares.Get(row, col); bool V_3 = 0; bool V_5 = 0; bool V_4 = 0; bool V_6 = 0; for (int k = 0; k < col && !V_3; k = k + 1) { - if (!(@this.squares.Get(row, k) != IL__ldsfld(Empty))) { + if (!(squares.Get(row, k) != IL__ldsfld(Empty))) { V_3 = 1; } else { - if (@this.squares.Get(row, k) != i || !@this.safeDiscs.Get(row, k)) { + if (squares.Get(row, k) != i || !safeDiscs.Get(row, k)) { V_5 = 1; } } } k = col + 1; for (; k < 8 && !V_4; k = k + 1) { - if (!(@this.squares.Get(row, k) != IL__ldsfld(Empty))) { + if (!(squares.Get(row, k) != IL__ldsfld(Empty))) { V_4 = 1; } else { - if (@this.squares.Get(row, k) != i || !@this.safeDiscs.Get(row, k)) { + if (squares.Get(row, k) != i || !safeDiscs.Get(row, k)) { V_6 = 1; } } @@ -231,22 +231,22 @@ namespace Reversi V_5 = 0; V_6 = 0; for (int j = 0; j < row && !V_3; j = j + 1) { - if (!(@this.squares.Get(j, col) != IL__ldsfld(Empty))) { + if (!(squares.Get(j, col) != IL__ldsfld(Empty))) { V_3 = 1; } else { - if (@this.squares.Get(j, col) != i || !@this.safeDiscs.Get(j, col)) { + if (squares.Get(j, col) != i || !safeDiscs.Get(j, col)) { V_5 = 1; } } } j = row + 1; for (; j < 8 && !V_4; j = j + 1) { - if (!(@this.squares.Get(j, col) != IL__ldsfld(Empty))) { + if (!(squares.Get(j, col) != IL__ldsfld(Empty))) { V_4 = 1; } else { - if (@this.squares.Get(j, col) != i || !@this.safeDiscs.Get(j, col)) { + if (squares.Get(j, col) != i || !safeDiscs.Get(j, col)) { V_6 = 1; } } @@ -261,11 +261,11 @@ namespace Reversi j = row - 1; k = col - 1; for (; j >= 0 && k >= 0 && !V_3; k = k - 1) { - if (!(@this.squares.Get(j, k) != IL__ldsfld(Empty))) { + if (!(squares.Get(j, k) != IL__ldsfld(Empty))) { V_3 = 1; } else { - if (@this.squares.Get(j, k) != i || !@this.safeDiscs.Get(j, k)) { + if (squares.Get(j, k) != i || !safeDiscs.Get(j, k)) { V_5 = 1; } } @@ -274,11 +274,11 @@ namespace Reversi j = row + 1; k = col + 1; for (; j < 8 && k < 8 && !V_4; k = k + 1) { - if (!(@this.squares.Get(j, k) != IL__ldsfld(Empty))) { + if (!(squares.Get(j, k) != IL__ldsfld(Empty))) { V_4 = 1; } else { - if (@this.squares.Get(j, k) != i || !@this.safeDiscs.Get(j, k)) { + if (squares.Get(j, k) != i || !safeDiscs.Get(j, k)) { V_6 = 1; } } @@ -294,11 +294,11 @@ namespace Reversi j = row - 1; k = col + 1; for (; j >= 0 && k < 8 && !V_3; k = k + 1) { - if (!(@this.squares.Get(j, k) != IL__ldsfld(Empty))) { + if (!(squares.Get(j, k) != IL__ldsfld(Empty))) { V_3 = 1; } else { - if (@this.squares.Get(j, k) != i || !@this.safeDiscs.Get(j, k)) { + if (squares.Get(j, k) != i || !safeDiscs.Get(j, k)) { V_5 = 1; } } @@ -307,11 +307,11 @@ namespace Reversi j = row + 1; k = col - 1; for (; j < 8 && k >= 0 && !V_4; k = k - 1) { - if (!(@this.squares.Get(j, k) != IL__ldsfld(Empty))) { + if (!(squares.Get(j, k) != IL__ldsfld(Empty))) { V_4 = 1; } else { - if (@this.squares.Get(j, k) != i || !@this.safeDiscs.Get(j, k)) { + if (squares.Get(j, k) != i || !safeDiscs.Get(j, k)) { V_6 = 1; } } diff --git a/src/AstBuilder.cs b/src/AstBuilder.cs index aed11cb85..98f74e0be 100644 --- a/src/AstBuilder.cs +++ b/src/AstBuilder.cs @@ -31,7 +31,6 @@ namespace Decompiler astCompileUnit.AcceptVisitor(new Transforms.Ast.RestoreLoop(), null); } if (Options.ReduceAstOther) { - astCompileUnit.AcceptVisitor(new Transforms.Ast.SimplifyTypeReferences(), null); astCompileUnit.AcceptVisitor(new Transforms.Ast.Idioms(), null); astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveEmptyElseBody(), null); astCompileUnit.AcceptVisitor(new Transforms.Ast.PushNegation(), null); @@ -42,6 +41,7 @@ namespace Decompiler if (Options.ReduceAstOther) { astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveParenthesis(), null); astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveParenthesis(), null); + astCompileUnit.AcceptVisitor(new Transforms.Ast.SimplifyTypeReferences(), null); } if (Options.ReduceAstLoops) { astCompileUnit.AcceptVisitor(new Transforms.Ast.RestoreLoop(), null); diff --git a/src/AstMetodBodyBuilder.cs b/src/AstMetodBodyBuilder.cs index de5a54e72..4ed625763 100644 --- a/src/AstMetodBodyBuilder.cs +++ b/src/AstMetodBodyBuilder.cs @@ -487,7 +487,12 @@ namespace Decompiler case Code.Initobj: throw new NotImplementedException(); case Code.Isinst: throw new NotImplementedException(); case Code.Jmp: throw new NotImplementedException(); - case Code.Ldarg: return new Ast.IdentifierExpression(((ParameterDefinition)operand).Name); + case Code.Ldarg: + if (methodDef.HasThis && ((ParameterDefinition)operand).Sequence == 0) { + return new Ast.ThisReferenceExpression(); + } else { + return new Ast.IdentifierExpression(((ParameterDefinition)operand).Name); + } case Code.Ldarga: throw new NotImplementedException(); case Code.Ldc_I4: case Code.Ldc_I8: diff --git a/src/Transforms/Ast/RemoveParenthesis.cs b/src/Transforms/Ast/RemoveParenthesis.cs index 1c67c0afc..4c929cc51 100644 --- a/src/Transforms/Ast/RemoveParenthesis.cs +++ b/src/Transforms/Ast/RemoveParenthesis.cs @@ -13,6 +13,7 @@ namespace Decompiler.Transforms.Ast // The following do not need to be parenthesized if (parenthesizedExpression.Expression is IdentifierExpression || parenthesizedExpression.Expression is PrimitiveExpression || + parenthesizedExpression.Expression is ThisReferenceExpression || parenthesizedExpression.Expression is ParenthesizedExpression) { ReplaceCurrentNode(parenthesizedExpression.Expression); return null; diff --git a/src/Transforms/Ast/SimplifyTypeReferences.cs b/src/Transforms/Ast/SimplifyTypeReferences.cs index d1686e895..a1fe547dd 100644 --- a/src/Transforms/Ast/SimplifyTypeReferences.cs +++ b/src/Transforms/Ast/SimplifyTypeReferences.cs @@ -31,6 +31,10 @@ namespace Decompiler.Transforms.Ast return null; } } + if (memberReferenceExpression.TargetObject is ThisReferenceExpression) { + ReplaceCurrentNode(new IdentifierExpression(memberReferenceExpression.MemberName)); + return null; + } return base.VisitMemberReferenceExpression(memberReferenceExpression, data); }