Example #1
0
 internal SubmissionEntryPoint(NamedTypeSymbol containingType, TypeSymbol returnType, TypeSymbol submissionArrayType) :
     base(containingType)
 {
     Debug.Assert(containingType.IsSubmissionClass);
     Debug.Assert(returnType.SpecialType != SpecialType.System_Void);
     _parameters = ImmutableArray.Create <ParameterSymbol>(SynthesizedParameterSymbol.Create(this, submissionArrayType, 0, RefKind.None, "submissionArray"));
     _returnType = returnType;
 }
Example #2
0
        internal SynthesizedThrowIfNullMethod(SourceModuleSymbol containingModule, PrivateImplementationDetails privateImplType, MethodSymbol throwMethod, TypeSymbol returnType, TypeSymbol argumentParamType, TypeSymbol paramNameParamType)
            : base(containingModule, privateImplType, returnType, PrivateImplementationDetails.SynthesizedThrowIfNullFunctionName)
        {
            ThrowMethod = throwMethod;

            this.SetParameters(ImmutableArray.Create <ParameterSymbol>(
                                   SynthesizedParameterSymbol.Create(this, TypeWithAnnotations.Create(argumentParamType), ordinal: 0, RefKind.None, "argument"),
                                   SynthesizedParameterSymbol.Create(this, TypeWithAnnotations.Create(paramNameParamType), ordinal: 1, RefKind.None, "paramName")));
        }
Example #3
0
 private static ParameterSymbol CopyParameter(ParameterSymbol parameter, MethodSymbol owner)
 {
     return(SynthesizedParameterSymbol.Create(
                owner,
                parameter.Type,
                parameter.Ordinal,
                parameter.RefKind,
                GeneratedNames.LambdaCopyParameterName(parameter))); // Make sure nothing binds to this.
 }
            internal SubmissionEntryPoint(NamedTypeSymbol containingType, TypeWithAnnotations returnType, TypeSymbol submissionArrayType) :
                base(containingType)
            {
                Debug.Assert(containingType.IsSubmissionClass);
                Debug.Assert(!returnType.IsVoidType());
                _parameters = ImmutableArray.Create(SynthesizedParameterSymbol.Create(this,
                    TypeWithAnnotations.Create(submissionArrayType), 0, RefKind.None, "submissionArray"));

                _returnType = returnType;
            }
Example #5
0
        public SynthesizedSealedPropertyAccessor(PropertySymbol property, MethodSymbol overriddenAccessor)
        {
            Debug.Assert((object)property != null);
            Debug.Assert(property.IsSealed);
            Debug.Assert((object)overriddenAccessor != null);

            _property           = property;
            _overriddenAccessor = overriddenAccessor;
            _parameters         = SynthesizedParameterSymbol.DeriveParameters(overriddenAccessor, this);
        }
Example #6
0
            internal SubmissionEntryPoint(NamedTypeSymbol containingType, TypeSymbolWithAnnotations returnType, TypeSymbol submissionArrayType) :
                base(containingType)
            {
                Debug.Assert(containingType.IsSubmissionClass);
                Debug.Assert(returnType.SpecialType != SpecialType.System_Void);
                _parameters = ImmutableArray.Create(SynthesizedParameterSymbol.Create(this,
                                                                                      TypeSymbolWithAnnotations.Create(nonNullTypesContext: ContainingModule, submissionArrayType), 0, RefKind.None, "submissionArray"));

                _returnType = returnType;
            }
