Пример #1
0
 protected virtual Expr VisitZEROINIT(ExprZeroInit pExpr)
 {
     return(VisitEXPR(pExpr));
 }
Пример #2
0
 protected override Expr VisitZEROINIT(ExprZeroInit expr)
 {
     Debug.Assert(expr != null);
     return(GenerateConstant(expr));
 }
Пример #3
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);
        }