コード例 #1
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
                );
        }
コード例 #2
0
        private ArrayTypeSymbol SubstituteArrayType(ArrayTypeSymbol t)
        {
            var oldElement = t.ElementTypeWithAnnotations;
            TypeWithAnnotations element = oldElement.SubstituteType(this);

            if (element.IsSameAs(oldElement))
            {
                return(t);
            }

            if (t.IsSZArray)
            {
                ImmutableArray <NamedTypeSymbol> interfaces = t.InterfacesNoUseSiteDiagnostics();
                Debug.Assert(0 <= interfaces.Length && interfaces.Length <= 2);

                if (interfaces.Length == 1)
                {
                    Debug.Assert(interfaces[0] is NamedTypeSymbol); // IList<T>
                    interfaces = ImmutableArray.Create <NamedTypeSymbol>(
                        SubstituteNamedType(interfaces[0])
                        );
                }
                else if (interfaces.Length == 2)
                {
                    Debug.Assert(interfaces[0] is NamedTypeSymbol); // IList<T>
                    interfaces = ImmutableArray.Create <NamedTypeSymbol>(
                        SubstituteNamedType(interfaces[0]),
                        SubstituteNamedType(interfaces[1])
                        );
                }
                else if (interfaces.Length != 0)
                {
                    throw ExceptionUtilities.Unreachable;
                }

                return(ArrayTypeSymbol.CreateSZArray(
                           element,
                           t.BaseTypeNoUseSiteDiagnostics,
                           interfaces
                           ));
            }

            return(ArrayTypeSymbol.CreateMDArray(
                       element,
                       t.Rank,
                       t.Sizes,
                       t.LowerBounds,
                       t.BaseTypeNoUseSiteDiagnostics
                       ));
        }
コード例 #3
0
        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
                );
        }
コード例 #4
0
        internal override TypeSymbol SetUnknownNullabilityForReferenceTypes()
        {
            TypeSymbolWithAnnotations oldElementType = ElementType;
            TypeSymbolWithAnnotations newElementType = oldElementType.SetUnknownNullabilityForReferenceTypes();

            if (oldElementType.IsSameAs(newElementType))
            {
                return(this);
            }
            else
            {
                return(IsSZArray ?
                       ArrayTypeSymbol.CreateSZArray(newElementType, _baseType) :
                       ArrayTypeSymbol.CreateMDArray(newElementType, Rank, Sizes, LowerBounds, _baseType));
            }
        }
コード例 #5
0
        private ArrayTypeSymbol SubstituteArrayType(ArrayTypeSymbol t)
        {
            var oldElement            = new TypeWithModifiers(t.ElementType, t.CustomModifiers);
            TypeWithModifiers element = oldElement.SubstituteType(this);

            if (element == oldElement)
            {
                return(t);
            }

            if (t.IsSZArray)
            {
                ImmutableArray <NamedTypeSymbol> interfaces = t.InterfacesNoUseSiteDiagnostics();
                Debug.Assert(0 <= interfaces.Length && interfaces.Length <= 2);

                if (interfaces.Length == 1)
                {
                    Debug.Assert(interfaces[0] is NamedTypeSymbol); // IList<T>
                    interfaces = ImmutableArray.Create <NamedTypeSymbol>((NamedTypeSymbol)SubstituteType(interfaces[0]).AsTypeSymbolOnly());
                }
                else if (interfaces.Length == 2)
                {
                    Debug.Assert(interfaces[0] is NamedTypeSymbol); // IList<T>
                    interfaces = ImmutableArray.Create <NamedTypeSymbol>((NamedTypeSymbol)SubstituteType(interfaces[0]).AsTypeSymbolOnly(), (NamedTypeSymbol)SubstituteType(interfaces[1]).AsTypeSymbolOnly());
                }
                else if (interfaces.Length != 0)
                {
                    throw ExceptionUtilities.Unreachable;
                }

                return(ArrayTypeSymbol.CreateSZArray(
                           element.Type,
                           t.BaseTypeNoUseSiteDiagnostics,
                           interfaces,
                           element.CustomModifiers));
            }

            return(ArrayTypeSymbol.CreateMDArray(
                       element.Type,
                       t.Rank,
                       t.Sizes,
                       t.LowerBounds,
                       t.BaseTypeNoUseSiteDiagnostics,
                       element.CustomModifiers));
        }
コード例 #6
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);
        }
コード例 #7
0
        internal override bool ApplyNullableTransforms(ImmutableArray <bool> transforms, INonNullTypesContext nonNullTypesContext, ref int position, out TypeSymbol result)
        {
            TypeSymbolWithAnnotations oldElementType = ElementType;
            TypeSymbolWithAnnotations newElementType;

            if (!oldElementType.ApplyNullableTransforms(transforms, nonNullTypesContext, ref position, out newElementType))
            {
                result = this;
                return(false);
            }

            if (oldElementType.IsSameAs(newElementType))
            {
                result = this;
            }
            else
            {
                result = IsSZArray ?
                         ArrayTypeSymbol.CreateSZArray(newElementType, _baseType) :
                         ArrayTypeSymbol.CreateMDArray(newElementType, Rank, Sizes, LowerBounds, _baseType);
            }

            return(true);
        }