Example #7
0
            internal AsyncForwardEntryPoint(
                CSharpCompilation compilation,
                NamedTypeSymbol containingType,
                MethodSymbol userMain
                ) : base(containingType)
            {
                // There should be no way for a userMain to be passed in unless it already passed the
                // parameter checks for determining entrypoint validity.
                Debug.Assert(userMain.ParameterCount == 0 || userMain.ParameterCount == 1);

                UserMain = userMain;
                _userMainReturnTypeSyntax = userMain.ExtractReturnTypeSyntax();
                var binder = compilation.GetBinder(_userMainReturnTypeSyntax);

                _parameters = SynthesizedParameterSymbol.DeriveParameters(userMain, this);

                var arguments = Parameters.SelectAsArray(
                    (p, s) => (BoundExpression) new BoundParameter(s, p, p.Type),
                    _userMainReturnTypeSyntax
                    );

                // Main(args) or Main()
                BoundCall userMainInvocation = new BoundCall(
                    syntax: _userMainReturnTypeSyntax,
                    receiverOpt: null,
                    method: userMain,
                    arguments: arguments,
                    argumentNamesOpt: default(ImmutableArray <string>),
                    argumentRefKindsOpt: default(ImmutableArray <RefKind>),
                    isDelegateCall: false,
                    expanded: false,
                    invokedAsExtensionMethod: false,
                    argsToParamsOpt: default(ImmutableArray <int>),
                    defaultArguments: default(BitVector),
                    resultKind: LookupResultKind.Viable,
                    type: userMain.ReturnType
                    )
                {
                    WasCompilerGenerated = true
                };

                // The diagnostics that would be produced here will already have been captured and returned.
                var success = binder.GetAwaitableExpressionInfo(
                    userMainInvocation,
                    out _getAwaiterGetResultCall !,
                    _userMainReturnTypeSyntax,
                    BindingDiagnosticBag.Discarded
                    );

                Debug.Assert(
                    ReturnType.IsVoidType() || ReturnType.SpecialType == SpecialType.System_Int32
                    );
            }
Example #8
0
 internal Constructor(
     SourceMemberContainerTypeSymbol delegateType,
     TypeWithAnnotations voidType,
     TypeWithAnnotations objectType,
     TypeWithAnnotations intPtrType,
     DelegateDeclarationSyntax syntax)
     : base(delegateType, voidType, syntax, MethodKind.Constructor, DeclarationModifiers.Public)
 {
     InitializeParameters(ImmutableArray.Create <ParameterSymbol>(
                              SynthesizedParameterSymbol.Create(this, objectType, 0, RefKind.None, "object"),
                              SynthesizedParameterSymbol.Create(this, intPtrType, 1, RefKind.None, "method")));
 }
 internal AnonymousTypeEqualsMethodSymbol(NamedTypeSymbol container)
     : base(container, WellKnownMemberNames.ObjectEquals)
 {
     _parameters = ImmutableArray.Create <ParameterSymbol>(
         SynthesizedParameterSymbol.Create(
             this,
             TypeWithAnnotations.Create(this.Manager.System_Object),
             0,
             RefKind.None,
             "value"
             )
         );
 }
Example #10
0
        /// <summary>
        /// For each parameter of a source method, construct a corresponding synthesized parameter
        /// for a destination method.
        /// </summary>
        /// <param name="sourceMethod">Has parameters.</param>
        /// <param name="destinationMethod">Needs parameters.</param>
        /// <returns>Synthesized parameters to add to destination method.</returns>
        internal static ImmutableArray <ParameterSymbol> DeriveParameters(MethodSymbol sourceMethod, MethodSymbol destinationMethod)
        {
            var builder = ArrayBuilder <ParameterSymbol> .GetInstance();

            foreach (var oldParam in sourceMethod.Parameters)
            {
                //same properties as the old one, just change the owner
                builder.Add(SynthesizedParameterSymbol.Create(destinationMethod, oldParam.Type, oldParam.Ordinal,
                                                              oldParam.RefKind, oldParam.Name, oldParam.CustomModifiers, oldParam.RefCustomModifiers));
            }

            return(builder.ToImmutableAndFree());
        }
