Browse Source

Apply the negation reduction twice.

Also handle expressions in from "!!a"
pull/1/head^2
David Srbecký 18 years ago
parent
commit
0d3dd5de44
  1. 26
      bin/Debug/output.cs
  2. 1
      src/AstBuilder.cs
  3. 10
      src/Transforms/Ast/PushNegation.cs

26
bin/Debug/output.cs

@ -106,7 +106,7 @@ namespace Reversi @@ -106,7 +106,7 @@ namespace Reversi
for (int j = (col + dc); ((((i >= 0) && (i < 8)) && (j >= 0)) && (j < 8)) && (((@this.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))) || (((@this.squares).Get(i, j)) != color))) {
return 0;
}
return 1;
@ -206,7 +206,7 @@ namespace Reversi @@ -206,7 +206,7 @@ namespace Reversi
V_3 = 1;
}
else {
if ((!(((@this.squares).Get(row, k)) == i) || !((@this.safeDiscs).Get(row, k)))) {
if (((((@this.squares).Get(row, k)) != i) || (!((@this.safeDiscs).Get(row, k))))) {
V_5 = 1;
}
}
@ -217,12 +217,12 @@ namespace Reversi @@ -217,12 +217,12 @@ namespace Reversi
V_4 = 1;
}
else {
if ((!(((@this.squares).Get(row, k)) == i) || !((@this.safeDiscs).Get(row, k)))) {
if (((((@this.squares).Get(row, k)) != i) || (!((@this.safeDiscs).Get(row, k))))) {
V_6 = 1;
}
}
}
if (((!(!V_3 || !V_4) || !(!V_3 || !V_6)) || (V_5 && V_4))) {
if ((((V_3 && V_4) || (V_3 && V_6)) || (V_5 && V_4))) {
return 1;
}
V_3 = 0;
@ -234,7 +234,7 @@ namespace Reversi @@ -234,7 +234,7 @@ namespace Reversi
V_3 = 1;
}
else {
if ((!(((@this.squares).Get(j, col)) == i) || !((@this.safeDiscs).Get(j, col)))) {
if (((((@this.squares).Get(j, col)) != i) || (!((@this.safeDiscs).Get(j, col))))) {
V_5 = 1;
}
}
@ -245,12 +245,12 @@ namespace Reversi @@ -245,12 +245,12 @@ namespace Reversi
V_4 = 1;
}
else {
if ((!(((@this.squares).Get(j, col)) == i) || !((@this.safeDiscs).Get(j, col)))) {
if (((((@this.squares).Get(j, col)) != i) || (!((@this.safeDiscs).Get(j, col))))) {
V_6 = 1;
}
}
}
if (((!(!V_3 || !V_4) || !(!V_3 || !V_6)) || (V_5 && V_4))) {
if ((((V_3 && V_4) || (V_3 && V_6)) || (V_5 && V_4))) {
return 1;
}
V_3 = 0;
@ -264,7 +264,7 @@ namespace Reversi @@ -264,7 +264,7 @@ namespace Reversi
V_3 = 1;
}
else {
if ((!(((@this.squares).Get(j, k)) == i) || !((@this.safeDiscs).Get(j, k)))) {
if (((((@this.squares).Get(j, k)) != i) || (!((@this.safeDiscs).Get(j, k))))) {
V_5 = 1;
}
}
@ -277,13 +277,13 @@ namespace Reversi @@ -277,13 +277,13 @@ namespace Reversi
V_4 = 1;
}
else {
if ((!(((@this.squares).Get(j, k)) == i) || !((@this.safeDiscs).Get(j, k)))) {
if (((((@this.squares).Get(j, k)) != i) || (!((@this.safeDiscs).Get(j, k))))) {
V_6 = 1;
}
}
j = (j + 1);
}
if (((!(!V_3 || !V_4) || !(!V_3 || !V_6)) || (V_5 && V_4))) {
if ((((V_3 && V_4) || (V_3 && V_6)) || (V_5 && V_4))) {
return 1;
}
V_3 = 0;
@ -297,7 +297,7 @@ namespace Reversi @@ -297,7 +297,7 @@ namespace Reversi
V_3 = 1;
}
else {
if ((!(((@this.squares).Get(j, k)) == i) || !((@this.safeDiscs).Get(j, k)))) {
if (((((@this.squares).Get(j, k)) != i) || (!((@this.safeDiscs).Get(j, k))))) {
V_5 = 1;
}
}
@ -310,13 +310,13 @@ namespace Reversi @@ -310,13 +310,13 @@ namespace Reversi
V_4 = 1;
}
else {
if ((!(((@this.squares).Get(j, k)) == i) || !((@this.safeDiscs).Get(j, k)))) {
if (((((@this.squares).Get(j, k)) != i) || (!((@this.safeDiscs).Get(j, k))))) {
V_6 = 1;
}
}
j = (j + 1);
}
if (((!(!V_3 || !V_4) || !(!V_3 || !V_6)) || (V_5 && V_4))) {
if ((((V_3 && V_4) || (V_3 && V_6)) || (V_5 && V_4))) {
return 1;
}
return 0;

1
src/AstBuilder.cs

@ -35,6 +35,7 @@ namespace Decompiler @@ -35,6 +35,7 @@ namespace Decompiler
astCompileUnit.AcceptVisitor(new Transforms.Ast.Idioms(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveEmptyElseBody(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.PushNegation(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.PushNegation(), null);
astCompileUnit.AcceptVisitor(new Transforms.Ast.RemoveParenthesis(), null);
}
}

10
src/Transforms/Ast/PushNegation.cs

@ -10,6 +10,16 @@ namespace Decompiler.Transforms.Ast @@ -10,6 +10,16 @@ namespace Decompiler.Transforms.Ast
{
public override object VisitUnaryOperatorExpression(UnaryOperatorExpression unary, object data)
{
// Remove double negation
// !!a
if (unary.Op == UnaryOperatorType.Not &&
unary.Expression is UnaryOperatorExpression &&
(unary.Expression as UnaryOperatorExpression).Op == UnaryOperatorType.Not) {
Expression newParenth = new ParenthesizedExpression((unary.Expression as UnaryOperatorExpression).Expression);
ReplaceCurrentNode(newParenth);
return newParenth.AcceptVisitor(this, data);
}
// Basic assumtion is that we have something in form !(a)
if (unary.Op == UnaryOperatorType.Not &&
unary.Expression is ParenthesizedExpression) {

Loading…
Cancel
Save