Inheritance: MethPropWithType
Exemplo n.º 1
0
        internal static bool HasIsExternalInitModifier(MethWithType mwtSet)
        {
            var types = (mwtSet.Meth()?.AssociatedMemberInfo as MethodInfo)?.ReturnParameter.GetRequiredCustomModifiers();

            return(types != null &&
                   types.Any(type => type.Name == "IsExternalInit" && !type.IsNested && type.Namespace == "System.Runtime.CompilerServices"));
        }
Exemplo n.º 2
0
        // Value
        public EXPR BindValue(EXPR exprSrc)
        {
            Debug.Assert(exprSrc != null && exprSrc.type.IsNullableType());

            // For new T?(x), the answer is x.
            if (CNullable.IsNullableConstructor(exprSrc))
            {
                Debug.Assert(exprSrc.asCALL().GetOptionalArguments() != null && !exprSrc.asCALL().GetOptionalArguments().isLIST());
                return(exprSrc.asCALL().GetOptionalArguments());
            }

            CType         typeBase = exprSrc.type.AsNullableType().GetUnderlyingType();
            AggregateType ats      = exprSrc.type.AsNullableType().GetAts(GetErrorContext());

            if (ats == null)
            {
                EXPRPROP rval = GetExprFactory().CreateProperty(typeBase, exprSrc);
                rval.SetError();
                return(rval);
            }

            // UNDONE: move this to transform pass ...
            PropertySymbol prop = GetSymbolLoader().getBSymmgr().propNubValue;

            if (prop == null)
            {
                prop = GetSymbolLoader().getPredefinedMembers().GetProperty(PREDEFPROP.PP_G_OPTIONAL_VALUE);
                GetSymbolLoader().getBSymmgr().propNubValue = prop;
            }

            PropWithType     pwt       = new PropWithType(prop, ats);
            MethWithType     mwt       = new MethWithType(prop != null ? prop.methGet : null, ats);
            MethPropWithInst mpwi      = new MethPropWithInst(prop, ats);
            EXPRMEMGRP       pMemGroup = GetExprFactory().CreateMemGroup(exprSrc, mpwi);
            EXPRPROP         exprRes   = GetExprFactory().CreateProperty(typeBase, null, null, pMemGroup, pwt, mwt, null);

            if (prop == null)
            {
                exprRes.SetError();
            }

            return(exprRes);
        }
Exemplo n.º 3
0
        // Value
        public Expr BindValue(Expr exprSrc)
        {
            Debug.Assert(exprSrc != null && exprSrc.Type.IsNullableType());

            // For new T?(x), the answer is x.
            if (IsNullableConstructor(exprSrc, out ExprCall call))
            {
                var args = call.OptionalArguments;
                Debug.Assert(args != null && !(args is ExprList));
                return(args);
            }

            CType         typeBase = exprSrc.Type.AsNullableType().GetUnderlyingType();
            AggregateType ats      = exprSrc.Type.AsNullableType().GetAts(GetErrorContext());

            if (ats == null)
            {
                ExprProperty rval = GetExprFactory().CreateProperty(typeBase, exprSrc);
                rval.SetError();
                return(rval);
            }

            PropertySymbol prop = GetSymbolLoader().getBSymmgr().propNubValue;

            if (prop == null)
            {
                prop = GetSymbolLoader().getPredefinedMembers().GetProperty(PREDEFPROP.PP_G_OPTIONAL_VALUE);
                GetSymbolLoader().getBSymmgr().propNubValue = prop;
            }

            PropWithType     pwt       = new PropWithType(prop, ats);
            MethWithType     mwt       = new MethWithType(prop?.methGet, ats);
            MethPropWithInst mpwi      = new MethPropWithInst(prop, ats);
            ExprMemberGroup  pMemGroup = GetExprFactory().CreateMemGroup(exprSrc, mpwi);
            ExprProperty     exprRes   = GetExprFactory().CreateProperty(typeBase, null, null, pMemGroup, pwt, mwt, null);

            if (prop == null)
            {
                exprRes.SetError();
            }

            return(exprRes);
        }
