public override BoundNode VisitNullCoalescingOperator(BoundNullCoalescingOperator node)
        {
            BoundExpression rewrittenLeft = (BoundExpression)Visit(node.LeftOperand);
            BoundExpression rewrittenRight = (BoundExpression)Visit(node.RightOperand);
            TypeSymbol rewrittenResultType = VisitType(node.Type);

            return MakeNullCoalescingOperator(node.Syntax, rewrittenLeft, rewrittenRight, node.LeftConversion, rewrittenResultType);
        }
        private BoundNode FuseNodes(BoundConditionalAccess conditionalAccess, BoundNullCoalescingOperator node)
        {
            var type = node.RightOperand.Type;
            conditionalAccess = conditionalAccess.Update(conditionalAccess.Receiver, conditionalAccess.AccessExpression, type);

            var whenNull = (BoundExpression)Visit(node.RightOperand);
            if (whenNull.IsDefaultValue() && whenNull.Type.SpecialType != SpecialType.System_Decimal)
            {
                whenNull = null;
            }

            return RewriteConditionalAccess(conditionalAccess, used: true, rewrittenWhenNull: whenNull);
        }
        public override BoundNode VisitNullCoalescingOperator(BoundNullCoalescingOperator node)
        {
            // check for common pattern   a?.b ?? c  where b is a value type
            // in such cases the result of the expression is either b or c
            // we can skip nullable wrapping/unwrapping

            BoundConditionalAccess conditionalAccess;
            var leftConversion = node.LeftConversion;

            if ((leftConversion.IsIdentity || leftConversion.Kind == ConversionKind.ExplicitNullable) &&
                TryGetOptimizableNullableConditionalAccess(node.LeftOperand, out conditionalAccess))
            {
                return FuseNodes(conditionalAccess, node);
            }

            BoundExpression rewrittenLeft = (BoundExpression)Visit(node.LeftOperand);
            BoundExpression rewrittenRight = (BoundExpression)Visit(node.RightOperand);
            TypeSymbol rewrittenResultType = VisitType(node.Type);

            return MakeNullCoalescingOperator(node.Syntax, rewrittenLeft, rewrittenRight, node.LeftConversion, rewrittenResultType);
        }
 private BoundExpression VisitNullCoalescingOperator(BoundNullCoalescingOperator node)
 {
     var left = Visit(node.LeftOperand);
     var right = Visit(node.RightOperand);
     if (node.LeftConversion.IsUserDefined)
     {
         TypeSymbol lambdaParamType = node.LeftOperand.Type.StrippedType();
         return ExprFactory("Coalesce", left, right, MakeConversionLambda(node.LeftConversion, lambdaParamType, node.Type));
     }
     else
     {
         return ExprFactory("Coalesce", left, right);
     }
 }
Пример #5
0
        public override BoundNode VisitNullCoalescingOperator(BoundNullCoalescingOperator node)
        {
            BoundSpillSequence2 ss = null;
            var right = VisitExpression(ref ss, node.RightOperand);
            BoundExpression left;
            if (ss == null)
            {
                left = VisitExpression(ref ss, node.LeftOperand);
            }
            else
            {
                var ssLeft = new BoundSpillSequence2();
                left = VisitExpression(ref ssLeft, node.LeftOperand);
                left = Spill(ssLeft, left);

                ssLeft.Add(F.If(
                    F.ObjectEqual(left, F.Null(left.Type)),
                    UpdateStatement(ss, F.Assignment(left, right))
                    ));
                return UpdateExpression(ssLeft, left);
            }

            return UpdateExpression(ss, node.Update(left, right, node.LeftConversion, node.Type));
        }
        public override BoundNode VisitNullCoalescingOperator(BoundNullCoalescingOperator node)
        {
            if (_inExpressionLambda && node.LeftOperand.IsLiteralNull())
            {
                Error(ErrorCode.ERR_ExpressionTreeContainsBadCoalesce, node.LeftOperand);
            }

            return base.VisitNullCoalescingOperator(node);
        }
        public override BoundNode VisitNullCoalescingOperator(BoundNullCoalescingOperator node)
        {
            if (inExpressionLambda && node.LeftOperand.ConstantValue != null && node.LeftOperand.ConstantValue.IsNull)
            {
                Error(ErrorCode.ERR_ExpressionTreeContainsBadCoalesce, node.LeftOperand);
            }

            return base.VisitNullCoalescingOperator(node);
        }