Пример #1
0
 internal static PEParameterSymbol Create(
     PEModuleSymbol moduleSymbol,
     PEPropertySymbol containingSymbol,
     bool isContainingSymbolVirtual,
     int ordinal,
     ParameterHandle handle,
     ParamInfo <TypeSymbol> parameterInfo,
     Symbol nullableContext,
     out bool isBad
     )
 {
     return(Create(
                moduleSymbol,
                containingSymbol,
                isContainingSymbolVirtual,
                ordinal,
                parameterInfo.IsByRef,
                parameterInfo.RefCustomModifiers,
                parameterInfo.Type,
                handle,
                nullableContext,
                parameterInfo.CustomModifiers,
                isReturn: false,
                out isBad
                ));
 }
Пример #2
0
        internal static PEPropertySymbol Create(
            PEModuleSymbol moduleSymbol,
            PENamedTypeSymbol containingType,
            PropertyDefinitionHandle handle,
            PEMethodSymbol getMethod,
            PEMethodSymbol setMethod)
        {
            Debug.Assert((object)moduleSymbol != null);
            Debug.Assert((object)containingType != null);
            Debug.Assert(!handle.IsNil);

            var                     metadataDecoder = new MetadataDecoder(moduleSymbol, containingType);
            SignatureHeader         callingConvention;
            BadImageFormatException propEx;
            var                     propertyParams = metadataDecoder.GetSignatureForProperty(handle, out callingConvention, out propEx);

            Debug.Assert(propertyParams.Length > 0);

            var returnInfo = propertyParams[0];

            PEPropertySymbol result = returnInfo.CustomModifiers.IsDefaultOrEmpty && returnInfo.RefCustomModifiers.IsDefaultOrEmpty
                ? new PEPropertySymbol(moduleSymbol, containingType, handle, getMethod, setMethod, propertyParams, metadataDecoder)
                : new PEPropertySymbolWithCustomModifiers(moduleSymbol, containingType, handle, getMethod, setMethod, propertyParams, metadataDecoder);

            // A property should always have this modreq, and vice versa.
            var isBad = (result.RefKind == RefKind.In) != result.RefCustomModifiers.HasInAttributeModifier();

            if (propEx != null || isBad)
            {
                result._lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, result);
            }

            return(result);
        }
