Exemple #1
0
        public static FunctionPointerType FromSignature(MethodSignature <IType> signature, MetadataModule module)
        {
            IType returnType          = signature.ReturnType;
            bool  returnIsRefReadOnly = false;

            if (returnType is ModifiedType modReturn && modReturn.Modifier.IsKnownType(KnownAttribute.In))
            {
                returnType          = modReturn.ElementType;
                returnIsRefReadOnly = true;
            }
            var parameterTypes          = ImmutableArray.CreateBuilder <IType>(signature.ParameterTypes.Length);
            var parameterReferenceKinds = ImmutableArray.CreateBuilder <ReferenceKind>(signature.ParameterTypes.Length);

            foreach (var p in signature.ParameterTypes)
            {
                IType         paramType = p;
                ReferenceKind kind      = ReferenceKind.None;
                if (p is ModifiedType modreq)
                {
                    if (modreq.Modifier.IsKnownType(KnownAttribute.In))
                    {
                        kind      = ReferenceKind.In;
                        paramType = modreq.ElementType;
                    }
                    else if (modreq.Modifier.IsKnownType(KnownAttribute.Out))
                    {
                        kind      = ReferenceKind.Out;
                        paramType = modreq.ElementType;
                    }
                }
                if (paramType.Kind == TypeKind.ByReference)
                {
                    if (kind == ReferenceKind.None)
                    {
                        kind = ReferenceKind.Ref;
                    }
                }
                else
                {
                    kind = ReferenceKind.None;
                }
                parameterTypes.Add(paramType);
                parameterReferenceKinds.Add(kind);
            }
            return(new FunctionPointerType(
                       module, signature.Header.CallingConvention,
                       returnType, returnIsRefReadOnly,
                       parameterTypes.MoveToImmutable(), parameterReferenceKinds.MoveToImmutable()));
        }
Exemple #2
0
 public TypeProvider(MetadataModule module)
 {
     this.module      = module;
     this.compilation = module.Compilation;
 }
Exemple #3
0
        public static FunctionPointerType FromSignature(MethodSignature <IType> signature, MetadataModule module)
        {
            IType returnType          = signature.ReturnType;
            bool  returnIsRefReadOnly = false;
            var   customCallConvs     = ImmutableArray.CreateBuilder <IType>();

            while (returnType is ModifiedType modReturn)
            {
                if (modReturn.Modifier.IsKnownType(KnownAttribute.In))
                {
                    returnType          = modReturn.ElementType;
                    returnIsRefReadOnly = true;
                }
                else if (modReturn.Modifier.Name.StartsWith("CallConv", StringComparison.Ordinal) &&
                         modReturn.Modifier.Namespace == "System.Runtime.CompilerServices")
                {
                    returnType = modReturn.ElementType;
                    customCallConvs.Add(modReturn.Modifier);
                }
                else
                {
                    break;
                }
            }
            var parameterTypes          = ImmutableArray.CreateBuilder <IType>(signature.ParameterTypes.Length);
            var parameterReferenceKinds = ImmutableArray.CreateBuilder <ReferenceKind>(signature.ParameterTypes.Length);

            foreach (var p in signature.ParameterTypes)
            {
                IType         paramType = p;
                ReferenceKind kind      = ReferenceKind.None;
                if (p is ModifiedType modreq)
                {
                    if (modreq.Modifier.IsKnownType(KnownAttribute.In))
                    {
                        kind      = ReferenceKind.In;
                        paramType = modreq.ElementType;
                    }
                    else if (modreq.Modifier.IsKnownType(KnownAttribute.Out))
                    {
                        kind      = ReferenceKind.Out;
                        paramType = modreq.ElementType;
                    }
                }
                if (paramType.Kind == TypeKind.ByReference)
                {
                    if (kind == ReferenceKind.None)
                    {
                        kind = ReferenceKind.Ref;
                    }
                }
                else
                {
                    kind = ReferenceKind.None;
                }
                parameterTypes.Add(paramType);
                parameterReferenceKinds.Add(kind);
            }
            return(new FunctionPointerType(
                       module, signature.Header.CallingConvention, customCallConvs.ToImmutable(),
                       returnType, returnIsRefReadOnly,
                       parameterTypes.MoveToImmutable(), parameterReferenceKinds.MoveToImmutable()));
        }