diff --git a/src/ZoneCodeGenerator/Domain/Evaluation/OperandDynamic.cs b/src/ZoneCodeGenerator/Domain/Evaluation/OperandDynamic.cs index 54013162..e9bec194 100644 --- a/src/ZoneCodeGenerator/Domain/Evaluation/OperandDynamic.cs +++ b/src/ZoneCodeGenerator/Domain/Evaluation/OperandDynamic.cs @@ -13,5 +13,10 @@ namespace ZoneCodeGenerator.Domain.Evaluation { throw new Exception("A dynamic operand cannot be evaluated."); } + + public override string ToString() + { + return "dynamic"; + } } } diff --git a/src/ZoneCodeGenerator/Domain/Evaluation/OperandStatic.cs b/src/ZoneCodeGenerator/Domain/Evaluation/OperandStatic.cs index 0bcdfe35..42d39ac8 100644 --- a/src/ZoneCodeGenerator/Domain/Evaluation/OperandStatic.cs +++ b/src/ZoneCodeGenerator/Domain/Evaluation/OperandStatic.cs @@ -20,5 +20,10 @@ namespace ZoneCodeGenerator.Domain.Evaluation { Value = value; } + + public override string ToString() + { + return Value.ToString(); + } } } diff --git a/src/ZoneCodeGenerator/Domain/Evaluation/Operation.cs b/src/ZoneCodeGenerator/Domain/Evaluation/Operation.cs index ef031984..3ae2afab 100644 --- a/src/ZoneCodeGenerator/Domain/Evaluation/Operation.cs +++ b/src/ZoneCodeGenerator/Domain/Evaluation/Operation.cs @@ -25,5 +25,33 @@ namespace ZoneCodeGenerator.Domain.Evaluation Operand2 = operand2; 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}"; + } } }