コード例 #1
0
        public override ExpressionNode VisitIsNullExpression(IsNullExpression expression)
        {
            Visit(expression.Expression);

            Label loadTrue    = _ilEmitContext.ILGenerator.DefineLabel();
            Label finishLabel = _ilEmitContext.ILGenerator.DefineLabel();

            if (expression.Negated)
            {
                _ilEmitContext.ILGenerator.Emit(OpCodes.Brtrue, loadTrue);
            }
            else
            {
                _ilEmitContext.ILGenerator.Emit(OpCodes.Brfalse, loadTrue);
            }

            _ilEmitContext.ILGenerator.Emit(OpCodes.Ldc_I4_0);
            _ilEmitContext.ILGenerator.Emit(OpCodes.Br, finishLabel);

            _ilEmitContext.ILGenerator.MarkLabel(loadTrue);
            _ilEmitContext.ILGenerator.Emit(OpCodes.Ldc_I4_1);

            _ilEmitContext.ILGenerator.MarkLabel(finishLabel);
            _ilEmitContext.ILGenerator.Emit(OpCodes.Box, typeof(bool));

            return(expression);
        }
コード例 #2
0
		public override ExpressionNode VisitIsNullExpression(IsNullExpression expression)
		{
			Visit(expression.Expression);
			
			if (_lastExpressionsYieldsNullOrFalse && !expression.Negated)
				_lastExpressionsYieldsNullOrFalse = false;
				
			return expression;
		}
コード例 #3
0
        public override ExpressionNode VisitIsNullExpression(IsNullExpression expression)
        {
            Visit(expression.Expression);

            if (_lastExpressionsYieldsNullOrFalse && !expression.Negated)
            {
                _lastExpressionsYieldsNullOrFalse = false;
            }

            return(expression);
        }
コード例 #4
0
        public override ExpressionNode VisitIsNullExpression(IsNullExpression expression)
        {
            _xmlWriter.WriteStartElement("isNullExpression");
            _xmlWriter.WriteAttributeString("negated", XmlConvert.ToString(expression.Negated));
            WriteTypeAttribute(expression.ExpressionType);

            WriteAstNode("expression", expression.Expression);

            _xmlWriter.WriteEndElement();

            return(expression);
        }
コード例 #5
0
        public override ExpressionNode VisitIsNullExpression(IsNullExpression expression)
        {
            Visit(expression.Expression);

            _writer.Write(" IS ");
            if (expression.Negated)
            {
                _writer.Write("NOT ");
            }
            _writer.Write("NULL");
            return(expression);
        }
コード例 #6
0
        public override ExpressionNode VisitIsNullExpression(IsNullExpression expression)
        {
            base.VisitIsNullExpression(expression);

            ConstantExpression constantExpression = expression.Expression as ConstantExpression;

            if (constantExpression != null)
            {
                if (expression.Negated)
                {
                    return(LiteralExpression.FromBoolean(constantExpression.GetValue() != null));
                }
                else
                {
                    return(LiteralExpression.FromBoolean(constantExpression.GetValue() == null));
                }
            }

            return(expression);
        }
コード例 #7
0
ファイル: Comparer.cs プロジェクト: chenzuo/nquery
		private static bool VisitIsNullExpression(IsNullExpression node1, IsNullExpression node2)
		{
			return node2 != null &&
				   node1.Negated == node2.Negated &&
				   Visit(node1.Expression, node2.Expression);
		}
コード例 #8
0
 private static bool VisitIsNullExpression(IsNullExpression node1, IsNullExpression node2)
 {
     return(node2 != null &&
            node1.Negated == node2.Negated &&
            Visit(node1.Expression, node2.Expression));
 }
コード例 #9
0
ファイル: SourceGenerator.cs プロジェクト: chenzuo/nquery
		public override ExpressionNode VisitIsNullExpression(IsNullExpression expression)
		{
			Visit(expression.Expression);

			_writer.Write(" IS ");
			if (expression.Negated)
				_writer.Write("NOT ");
			_writer.Write("NULL");
			return expression;
		}
コード例 #10
0
ファイル: ExpressionBuilder.cs プロジェクト: chenzuo/nquery
 public void PushIsNull()
 {
     ExpressionNode operand = _expressionStack.Pop();
     IsNullExpression isNullExpression = new IsNullExpression(false, operand);
     _expressionStack.Push(isNullExpression);
 }
コード例 #11
0
 public virtual ExpressionNode VisitIsNullExpression(IsNullExpression expression)
 {
     expression.Expression = VisitExpression(expression.Expression);
     return(expression);
 }
コード例 #12
0
ファイル: StandardVisitor.cs プロジェクト: chenzuo/nquery
		public virtual ExpressionNode VisitIsNullExpression(IsNullExpression expression)
		{
			expression.Expression = VisitExpression(expression.Expression);
			return expression;
		}
