Ejemplo n.º 1
0
        protected override Expr VisitCAST(ExprCast pExpr)
        {
            Debug.Assert(pExpr != null);

            Expr pArgument = pExpr.Argument;

            // If we have generated an identity cast or reference cast to a base class
            // we can omit the cast.
            if (pArgument.Type == pExpr.Type ||
                SymbolLoader.IsBaseClassOfClass(pArgument.Type, pExpr.Type) ||
                CConversions.FImpRefConv(GetSymbolLoader(), pArgument.Type, pExpr.Type))
            {
                return(Visit(pArgument));
            }

            // If we have a cast to PredefinedType.PT_G_EXPRESSION and the thing that we're casting is
            // a EXPRBOUNDLAMBDA that is an expression tree, then just visit the expression tree.
            if (pExpr.Type != null &&
                pExpr.Type.isPredefType(PredefinedType.PT_G_EXPRESSION) &&
                pArgument is ExprBoundLambda)
            {
                return(Visit(pArgument));
            }

            Expr result = GenerateConversion(pArgument, pExpr.Type, pExpr.isChecked());

            if ((pExpr.Flags & EXPRFLAG.EXF_UNBOXRUNTIME) != 0)
            {
                // Propagate the unbox flag to the call for the ExpressionTreeCallRewriter.
                result.Flags |= EXPRFLAG.EXF_UNBOXRUNTIME;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public ExprCast CreateCast(EXPRFLAG nFlags, ExprClass pType, Expr pArg)
        {
            Debug.Assert(pArg != null);
            Debug.Assert(pType != null);
            Debug.Assert(0 == (nFlags & ~(EXPRFLAG.EXF_CAST_ALL | EXPRFLAG.EXF_MASK_ANY)));
            ExprCast rval = new ExprCast();

            rval.Argument        = pArg;
            rval.Flags           = nFlags;
            rval.DestinationType = pType;
            return(rval);
        }
Ejemplo n.º 3
0
        public ExprCast CreateCast(EXPRFLAG nFlags, ExprTypeOrNamespace pType, Expr pArg)
        {
            Debug.Assert(pArg != null);
            Debug.Assert(pType != null);
            Debug.Assert(0 == (nFlags & ~(EXPRFLAG.EXF_CAST_ALL | EXPRFLAG.EXF_MASK_ANY)));
            ExprCast rval = new ExprCast();

            rval.Type            = pType.TypeOrNamespace as CType;
            rval.Kind            = ExpressionKind.EK_CAST;
            rval.Argument        = pArg;
            rval.Flags           = nFlags;
            rval.DestinationType = pType;
            Debug.Assert(rval != null);
            return(rval);
        }
Ejemplo n.º 4
0
        private Expr GenerateConstant(Expr expr)
        {
            EXPRFLAG flags = 0;

            AggregateType pObject = GetSymbolLoader().GetPredefindType(PredefinedType.PT_OBJECT);

            if (expr.Type is NullType)
            {
                ExprTypeOf pTypeOf = CreateTypeOf(pObject);
                return(GenerateCall(PREDEFMETH.PM_EXPRESSION_CONSTANT_OBJECT_TYPE, expr, pTypeOf));
            }

            AggregateType stringType = GetSymbolLoader().GetPredefindType(PredefinedType.PT_STRING);

            if (expr.Type != stringType)
            {
                flags = EXPRFLAG.EXF_BOX;
            }

            ExprCast   cast     = GetExprFactory().CreateCast(flags, pObject, expr);
            ExprTypeOf pTypeOf2 = CreateTypeOf(expr.Type);

            return(GenerateCall(PREDEFMETH.PM_EXPRESSION_CONSTANT_OBJECT_TYPE, cast, pTypeOf2));
        }
Ejemplo n.º 5
0
 protected virtual Expr VisitCAST(ExprCast pExpr)
 {
     return(VisitEXPR(pExpr));
 }
Ejemplo n.º 6
0
        private Expr CreateZeroInit(ExprTypeOrNamespace pTypeExpr, Expr pOptionalOriginalConstructorCall, bool isConstructor)
        {
            Debug.Assert(pTypeExpr != null);
            CType pType    = pTypeExpr.TypeOrNamespace.AsType();
            bool  bIsError = false;

            if (pType.isEnumType())
            {
                // For enum types, we create a constant that has the default value
                // as an object pointer.
                ExprConstant expr = CreateConstant(pType, ConstVal.Get(Activator.CreateInstance(pType.AssociatedSystemType)));
                return(expr);
            }

            switch (pType.fundType())
            {
            default:
                bIsError = true;
                break;

            case FUNDTYPE.FT_PTR:
            {
                CType nullType = GetTypes().GetNullType();

                // It looks like this if is always false ...
                if (nullType.fundType() == pType.fundType())
                {
                    // Create a constant here.

                    ExprConstant expr = CreateConstant(pType, ConstVal.GetDefaultValue(ConstValKind.IntPtr));
                    return(expr);
                }

                // Just allocate a new node and fill it in.

                ExprCast cast = CreateCast(0, pTypeExpr, CreateNull());
                return(cast);
            }

            case FUNDTYPE.FT_REF:
            case FUNDTYPE.FT_I1:
            case FUNDTYPE.FT_U1:
            case FUNDTYPE.FT_I2:
            case FUNDTYPE.FT_U2:
            case FUNDTYPE.FT_I4:
            case FUNDTYPE.FT_U4:
            case FUNDTYPE.FT_I8:
            case FUNDTYPE.FT_U8:
            case FUNDTYPE.FT_R4:
            case FUNDTYPE.FT_R8:
            {
                ExprConstant expr           = CreateConstant(pType, ConstVal.GetDefaultValue(pType.constValKind()));
                ExprConstant exprInOriginal = CreateConstant(pType, ConstVal.GetDefaultValue(pType.constValKind()));
                exprInOriginal.OptionalConstructorCall = pOptionalOriginalConstructorCall;
                return(expr);
            }

            case FUNDTYPE.FT_STRUCT:
                if (pType.isPredefType(PredefinedType.PT_DECIMAL))
                {
                    ExprConstant expr         = CreateConstant(pType, ConstVal.GetDefaultValue(pType.constValKind()));
                    ExprConstant exprOriginal = CreateConstant(pType, ConstVal.GetDefaultValue(pType.constValKind()));
                    exprOriginal.OptionalConstructorCall = pOptionalOriginalConstructorCall;
                    return(expr);
                }
                break;

            case FUNDTYPE.FT_VAR:
                break;
            }

            ExprZeroInit rval = new ExprZeroInit();

            rval.Kind  = ExpressionKind.EK_ZEROINIT;
            rval.Type  = pType;
            rval.Flags = 0;
            rval.OptionalConstructorCall = pOptionalOriginalConstructorCall;
            rval.IsConstructor           = isConstructor;

            if (bIsError)
            {
                rval.SetError();
            }

            Debug.Assert(rval != null);
            return(rval);
        }