Example #11
0
        public SynthesizedEmbeddedNullableAttributeSymbol(
            string name,
            NamespaceSymbol containingNamespace,
            ModuleSymbol containingModule,
            NamedTypeSymbol systemAttributeType,
            TypeSymbol systemByteType
            ) : base(name, containingNamespace, containingModule, baseType: systemAttributeType)
        {
            _byteTypeSymbol = systemByteType;

            var annotatedByteType = TypeWithAnnotations.Create(systemByteType);

            var byteArrayType = TypeWithAnnotations.Create(
                ArrayTypeSymbol.CreateSZArray(systemByteType.ContainingAssembly, annotatedByteType)
                );

            _fields = ImmutableArray.Create <FieldSymbol>(
                new SynthesizedFieldSymbol(
                    this,
                    byteArrayType.Type,
                    NullableFlagsFieldName,
                    isPublic: true,
                    isReadOnly: true,
                    isStatic: false
                    )
                );

            _constructors = ImmutableArray.Create <MethodSymbol>(
                new SynthesizedEmbeddedAttributeConstructorWithBodySymbol(
                    this,
                    m =>
                    ImmutableArray.Create(
                        SynthesizedParameterSymbol.Create(m, annotatedByteType, 0, RefKind.None)
                        ),
                    GenerateSingleByteConstructorBody
                    ),
                new SynthesizedEmbeddedAttributeConstructorWithBodySymbol(
                    this,
                    m =>
                    ImmutableArray.Create(
                        SynthesizedParameterSymbol.Create(m, byteArrayType, 0, RefKind.None)
                        ),
                    GenerateByteArrayConstructorBody
                    )
                );

            // Ensure we never get out of sync with the description
            Debug.Assert(
                _constructors.Length == AttributeDescription.NullableAttribute.Signatures.Length
                );
        }
        public SynthesizedEmbeddedNativeIntegerAttributeSymbol(
            string name,
            NamespaceSymbol containingNamespace,
            ModuleSymbol containingModule,
            NamedTypeSymbol systemAttributeType,
            TypeSymbol boolType
            ) : base(name, containingNamespace, containingModule, baseType: systemAttributeType)
        {
            _boolType = boolType;

            var boolArrayType = TypeWithAnnotations.Create(
                ArrayTypeSymbol.CreateSZArray(
                    boolType.ContainingAssembly,
                    TypeWithAnnotations.Create(boolType)
                    )
                );

            _fields = ImmutableArray.Create <FieldSymbol>(
                new SynthesizedFieldSymbol(
                    this,
                    boolArrayType.Type,
                    FieldName,
                    isPublic: true,
                    isReadOnly: true,
                    isStatic: false
                    )
                );

            _constructors = ImmutableArray.Create <MethodSymbol>(
                new SynthesizedEmbeddedAttributeConstructorWithBodySymbol(
                    this,
                    m => ImmutableArray <ParameterSymbol> .Empty,
                    (f, s, p) => GenerateParameterlessConstructorBody(f, s)
                    ),
                new SynthesizedEmbeddedAttributeConstructorWithBodySymbol(
                    this,
                    m =>
                    ImmutableArray.Create(
                        SynthesizedParameterSymbol.Create(m, boolArrayType, 0, RefKind.None)
                        ),
                    (f, s, p) => GenerateBoolArrayConstructorBody(f, s, p)
                    )
                );

            // Ensure we never get out of sync with the description
            Debug.Assert(
                _constructors.Length
                == AttributeDescription.NativeIntegerAttribute.Signatures.Length
                );
        }
Example #13
0
        public SynthesizedRecordObjEquals(NamedTypeSymbol containingType, MethodSymbol typedRecordEquals, int memberOffset)
        {
            var compilation = containingType.DeclaringCompilation;

            _typedRecordEquals = typedRecordEquals;
            _memberOffset      = memberOffset;
            ContainingType     = containingType;
            Parameters         = ImmutableArray.Create <ParameterSymbol>(SynthesizedParameterSymbol.Create(
                                                                             this,
                                                                             TypeWithAnnotations.Create(compilation.GetSpecialType(SpecialType.System_Object), NullableAnnotation.Annotated),
                                                                             ordinal: 0,
                                                                             RefKind.None));
            ReturnTypeWithAnnotations = TypeWithAnnotations.Create(compilation.GetSpecialType(SpecialType.System_Boolean));
        }