コード例 #13
0
ファイル: ILTranslator.cs プロジェクト: chenzuo/nquery
		public override ExpressionNode VisitIsNullExpression(IsNullExpression expression)
		{
			Visit(expression.Expression);

			Label loadTrue = _ilEmitContext.ILGenerator.DefineLabel();
			Label finishLabel = _ilEmitContext.ILGenerator.DefineLabel();

			if (expression.Negated)
				_ilEmitContext.ILGenerator.Emit(OpCodes.Brtrue, loadTrue);
			else
				_ilEmitContext.ILGenerator.Emit(OpCodes.Brfalse, loadTrue);

			_ilEmitContext.ILGenerator.Emit(OpCodes.Ldc_I4_0);
			_ilEmitContext.ILGenerator.Emit(OpCodes.Br, finishLabel);

			_ilEmitContext.ILGenerator.MarkLabel(loadTrue);
			_ilEmitContext.ILGenerator.Emit(OpCodes.Ldc_I4_1);

			_ilEmitContext.ILGenerator.MarkLabel(finishLabel);
			_ilEmitContext.ILGenerator.Emit(OpCodes.Box, typeof(bool));

			return expression;
		}
コード例 #14
0
ファイル: ConstantFolder.cs プロジェクト: chenzuo/nquery
		public override ExpressionNode VisitIsNullExpression(IsNullExpression expression)
		{
			base.VisitIsNullExpression(expression);

			ConstantExpression constantExpression = expression.Expression as ConstantExpression;

			if (constantExpression != null)
			{
				if (expression.Negated)
					return LiteralExpression.FromBoolean(constantExpression.GetValue() != null);
				else
					return LiteralExpression.FromBoolean(constantExpression.GetValue() == null);
			}

			return expression;
		}
コード例 #15
0
ファイル: Normalizer.cs プロジェクト: resonancellc/nquery
        public override ExpressionNode VisitUnaryExpression(UnaryExpression expression)
        {
            // First visit arguments
            base.VisitUnaryExpression(expression);

            if (expression.Op == UnaryOperator.LogicalNot)
            {
                // Replace "NOT NOT expr" by "expr"

                UnaryExpression unOp = expression.Operand as UnaryExpression;
                if (unOp != null)
                {
                    if (unOp.Op == UnaryOperator.LogicalNot)
                    {
                        return(VisitExpression(unOp.Operand));
                    }
                }

                // Replace "NOT expr IS NULL" and "NOT expr IS NOT NULL" by
                //         "expr IS NOT NULL" and "expr IS NULL" resp.

                IsNullExpression isNull = expression.Operand as IsNullExpression;
                if (isNull != null)
                {
                    isNull.Negated = !isNull.Negated;
                    return(VisitExpression(isNull));
                }

                // Apply negation on EXISTS

                ExistsSubselect existsSubselect = expression.Operand as ExistsSubselect;
                if (existsSubselect != null)
                {
                    existsSubselect.Negated = !existsSubselect.Negated;
                    return(existsSubselect);
                }

                // Apply negation on ALL/ANY subquery

                AllAnySubselect allAnySubselect = expression.Operand as AllAnySubselect;
                if (allAnySubselect != null)
                {
                    allAnySubselect.Op   = AstUtil.NegateBinaryOp(allAnySubselect.Op);
                    allAnySubselect.Type = (allAnySubselect.Type == AllAnySubselect.AllAnyType.All) ? AllAnySubselect.AllAnyType.Any : AllAnySubselect.AllAnyType.All;
                    return(allAnySubselect);
                }

                // Apply De Morgan's law

                BinaryExpression binOp = expression.Operand as BinaryExpression;

                if (binOp != null)
                {
                    BinaryOperator negatedOp = AstUtil.NegateBinaryOp(binOp.Op);

                    if (negatedOp != null)
                    {
                        ExpressionNode newLeft;
                        ExpressionNode newRight;

                        if (binOp.Op == BinaryOperator.LogicalAnd || binOp.Op == BinaryOperator.LogicalOr)
                        {
                            newLeft  = new UnaryExpression(expression.Op, binOp.Left);
                            newRight = new UnaryExpression(expression.Op, binOp.Right);
                        }
                        else
                        {
                            newLeft  = binOp.Left;
                            newRight = binOp.Right;
                        }

                        binOp.Op    = negatedOp;
                        binOp.Left  = newLeft;
                        binOp.Right = newRight;
                        return(VisitExpression(binOp));
                    }
                }
            }

            return(expression);
        }
コード例 #16
0
ファイル: XmlProducer.cs プロジェクト: chenzuo/nquery
		public override ExpressionNode VisitIsNullExpression(IsNullExpression expression)
		{
			_xmlWriter.WriteStartElement("isNullExpression");
			_xmlWriter.WriteAttributeString("negated", XmlConvert.ToString(expression.Negated));
			WriteTypeAttribute(expression.ExpressionType);

			WriteAstNode("expression", expression.Expression);

			_xmlWriter.WriteEndElement();

			return expression;
		}