Browse Source

ldsfld

stsfld
pull/1/head^2
David Srbecký 18 years ago
parent
commit
3f268ec44f
  1. 38
      bin/Debug/output.cs
  2. 12
      src/AstMetodBodyBuilder.cs
  3. 3
      src/Transforms/Ast/RemoveParenthesis.cs
  4. 11
      src/Transforms/Ast/SimplifyTypeReferences.cs

38
bin/Debug/output.cs

@ -33,14 +33,14 @@ namespace Reversi
{ {
for (int i = 0; i < 8; i = i + 1) { for (int i = 0; i < 8; i = i + 1) {
for (int j = 0; j < 8; j = j + 1) { for (int j = 0; j < 8; j = j + 1) {
squares.Set(i, j, IL__ldsfld(Empty)); squares.Set(i, j, Empty);
safeDiscs.Set(i, j, 0); safeDiscs.Set(i, j, 0);
} }
} }
squares.Set(3, 3, IL__ldsfld(White)); squares.Set(3, 3, White);
squares.Set(3, 4, IL__ldsfld(Black)); squares.Set(3, 4, Black);
squares.Set(4, 3, IL__ldsfld(Black)); squares.Set(4, 3, Black);
squares.Set(4, 4, IL__ldsfld(White)); squares.Set(4, 4, White);
UpdateCounts(); UpdateCounts();
} }
public int GetSquareContents(int row, int col) public int GetSquareContents(int row, int col)
@ -76,7 +76,7 @@ namespace Reversi
} }
public bool IsValidMove(int color, int row, int col) public bool IsValidMove(int color, int row, int col)
{ {
if (!(squares.Get(row, col) == IL__ldsfld(Empty))) { if (squares.Get(row, col) != Empty) {
return 0; return 0;
} }
for (int i = -1; i <= 1; i = i + 1) { for (int i = -1; i <= 1; i = i + 1) {
@ -124,7 +124,7 @@ namespace Reversi
V_2 = 0; V_2 = 0;
for (int i = 0; i < 8; i = i + 1) { for (int i = 0; i < 8; i = i + 1) {
for (int j = 0; j < 8; j = j + 1) { for (int j = 0; j < 8; j = j + 1) {
if (!(squares.Get(i, j) == IL__ldsfld(Empty)) && !safeDiscs.Get(i, j) && !IsOutflankable(i, j)) { if (squares.Get(i, j) != Empty && !safeDiscs.Get(i, j) && !IsOutflankable(i, j)) {
safeDiscs.Set(i, j, 1); safeDiscs.Set(i, j, 1);
V_2 = 1; V_2 = 1;
} }
@ -136,16 +136,16 @@ namespace Reversi
j = 0; j = 0;
for (; j < 8; j = j + 1) { for (; j < 8; j = j + 1) {
bool V_5 = 0; bool V_5 = 0;
if (!(squares.Get(i, j) == IL__ldsfld(Empty))) { if (squares.Get(i, j) != Empty) {
for (int k = -1; k <= 1; k = k + 1) { for (int k = -1; k <= 1; k = k + 1) {
for (int l = -1; l <= 1; l = l + 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 && !(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) == Empty) {
V_5 = 1; V_5 = 1;
} }
} }
} }
} }
if (!(squares.Get(i, j) != IL__ldsfld(Black))) { if (squares.Get(i, j) == Black) {
IL__dup(this); IL__dup(this);
object expr123 = expr122.blackCount; object expr123 = expr122.blackCount;
int expr129 = expr123 + 1; int expr129 = expr123 + 1;
@ -164,7 +164,7 @@ namespace Reversi
} }
} }
else { else {
if (!(squares.Get(i, j) != IL__ldsfld(White))) { if (squares.Get(i, j) == White) {
IL__dup(this); IL__dup(this);
object expr176 = expr175.whiteCount; object expr176 = expr175.whiteCount;
int expr17C = expr176 + 1; int expr17C = expr176 + 1;
@ -203,7 +203,7 @@ namespace Reversi
bool V_4 = 0; bool V_4 = 0;
bool V_6 = 0; bool V_6 = 0;
for (int k = 0; k < col && !V_3; k = k + 1) { for (int k = 0; k < col && !V_3; k = k + 1) {
if (!(squares.Get(row, k) != IL__ldsfld(Empty))) { if (squares.Get(row, k) == Empty) {
V_3 = 1; V_3 = 1;
} }
else { else {
@ -214,7 +214,7 @@ namespace Reversi
} }
k = col + 1; k = col + 1;
for (; k < 8 && !V_4; k = k + 1) { for (; k < 8 && !V_4; k = k + 1) {
if (!(squares.Get(row, k) != IL__ldsfld(Empty))) { if (squares.Get(row, k) == Empty) {
V_4 = 1; V_4 = 1;
} }
else { else {
@ -231,7 +231,7 @@ namespace Reversi
V_5 = 0; V_5 = 0;
V_6 = 0; V_6 = 0;
for (int j = 0; j < row && !V_3; j = j + 1) { for (int j = 0; j < row && !V_3; j = j + 1) {
if (!(squares.Get(j, col) != IL__ldsfld(Empty))) { if (squares.Get(j, col) == Empty) {
V_3 = 1; V_3 = 1;
} }
else { else {
@ -242,7 +242,7 @@ namespace Reversi
} }
j = row + 1; j = row + 1;
for (; j < 8 && !V_4; j = j + 1) { for (; j < 8 && !V_4; j = j + 1) {
if (!(squares.Get(j, col) != IL__ldsfld(Empty))) { if (squares.Get(j, col) == Empty) {
V_4 = 1; V_4 = 1;
} }
else { else {
@ -261,7 +261,7 @@ namespace Reversi
j = row - 1; j = row - 1;
k = col - 1; k = col - 1;
for (; j >= 0 && k >= 0 && !V_3; k = k - 1) { for (; j >= 0 && k >= 0 && !V_3; k = k - 1) {
if (!(squares.Get(j, k) != IL__ldsfld(Empty))) { if (squares.Get(j, k) == Empty) {
V_3 = 1; V_3 = 1;
} }
else { else {
@ -274,7 +274,7 @@ namespace Reversi
j = row + 1; j = row + 1;
k = col + 1; k = col + 1;
for (; j < 8 && k < 8 && !V_4; k = k + 1) { for (; j < 8 && k < 8 && !V_4; k = k + 1) {
if (!(squares.Get(j, k) != IL__ldsfld(Empty))) { if (squares.Get(j, k) == Empty) {
V_4 = 1; V_4 = 1;
} }
else { else {
@ -294,7 +294,7 @@ namespace Reversi
j = row - 1; j = row - 1;
k = col + 1; k = col + 1;
for (; j >= 0 && k < 8 && !V_3; k = k + 1) { for (; j >= 0 && k < 8 && !V_3; k = k + 1) {
if (!(squares.Get(j, k) != IL__ldsfld(Empty))) { if (squares.Get(j, k) == Empty) {
V_3 = 1; V_3 = 1;
} }
else { else {
@ -307,7 +307,7 @@ namespace Reversi
j = row + 1; j = row + 1;
k = col - 1; k = col - 1;
for (; j < 8 && k >= 0 && !V_4; k = k - 1) { for (; j < 8 && k >= 0 && !V_4; k = k - 1) {
if (!(squares.Get(j, k) != IL__ldsfld(Empty))) { if (squares.Get(j, k) == Empty) {
V_4 = 1; V_4 = 1;
} }
else { else {

12
src/AstMetodBodyBuilder.cs

@ -498,7 +498,8 @@ namespace Decompiler
case Code.Ldc_I8: case Code.Ldc_I8:
case Code.Ldc_R4: case Code.Ldc_R4:
case Code.Ldc_R8: return new Ast.PrimitiveExpression(operand, null); case Code.Ldc_R8: return new Ast.PrimitiveExpression(operand, null);
case Code.Ldfld: { case Code.Ldfld:
case Code.Ldsfld: {
FieldDefinition field = (FieldDefinition) operand; FieldDefinition field = (FieldDefinition) operand;
if (field.IsStatic) { if (field.IsStatic) {
return new Ast.MemberReferenceExpression( return new Ast.MemberReferenceExpression(
@ -509,7 +510,8 @@ namespace Decompiler
return new Ast.MemberReferenceExpression(arg1, field.Name); return new Ast.MemberReferenceExpression(arg1, field.Name);
} }
} }
case Code.Stfld: { case Code.Stfld:
case Code.Stsfld: {
FieldDefinition field = (FieldDefinition) operand; FieldDefinition field = (FieldDefinition) operand;
if (field.IsStatic) { if (field.IsStatic) {
return new AssignmentExpression( return new AssignmentExpression(
@ -528,14 +530,13 @@ namespace Decompiler
); );
} }
} }
case Code.Ldflda: throw new NotImplementedException(); case Code.Ldflda:
case Code.Ldsflda: throw new NotImplementedException();
case Code.Ldftn: throw new NotImplementedException(); case Code.Ldftn: throw new NotImplementedException();
case Code.Ldloc: return new Ast.IdentifierExpression(((VariableDefinition)operand).Name); case Code.Ldloc: return new Ast.IdentifierExpression(((VariableDefinition)operand).Name);
case Code.Ldloca: throw new NotImplementedException(); case Code.Ldloca: throw new NotImplementedException();
case Code.Ldnull: return new Ast.PrimitiveExpression(null, null); case Code.Ldnull: return new Ast.PrimitiveExpression(null, null);
case Code.Ldobj: throw new NotImplementedException(); case Code.Ldobj: throw new NotImplementedException();
case Code.Ldsfld: throw new NotImplementedException();
case Code.Ldsflda: throw new NotImplementedException();
case Code.Ldstr: return new Ast.PrimitiveExpression(operand, null); case Code.Ldstr: return new Ast.PrimitiveExpression(operand, null);
case Code.Ldtoken: case Code.Ldtoken:
if (operand is Cecil.TypeReference) { if (operand is Cecil.TypeReference) {
@ -578,7 +579,6 @@ namespace Decompiler
return astLocalVar; return astLocalVar;
} }
case Code.Stobj: throw new NotImplementedException(); case Code.Stobj: throw new NotImplementedException();
case Code.Stsfld: throw new NotImplementedException();
case Code.Switch: throw new NotImplementedException(); case Code.Switch: throw new NotImplementedException();
case Code.Tail: throw new NotImplementedException(); case Code.Tail: throw new NotImplementedException();
case Code.Throw: throw new NotImplementedException(); case Code.Throw: throw new NotImplementedException();

3
src/Transforms/Ast/RemoveParenthesis.cs

@ -61,6 +61,9 @@ namespace Decompiler.Transforms.Ast
if (GetPrecedence(invocation.TargetObject) >= GetPrecedence(invocation)) { if (GetPrecedence(invocation.TargetObject) >= GetPrecedence(invocation)) {
invocation.TargetObject = Deparenthesize(invocation.TargetObject); invocation.TargetObject = Deparenthesize(invocation.TargetObject);
} }
for(int i = 0; i < invocation.Arguments.Count; i++) {
invocation.Arguments[i] = Deparenthesize(invocation.Arguments[i]);
}
return base.VisitInvocationExpression(invocation, data); return base.VisitInvocationExpression(invocation, data);
} }

11
src/Transforms/Ast/SimplifyTypeReferences.cs

@ -8,11 +8,20 @@ namespace Decompiler.Transforms.Ast
{ {
public class SimplifyTypeReferences: AbstractAstTransformer public class SimplifyTypeReferences: AbstractAstTransformer
{ {
string currentNamepace = string.Empty;
string currentClass = null; string currentClass = null;
public override object VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data)
{
currentNamepace = namespaceDeclaration.Name;
base.VisitNamespaceDeclaration(namespaceDeclaration, data);
currentNamepace = string.Empty;
return null;
}
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{ {
currentClass = typeDeclaration.Name; currentClass = currentNamepace + "." + typeDeclaration.Name;
base.VisitTypeDeclaration(typeDeclaration, data); base.VisitTypeDeclaration(typeDeclaration, data);
currentClass = null; currentClass = null;
return null; return null;

Loading…
Cancel
Save