protected override ICode VisitUnboxAny(ExprUnboxAny e)
        {
            if (!e.Type.IsValueType)
            {
                // On ref-type, unbox-any becomes a castclass
                var expr = (Expr)this.Visit(e.Expr);
                var cast = new ExprCast(e.Ctx, expr, e.Type);
                return(cast);
            }
            var ctx = e.Ctx;

            if (e.Type.IsNullable())
            {
                // If obj==null create Nullable with hasValue=false
                // If obj.Type not assignable to e.InnerType throw InvalidCastEx
                var innerType    = e.Type.GetNullableInnerType();
                var unboxMethod  = ((Func <object, int?>)InternalFunctions.UnboxAnyNullable <int>).Method.GetGenericMethodDefinition();
                var mUnbox       = ctx.Module.Import(unboxMethod).MakeGeneric(innerType);
                var unboxAnyCall = new ExprCall(ctx, mUnbox, null, e.Expr);
                return(unboxAnyCall);
            }
            else
            {
                // If obj==null throw NullRefEx
                // If obj.Type not assignable to e.Type throw InvalidCastEx
                // otherwise unbox
                var unboxMethod  = ((Func <object, int>)InternalFunctions.UnboxAnyNonNullable <int>).Method.GetGenericMethodDefinition();
                var mUnbox       = ctx.Module.Import(unboxMethod).MakeGeneric(e.Type);
                var unboxAnyCall = new ExprCall(ctx, mUnbox, null, e.Expr);
                return(unboxAnyCall);
            }
        }
Esempio n. 2
0
        private Stmt Cast(TypeReference toType)
        {
            var expr = this.stack.Pop();
            var cast = new ExprCast(this.ctx, expr, toType);

            return(this.SsaLocalAssignment(cast));
        }
Esempio n. 3
0
        public bool VisitExprCast(ExprCast expr, TCtx arg)
        {
            var res = this.Visit(expr, "Cast", arg, out var argOut) && this.Accept("Expression", expr.Expression, argOut) && this.Accept("SqlType", expr.SqlType, argOut);

            this._visitor.EndVisitExpr(expr, arg);
            return(res);
        }
        protected override ICode VisitCast(ExprCast e)
        {
            var ctx   = e.Ctx;
            var mCast = ctx.Module.Import(((Func <object, Type, object>)InternalFunctions.Cast).Method);
            var eType = new ExprJsTypeVarName(ctx, e.Type);
            var expr  = new ExprCall(ctx, e.Type, mCast, null, e.Expr, eType);

            return(expr);
        }
Esempio n. 5
0
 protected bool VisitExprCastCommon(ExprCast exprCast, IExpr?parent)
 {
     this.Builder.Append("CAST(");
     exprCast.Expression.Accept(this, exprCast);
     this.Builder.Append(" AS ");
     exprCast.SqlType.Accept(this, exprCast);
     this.Builder.Append(')');
     return(true);
 }
Esempio n. 6
0
        protected virtual ICode VisitCast(ExprCast e)
        {
            this.ThrowOnNoOverride();
            var expr = (Expr)this.Visit(e.Expr);

            if (expr != e.Expr)
            {
                return(new ExprCast(e.Ctx, expr, e.Type));
            }
            else
            {
                return(e);
            }
        }
Esempio n. 7
0
 public static ExprCast WithSqlType(this ExprCast original, ExprType newSqlType)
 => new ExprCast(expression: original.Expression, sqlType: newSqlType);
Esempio n. 8
0
 public static ExprCast WithExpression(this ExprCast original, IExprSelecting newExpression)
 => new ExprCast(expression: newExpression, sqlType: original.SqlType);
Esempio n. 9
0
 protected override ICode VisitCast(ExprCast e)
 {
     throw new InvalidOperationException("This should never occur");
 }
Esempio n. 10
0
 public override bool VisitExprCast(ExprCast exprCast, IExpr?parent)
 {
     return(this.VisitExprCastCommon(exprCast, parent));
 }
Esempio n. 11
0
 protected override ICode VisitCast(ExprCast e)
 {
     this.code.AppendFormat("({0})", e.Type);
     this.Visit(e.Expr);
     return(e);
 }
Esempio n. 12
0
 public abstract bool VisitExprCast(ExprCast exprCast, IExpr?parent);
Esempio n. 13
0
 public TRes VisitExprCast(ExprCast exprCast, ExprValueTypeAnalyzerCtx <TRes, TCtx> ctx)
 {
     return(exprCast.SqlType.Accept(this, ctx));
 }