Example #14
0
        internal SynthesizedDelegateInvokeMethod(NamedTypeSymbol containingType, ArrayBuilder <TypeWithAnnotations> parameterTypes, ArrayBuilder <RefKind> parameterRefKinds, TypeWithAnnotations returnType, RefKind refKind)
        {
            _containingType = containingType;

            var parameters = ArrayBuilder <ParameterSymbol> .GetInstance(parameterTypes.Count);

            for (int i = 0; i < parameterTypes.Count; i++)
            {
                parameters.Add(SynthesizedParameterSymbol.Create(this, parameterTypes[i], i, parameterRefKinds[i]));
            }
            Parameters = parameters.ToImmutableAndFree();
            ReturnTypeWithAnnotations = returnType;
            RefKind = refKind;
        }
Example #15
0
 public SynthesizedRecordCopyCtor(
     SourceMemberContainerTypeSymbol containingType,
     int memberOffset)
     : base(containingType)
 {
     _memberOffset = memberOffset;
     Parameters    = ImmutableArray.Create(SynthesizedParameterSymbol.Create(
                                               this,
                                               TypeWithAnnotations.Create(
                                                   isNullableEnabled: true,
                                                   ContainingType),
                                               ordinal: 0,
                                               RefKind.None));
 }
            internal BeginInvokeMethod(
                InvokeMethod invoke,
                TypeWithAnnotations iAsyncResultType,
                TypeWithAnnotations objectType,
                TypeWithAnnotations asyncCallbackType,
                DelegateDeclarationSyntax syntax
            )
                : base(
                    (SourceNamedTypeSymbol)invoke.ContainingType,
                    iAsyncResultType,
                    syntax,
                    MethodKind.Ordinary,
                    DeclarationModifiers.Virtual | DeclarationModifiers.Public
                )
            {
                var parameters = ArrayBuilder<ParameterSymbol>.GetInstance();
                foreach (SourceParameterSymbol p in invoke.Parameters)
                {
                    var synthesizedParam = new SourceClonedParameterSymbol(
                        originalParam: p,
                        newOwner: this,
                        newOrdinal: p.Ordinal,
                        suppressOptional: true
                    );
                    parameters.Add(synthesizedParam);
                }

                int paramCount = invoke.ParameterCount;
                parameters.Add(
                    SynthesizedParameterSymbol.Create(
                        this,
                        asyncCallbackType,
                        paramCount,
                        RefKind.None,
                        GetUniqueParameterName(parameters, "callback")
                    )
                );
                parameters.Add(
                    SynthesizedParameterSymbol.Create(
                        this,
                        objectType,
                        paramCount + 1,
                        RefKind.None,
                        GetUniqueParameterName(parameters, "object")
                    )
                );

                InitializeParameters(parameters.ToImmutableAndFree());
            }
Example #17
0
        internal SynthesizedSubmissionConstructor(NamedTypeSymbol containingType, BindingDiagnosticBag diagnostics)
            : base(containingType)
        {
            Debug.Assert(containingType.TypeKind == TypeKind.Submission);
            Debug.Assert(diagnostics != null);

            var compilation = containingType.DeclaringCompilation;

            var submissionArrayType = compilation.CreateArrayTypeSymbol(compilation.GetSpecialType(SpecialType.System_Object));
            var useSiteInfo         = submissionArrayType.GetUseSiteInfo();

            diagnostics.Add(useSiteInfo, NoLocation.Singleton);

            _parameters = ImmutableArray.Create <ParameterSymbol>(
                SynthesizedParameterSymbol.Create(this, TypeWithAnnotations.Create(submissionArrayType), 0, RefKind.None, "submissionArray"));
        }