Exemplo n.º 4
0
        // If we have this.prop = 123, but the implementation of the property is in the
        // base class, then the object is of the base class type. Note that to get
        // the object, we must go through the MEMGRP.
        //
        // "throughObject" is
        // of the type we are actually calling through.  (We need to know the
        // "through" type to ensure that protected semantics are correctly enforced.)

        public ExprProperty(CType type, Expr pOptionalObjectThrough, Expr pOptionalArguments, ExprMemberGroup pMemberGroup, PropWithType pwtSlot, MethWithType mwtSet)
            : base(ExpressionKind.Property, type)
        {
            OptionalObjectThrough = pOptionalObjectThrough;
            OptionalArguments     = pOptionalArguments;
            MemberGroup           = pMemberGroup;

            if (pwtSlot != null)
            {
                PropWithTypeSlot = pwtSlot;
            }

            if (mwtSet != null)
            {
                MethWithTypeSet = mwtSet;
                if (!HasIsExternalInitModifier(mwtSet))
                {
                    Flags = EXPRFLAG.EXF_LVALUE;
                }
            }
        }
Exemplo n.º 5
0
 public static ExprProperty CreateProperty(CType type, Expr optionalObjectThrough, Expr arguments, ExprMemberGroup memberGroup, PropWithType property, MethWithType setMethod) =>
 new ExprProperty(type, optionalObjectThrough, arguments, memberGroup, property, setMethod);
        public EXPRPROP CreateProperty(CType pType, EXPR pOptionalObjectThrough, EXPR pOptionalArguments, EXPRMEMGRP pMemberGroup, PropWithType pwtSlot, MethWithType mwtGet, MethWithType mwtSet)
        {
            EXPRPROP rval = new EXPRPROP();

            rval.kind  = ExpressionKind.EK_PROP;
            rval.type  = pType;
            rval.flags = 0;
            rval.SetOptionalObjectThrough(pOptionalObjectThrough);
            rval.SetOptionalArguments(pOptionalArguments);
            rval.SetMemberGroup(pMemberGroup);

            if (pwtSlot != null)
            {
                rval.pwtSlot = pwtSlot;
            }
            if (mwtSet != null)
            {
                rval.mwtSet = mwtSet;
            }
            Debug.Assert(rval != null);
            return(rval);
        }
Exemplo n.º 7
0
        public ExprProperty CreateProperty(CType pType, Expr pOptionalObjectThrough, Expr pOptionalArguments, ExprMemberGroup pMemberGroup, PropWithType pwtSlot, MethWithType mwtGet, MethWithType mwtSet)
        {
            ExprProperty rval = new ExprProperty();

            rval.Kind  = ExpressionKind.EK_PROP;
            rval.Type  = pType;
            rval.Flags = 0;
            rval.OptionalObjectThrough = pOptionalObjectThrough;
            rval.OptionalArguments     = pOptionalArguments;
            rval.MemberGroup           = pMemberGroup;

            if (pwtSlot != null)
            {
                rval.PropWithTypeSlot = pwtSlot;
            }
            if (mwtSet != null)
            {
                rval.MethWithTypeSet = mwtSet;
            }
            Debug.Assert(rval != null);
            return(rval);
        }
Exemplo n.º 8
0
            public GroupToArgsBinder(ExpressionBinder exprBinder, BindingFlag bindFlags, EXPRMEMGRP grp, ArgInfos args, ArgInfos originalArgs, bool bHasNamedArguments, AggregateType atsDelegate)
            {
                Debug.Assert(grp != null);
                Debug.Assert(exprBinder != null);
                Debug.Assert(args != null);

                _pExprBinder = exprBinder;
                _fCandidatesUnsupported = false;
                _fBindFlags = bindFlags;
                _pGroup = grp;
                _pArguments = args;
                _pOriginalArguments = originalArgs;
                _bHasNamedArguments = bHasNamedArguments;
                _pDelegate = atsDelegate;
                _pCurrentType = null;
                _pCurrentSym = null;
                _pCurrentTypeArgs = null;
                _pCurrentParameters = null;
                _pBestParameters = null;
                _nArgBest = -1;
                _nWrongCount = 0;
                _bIterateToEndOfNsList = false;
                _bBindingCollectionAddArgs = false;
                _results = new GroupToArgsBinderResult();
                _methList = new List<CandidateFunctionMember>();
                _mpwiParamTypeConstraints = new MethPropWithInst();
                _mpwiBogus = new MethPropWithInst();
                _mpwiCantInferInstArg = new MethPropWithInst();
                _mwtBadArity = new MethWithType();
                _HiddenTypes = new List<CType>();
            }