Пример #3
0
        private static ImmutableArray <ParameterSymbol> GetParameters(
            PEModuleSymbol moduleSymbol,
            PEPropertySymbol property,
            ParamInfo <TypeSymbol>[] propertyParams,
            ParamInfo <TypeSymbol>[] accessorParams,
            bool isPropertyVirtual,
            out bool anyParameterIsBad)
        {
            anyParameterIsBad = false;

            // First parameter is the property type.
            if (propertyParams.Length < 2)
            {
                return(ImmutableArray <ParameterSymbol> .Empty);
            }

            var numAccessorParams = accessorParams.Length;

            var parameters = new ParameterSymbol[propertyParams.Length - 1];

            for (int i = 1; i < propertyParams.Length; i++) // from 1 to skip property/return type
            {
                // NOTE: this is a best guess at the Dev10 behavior.  The actual behavior is
                // in the unmanaged helper code that Dev10 uses to load the metadata.
                var  propertyParam = propertyParams[i];
                var  paramHandle   = i < numAccessorParams ? accessorParams[i].Handle : propertyParam.Handle;
                var  ordinal       = i - 1;
                bool isBad;

                // https://github.com/dotnet/roslyn/issues/29821: handle extra annotations
                parameters[ordinal] = PEParameterSymbol.Create(moduleSymbol, property, isPropertyVirtual, ordinal, paramHandle, propertyParam, nullableContext: property, extraAnnotations: default, out isBad);
Пример #4
0
 /// <summary>
 /// Construct a parameter symbol for a property loaded from metadata.
 /// </summary>
 /// <param name="moduleSymbol"></param>
 /// <param name="containingSymbol"></param>
 /// <param name="ordinal"></param>
 /// <param name="handle">The property parameter doesn't have a name in metadata,
 /// so this is the handle of a corresponding accessor parameter, if there is one,
 /// or of the ParamInfo passed in, otherwise).</param>
 /// <param name="isBad" />
 /// <param name="parameter"></param>
 internal static PEParameterSymbol Create(
     PEModuleSymbol moduleSymbol,
     PEPropertySymbol containingSymbol,
     int ordinal,
     ParameterHandle handle,
     ParamInfo <TypeSymbol> parameter,
     out bool isBad)
 {
     return(Create(moduleSymbol, containingSymbol, ordinal, parameter.IsByRef, parameter.CountOfCustomModifiersPrecedingByRef, parameter.Type, handle, parameter.CustomModifiers, out isBad));
 }
Пример #5
0
 /// <summary>
 /// Construct a parameter symbol for a property loaded from metadata.
 /// </summary>
 /// <param name="moduleSymbol"></param>
 /// <param name="containingSymbol"></param>
 /// <param name="ordinal"></param>
 /// <param name="handle">The property parameter doesn't have a name in metadata,
 /// so this is the handle of a corresponding accessor parameter, if there is one,
 /// or of the ParamInfo passed in, otherwise).</param>
 /// <param name="isBad" />
 /// <param name="parameter"></param>
 internal PEParameterSymbol(
     PEModuleSymbol moduleSymbol,
     PEPropertySymbol containingSymbol,
     int ordinal,
     ParameterHandle handle,
     ParamInfo <TypeSymbol> parameter,
     out bool isBad)
     : this(moduleSymbol, containingSymbol, ordinal, parameter.IsByRef, parameter.HasByRefBeforeCustomModifiers, parameter.Type, handle, parameter.CustomModifiers, out isBad)
 {
 }
Пример #6
0
        internal static PEPropertySymbol Create(
            PEModuleSymbol moduleSymbol,
            PEPropertySymbol indexer)
        {
            Debug.Assert(indexer.IsIndexer);
            var ps = Create(moduleSymbol, indexer._containingType, indexer._handle, indexer._getMethod, indexer._setMethod);

            ps._namedIndexer = true;
            return(ps);
        }
Пример #7
0
 /// <summary>
 /// Construct a parameter symbol for a property loaded from metadata.
 /// </summary>
 /// <param name="moduleSymbol"></param>
 /// <param name="containingSymbol"></param>
 /// <param name="ordinal"></param>
 /// <param name="handle">The property parameter doesn't have a name in metadata,
 /// so this is the handle of a corresponding accessor parameter, if there is one,
 /// or of the ParamInfo passed in, otherwise).</param>
 /// <param name="parameterInfo" />
 /// <param name="isBad" />
 internal static PEParameterSymbol Create(
     PEModuleSymbol moduleSymbol,
     PEPropertySymbol containingSymbol,
     bool isContainingSymbolVirtual,
     int ordinal,
     ParameterHandle handle,
     ParamInfo <TypeSymbol> parameterInfo,
     ImmutableArray <byte> extraAnnotations,
     out bool isBad)
 {
     return(Create(
                moduleSymbol, containingSymbol, isContainingSymbolVirtual, ordinal,
                parameterInfo.IsByRef, parameterInfo.RefCustomModifiers, parameterInfo.Type, extraAnnotations,
                handle, parameterInfo.CustomModifiers, isReturn: false, out isBad));
 }
Пример #8
0
        private static ImmutableArray <ParameterSymbol> GetParameters(
            PEModuleSymbol moduleSymbol,
            PEPropertySymbol property,
            ParamInfo <TypeSymbol>[] propertyParams,
            ParamInfo <TypeSymbol>[] accessorParams,
            bool isPropertyVirtual,
            out bool anyParameterIsBad)
        {
            anyParameterIsBad = false;

            // First parameter is the property type.
            if (propertyParams.Length < 2)
            {
                return(ImmutableArray <ParameterSymbol> .Empty);
            }

            var numAccessorParams = accessorParams.Length;

            var parameters = new ParameterSymbol[propertyParams.Length - 1];

            for (int i = 1; i < propertyParams.Length; i++) // from 1 to skip property/return type
            {
                // NOTE: this is a best guess at the Dev10 behavior.  The actual behavior is
                // in the unmanaged helper code that Dev10 uses to load the metadata.
                var  propertyParam = propertyParams[i];
                var  paramHandle   = i < numAccessorParams ? accessorParams[i].Handle : propertyParam.Handle;
                var  ordinal       = i - 1;
                bool isBad;

                parameters[ordinal] = PEParameterSymbol.Create(moduleSymbol, property, isPropertyVirtual, ordinal, paramHandle, propertyParam, out isBad);

                if (isBad)
                {
                    anyParameterIsBad = true;
                }
            }

            return(parameters.AsImmutableOrNull());
        }
Пример #9
0
        internal static PEPropertySymbol Create(
            PEModuleSymbol moduleSymbol,
            PENamedTypeSymbol containingType,
            PropertyDefinitionHandle handle,
            PEMethodSymbol getMethod,
            PEMethodSymbol setMethod)
        {
            Debug.Assert((object)moduleSymbol != null);
            Debug.Assert((object)containingType != null);
            Debug.Assert(!handle.IsNil);

            var metadataDecoder = new MetadataDecoder(moduleSymbol, containingType);
            SignatureHeader callingConvention;
            BadImageFormatException propEx;
            var propertyParams = metadataDecoder.GetSignatureForProperty(handle, out callingConvention, out propEx);
            Debug.Assert(propertyParams.Length > 0);

            var returnInfo = propertyParams[0];
            PEPropertySymbol result;

            if (returnInfo.CustomModifiers.IsDefaultOrEmpty && returnInfo.RefCustomModifiers.IsDefaultOrEmpty)
            {
                result = new PEPropertySymbol(moduleSymbol, containingType, handle, getMethod, setMethod, 0, propertyParams, metadataDecoder);
            }
            else
            {
                result = new PEPropertySymbolWithCustomModifiers(moduleSymbol, containingType, handle, getMethod, setMethod, propertyParams, metadataDecoder);
            }

            if (propEx != null)
            {
                result._lazyUseSiteDiagnostic = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, result);
            }

            return result;
        }
Пример #10
0
 /// <summary>
 /// Associate the method with a particular property. Returns
 /// false if the method is already associated with a property or event.
 /// </summary>
 internal bool SetAssociatedProperty(PEPropertySymbol propertySymbol, MethodKind methodKind)
 {
     Debug.Assert((methodKind == MethodKind.PropertyGet) || (methodKind == MethodKind.PropertySet));
     return this.SetAssociatedPropertyOrEvent(propertySymbol, methodKind);
 }
Пример #11
0
        private static ImmutableArray<ParameterSymbol> GetParameters(
            PEModuleSymbol moduleSymbol,
            PEPropertySymbol property,
            MetadataDecoder.ParamInfo[] propertyParams,
            MetadataDecoder.ParamInfo[] accessorParams,
            out bool anyParameterIsBad)
        {
            anyParameterIsBad = false;

            // First parameter is the property type.
            if (propertyParams.Length < 2)
            {
                return ImmutableArray<ParameterSymbol>.Empty;
            }

            var numAccessorParams = accessorParams.Length;

            var parameters = new ParameterSymbol[propertyParams.Length - 1];
            for (int i = 1; i < propertyParams.Length; i++) // from 1 to skip property/return type
            {
                // NOTE: this is a best guess at the Dev10 behavior.  The actual behavior is
                // in the unmanaged helper code that Dev10 uses to load the metadata.
                var propertyParam = propertyParams[i];
                var paramHandle = i < numAccessorParams ? accessorParams[i].Handle : propertyParam.Handle;
                var ordinal = i - 1;
                bool isBad;
                parameters[ordinal] = new PEParameterSymbol(moduleSymbol, property, ordinal, paramHandle, propertyParam, out isBad);

                if (isBad)
                {
                    anyParameterIsBad = true;
                }
            }
            return parameters.AsImmutableOrNull();
        }
Пример #12
0
 /// <summary>
 /// Construct a parameter symbol for a property loaded from metadata.
 /// </summary>
 /// <param name="moduleSymbol"></param>
 /// <param name="containingSymbol"></param>
 /// <param name="ordinal"></param>
 /// <param name="handle">The property parameter doesn't have a name in metadata,
 /// so this is the handle of a corresponding accessor parameter, if there is one,
 /// or of the ParamInfo passed in, otherwise).</param>
 /// <param name="isBad" />
 /// <param name="parameter"></param>
 internal static PEParameterSymbol Create(
     PEModuleSymbol moduleSymbol,
     PEPropertySymbol containingSymbol,
     int ordinal,
     ParameterHandle handle,
     ParamInfo<TypeSymbol> parameter,
     out bool isBad)
 {
     return Create(moduleSymbol, containingSymbol, ordinal, parameter.IsByRef, parameter.CountOfCustomModifiersPrecedingByRef, parameter.Type, handle, parameter.CustomModifiers, out isBad);
 }
Пример #13
0
 /// <summary>
 /// Construct a parameter symbol for a property loaded from metadata.
 /// </summary>
 /// <param name="moduleSymbol"></param>
 /// <param name="containingSymbol"></param>
 /// <param name="ordinal"></param>
 /// <param name="handle">The property parameter doesn't have a name in metadata,
 /// so this is the handle of a corresponding accessor parameter, if there is one,
 /// or of the ParamInfo passed in, otherwise).</param>
 /// <param name="isBad" />
 /// <param name="parameter"></param>
 internal PEParameterSymbol(
     PEModuleSymbol moduleSymbol,
     PEPropertySymbol containingSymbol,
     int ordinal,
     ParameterHandle handle,
     MetadataDecoder.ParamInfo parameter,
     out bool isBad)
     : this(moduleSymbol, containingSymbol, ordinal, parameter.IsByRef, parameter.HasByRefBeforeCustomModifiers, parameter.Type, handle, parameter.CustomModifiers, out isBad)
 {
 }
Пример #14
0
 /// <summary>
 /// Associate the method with a particular property. Returns
 /// false if the method is already associated with a property or event.
 /// </summary>
 internal bool SetAssociatedProperty(PEPropertySymbol propertySymbol, MethodKind methodKind)
 {
     Debug.Assert((methodKind == MethodKind.PropertyGet) || (methodKind == MethodKind.PropertySet));
     return(this.SetAssociatedPropertyOrEvent(propertySymbol, methodKind));
 }
Пример #15
0
        private void VerifyAccessor(MethodSymbol accessor, PEPropertySymbol associatedProperty, MethodKind methodKind)
        {
            Assert.NotNull(accessor);
            Assert.Equal(accessor.AssociatedSymbol, associatedProperty);
            Assert.Equal(accessor.MethodKind, methodKind);

            if (associatedProperty != null)
            {
                var method = (methodKind == MethodKind.PropertyGet) ? associatedProperty.GetMethod : associatedProperty.SetMethod;
                Assert.Equal(accessor, method);
            }
        }
Пример #16
0
 private static void VerifyAccessibility(PEPropertySymbol property, Accessibility propertyAccessibility, Accessibility getAccessibility, Accessibility setAccessibility)
 {
     Assert.Equal(property.DeclaredAccessibility, propertyAccessibility);
     Assert.False(property.MustCallMethodsDirectly);
     VerifyAccessorAccessibility(property.GetMethod, getAccessibility);
     VerifyAccessorAccessibility(property.SetMethod, setAccessibility);
 }