Example #18
0
        private ImmutableArray <ParameterSymbol> MakeParameters()
        {
            int ordinal = 0;
            var builder = ArrayBuilder <ParameterSymbol> .GetInstance();

            var parameters        = this.BaseMethodParameters;
            var inheritAttributes = InheritsBaseMethodAttributes;

            foreach (var p in parameters)
            {
                builder.Add(SynthesizedParameterSymbol.Create(
                                this,
                                this.TypeMap.SubstituteType(p.OriginalDefinition.TypeWithAnnotations),
                                ordinal++,
                                p.RefKind,
                                p.Name,
                                // the synthesized parameter doesn't need to have the same ref custom modifiers as the base
                                refCustomModifiers: default,
        public static InjectedNonNullTypesAttributeSymbol Create(NamespaceSymbol containingNamespace)
        {
            return(new InjectedNonNullTypesAttributeSymbol(AttributeDescription.NonNullTypesAttribute, containingNamespace, containingNamespace.DeclaringCompilation, makeConstructor));

            ImmutableArray <MethodSymbol> makeConstructor(CSharpCompilation compilation, NamedTypeSymbol containingType, DiagnosticBag diagnostics)
            {
                var boolType = compilation.GetSpecialType(SpecialType.System_Boolean);

                Binder.ReportUseSiteDiagnostics(boolType, diagnostics, Location.None);

                var boolWithAnnotations = TypeSymbolWithAnnotations.Create(boolType);

                // https://github.com/dotnet/roslyn/issues/30143: Constructor should save the parameter into a field (for users of reflection)
                return(ImmutableArray.Create <MethodSymbol>(
                           new NonNullTypesAttributeConstructorSymbol(
                               containingType,
                               m => ImmutableArray.Create(SynthesizedParameterSymbol.Create(m, boolWithAnnotations, 0, ConstantValue.True, name: "flag")))));
            }
        }
            internal EndInvokeMethod(
                InvokeMethod invoke,
                TypeWithAnnotations iAsyncResultType,
                DelegateDeclarationSyntax syntax
            )
                : base(
                    (SourceNamedTypeSymbol)invoke.ContainingType,
                    invoke.ReturnTypeWithAnnotations,
                    syntax,
                    MethodKind.Ordinary,
                    DeclarationModifiers.Virtual | DeclarationModifiers.Public
                )
            {
                _invoke = invoke;

                var parameters = ArrayBuilder<ParameterSymbol>.GetInstance();
                int ordinal = 0;

                foreach (SourceParameterSymbol p in invoke.Parameters)
                {
                    if (p.RefKind != RefKind.None)
                    {
                        var synthesizedParam = new SourceClonedParameterSymbol(
                            originalParam: p,
                            newOwner: this,
                            newOrdinal: ordinal++,
                            suppressOptional: true
                        );
                        parameters.Add(synthesizedParam);
                    }
                }

                parameters.Add(
                    SynthesizedParameterSymbol.Create(
                        this,
                        iAsyncResultType,
                        ordinal++,
                        RefKind.None,
                        GetUniqueParameterName(parameters, "result")
                    )
                );
                InitializeParameters(parameters.ToImmutableAndFree());
            }
 internal AnonymousTypeConstructorSymbol(NamedTypeSymbol container, ImmutableArray<AnonymousTypePropertySymbol> properties)
     : base(container, WellKnownMemberNames.InstanceConstructorName)
 {
     // Create constructor parameters
     int fieldsCount = properties.Length;
     if (fieldsCount > 0)
     {
         ParameterSymbol[] paramsArr = new ParameterSymbol[fieldsCount];
         for (int index = 0; index < fieldsCount; index++)
         {
             PropertySymbol property = properties[index];
             paramsArr[index] = new SynthesizedParameterSymbol(this, property.Type, index, RefKind.None, property.Name);
         }
         _parameters = paramsArr.AsImmutableOrNull();
     }
     else
     {
         _parameters = ImmutableArray<ParameterSymbol>.Empty;
     }
 }
        public SynthesizedEmbeddedLifetimeAnnotationAttributeSymbol(
            string name,
            NamespaceSymbol containingNamespace,
            ModuleSymbol containingModule,
            NamedTypeSymbol systemAttributeType,
            TypeSymbol boolType)
            : base(name, containingNamespace, containingModule, baseType: systemAttributeType)
        {
            _fields = ImmutableArray.Create <FieldSymbol>(
                new SynthesizedFieldSymbol(this, boolType, "IsRefScoped", isPublic: true, isReadOnly: true, isStatic: false),
                new SynthesizedFieldSymbol(this, boolType, "IsValueScoped", isPublic: true, isReadOnly: true, isStatic: false));

            _constructors = ImmutableArray.Create <MethodSymbol>(
                new SynthesizedEmbeddedAttributeConstructorWithBodySymbol(
                    this,
                    m => ImmutableArray.Create(
                        SynthesizedParameterSymbol.Create(m, TypeWithAnnotations.Create(boolType), 0, RefKind.None),
                        SynthesizedParameterSymbol.Create(m, TypeWithAnnotations.Create(boolType), 1, RefKind.None)),
                    (f, s, p) => GenerateConstructorBody(f, s, p)));
        }
Example #23
0
 internal AnonymousTypeConstructorSymbol(NamedTypeSymbol container, ImmutableArray<AnonymousTypePropertySymbol> properties)
     : base(container, WellKnownMemberNames.InstanceConstructorName)
 {
     // Create constructor parameters
     int fieldsCount = properties.Length;
     if (fieldsCount > 0)
     {
         ParameterSymbol[] paramsArr = new ParameterSymbol[fieldsCount];
         for (int index = 0; index < fieldsCount; index++)
         {
             PropertySymbol property = properties[index];
             paramsArr[index] = new SynthesizedParameterSymbol(this, property.Type, index, RefKind.None, property.Name);
         }
         this.parameters = paramsArr.AsImmutableOrNull();
     }
     else
     {
         this.parameters = ImmutableArray<ParameterSymbol>.Empty;
     }
 }
Example #24
0
        public SynthesizedEmbeddedNullablePublicOnlyAttributeSymbol(
            string name,
            NamespaceSymbol containingNamespace,
            ModuleSymbol containingModule,
            NamedTypeSymbol systemAttributeType,
            TypeSymbol systemBooleanType
            ) : base(name, containingNamespace, containingModule, baseType: systemAttributeType)
        {
            _fields = ImmutableArray.Create <FieldSymbol>(
                new SynthesizedFieldSymbol(
                    this,
                    systemBooleanType,
                    "IncludesInternals",
                    isPublic: true,
                    isReadOnly: true,
                    isStatic: false
                    )
                );

            _constructors = ImmutableArray.Create <MethodSymbol>(
                new SynthesizedEmbeddedAttributeConstructorWithBodySymbol(
                    this,
                    m =>
                    ImmutableArray.Create(
                        SynthesizedParameterSymbol.Create(
                            m,
                            TypeWithAnnotations.Create(systemBooleanType),
                            0,
                            RefKind.None
                            )
                        ),
                    GenerateConstructorBody
                    )
                );

            // Ensure we never get out of sync with the description
            Debug.Assert(
                _constructors.Length
                == AttributeDescription.NullablePublicOnlyAttribute.Signatures.Length
                );
        }
            internal InvokeMethod(SynthesizedDelegateSymbol containingType, BitVector byRefParameters, TypeSymbol voidReturnTypeOpt)
            {
                var typeParams = containingType.TypeParameters;

                _containingType = containingType;

                // if we are given Void type the method returns Void, otherwise its return type is the last type parameter of the delegate:
                _returnType = voidReturnTypeOpt ?? typeParams.Last();

                var parameters = new ParameterSymbol[typeParams.Length - ((object)voidReturnTypeOpt != null ? 0 : 1)];

                for (int i = 0; i < parameters.Length; i++)
                {
                    // we don't need to distinguish between out and ref since this is an internal synthesized symbol:
                    var refKind = !byRefParameters.IsNull && byRefParameters[i] ? RefKind.Ref : RefKind.None;

                    parameters[i] = SynthesizedParameterSymbol.Create(this, TypeWithAnnotations.Create(typeParams[i]), i, refKind);
                }

                _parameters = parameters.AsImmutableOrNull();
            }
Example #26
0
        public SynthesizedEmbeddedNullableAttributeSymbol(
            CSharpCompilation compilation,
            DiagnosticBag diagnostics)
            : base(AttributeDescription.NullableAttribute, compilation, diagnostics, includeAttributeUsageAttribute: true)
        {
            var byteType = TypeWithAnnotations.Create(compilation.GetSpecialType(SpecialType.System_Byte));

            _byteTypeSymbol = byteType.Type;
            Binder.ReportUseSiteDiagnostics(_byteTypeSymbol, diagnostics, Location.None);

            var byteArrayType = TypeWithAnnotations.Create(
                ArrayTypeSymbol.CreateSZArray(
                    _byteTypeSymbol.ContainingAssembly,
                    byteType));

            _fields = ImmutableArray.Create <FieldSymbol>(
                new SynthesizedFieldSymbol(
                    this,
                    byteArrayType.Type,
                    NullableFlagsFieldName,
                    isPublic: true,
                    isReadOnly: true,
                    isStatic: false));

            _constructors = ImmutableArray.Create <MethodSymbol>(
                new SynthesizedEmbeddedAttributeConstructorWithBodySymbol(
                    this,
                    m => ImmutableArray.Create(SynthesizedParameterSymbol.Create(m, byteType, 0, RefKind.None)),
                    GenerateSingleByteConstructorBody
                    ),
                new SynthesizedEmbeddedAttributeConstructorWithBodySymbol(
                    this,
                    m => ImmutableArray.Create(SynthesizedParameterSymbol.Create(m, byteArrayType, 0, RefKind.None)),
                    GenerateByteArrayConstructorBody
                    )
                );

            // Ensure we never get out of sync with the description
            Debug.Assert(_constructors.Length == AttributeDescription.NullableAttribute.Signatures.Length);
        }
Example #27
0
 public SynthesizedRecordDeconstruct(
     SourceMemberContainerTypeSymbol containingType,
     ImmutableArray <ParameterSymbol> ctorParameters,
     ImmutableArray <PropertySymbol> properties,
     int memberOffset)
 {
     _memberOffset = memberOffset;
     Debug.Assert(properties.All(prop => prop.GetMethod is object));
     _properties               = properties;
     ContainingType            = containingType;
     ReturnTypeWithAnnotations = TypeWithAnnotations.Create(
         ContainingType.DeclaringCompilation.GetSpecialType(SpecialType.System_Void));
     Parameters = ctorParameters.SelectAsArray(
         (param, ordinal, _) =>
         SynthesizedParameterSymbol.Create(
             this,
             param.TypeWithAnnotations,
             ordinal,
             RefKind.Out,
             param.Name),
         arg: (object?)null);
 }
Example #28
0
            internal AnonymousTypeConstructorSymbol(NamedTypeSymbol container, ImmutableArray <AnonymousTypePropertySymbol> properties)
                : base(container, WellKnownMemberNames.InstanceConstructorName)
            {
                // Create constructor parameters
                int fieldsCount = properties.Length;

                if (fieldsCount > 0)
                {
                    var paramsArr = ArrayBuilder <ParameterSymbol> .GetInstance(fieldsCount);

                    for (int index = 0; index < fieldsCount; index++)
                    {
                        PropertySymbol property = properties[index];
                        paramsArr.Add(SynthesizedParameterSymbol.Create(this, property.TypeWithAnnotations, index, RefKind.None, property.Name));
                    }
                    _parameters = paramsArr.ToImmutableAndFree();
                }
                else
                {
                    _parameters = ImmutableArray <ParameterSymbol> .Empty;
                }
            }
Example #29
0
        private ImmutableArray <ParameterSymbol> MakeParameters()
        {
            int ordinal = 0;
            var builder = ArrayBuilder <ParameterSymbol> .GetInstance();

            var parameters = this.BaseMethodParameters;

            foreach (var p in parameters)
            {
                builder.Add(SynthesizedParameterSymbol.Create(this, this.TypeMap.SubstituteType(p.OriginalDefinition.Type).Type, ordinal++, p.RefKind, p.Name));
            }
            var extraSynthed = ExtraSynthesizedRefParameters;

            if (!extraSynthed.IsDefaultOrEmpty)
            {
                foreach (var extra in extraSynthed)
                {
                    builder.Add(SynthesizedParameterSymbol.Create(this, this.TypeMap.SubstituteType(extra).Type, ordinal++, RefKind.Ref));
                }
            }
            return(builder.ToImmutableAndFree());
        }
Example #30
0
 public DelegateConstructor(
     NamedTypeSymbol containingType,
     TypeSymbol objectType,
     TypeSymbol intPtrType
     ) : base(containingType)
 {
     _parameters = ImmutableArray.Create <ParameterSymbol>(
         SynthesizedParameterSymbol.Create(
             this,
             TypeWithAnnotations.Create(objectType),
             0,
             RefKind.None,
             "object"
             ),
         SynthesizedParameterSymbol.Create(
             this,
             TypeWithAnnotations.Create(intPtrType),
             1,
             RefKind.None,
             "method"
             )
         );
 }
        public SynthesizedImplementationMethod(
            MethodSymbol interfaceMethod,
            NamedTypeSymbol implementingType,
            string name                       = null,
            bool generateDebugInfo            = true,
            PropertySymbol associatedProperty = null)
        {
            //it does not make sense to add methods to substituted types
            Debug.Assert(implementingType.IsDefinition);

            _name               = name ?? ExplicitInterfaceHelpers.GetMemberName(interfaceMethod.Name, interfaceMethod.ContainingType, aliasQualifierOpt: null);
            _implementingType   = implementingType;
            _generateDebugInfo  = generateDebugInfo;
            _associatedProperty = associatedProperty;
            _explicitInterfaceImplementations = ImmutableArray.Create <MethodSymbol>(interfaceMethod);

            // alpha-rename to get the implementation's type parameters
            var typeMap = interfaceMethod.ContainingType.TypeSubstitution ?? TypeMap.Empty;

            typeMap.WithAlphaRename(interfaceMethod, this, out _typeParameters);

            _interfaceMethod = interfaceMethod.ConstructIfGeneric(_typeParameters.Cast <TypeParameterSymbol, TypeSymbol>());
            _parameters      = SynthesizedParameterSymbol.DeriveParameters(_interfaceMethod, this);
        }
            internal InvokeMethod(SynthesizedDelegateSymbol containingType, BitVector byRefParameters, TypeSymbol voidReturnTypeOpt)
            {
                var typeParams = containingType.TypeParameters;

                _containingType = containingType;

                // if we are given Void type the method returns Void, otherwise its return type is the last type parameter of the delegate:
                _returnType = voidReturnTypeOpt ?? typeParams.Last();

                var parameters = new ParameterSymbol[typeParams.Length - ((object)voidReturnTypeOpt != null ? 0 : 1)];
                for (int i = 0; i < parameters.Length; i++)
                {
                    // we don't need to distinguish between out and ref since this is an internal synthesized symbol:
                    var refKind = !byRefParameters.IsNull && byRefParameters[i] ? RefKind.Ref : RefKind.None;

                    parameters[i] = new SynthesizedParameterSymbol(this, typeParams[i], i, refKind);
                }

                _parameters = parameters.AsImmutableOrNull();
            }