Exemplo n.º 9
0
            private void ReportErrorsOnFailure()
            {
                // First and foremost, report if the user specified a name more than once.
                if (_pDuplicateSpecifiedName != null)
                {
                    GetErrorContext().Error(ErrorCode.ERR_DuplicateNamedArgument, _pDuplicateSpecifiedName);
                    return;
                }

                Debug.Assert(_methList.IsEmpty());
                // Report inaccessible.
                if (_results.GetInaccessibleResult())
                {
                    // We might have called this, but it is inaccesable...
                    GetSemanticChecker().ReportAccessError(_results.GetInaccessibleResult(), _pExprBinder.ContextForMemberLookup(), GetTypeQualifier(_pGroup));
                    return;
                }

                // Report bogus.
                if (_mpwiBogus)
                {
                    // We might have called this, but it is bogus...
                    GetErrorContext().ErrorRef(ErrorCode.ERR_BindToBogus, _mpwiBogus);
                    return;
                }

                bool bUseDelegateErrors = false;
                Name nameErr = _pGroup.name;

                // Check for an invoke.
                if (_pGroup.GetOptionalObject() != null &&
                        _pGroup.GetOptionalObject().type != null &&
                        _pGroup.GetOptionalObject().type.isDelegateType() &&
                        _pGroup.name == GetSymbolLoader().GetNameManager().GetPredefName(PredefinedName.PN_INVOKE))
                {
                    Debug.Assert(!_results.GetBestResult() || _results.GetBestResult().MethProp().getClass().IsDelegate());
                    Debug.Assert(!_results.GetBestResult() || _results.GetBestResult().GetType().getAggregate().IsDelegate());
                    bUseDelegateErrors = true;
                    nameErr = _pGroup.GetOptionalObject().type.getAggregate().name;
                }

                if (_results.GetBestResult())
                {
                    // If we had some invalid arguments for best matching.
                    ReportErrorsForBestMatching(bUseDelegateErrors, nameErr);
                }
                else if (_results.GetUninferrableResult() || _mpwiCantInferInstArg)
                {
                    if (!_results.GetUninferrableResult())
                    {
                        //copy the extension method for which instacne argument type inference failed
                        _results.GetUninferrableResult().Set(_mpwiCantInferInstArg.Sym.AsMethodSymbol(), _mpwiCantInferInstArg.GetType(), _mpwiCantInferInstArg.TypeArgs);
                    }
                    Debug.Assert(_results.GetUninferrableResult().Sym.IsMethodSymbol());

                    MethodSymbol sym = _results.GetUninferrableResult().Meth();
                    TypeArray pCurrentParameters = sym.Params;
                    // if we tried to bind to an extensionmethod and the instance argument Type Inference failed then the method does not exist
                    // on the type at all. this is treated as a lookup error
                    CType type = null;
                    if (_pGroup.GetOptionalObject() != null)
                    {
                        type = _pGroup.GetOptionalObject().type;
                    }
                    else if (_pGroup.GetOptionalLHS() != null)
                    {
                        type = _pGroup.GetOptionalLHS().type;
                    }

                    MethWithType mwtCantInfer = new MethWithType();
                    mwtCantInfer.Set(_results.GetUninferrableResult().Meth(), _results.GetUninferrableResult().GetType());
                    GetErrorContext().Error(ErrorCode.ERR_CantInferMethTypeArgs, mwtCantInfer);
                }
                else if (_mwtBadArity)
                {
                    int cvar = _mwtBadArity.Meth().typeVars.size;
                    GetErrorContext().ErrorRef(cvar > 0 ? ErrorCode.ERR_BadArity : ErrorCode.ERR_HasNoTypeVars, _mwtBadArity, new ErrArgSymKind(_mwtBadArity.Meth()), _pArguments.carg);
                }
                else if (_mpwiParamTypeConstraints)
                {
                    // This will always report an error
                    TypeBind.CheckMethConstraints(GetSemanticChecker(), GetErrorContext(), new MethWithInst(_mpwiParamTypeConstraints));
                }
                else if (_pInvalidSpecifiedName != null)
                {
                    // Give a better message for delegate invoke.
                    if (_pGroup.GetOptionalObject() != null &&
                            _pGroup.GetOptionalObject().type.IsAggregateType() &&
                            _pGroup.GetOptionalObject().type.AsAggregateType().GetOwningAggregate().IsDelegate())
                    {
                        GetErrorContext().Error(ErrorCode.ERR_BadNamedArgumentForDelegateInvoke, _pGroup.GetOptionalObject().type.AsAggregateType().GetOwningAggregate().name, _pInvalidSpecifiedName);
                    }
                    else
                    {
                        GetErrorContext().Error(ErrorCode.ERR_BadNamedArgument, _pGroup.name, _pInvalidSpecifiedName);
                    }
                }
                else if (_pNameUsedInPositionalArgument != null)
                {
                    GetErrorContext().Error(ErrorCode.ERR_NamedArgumentUsedInPositional, _pNameUsedInPositionalArgument);
                }
                else
                {
                    CParameterizedError error;

                    if (_pDelegate != null)
                    {
                        GetErrorContext().MakeError(out error, ErrorCode.ERR_MethDelegateMismatch, nameErr, _pDelegate);
                        GetErrorContext().AddRelatedTypeLoc(error, _pDelegate);
                    }
                    else
                    {
                        // The number of arguments must be wrong.

                        if (_fCandidatesUnsupported)
                        {
                            GetErrorContext().MakeError(out error, ErrorCode.ERR_BindToBogus, nameErr);
                        }
                        else if (bUseDelegateErrors)
                        {
                            Debug.Assert(0 == (_pGroup.flags & EXPRFLAG.EXF_CTOR));
                            GetErrorContext().MakeError(out error, ErrorCode.ERR_BadDelArgCount, nameErr, _pArguments.carg);
                        }
                        else
                        {
                            if (0 != (_pGroup.flags & EXPRFLAG.EXF_CTOR))
                            {
                                Debug.Assert(!_pGroup.GetParentType().IsTypeParameterType());
                                GetErrorContext().MakeError(out error, ErrorCode.ERR_BadCtorArgCount, _pGroup.GetParentType(), _pArguments.carg);
                            }
                            else
                            {
                                GetErrorContext().MakeError(out error, ErrorCode.ERR_BadArgCount, nameErr, _pArguments.carg);
                            }
                        }
                    }

                    // Report possible matches (same name and is accesible). We stored these in m_swtWrongCount.
                    for (int i = 0; i < _nWrongCount; i++)
                    {
                        if (GetSemanticChecker().CheckAccess(
                                    _swtWrongCount[i].Sym,
                                    _swtWrongCount[i].GetType(),
                                    _pExprBinder.ContextForMemberLookup(),
                                    GetTypeQualifier(_pGroup)))
                        {
                            GetErrorContext().AddRelatedSymLoc(error, _swtWrongCount[i].Sym);
                        }
                    }
                    GetErrorContext().SubmitError(error);
                }
            }
