Browse Source

Constructors of multidimensional arrays.

Typing for setting an element of multidimensional array.
pull/1/head^2
David Srbecký 18 years ago
parent
commit
7b93f5762b
  1. 14
      bin/Debug/output.cs
  2. 20
      src/AstMetodBodyBuilder.cs

14
bin/Debug/output.cs

@ -41,12 +41,12 @@ namespace Reversi
public Board()
{
// Constructor
squares = new System.Int32[,](8, 8);
safeDiscs = new System.Boolean[,](8, 8);
squares = new int[8, 8];
safeDiscs = new bool[8, 8];
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
squares[i, j] = Empty;
safeDiscs[i, j] = 0;
safeDiscs[i, j] = false;
}
}
UpdateCounts();
@ -55,8 +55,8 @@ namespace Reversi
public Board(Reversi.Board board)
{
// Constructor
squares = new System.Int32[,](8, 8);
safeDiscs = new System.Boolean[,](8, 8);
squares = new int[8, 8];
safeDiscs = new bool[8, 8];
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
squares[i, j] = board.squares[i, j];
@ -82,7 +82,7 @@ namespace Reversi
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
squares[i, j] = Empty;
safeDiscs[i, j] = 0;
safeDiscs[i, j] = false;
}
}
squares[3, 3] = White;
@ -180,7 +180,7 @@ namespace Reversi
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (squares[i, j] != Empty && !safeDiscs[i, j] && !IsOutflankable(i, j)) {
safeDiscs[i, j] = 1;
safeDiscs[i, j] = true;
flag = true;
}
}

20
src/AstMetodBodyBuilder.cs

@ -484,7 +484,7 @@ namespace Decompiler
return new Ast.AssignmentExpression(
new Ast.IndexerExpression(target, methodArgs),
AssignmentOperatorType.Assign,
val
Convert(val, ((Cecil.ArrayType)target.UserData["Type"]).ElementType)
);
}
@ -571,9 +571,16 @@ namespace Decompiler
case Code.Localloc: throw new NotImplementedException();
case Code.Mkrefany: throw new NotImplementedException();
case Code.Newobj:
Cecil.TypeReference declaringType = ((MethodReference)operand).DeclaringType;
// TODO: Ensure that the corrent overloaded constructor is called
if (declaringType is ArrayType) {
return new Ast.ArrayCreateExpression(
new Ast.TypeReference(((ArrayType)declaringType).ElementType.FullName, new int[] {}),
new List<Expression>(args)
);
}
return new Ast.ObjectCreateExpression(
new Ast.TypeReference(((MethodReference)operand).DeclaringType.FullName),
new Ast.TypeReference(declaringType.FullName),
new List<Expression>(args)
);
case Code.No: throw new NotImplementedException();
@ -624,15 +631,20 @@ namespace Decompiler
}
static Ast.Expression Convert(Ast.Expression expr, Cecil.TypeReference reqType)
{
return Convert(expr, reqType.FullName);
}
static Ast.Expression Convert(Ast.Expression expr, string reqType)
{
if (expr.UserData.ContainsKey("Type")) {
Cecil.TypeReference exprType = (Cecil.TypeReference)expr.UserData["Type"];
if (exprType == ByteCode.TypeZero &&
reqType.FullName == ByteCode.TypeBool.FullName) {
reqType == ByteCode.TypeBool.FullName) {
return new PrimitiveExpression(false, "false");
}
if (exprType == ByteCode.TypeOne &&
reqType.FullName == ByteCode.TypeBool.FullName) {
reqType == ByteCode.TypeBool.FullName) {
return new PrimitiveExpression(true, "true");
}
}

Loading…
Cancel
Save