Beispiel #1
0
            /// <summary>
            /// Return the boolean expression to be evaluated for the given test. Returns `null` if the test is trivially true.
            /// </summary>
            protected BoundExpression LowerTest(BoundDagTest test)
            {
                _factory.Syntax = test.Syntax;
                BoundExpression input = _tempAllocator.GetTemp(test.Input);

                switch (test)
                {
                case BoundDagNonNullTest d:
                    return(_localRewriter.MakeNullCheck(d.Syntax, input, input.Type.IsNullableType() ? BinaryOperatorKind.NullableNullNotEqual : BinaryOperatorKind.NotEqual));

                case BoundDagTypeTest d:
                    // Note that this tests for non-null as a side-effect. We depend on that to sometimes avoid the null check.
                    return(_factory.Is(input, d.Type));

                case BoundDagNullTest d:
                    return(_localRewriter.MakeNullCheck(d.Syntax, input, input.Type.IsNullableType() ? BinaryOperatorKind.NullableNullEqual : BinaryOperatorKind.Equal));

                case BoundDagValueTest d:
                    Debug.Assert(!input.Type.IsNullableType());
                    return(MakeEqual(_localRewriter.MakeLiteral(d.Syntax, d.Value, input.Type), input));

                default:
                    throw ExceptionUtilities.UnexpectedValue(test);
                }
            }