protected override ICode VisitBox(ExprBox e) { var ctx = e.Ctx; var expr = (Expr)this.Visit(e.Expr); if (e.Type.IsUnsignedInteger() && expr.Type.IsSignedInteger()) { expr = new ExprConv(ctx, expr, e.Type, false); } if (!e.Type.IsValueType) { // For ref-types 'box' does nothing return this.Visit(e.Expr); } var eType = new ExprJsTypeVarName(ctx, e.Type); if (e.Type.IsNullable()) { var exprIsVar = expr.IsVar(); var innerType = e.Type.GetNullableInnerType(); var temp = exprIsVar ? null : new ExprVarLocal(ctx, e.Type); var box = new ExprBox(ctx, temp ?? expr, innerType).Named("box"); var nullableJs = exprIsVar ? "(expr !== null ? box : null)" : "((temp = expr) !== null ? box : null)"; var nullableExpr = new ExprJsExplicit(ctx, nullableJs, innerType, temp.Named("temp"), expr.Named("expr"), box); return nullableExpr; } else { var deepCopyExpr = InternalFunctions.ValueTypeDeepCopyIfRequired(e.Type, () => (Expr)this.Visit(expr)); var int2bool = e.Type.IsBoolean() && expr.Type.IsInteger() ? "!!" : ""; var js = "{v:" + int2bool + "expr,_:type}"; var ret = new ExprJsExplicit(ctx, js, e.Type, (deepCopyExpr ?? expr).Named("expr"), eType.Named("type")); return ret; } }
protected override ICode VisitBox(ExprBox e) { throw new InvalidOperationException("This should never occur"); }
protected override ICode VisitBox(ExprBox e) { this.code.Append("box("); this.Visit(e.Expr); this.code.Append(")"); return e; }
protected override ICode VisitBox(ExprBox e) { this.types.Add(e.Type); return base.VisitBox(e); }
private Stmt Box(TypeReference type) { var value = this.stack.Pop(); var expr = new ExprBox(this.ctx, value, type); return this.SsaLocalAssignment(expr); }