private static void WriteNestedExpression(this IndentedTextWriter writer, int parentPrecedence, BoundExpression expression) { if (expression is BoundUnaryExpression unary) { writer.WriteNestedExpression(parentPrecedence, SyntaxFacts.GetUnaryOperatorPrecedence(unary.Operator.SyntaxKind), unary); } else if (expression is BoundBinaryExpression binary) { writer.WriteNestedExpression(parentPrecedence, SyntaxFacts.GetBinaryOperatorPrecedence(binary.Operator.SyntaxKind), binary); } else { expression.WriteTo(writer); } }
private static void WriteNestedExpression(this IndentedTextWriter writer, int parentPrecedence, int currentPrecedence, BoundExpression expression) { var needsParenthesis = parentPrecedence >= currentPrecedence; if (needsParenthesis) { writer.WritePunctuation(SyntaxKind.OpenParenthesisToken); } expression.WriteTo(writer); if (needsParenthesis) { writer.WritePunctuation(SyntaxKind.CloseParenthesisToken); } }