Exemple #1
0
        internal static (IType, IParameter[]) DecodeSignature(MetadataModule module, IParameterizedMember owner, MethodSignature <IType> signature, ParameterHandleCollection?parameterHandles)
        {
            var metadata = module.metadata;
            int i        = 0;
            CustomAttributeHandleCollection?returnTypeAttributes = null;

            IParameter[] parameters = new IParameter[signature.RequiredParameterCount
                                                     + (signature.Header.CallingConvention == SignatureCallingConvention.VarArgs ? 1 : 0)];
            if (parameterHandles != null)
            {
                foreach (var parameterHandle in parameterHandles)
                {
                    var par = metadata.GetParameter(parameterHandle);
                    if (par.SequenceNumber == 0)
                    {
                        // "parameter" holds return type attributes
                        returnTypeAttributes = par.GetCustomAttributes();
                    }
                    else if (par.SequenceNumber > 0 && i < signature.RequiredParameterCount)
                    {
                        Debug.Assert(par.SequenceNumber - 1 == i);
                        var parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType(
                            signature.ParameterTypes[i], module.Compilation,
                            par.GetCustomAttributes(), metadata, module.TypeSystemOptions);
                        parameters[i] = new MetadataParameter(module, owner, parameterType, parameterHandle);
                        i++;
                    }
                }
            }
            while (i < signature.RequiredParameterCount)
            {
                var parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType(
                    signature.ParameterTypes[i], module.Compilation, null, metadata, module.TypeSystemOptions);
                parameters[i] = new DefaultParameter(parameterType, name: string.Empty, owner,
                                                     isRef: parameterType.Kind == TypeKind.ByReference);
                i++;
            }
            if (signature.Header.CallingConvention == SignatureCallingConvention.VarArgs)
            {
                parameters[i] = new DefaultParameter(SpecialType.ArgList, name: string.Empty, owner);
                i++;
            }
            Debug.Assert(i == parameters.Length);
            var returnType = ApplyAttributeTypeVisitor.ApplyAttributesToType(signature.ReturnType,
                                                                             module.Compilation, returnTypeAttributes, metadata, module.TypeSystemOptions);

            return(returnType, parameters);
        }
Exemple #2
0
        protected IParameter[] CreateParameters(Func <IType, IType> substitution)
        {
            var paramDefs = ((IParameterizedMember)this.baseMember).Parameters;

            if (paramDefs.Count == 0)
            {
                return(Empty <IParameter> .Array);
            }
            else
            {
                var parameters = new IParameter[paramDefs.Count];
                for (int i = 0; i < parameters.Length; i++)
                {
                    var   p       = paramDefs[i];
                    IType newType = substitution(p.Type);
                    parameters[i] = new DefaultParameter(
                        newType, p.Name, this,
                        p.Attributes, p.IsRef, p.IsOut,
                        p.IsParams, p.IsOptional, p.ConstantValue
                        );
                }
                return(parameters);
            }
        }
Exemple #3
0
        protected IList <IParameter> CreateParameters(TypeVisitor substitution)
        {
            var paramDefs = ((IParameterizedMember)this.baseMember).Parameters;

            if (paramDefs.Count == 0)
            {
                return(EmptyList <IParameter> .Instance);
            }
            else
            {
                var parameters = new IParameter[paramDefs.Count];
                for (int i = 0; i < parameters.Length; i++)
                {
                    var   p       = paramDefs[i];
                    IType newType = p.Type.AcceptVisitor(substitution);
                    parameters[i] = new DefaultParameter(
                        newType, p.Name, this,
                        p.Region, p.Attributes, p.IsRef, p.IsOut,
                        p.IsParams, p.IsOptional, p.ConstantValue
                        );
                }
                return(Array.AsReadOnly(parameters));
            }
        }
Exemple #4
0
        internal static (IType, IParameter[]) DecodeSignature(MetadataModule module, IParameterizedMember owner, MethodSignature <IType> signature, ParameterHandleCollection?parameterHandles, Nullability nullableContext)
        {
            var metadata = module.metadata;
            int i        = 0;
            CustomAttributeHandleCollection?returnTypeAttributes = null;

            IParameter[] parameters = new IParameter[signature.RequiredParameterCount
                                                     + (signature.Header.CallingConvention == SignatureCallingConvention.VarArgs ? 1 : 0)];
            IType parameterType;

            if (parameterHandles != null)
            {
                foreach (var parameterHandle in parameterHandles)
                {
                    var par = metadata.GetParameter(parameterHandle);
                    if (par.SequenceNumber == 0)
                    {
                        // "parameter" holds return type attributes
                        returnTypeAttributes = par.GetCustomAttributes();
                    }
                    else if (par.SequenceNumber > 0 && i < signature.RequiredParameterCount)
                    {
                        // "Successive rows of the Param table that are owned by the same method shall be
                        // ordered by increasing Sequence value - although gaps in the sequence are allowed"
                        Debug.Assert(i < par.SequenceNumber);
                        // Fill gaps in the sequence with non-metadata parameters:
                        while (i < par.SequenceNumber - 1)
                        {
                            parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType(
                                signature.ParameterTypes[i], module.Compilation, null, metadata, module.TypeSystemOptions, nullableContext);
                            parameters[i] = new DefaultParameter(parameterType, name: string.Empty, owner,
                                                                 referenceKind: parameterType.Kind == TypeKind.ByReference ? ReferenceKind.Ref : ReferenceKind.None);
                            i++;
                        }
                        parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType(
                            signature.ParameterTypes[i], module.Compilation,
                            par.GetCustomAttributes(), metadata, module.TypeSystemOptions, nullableContext);
                        parameters[i] = new MetadataParameter(module, owner, parameterType, parameterHandle);
                        i++;
                    }
                }
            }
            while (i < signature.RequiredParameterCount)
            {
                parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType(
                    signature.ParameterTypes[i], module.Compilation, null, metadata, module.TypeSystemOptions, nullableContext);
                parameters[i] = new DefaultParameter(parameterType, name: string.Empty, owner,
                                                     referenceKind: parameterType.Kind == TypeKind.ByReference ? ReferenceKind.Ref : ReferenceKind.None);
                i++;
            }
            if (signature.Header.CallingConvention == SignatureCallingConvention.VarArgs)
            {
                parameters[i] = new DefaultParameter(SpecialType.ArgList, name: string.Empty, owner);
                i++;
            }
            Debug.Assert(i == parameters.Length);
            var returnType = ApplyAttributeTypeVisitor.ApplyAttributesToType(signature.ReturnType,
                                                                             module.Compilation, returnTypeAttributes, metadata, module.TypeSystemOptions, nullableContext);

            return(returnType, parameters);
        }
