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); } }
private Stmt Cast(TypeReference toType) { var expr = this.stack.Pop(); var cast = new ExprCast(this.ctx, expr, toType); return(this.SsaLocalAssignment(cast)); }
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); }
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); }
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); } }
public static ExprCast WithSqlType(this ExprCast original, ExprType newSqlType) => new ExprCast(expression: original.Expression, sqlType: newSqlType);
public static ExprCast WithExpression(this ExprCast original, IExprSelecting newExpression) => new ExprCast(expression: newExpression, sqlType: original.SqlType);
protected override ICode VisitCast(ExprCast e) { throw new InvalidOperationException("This should never occur"); }
public override bool VisitExprCast(ExprCast exprCast, IExpr?parent) { return(this.VisitExprCastCommon(exprCast, parent)); }
protected override ICode VisitCast(ExprCast e) { this.code.AppendFormat("({0})", e.Type); this.Visit(e.Expr); return(e); }
public abstract bool VisitExprCast(ExprCast exprCast, IExpr?parent);
public TRes VisitExprCast(ExprCast exprCast, ExprValueTypeAnalyzerCtx <TRes, TCtx> ctx) { return(exprCast.SqlType.Accept(this, ctx)); }