Exemplo n.º 10
0
        protected void PostBindProperty(bool fBaseCall, PropWithType pwt, EXPR pObject, out MethWithType pmwtGet, out MethWithType pmwtSet)
        {
            pmwtGet = new MethWithType();
            pmwtSet = new MethWithType();
            // Get the accessors.
            if (pwt.Prop().methGet != null)
            {
                pmwtGet.Set(pwt.Prop().methGet, pwt.GetType());
            }
            else
            {
                pmwtGet.Clear();
            }

            if (pwt.Prop().methSet != null)
            {
                pmwtSet.Set(pwt.Prop().methSet, pwt.GetType());
            }
            else
            {
                pmwtSet.Clear();
            }

            // If it is virtual, find a remap of the method to something more specific.  This
            // may alter where the accessors are found.
            if (fBaseCall && pObject != null)
            {
                if (pmwtGet)
                {
                    RemapToOverride(GetSymbolLoader(), pmwtGet, pObject.type);
                }
                if (pmwtSet)
                {
                    RemapToOverride(GetSymbolLoader(), pmwtSet, pObject.type);
                }
            }

            if (pwt.Prop().RetType != null)
            {
                checkUnsafe(pwt.Prop().RetType);
            }
        }
Exemplo n.º 11
0
 protected bool CheckPropertyAccess(MethWithType mwt, PropWithType pwtSlot, CType type)
 {
     ACCESSERROR error = SemanticChecker.CheckAccess2(mwt.Meth(), mwt.GetType(), ContextForMemberLookup(), type);
     if (error == ACCESSERROR.ACCESSERROR_NOACCESSTHRU)
     {
         ErrorContext.Error(ErrorCode.ERR_BadProtectedAccess, pwtSlot, type, ContextForMemberLookup());
         return false;
     }
     else if (error == ACCESSERROR.ACCESSERROR_NOACCESS)
     {
         ErrorContext.Error(mwt.Meth().isSetAccessor() ? ErrorCode.ERR_InaccessibleSetter : ErrorCode.ERR_InaccessibleGetter, pwtSlot);
         return false;
     }
     return true;
 }
