Browse Source

Generate property getters and setters.

Insert empty lines between generated methods.
pull/1/head^2
David Srbecký 18 years ago
parent
commit
9d1705486d
  1. 23
      bin/Debug/output.cs
  2. 48
      src/AstBuilder.cs

23
bin/Debug/output.cs

@ -15,20 +15,29 @@ namespace Reversi
private int whiteSafeCount; private int whiteSafeCount;
private System.Int32[,] squares; private System.Int32[,] squares;
private System.Boolean[,] safeDiscs; private System.Boolean[,] safeDiscs;
public int BlackCount { public int BlackCount {
get { return blackCount; }
} }
public int WhiteCount { public int WhiteCount {
get { return whiteCount; }
} }
public int EmptyCount { public int EmptyCount {
get { return emptyCount; }
} }
public int BlackFrontierCount { public int BlackFrontierCount {
get { return blackFrontierCount; }
} }
public int WhiteFrontierCount { public int WhiteFrontierCount {
get { return whiteFrontierCount; }
} }
public int BlackSafeCount { public int BlackSafeCount {
get { return blackSafeCount; }
} }
public int WhiteSafeCount { public int WhiteSafeCount {
get { return whiteSafeCount; }
} }
public void SetForNewGame() public void SetForNewGame()
{ {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
@ -43,10 +52,12 @@ namespace Reversi
squares[4, 4] = White; squares[4, 4] = White;
UpdateCounts(); UpdateCounts();
} }
public int GetSquareContents(int row, int col) public int GetSquareContents(int row, int col)
{ {
return squares[row, col]; return squares[row, col];
} }
public void MakeMove(int color, int row, int col) public void MakeMove(int color, int row, int col)
{ {
squares[row, col] = color; squares[row, col] = color;
@ -63,6 +74,7 @@ namespace Reversi
} }
UpdateCounts(); UpdateCounts();
} }
public bool HasAnyValidMove(int color) public bool HasAnyValidMove(int color)
{ {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
@ -74,6 +86,7 @@ namespace Reversi
} }
return 0; return 0;
} }
public bool IsValidMove(int color, int row, int col) public bool IsValidMove(int color, int row, int col)
{ {
if (squares[row, col] != Empty) { if (squares[row, col] != Empty) {
@ -88,6 +101,7 @@ namespace Reversi
} }
return 0; return 0;
} }
public int GetValidMoveCount(int color) public int GetValidMoveCount(int color)
{ {
int i = 0; int i = 0;
@ -100,6 +114,7 @@ namespace Reversi
} }
return i; return i;
} }
private bool IsOutflanking(int color, int row, int col, int dr, int dc) private bool IsOutflanking(int color, int row, int col, int dr, int dc)
{ {
int i = row + dr; int i = row + dr;
@ -111,6 +126,7 @@ namespace Reversi
} }
return 1; return 1;
} }
private void UpdateCounts() private void UpdateCounts()
{ {
blackCount = 0; blackCount = 0;
@ -180,10 +196,10 @@ namespace Reversi
object expr1A5 = expr1A4.whiteSafeCount; object expr1A5 = expr1A4.whiteSafeCount;
int expr1AB = expr1A5 + 1; int expr1AB = expr1A5 + 1;
expr1A4.whiteSafeCount = expr1AB; expr1A4.whiteSafeCount = expr1AB;
goto BasicBlock_313; goto BasicBlock_327;
} }
else { else {
goto BasicBlock_313; goto BasicBlock_327;
} }
} }
IL__dup(this); IL__dup(this);
@ -191,10 +207,11 @@ namespace Reversi
int expr1BB = expr1B5 + 1; int expr1BB = expr1B5 + 1;
expr1B4.emptyCount = expr1BB; expr1B4.emptyCount = expr1BB;
} }
BasicBlock_313: BasicBlock_327:
} }
} }
} }
private bool IsOutflankable(int row, int col) private bool IsOutflankable(int row, int col)
{ {
int i = squares[row, col]; int i = squares[row, col];

48
src/AstBuilder.cs

@ -215,6 +215,24 @@ namespace Decompiler
astType.Children.Add(astField); astType.Children.Add(astField);
} }
if (typeDef.Fields.Count > 0) {
astType.Children.Add(new IdentifierExpression("\n"));
}
// Add events
foreach(EventDefinition eventDef in typeDef.Events) {
Ast.EventDeclaration astEvent = new Ast.EventDeclaration();
astEvent.Name = eventDef.Name;
astEvent.TypeReference = new Ast.TypeReference(eventDef.EventType.FullName);
astEvent.Modifier = ConvertModifiers(eventDef.AddMethod);
astType.Children.Add(astEvent);
}
if (typeDef.Events.Count > 0) {
astType.Children.Add(new IdentifierExpression("\n"));
}
// Add properties // Add properties
foreach(PropertyDefinition propDef in typeDef.Properties) { foreach(PropertyDefinition propDef in typeDef.Properties) {
Ast.PropertyDeclaration astProp = new Ast.PropertyDeclaration( Ast.PropertyDeclaration astProp = new Ast.PropertyDeclaration(
@ -224,18 +242,28 @@ namespace Decompiler
new List<ParameterDeclarationExpression>() new List<ParameterDeclarationExpression>()
); );
astProp.TypeReference = new Ast.TypeReference(propDef.PropertyType.FullName); astProp.TypeReference = new Ast.TypeReference(propDef.PropertyType.FullName);
if (propDef.GetMethod != null) {
astProp.GetRegion = new PropertyGetRegion(
AstMetodBodyBuilder.CreateMetodBody(propDef.GetMethod),
new List<AttributeSection>()
);
}
if (propDef.SetMethod != null) {
astProp.SetRegion = new PropertySetRegion(
AstMetodBodyBuilder.CreateMetodBody(propDef.SetMethod),
new List<AttributeSection>()
);
}
astType.Children.Add(astProp); astType.Children.Add(astProp);
} }
foreach(EventDefinition eventDef in typeDef.Events) { if (typeDef.Properties.Count > 0) {
Ast.EventDeclaration astEvent = new Ast.EventDeclaration(); astType.Children.Add(new IdentifierExpression("\n"));
astEvent.Name = eventDef.Name;
astEvent.TypeReference = new Ast.TypeReference(eventDef.EventType.FullName);
astEvent.Modifier = ConvertModifiers(eventDef.AddMethod);
astType.Children.Add(astEvent);
} }
// Add methods
foreach(MethodDefinition methodDef in typeDef.Methods) { foreach(MethodDefinition methodDef in typeDef.Methods) {
if (methodDef.IsSpecialName) continue; if (methodDef.IsSpecialName) continue;
@ -260,6 +288,12 @@ namespace Decompiler
astMethod.Body = AstMetodBodyBuilder.CreateMetodBody(methodDef); astMethod.Body = AstMetodBodyBuilder.CreateMetodBody(methodDef);
astType.Children.Add(astMethod); astType.Children.Add(astMethod);
astType.Children.Add(new IdentifierExpression("\n"));
}
if (astType.Children.Last is IdentifierExpression) {
astType.Children.Last.Remove();
} }
} }
} }

Loading…
Cancel
Save