Esempio n. 1
0
        private Stmt Box(TypeReference type)
        {
            var value = this.stack.Pop();
            var expr  = new ExprBox(this.ctx, value, type);

            return(this.SsaLocalAssignment(expr));
        }
        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)
 {
     this.code.Append("box(");
     this.Visit(e.Expr);
     this.code.Append(")");
     return(e);
 }
Esempio n. 4
0
        protected override Expr VisitBox(ExprBox e)
        {
            this.Visit(e.ExprToBox);
            var instBox = this.il.Create(OpCodes.Box, e.ReturnType);

            this.Emit(e, instBox);
            return(e);
        }
Esempio n. 5
0
        protected virtual ICode VisitBox(ExprBox e)
        {
            this.ThrowOnNoOverride();
            var expr = (Expr)this.Visit(e.Expr);

            if (expr != e.Expr)
            {
                return(new ExprBox(e.Ctx, expr, e.Type));
            }
            else
            {
                return(e);
            }
        }
Esempio n. 6
0
 protected override ICode VisitBox(ExprBox e)
 {
     throw new InvalidOperationException("This should never occur");
 }
Esempio n. 7
0
 protected virtual Expr VisitBox (ExprBox e)
 {
     return this.VisitCollection (e, exprs => new ExprBox (e.MethodInfo, exprs.First ()), e.ExprToBox);
 }
Esempio n. 8
0
 protected override ICode VisitBox(ExprBox e)
 {
     this.types.Add(e.Type);
     return(base.VisitBox(e));
 }