Beispiel #1
0
 internal void And(VisitedExpression andAlso)
 {
     // useNewPrecedence doesn't matter here since there was no change with the AND operator
     _where = OperatorExpression.Build(Operator.And, true, _where, andAlso);
 }
Beispiel #2
0
 internal void And(VisitedExpression andAlso)
 {
     _where = OperatorExpression.Build(Operator.And, _where, andAlso);
 }
Beispiel #3
0
        private void WriteSql(StringBuilder sqlText, OperatorExpression rightParent)
        {
            OperatorExpression leftOp  = left as OperatorExpression;
            OperatorExpression rightOp = right as OperatorExpression;

            bool wrapLeft, wrapRight;

            if (!useNewPrecedences)
            {
                wrapLeft  = leftOp != null && (op.RightAssoc ? leftOp.op.RightPrecedence <= op.LeftPrecedence : leftOp.op.RightPrecedence < op.LeftPrecedence);
                wrapRight = rightOp != null && (!op.RightAssoc ? rightOp.op.LeftPrecedence <= op.RightPrecedence : rightOp.op.LeftPrecedence < op.RightPrecedence);
            }
            else
            {
                wrapLeft  = leftOp != null && (op.RightAssoc ? leftOp.op.NewPrecedence <= op.NewPrecedence : leftOp.op.NewPrecedence < op.NewPrecedence);
                wrapRight = rightOp != null && (!op.RightAssoc ? rightOp.op.NewPrecedence <= op.NewPrecedence : rightOp.op.NewPrecedence < op.NewPrecedence);
            }

            // Avoid parentheses for prefix operators if possible,
            // e.g. BitwiseNot: (a & (~ b)) & c is written as a & ~ b & c
            // but (a + (~ b)) + c must be written as a + (~ b) + c
            if (!useNewPrecedences)
            {
                if (wrapRight && rightOp.left == null && (rightParent == null || (!rightParent.op.RightAssoc ? rightOp.op.RightPrecedence >= rightParent.op.LeftPrecedence : rightOp.op.RightPrecedence > rightParent.op.LeftPrecedence)))
                {
                    wrapRight = false;
                }
            }
            else
            {
                if (wrapRight && rightOp.left == null && (rightParent == null || (!rightParent.op.RightAssoc ? rightOp.op.NewPrecedence >= rightParent.op.NewPrecedence : rightOp.op.NewPrecedence > rightParent.op.NewPrecedence)))
                {
                    wrapRight = false;
                }
            }

            if (left != null)
            {
                if (wrapLeft)
                {
                    sqlText.Append("(");
                }
                if (leftOp != null && !wrapLeft)
                {
                    leftOp.WriteSql(sqlText, this);
                }
                else
                {
                    left.WriteSql(sqlText);
                }
                if (wrapLeft)
                {
                    sqlText.Append(")");
                }
            }

            sqlText.Append(op.Op);

            if (right != null)
            {
                if (wrapRight)
                {
                    sqlText.Append("(");
                }
                if (rightOp != null && !wrapRight)
                {
                    rightOp.WriteSql(sqlText, rightParent);
                }
                else
                {
                    right.WriteSql(sqlText);
                }
                if (wrapRight)
                {
                    sqlText.Append(")");
                }
            }

            base.WriteSql(sqlText);
        }
Beispiel #4
0
        private void WriteSql(StringBuilder sqlText, OperatorExpression rightParent)
        {
            OperatorExpression leftOp = left as OperatorExpression;
            OperatorExpression rightOp = right as OperatorExpression;

            bool wrapLeft = leftOp != null && (op.RightAssoc ? leftOp.op.RightPrecedence <= op.LeftPrecedence : leftOp.op.RightPrecedence < op.LeftPrecedence);
            bool wrapRight = rightOp != null && (!op.RightAssoc ? rightOp.op.LeftPrecedence <= op.RightPrecedence : rightOp.op.LeftPrecedence < op.RightPrecedence);

            // Avoid parentheses for prefix operators if possible,
            // e.g. BitwiseNot: (a & (~ b)) & c is written as a & ~ b & c
            // but (a + (~ b)) + c must be written as a + (~ b) + c
            if (wrapRight && rightOp.left == null && (rightParent == null || (!rightParent.op.RightAssoc ? rightOp.op.RightPrecedence >= rightParent.op.LeftPrecedence : rightOp.op.RightPrecedence > rightParent.op.LeftPrecedence)))
                wrapRight = false;

            if (left != null)
            {
                if (wrapLeft)
                    sqlText.Append("(");
                if (leftOp != null && !wrapLeft)
                    leftOp.WriteSql(sqlText, this);
                else
                    left.WriteSql(sqlText);
                if (wrapLeft)
                    sqlText.Append(")");
            }

            sqlText.Append(op.Op);

            if (right != null)
            {
                if (wrapRight)
                    sqlText.Append("(");
                if (rightOp != null && !wrapRight)
                    rightOp.WriteSql(sqlText, rightParent);
                else
                    right.WriteSql(sqlText);
                if (wrapRight)
                    sqlText.Append(")");
            }

            base.WriteSql(sqlText);
        }