Ejemplo n.º 1
0
        protected override Expression DoResolve(ResolveContext rc)
        {
            if (rc.IsRuntimeBinder)
            {
                if (UnwrapLeft == null && !Left.Type.IsNullableType)
                {
                    Left = Wrap.Create(Left, rc.Module.PredefinedTypes.Nullable.TypeSpec.MakeGenericType(rc.Module, new[] { Left.Type }));
                }

                if (UnwrapRight == null && !Right.Type.IsNullableType)
                {
                    Right = Wrap.Create(Right, rc.Module.PredefinedTypes.Nullable.TypeSpec.MakeGenericType(rc.Module, new[] { Right.Type }));
                }
            }
            else
            {
                if (UnwrapLeft == null && Left != null && Left.Type.IsNullableType)
                {
                    Left       = Unwrap.CreateUnwrapped(Left);
                    UnwrapLeft = Left as Unwrap;
                }

                if (UnwrapRight == null && Right != null && Right.Type.IsNullableType)
                {
                    Right       = Unwrap.CreateUnwrapped(Right);
                    UnwrapRight = Right as Unwrap;
                }
            }

            type   = Binary.Type;
            eclass = Binary.eclass;

            return(this);
        }
Ejemplo n.º 2
0
        protected override Expression DoResolve(ResolveContext ec)
        {
            //
            // It's null when lifting non-nullable type
            //
            if (unwrap == null) {
                // S -> T? is wrap only
                if (type.IsNullableType)
                    return Wrap.Create (expr, type);

                // S -> T can be simplified
                return expr;
            }

            // Wrap target for T?
            if (type.IsNullableType) {
                if (!expr.Type.IsNullableType) {
                    expr = Wrap.Create (expr, type);
                    if (expr == null)
                        return null;
                }

                null_value = LiftedNull.Create (type, loc);
            } else if (TypeSpec.IsValueType (type)) {
                null_value = LiftedNull.Create (type, loc);
            } else {
                null_value = new NullConstant (type, loc);
            }

            eclass = ExprClass.Value;
            return this;
        }
Ejemplo n.º 3
0
        Expression LiftOperand(ResolveContext rc, Expression expr)
        {
            TypeSpec type;
            if (expr.IsNull) {
                type = Left.IsNull ? Right.Type : Left.Type;
            } else {
                type = expr.Type;
            }

            if (!type.IsNullableType)
                type = NullableInfo.MakeType (rc.Module, type);

            return Wrap.Create (expr, type);
        }
Ejemplo n.º 4
0
        Expression LiftOperand(ResolveContext rc, Expression expr)
        {
            TypeSpec type;

            if (expr.IsNull)
            {
                type = Left.IsNull ? Right.Type : Left.Type;
            }
            else
            {
                type = expr.Type;
            }

            if (!type.IsNullableType)
            {
                type = rc.Module.PredefinedTypes.Nullable.TypeSpec.MakeGenericType(rc.Module, new[] { type });
            }

            return(Wrap.Create(expr, type));
        }
Ejemplo n.º 5
0
        public override Expression DoResolve(EmitContext ec)
        {
            wrap = Wrap.Create(expr, type);
            if (wrap == null)
            {
                return(null);
            }

            //
            // It's null when lifted conversion is transparent
            //
            if (unwrap == null)
            {
                return(wrap);
            }

            null_value = LiftedNull.Create(type, loc);

            eclass = ExprClass.Value;
            return(this);
        }
Ejemplo n.º 6
0
        public override Expression DoResolve(ResolveContext ec)
        {
            //
            // It's null when lifting non-nullable type
            //
            if (unwrap == null)
            {
                // S -> T? is wrap only
                if (TypeManager.IsNullableType(type))
                {
                    return(Wrap.Create(expr, type));
                }

                // S -> T can be simplified
                return(expr);
            }

            // Wrap target for T?
            if (TypeManager.IsNullableType(type))
            {
                expr = Wrap.Create(expr, type);
                if (expr == null)
                {
                    return(null);
                }

                null_value = LiftedNull.Create(type, loc);
            }
            else
            {
                null_value = new NullLiteral(type, loc);
            }

            eclass = ExprClass.Value;
            return(this);
        }