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

48
src/AstBuilder.cs

@ -215,6 +215,24 @@ namespace Decompiler @@ -215,6 +215,24 @@ namespace Decompiler
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
foreach(PropertyDefinition propDef in typeDef.Properties) {
Ast.PropertyDeclaration astProp = new Ast.PropertyDeclaration(
@ -224,18 +242,28 @@ namespace Decompiler @@ -224,18 +242,28 @@ namespace Decompiler
new List<ParameterDeclarationExpression>()
);
astProp.TypeReference = new Ast.TypeReference(propDef.PropertyType.FullName);
astType.Children.Add(astProp);
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>()
);
}
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(astProp);
}
astType.Children.Add(astEvent);
if (typeDef.Properties.Count > 0) {
astType.Children.Add(new IdentifierExpression("\n"));
}
// Add methods
foreach(MethodDefinition methodDef in typeDef.Methods) {
if (methodDef.IsSpecialName) continue;
@ -260,6 +288,12 @@ namespace Decompiler @@ -260,6 +288,12 @@ namespace Decompiler
astMethod.Body = AstMetodBodyBuilder.CreateMetodBody(methodDef);
astType.Children.Add(astMethod);
astType.Children.Add(new IdentifierExpression("\n"));
}
if (astType.Children.Last is IdentifierExpression) {
astType.Children.Last.Remove();
}
}
}

Loading…
Cancel
Save