Example #1
0
 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);
     }
 }
Example #2
0
        private static void WriteNestedExpression(this IndentedTextWriter writer, int parentPrecedence, int currentPrecedence, BoundExpression expression)
        {
            var needsParenthesis = parentPrecedence >= currentPrecedence;

            if (needsParenthesis)
            {
                writer.WritePunctuation("(");
            }

            expression.WriteTo(writer);

            if (needsParenthesis)
            {
                writer.WritePunctuation(")");
            }
        }
 public BoundUnaryExpression(BoundUnaryOperator op, BoundExpression operand)
 {
     this.op = op;
     Operand = operand;
 }