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