private static void WriteNestedExpression(this IndentedTextWriter writer, int parentPrecedence, BoundExpression expression) { if (expression is BoundUnaryExpression unary) { writer.WriteNestedExpression(parentPrecedence, SyntaxFacts.GetUnaryOperatorPrecedence(unary.Op.SyntaxKind), unary); } else if (expression is BoundBinaryExpression binary) { writer.WriteNestedExpression(parentPrecedence, SyntaxFacts.GetBinaryOperatorPrecedence(binary.Op.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); } }