ZoneCodeGenerator: Add toString methods for operands and operations for debugging purposes

This commit is contained in:
Jan 2019-11-08 03:00:43 +01:00
parent 6c1404116c
commit 2bcb776bbf
3 changed files with 38 additions and 0 deletions

View File

@ -13,5 +13,10 @@ namespace ZoneCodeGenerator.Domain.Evaluation
{ {
throw new Exception("A dynamic operand cannot be evaluated."); throw new Exception("A dynamic operand cannot be evaluated.");
} }
public override string ToString()
{
return "dynamic";
}
} }
} }

View File

@ -20,5 +20,10 @@ namespace ZoneCodeGenerator.Domain.Evaluation
{ {
Value = value; Value = value;
} }
public override string ToString()
{
return Value.ToString();
}
} }
} }

View File

@ -25,5 +25,33 @@ namespace ZoneCodeGenerator.Domain.Evaluation
Operand2 = operand2; Operand2 = operand2;
OperationType = type; OperationType = type;
} }
public override string ToString()
{
string operand1String;
string operand2String;
if (Operand1 is Operation operation1
&& operation1.OperationType.Precedence > OperationType.Precedence)
{
operand1String = $"({Operand1})";
}
else
{
operand1String = Operand1.ToString();
}
if (Operand2 is Operation operation2
&& operation2.OperationType.Precedence > OperationType.Precedence)
{
operand2String = $"({Operand2})";
}
else
{
operand2String = Operand2.ToString();
}
return $"{operand1String} {OperationType} {operand2String}";
}
} }
} }