Exemple #5
0
 public override string ToString()
 {
     return(DefaultParameter.ToString(this));
 }
Exemple #6
0
 public override string ToString()
 {
     return($"{MetadataTokens.GetToken(handle):X8} {DefaultParameter.ToString(this)}");
 }
Exemple #7
0
        internal static (IType returnType, IParameter[] parameters, ModifiedType returnTypeModifier) DecodeSignature(
            MetadataModule module, IParameterizedMember owner,
            MethodSignature <IType> signature, ParameterHandleCollection?parameterHandles,
            Nullability nullableContext, TypeSystemOptions typeSystemOptions,
            CustomAttributeHandleCollection?returnTypeAttributes = null)
        {
            var metadata = module.metadata;
            int i        = 0;

            IParameter[] parameters = new IParameter[signature.RequiredParameterCount
                                                     + (signature.Header.CallingConvention == SignatureCallingConvention.VarArgs ? 1 : 0)];
            IType parameterType;

            if (parameterHandles != null)
            {
                foreach (var parameterHandle in parameterHandles)
                {
                    var par = metadata.GetParameter(parameterHandle);
                    if (par.SequenceNumber == 0)
                    {
                        // "parameter" holds return type attributes.
                        // Note: for properties, the attributes normally stored on a method's return type
                        // are instead stored as normal attributes on the property.
                        // So MetadataProperty provides a non-null value for returnTypeAttributes,
                        // which then should be preferred over the attributes on the accessor's parameters.
                        if (returnTypeAttributes == null)
                        {
                            returnTypeAttributes = par.GetCustomAttributes();
                        }
                    }
                    else if (i < par.SequenceNumber && par.SequenceNumber <= signature.RequiredParameterCount)
                    {
                        // "Successive rows of the Param table that are owned by the same method shall be
                        // ordered by increasing Sequence value - although gaps in the sequence are allowed"
                        Debug.Assert(par.SequenceNumber <= signature.ParameterTypes.Length);
                        Debug.Assert(par.SequenceNumber <= parameters.Length);
                        // Fill gaps in the sequence with non-metadata parameters:
                        while (i < par.SequenceNumber - 1)
                        {
                            parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType(
                                signature.ParameterTypes[i], module.Compilation, null, metadata, typeSystemOptions, nullableContext);
                            parameters[i] = new DefaultParameter(parameterType, name: string.Empty, owner,
                                                                 referenceKind: parameterType.Kind == TypeKind.ByReference ? ReferenceKind.Ref : ReferenceKind.None);
                            i++;
                        }
                        parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType(
                            signature.ParameterTypes[i], module.Compilation,
                            par.GetCustomAttributes(), metadata, typeSystemOptions, nullableContext);
                        parameters[i] = new MetadataParameter(module, owner, parameterType, parameterHandle);
                        i++;
                    }
                }
            }
            while (i < signature.RequiredParameterCount)
            {
                parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType(
                    signature.ParameterTypes[i], module.Compilation, null, metadata, typeSystemOptions, nullableContext);
                parameters[i] = new DefaultParameter(parameterType, name: string.Empty, owner,
                                                     referenceKind: parameterType.Kind == TypeKind.ByReference ? ReferenceKind.Ref : ReferenceKind.None);
                i++;
            }
            if (signature.Header.CallingConvention == SignatureCallingConvention.VarArgs)
            {
                parameters[i] = new DefaultParameter(SpecialType.ArgList, name: string.Empty, owner);
                i++;
            }
            Debug.Assert(i == parameters.Length);
            var returnType = ApplyAttributeTypeVisitor.ApplyAttributesToType(signature.ReturnType,
                                                                             module.Compilation, returnTypeAttributes, metadata, typeSystemOptions, nullableContext,
                                                                             isSignatureReturnType: true);

            return(returnType, parameters, signature.ReturnType as ModifiedType);
        }