Exemplo n.º 12
0
        // Value
        public EXPR BindValue(EXPR exprSrc)
        {
            Debug.Assert(exprSrc != null && exprSrc.type.IsNullableType());

            // For new T?(x), the answer is x.
            if (CNullable.IsNullableConstructor(exprSrc))
            {
                Debug.Assert(exprSrc.asCALL().GetOptionalArguments() != null && !exprSrc.asCALL().GetOptionalArguments().isLIST());
                return exprSrc.asCALL().GetOptionalArguments();
            }

            CType typeBase = exprSrc.type.AsNullableType().GetUnderlyingType();
            AggregateType ats = exprSrc.type.AsNullableType().GetAts(GetErrorContext());
            if (ats == null)
            {
                EXPRPROP rval = GetExprFactory().CreateProperty(typeBase, exprSrc);
                rval.SetError();
                return rval;
            }

            PropertySymbol prop = GetSymbolLoader().getBSymmgr().propNubValue;
            if (prop == null)
            {
                prop = GetSymbolLoader().getPredefinedMembers().GetProperty(PREDEFPROP.PP_G_OPTIONAL_VALUE);
                GetSymbolLoader().getBSymmgr().propNubValue = prop;
            }

            PropWithType pwt = new PropWithType(prop, ats);
            MethWithType mwt = new MethWithType(prop != null ? prop.methGet : null, ats);
            MethPropWithInst mpwi = new MethPropWithInst(prop, ats);
            EXPRMEMGRP pMemGroup = GetExprFactory().CreateMemGroup(exprSrc, mpwi);
            EXPRPROP exprRes = GetExprFactory().CreateProperty(typeBase, null, null, pMemGroup, pwt, mwt, null);

            if (prop == null)
            {
                exprRes.SetError();
            }

            return exprRes;
        }
Exemplo n.º 13
0
        public ExprProperty CreateProperty(CType pType, Expr pOptionalObjectThrough, Expr pOptionalArguments, ExprMemberGroup pMemberGroup, PropWithType pwtSlot, MethWithType mwtGet, MethWithType mwtSet)
        {
            ExprProperty rval = new ExprProperty(pType);

            rval.OptionalObjectThrough = pOptionalObjectThrough;
            rval.OptionalArguments     = pOptionalArguments;
            rval.MemberGroup           = pMemberGroup;

            if (pwtSlot != null)
            {
                rval.PropWithTypeSlot = pwtSlot;
            }
            if (mwtSet != null)
            {
                rval.MethWithTypeSet = mwtSet;
            }
            return(rval);
        }
Exemplo n.º 14
0
        public EXPRPROP CreateProperty(CType pType, EXPR pOptionalObjectThrough, EXPR pOptionalArguments, EXPRMEMGRP pMemberGroup, PropWithType pwtSlot, MethWithType mwtGet, MethWithType mwtSet)
        {
            EXPRPROP rval = new EXPRPROP();
            rval.kind = ExpressionKind.EK_PROP;
            rval.type = pType;
            rval.flags = 0;
            rval.SetOptionalObjectThrough(pOptionalObjectThrough);
            rval.SetOptionalArguments(pOptionalArguments);
            rval.SetMemberGroup(pMemberGroup);

            if (pwtSlot != null)
            {
                rval.pwtSlot = pwtSlot;
            }
            if (mwtSet != null)
            {
                rval.mwtSet = mwtSet;
            }
            Debug.Assert(rval != null);
            return (rval);
        }