From f80d661c1ba4ec47fabf9f4c85489b05d774405d Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 14 Nov 2019 14:59:21 +0100 Subject: [PATCH] ZoneCodeGenerator: Add helper methods to Operation for the template engine to know whether parenthesis are required or not --- src/ZoneCodeGenerator/Domain/Evaluation/Operation.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ZoneCodeGenerator/Domain/Evaluation/Operation.cs b/src/ZoneCodeGenerator/Domain/Evaluation/Operation.cs index 3ae2afab..312dfafb 100644 --- a/src/ZoneCodeGenerator/Domain/Evaluation/Operation.cs +++ b/src/ZoneCodeGenerator/Domain/Evaluation/Operation.cs @@ -9,7 +9,13 @@ namespace ZoneCodeGenerator.Domain.Evaluation class Operation : IEvaluation { public IEvaluation Operand1 { get; } + public bool Operand1NeedsParenthesis => Operand1 is Operation operation1 && + operation1.OperationType.Precedence > OperationType.Precedence; + public IEvaluation Operand2 { get; } + public bool Operand2NeedsParenthesis => Operand2 is Operation operation2 && + operation2.OperationType.Precedence > OperationType.Precedence; + public OperationType OperationType { get; } public bool IsStatic => Operand1.IsStatic && Operand2.IsStatic;