Пример #1
0
        public ExprField CreateField(EXPRFLAG nFlags, CType pType, Expr pOptionalObject, FieldWithType FWT)
        {
            Debug.Assert(0 == (nFlags & ~(EXPRFLAG.EXF_MEMBERSET | EXPRFLAG.EXF_MASK_ANY)));
            ExprField rval = new ExprField(pType);

            rval.Flags          = nFlags;
            rval.OptionalObject = pOptionalObject;
            rval.FieldWithType  = FWT;
            return(rval);
        }
Пример #2
0
        private RuntimeBinderException ReportReadOnlyError(ExprField field, CheckLvalueKind kind, bool isNested)
        {
            Debug.Assert(field != null);

            bool isStatic = field.FieldWithType.Field().isStatic;

            int       index = (isNested ? 4 : 0) + (isStatic ? 2 : 0) + (kind == CheckLvalueKind.OutParameter ? 0 : 1);
            ErrorCode err   = s_ReadOnlyErrors[index];

            return(ErrorContext.Error(err, isNested ? new ErrArg[] { field.FieldWithType } : Array.Empty <ErrArg>()));
        }
Пример #3
0
        public ExprField CreateField(EXPRFLAG nFlags, CType pType, Expr pOptionalObject, uint nOffset, FieldWithType FWT, Expr pOptionalLHS)
        {
            Debug.Assert(0 == (nFlags & ~(EXPRFLAG.EXF_MEMBERSET | EXPRFLAG.EXF_MASK_ANY)));
            ExprField rval = new ExprField();

            rval.Kind           = ExpressionKind.EK_FIELD;
            rval.Type           = pType;
            rval.Flags          = nFlags;
            rval.OptionalObject = pOptionalObject;
            if (FWT != null)
            {
                rval.FieldWithType = FWT;
            }
            Debug.Assert(rval != null);
            return(rval);
        }
Пример #4
0
        protected override Expr VisitFIELD(ExprField expr)
        {
            Debug.Assert(expr != null);
            Expr pObject;

            if (expr.OptionalObject == null)
            {
                pObject = GetExprFactory().CreateNull();
            }
            else
            {
                pObject = Visit(expr.OptionalObject);
            }
            ExprFieldInfo pFieldInfo = GetExprFactory().CreateFieldInfo(expr.FieldWithType.Field(), expr.FieldWithType.GetType());

            return(GenerateCall(PREDEFMETH.PM_EXPRESSION_FIELD, pObject, pFieldInfo));
        }
Пример #5
0
        private void ReportReadOnlyError(ExprField field, CheckLvalueKind kind, bool isNested)
        {
            Debug.Assert(field != null);

            bool isStatic = field.FieldWithType.Field().isStatic;

            int       index = (isNested ? 4 : 0) + (isStatic ? 2 : 0) + (kind == CheckLvalueKind.OutParameter ? 0 : 1);
            ErrorCode err   = s_ReadOnlyErrors[index];

            if (isNested)
            {
                ErrorContext.Error(err, field.FieldWithType);
            }
            else
            {
                ErrorContext.Error(err);
            }
        }
Пример #6
0
        private RuntimeBinderException ReportReadOnlyError(ExprField field, bool isNested)
        {
            Debug.Assert(field != null);

            FieldWithType fieldWithType = field.FieldWithType;
            bool          isStatic      = fieldWithType.Field().isStatic;

            ErrArg[]  args;
            ErrorCode err;

            if (isNested)
            {
                args = new ErrArg[] { fieldWithType };
                err  = isStatic ? ErrorCode.ERR_AssgReadonlyStatic2 : ErrorCode.ERR_AssgReadonly2;
            }
            else
            {
                args = Array.Empty <ErrArg>();
                err  = isStatic ? ErrorCode.ERR_AssgReadonlyStatic : ErrorCode.ERR_AssgReadonly;
            }

            return(ErrorContext.Error(err, args));
        }
Пример #7
0
 protected virtual Expr VisitFIELD(ExprField pExpr)
 {
     return(VisitEXPR(pExpr));
 }
Пример #8
0
        // Return true if we actually report a failure.
        private bool TryReportLvalueFailure(Expr expr, CheckLvalueKind kind)
        {
            Debug.Assert(expr != null);

            // We have a lvalue failure. Was the reason because this field
            // was marked readonly? Give special messages for this case.

            bool isNested = false; // Did we recurse on a field or property to give a better error?

            Expr walk = expr;

            while (true)
            {
                Debug.Assert(walk != null);

                if (walk.isANYLOCAL_OK())
                {
                    ReportLocalError(walk.asANYLOCAL().Local, kind, isNested);
                    return(true);
                }

                Expr pObject = null;

                if (walk.isPROP())
                {
                    // We've already reported read-only-property errors.
                    Debug.Assert(walk.asPROP().MethWithTypeSet != null);
                    pObject = walk.asPROP().MemberGroup.OptionalObject;
                }
                else if (walk.isFIELD())
                {
                    ExprField field = walk.asFIELD();
                    if (field.FieldWithType.Field().isReadOnly)
                    {
                        ReportReadOnlyError(field, kind, isNested);
                        return(true);
                    }
                    if (!field.FieldWithType.Field().isStatic)
                    {
                        pObject = field.OptionalObject;
                    }
                }

                if (pObject != null && pObject.Type.isStructOrEnum())
                {
                    if (pObject.isCALL() || pObject.isPROP())
                    {
                        // assigning to RHS of method or property getter returning a value-type on the stack or
                        // passing RHS of method or property getter returning a value-type on the stack, as ref or out
                        ErrorContext.Error(ErrorCode.ERR_ReturnNotLValue, pObject.GetSymWithType());
                        return(true);
                    }
                    if (pObject.isCAST())
                    {
                        // An unboxing conversion.
                        //
                        // In the static compiler, we give the following error here:
                        // ErrorContext.Error(pObject.GetTree(), ErrorCode.ERR_UnboxNotLValue);
                        //
                        // But in the runtime, we allow this - mark that we're doing an
                        // unbox here, so that we gen the correct expression tree for it.
                        pObject.Flags |= EXPRFLAG.EXF_UNBOXRUNTIME;
                        return(false);
                    }
                }

                // everything else
                if (pObject != null && !pObject.isLvalue() && (walk.isFIELD() || (!isNested && walk.isPROP())))
                {
                    Debug.Assert(pObject.Type.isStructOrEnum());
                    walk = pObject;
                }
                else
                {
                    ErrorContext.Error(GetStandardLvalueError(kind));
                    return(true);
                }
                isNested = true;
            }
        }