internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); CSharpCompilation compilation = this.DeclaringCompilation; // do not emit CompilerGenerated attributes for fields inside compiler generated types: if (!_containingType.IsImplicitlyDeclared) { AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); } if (!this.SuppressDynamicAttribute && this.Type.ContainsDynamic() && compilation.HasDynamicEmitAttributes() && compilation.CanEmitBoolean()) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.Type, this.CustomModifiers.Length)); } if (Type.ContainsTuple() && compilation.HasTupleNamesAttributes && compilation.CanEmitSpecialType(SpecialType.System_String)) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeTupleNamesAttributeOpt(Type)); } }
internal sealed override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = this.DeclaringCompilation; if (this.IsParams) { AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_ParamArrayAttribute__ctor)); } // Synthesize DecimalConstantAttribute if we don't have an explicit custom attribute already: var defaultValue = this.ExplicitDefaultConstantValue; if (defaultValue != ConstantValue.NotAvailable && defaultValue.SpecialType == SpecialType.System_Decimal && DefaultValueFromAttributes == ConstantValue.NotAvailable) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDecimalConstantAttribute(defaultValue.DecimalValue)); } if (this.Type.ContainsDynamic()) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.Type, this.CustomModifiers.Length, this.RefKind)); } if (Type.ContainsTupleNames()) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeTupleNamesAttribute(Type)); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Diagnostics_DebuggerHiddenAttribute__ctor)); }
internal virtual IEnumerable<CSharpAttributeData> GetCustomAttributesToEmit(ModuleCompilationState compilationState) { CheckDefinitionInvariant(); Debug.Assert(this.Kind != SymbolKind.Assembly); return GetCustomAttributesToEmit(compilationState, emittingAssemblyAttributesInNetModule: false); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); if (this.Type.ContainsDynamic()) { var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.Type, this.CustomModifiers.Length)); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = this.DeclaringCompilation; // Dev11 doesn't synthesize this attribute, the debugger has a knowledge // of special name C# compiler uses for backing fields, which is not desirable. AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDebuggerBrowsableNeverAttribute()); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = this.DeclaringCompilation; // Dev11 doesn't synthesize this attribute, the debugger has a knowledge // of special name C# compiler uses for backing fields, which is not desirable. AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDebuggerBrowsableNeverAttribute()); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); if (_isAutoPropertyAccessor) { var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = this.DeclaringCompilation; if (this.ReturnType.ContainsDynamic() && compilation.HasDynamicEmitAttributes() && compilation.CanEmitBoolean()) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.ReturnType, this.ReturnTypeCustomModifiers.Length)); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = this.DeclaringCompilation; if (this.ReturnType.ContainsDynamic() && compilation.HasDynamicEmitAttributes() && compilation.CanEmitBoolean()) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.ReturnType, this.ReturnTypeCustomModifiers.Length)); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); // Dev11 doesn't synthesize this attribute, the debugger has a knowledge // of special name C# compiler uses for backing fields, which is not desirable. AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDebuggerBrowsableNeverAttribute()); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); AnonymousTypeManager manager = ((AnonymousTypeTemplateSymbol)this.ContainingSymbol).Manager; AddSynthesizedAttribute(ref attributes, manager.Compilation.SynthesizeAttribute( WellKnownMember.System_Diagnostics_DebuggerBrowsableAttribute__ctor, ImmutableArray.Create( new TypedConstant(manager.System_Diagnostics_DebuggerBrowsableState, TypedConstantKind.Enum, DebuggerBrowsableState.Never)))); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); AddSynthesizedAttribute(ref attributes, Manager.Compilation.TrySynthesizeAttribute( WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); if (Manager.Compilation.Options.OptimizationLevel == OptimizationLevel.Debug) { AddSynthesizedAttribute(ref attributes, TrySynthesizeDebuggerDisplayAttribute()); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); // Dev11 doesn't synthesize this attribute, the debugger has a knowledge // of special name C# compiler uses for backing fields, which is not desirable. AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDebuggerBrowsableNeverAttribute()); }
/// <remarks> /// These won't be returned by GetAttributes on source methods, but they /// will be returned by GetAttributes on metadata symbols. /// </remarks> internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); CSharpCompilation compilation = this.DeclaringCompilation; if (this.ContainsExtensionMethods) { // No need to check if [Extension] attribute was explicitly set since // we'll issue CS1112 error in those cases and won't generate IL. AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_ExtensionAttribute__ctor)); } if (this.Indexers.Any()) { string defaultMemberName = this.Indexers.First().MetadataName; // UNDONE: IndexerNameAttribute var defaultMemberNameConstant = new TypedConstant(compilation.GetSpecialType(SpecialType.System_String), TypedConstantKind.Primitive, defaultMemberName); AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute( WellKnownMember.System_Reflection_DefaultMemberAttribute__ctor, ImmutableArray.Create(defaultMemberNameConstant))); } NamedTypeSymbol baseType = this.BaseTypeNoUseSiteDiagnostics; if ((object)baseType != null) { if (baseType.ContainsDynamic()) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(baseType, customModifiersCount: 0)); } if (baseType.ContainsTuple()) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeTupleNamesAttributeOpt(baseType)); } } // Is this a concept or instance? // If so, add in the concept attributes, if we don't have them // already. // @t-mawind if (this.IsConcept && !this.HasConceptAttribute) { AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Concepts_ConceptAttribute__ctor)); } else if (this.IsInstance && !this.HasInstanceAttribute) { AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Concepts_ConceptInstanceAttribute__ctor)); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = this.DeclaringCompilation; var systemType = compilation.GetWellKnownType(WellKnownType.System_Type); var intType = compilation.GetSpecialType(SpecialType.System_Int32); var item1 = new TypedConstant(systemType, TypedConstantKind.Type, ((PointerTypeSymbol)this.Type).PointedAtType); var item2 = new TypedConstant(intType, TypedConstantKind.Primitive, this.FixedSize); AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute( WellKnownMember.System_Runtime_CompilerServices_FixedBufferAttribute__ctor, ImmutableArray.Create<TypedConstant>(item1, item2))); }
internal IEnumerable<CSharpAttributeData> GetCustomAttributesToEmit(ModuleCompilationState compilationState, bool emittingAssemblyAttributesInNetModule) { CheckDefinitionInvariant(); ImmutableArray<CSharpAttributeData> userDefined; ArrayBuilder<SynthesizedAttributeData> synthesized = null; userDefined = this.GetAttributes(); this.AddSynthesizedAttributes(compilationState, ref synthesized); // Note that callers of this method (CCI and ReflectionEmitter) have to enumerate // all items of the returned iterator, otherwise the synthesized ArrayBuilder may leak. return GetCustomAttributesToEmit(userDefined, synthesized, isReturnType: false, emittingAssemblyAttributesInNetModule: emittingAssemblyAttributesInNetModule); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { // Emit [Dynamic] on synthesized parameter symbols when the original parameter was dynamic // in order to facilitate debugging. In the case the necessary attributes are missing // this is a no-op. Emitting an error here, or when the original parameter was bound, would // adversely effect the compilation or potentially change overload resolution. var compilation = this.DeclaringCompilation; if (Type.ContainsDynamic() && compilation.HasDynamicEmitAttributes() && compilation.CanEmitBoolean()) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.Type, this.CustomModifiers.Length, this.RefKind)); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); if (this.IsExtensionMethod) { // No need to check if [Extension] attribute was explicitly set since // we'll issue CS1112 error in those cases and won't generate IL. var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute( WellKnownMember.System_Runtime_CompilerServices_ExtensionAttribute__ctor)); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = this.DeclaringCompilation; var systemType = compilation.GetWellKnownType(WellKnownType.System_Type); var intType = compilation.GetSpecialType(SpecialType.System_Int32); var item1 = new TypedConstant(systemType, TypedConstantKind.Type, ((PointerTypeSymbol)this.Type).PointedAtType); var item2 = new TypedConstant(intType, TypedConstantKind.Primitive, this.FixedSize); AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute( WellKnownMember.System_Runtime_CompilerServices_FixedBufferAttribute__ctor, ImmutableArray.Create <TypedConstant>(item1, item2))); }
internal IEnumerable <CSharpAttributeData> GetCustomAttributesToEmit(ModuleCompilationState compilationState, bool emittingAssemblyAttributesInNetModule) { CheckDefinitionInvariant(); ImmutableArray <CSharpAttributeData> userDefined; ArrayBuilder <SynthesizedAttributeData> synthesized = null; userDefined = this.GetAttributes(); this.AddSynthesizedAttributes(compilationState, ref synthesized); // Note that callers of this method (CCI and ReflectionEmitter) have to enumerate // all items of the returned iterator, otherwise the synthesized ArrayBuilder may leak. return(GetCustomAttributesToEmit(userDefined, synthesized, isReturnType: false, emittingAssemblyAttributesInNetModule: emittingAssemblyAttributesInNetModule)); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); // do not generate attributes for members of compiler-generated types: if (ContainingType.IsImplicitlyDeclared) { return; } var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); // do not generate attributes for members of compiler-generated types: if (ContainingType.IsImplicitlyDeclared) { return; } var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); }
internal sealed override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); if (debuggerHidden) { var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.SynthesizeAttribute(WellKnownMember.System_Diagnostics_DebuggerHiddenAttribute__ctor)); } if (this.ReturnType.ContainsDynamic()) { var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.ReturnType, this.ReturnTypeCustomModifiers.Length)); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); if (this.Type.ContainsDynamic()) { var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.Type, customModifiersCount: 0)); } if (Type.ContainsTupleNames()) { AddSynthesizedAttribute(ref attributes, DeclaringCompilation.SynthesizeTupleNamesAttribute(Type)); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = _assemblySymbol.DeclaringCompilation; if (compilation.Options.AllowUnsafe) { // NOTE: GlobalAttrBind::EmitCompilerGeneratedAttrs skips attribute if the well-known type isn't available. if (!(compilation.GetWellKnownType(WellKnownType.System_Security_UnverifiableCodeAttribute) is MissingMetadataTypeSymbol)) { AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute( WellKnownMember.System_Security_UnverifiableCodeAttribute__ctor)); } } }
internal sealed override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); if (debuggerHidden) { var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.SynthesizeAttribute(WellKnownMember.System_Diagnostics_DebuggerHiddenAttribute__ctor)); } if (this.ReturnType.ContainsDynamic()) { var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.ReturnType, this.ReturnTypeCustomModifiers.Length)); } }
internal static ImmutableArray <SynthesizedAttributeData> GetSynthesizedAttributes(this ISymbol symbol, bool forReturnType = false) { ArrayBuilder <SynthesizedAttributeData> attributes = null; if (!forReturnType) { var context = new ModuleCompilationState(); ((Symbol)symbol).AddSynthesizedAttributes(context, ref attributes); } else { Assert.True(symbol.Kind == SymbolKind.Method, "Incorrect usage of GetSynthesizedAttributes"); ((MethodSymbol)symbol).AddSynthesizedReturnTypeAttributes(ref attributes); } return(attributes != null?attributes.ToImmutableAndFree() : ImmutableArray.Create <SynthesizedAttributeData>()); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); if (ContainingSymbol.Kind == SymbolKind.NamedType && ContainingSymbol.IsImplicitlyDeclared) { return; } var compilation = ContainingSymbol.DeclaringCompilation; // this can only happen if frame is not nested in a source type/namespace (so far we do not do this) // if this happens for whatever reason, we do not need "CompilerGenerated" anyways Debug.Assert(compilation != null, "SynthesizedClass is not contained in a source module?"); AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute( WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); if (ContainingSymbol.Kind == SymbolKind.NamedType && ContainingSymbol.IsImplicitlyDeclared) { return; } var compilation = ContainingSymbol.DeclaringCompilation; // this can only happen if frame is not nested in a source type/namespace (so far we do not do this) // if this happens for whatever reason, we do not need "CompilerGenerated" anyways Debug.Assert(compilation != null, "SynthesizedClass is not contained in a source module?"); AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute( WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = this.DeclaringCompilation; if (this.ReturnType.ContainsDynamic() && compilation.HasDynamicEmitAttributes() && compilation.CanEmitBoolean()) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.ReturnType, this.ReturnTypeCustomModifiers.Length + this.RefCustomModifiers.Length, this.RefKind)); } if (ReturnType.ContainsTupleNames() && compilation.HasTupleNamesAttributes && compilation.CanEmitSpecialType(SpecialType.System_String)) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeTupleNamesAttribute(ReturnType)); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = this.DeclaringCompilation; var value = this.GetConstantValue(ConstantFieldsInProgress.Empty, earlyDecodingWellKnownAttributes: false); // Synthesize DecimalConstantAttribute when the default value is of type decimal if (this.IsConst && value != null && this.Type.SpecialType == SpecialType.System_Decimal) { var data = GetDecodedWellKnownAttributeData(); if (data == null || data.ConstValue == CodeAnalysis.ConstantValue.Unset) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDecimalConstantAttribute(value.DecimalValue)); } } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); // do not emit Dynamic or CompilerGenerated attributes for fields inside compiler generated types: if (_containingType.IsImplicitlyDeclared) { return; } CSharpCompilation compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); if (this.Type.ContainsDynamic() && compilation.HasDynamicEmitAttributes() && compilation.CanEmitBoolean()) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.Type, this.CustomModifiers.Length)); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = this.DeclaringCompilation; if (this.ReturnType.ContainsDynamic() && compilation.HasDynamicEmitAttributes() && compilation.CanEmitBoolean()) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.ReturnType, this.ReturnTypeCustomModifiers.Length + this.RefCustomModifiers.Length, this.RefKind)); } if (ReturnType.ContainsTupleNames() && compilation.HasTupleNamesAttributes && compilation.CanEmitSpecialType(SpecialType.System_String)) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeTupleNamesAttribute(ReturnType)); } }
internal IEnumerable <CSharpAttributeData> GetCustomAttributesToEmit(ModuleCompilationState compilationState, bool emittingRefAssembly, bool emittingAssemblyAttributesInNetModule) { CheckDefinitionInvariant(); ImmutableArray <CSharpAttributeData> userDefined = this.GetAttributes(); ArrayBuilder <SynthesizedAttributeData> synthesized = null; this.AddSynthesizedAttributes(compilationState, ref synthesized); if (emittingRefAssembly && !HasReferenceAssemblyAttribute) { var referenceAssemblyAttribute = this.DeclaringCompilation .TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_ReferenceAssemblyAttribute__ctor, isOptionalUse: true); Symbol.AddSynthesizedAttribute(ref synthesized, referenceAssemblyAttribute); } // Note that callers of this method (CCI and ReflectionEmitter) have to enumerate // all items of the returned iterator, otherwise the synthesized ArrayBuilder may leak. return(GetCustomAttributesToEmit(userDefined, synthesized, isReturnType: false, emittingAssemblyAttributesInNetModule: emittingAssemblyAttributesInNetModule)); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); // do not emit Dynamic or CompilerGenerated attributes for fields inside compiler generated types: if (containingType.IsImplicitlyDeclared) { return; } CSharpCompilation compilation = this.DeclaringCompilation; // Assume that someone checked earlier that the attribute ctor is available and has no use-site errors. AddSynthesizedAttribute(ref attributes, compilation.SynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); // TODO (tomat): do we need to emit dynamic attribute on any synthesized field? if (this.Type.ContainsDynamic()) { // Assume that someone checked earlier that the attribute ctor is available and has no use-site errors. AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.Type, customModifiersCount: 0)); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); var compilation = this.DeclaringCompilation; var value = this.GetConstantValue(ConstantFieldsInProgress.Empty, earlyDecodingWellKnownAttributes: false); // Synthesize DecimalConstantAttribute when the default value is of type decimal if (this.IsConst && value != null && this.Type.SpecialType == SpecialType.System_Decimal) { var data = GetDecodedWellKnownAttributeData(); if (data == null || data.ConstValue == CodeAnalysis.ConstantValue.Unset) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDecimalConstantAttribute(value.DecimalValue)); } } }
internal sealed override IEnumerable <CSharpAttributeData> GetCustomAttributesToEmit(ModuleCompilationState compilationState) { return(this.RetargetingModule.RetargetingTranslator.RetargetAttributes(this.underlyingParameter.GetCustomAttributesToEmit(compilationState))); }
internal override IEnumerable <CSharpAttributeData> GetCustomAttributesToEmit(ModuleCompilationState compilationState) { return(this.RetargetingTranslator.RetargetAttributes(_underlyingProperty.GetCustomAttributesToEmit(compilationState))); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); if (Type.ContainsDynamic()) { AddSynthesizedAttribute(ref attributes, DeclaringCompilation.SynthesizeDynamicAttribute(Type, TypeCustomModifiers.Length)); } if (Type.ContainsTupleNames()) { AddSynthesizedAttribute(ref attributes, DeclaringCompilation.SynthesizeTupleNamesAttribute(Type)); } }
protected override IEnumerable<CSharpAttributeData> GetCustomAttributesToEmit(ModuleCompilationState compilationState) { return UnderlyingProperty.GetCustomAttributesToEmit(compilationState); }
internal override IEnumerable <CSharpAttributeData> GetCustomAttributesToEmit(ModuleCompilationState compilationState) { return(GetAttributes()); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); AnonymousTypeManager manager = ((AnonymousTypeTemplateSymbol)this.ContainingSymbol).Manager; AddSynthesizedAttribute(ref attributes, manager.Compilation.TrySynthesizeAttribute( WellKnownMember.System_Diagnostics_DebuggerBrowsableAttribute__ctor, ImmutableArray.Create( new TypedConstant(manager.System_Diagnostics_DebuggerBrowsableState, TypedConstantKind.Enum, DebuggerBrowsableState.Never)))); }
protected override IEnumerable <CSharpAttributeData> GetCustomAttributesToEmit(ModuleCompilationState compilationState) { return(UnderlyingMethod.GetCustomAttributesToEmit(compilationState)); }
internal override IEnumerable<CSharpAttributeData> GetCustomAttributesToEmit(ModuleCompilationState compilationState) { return this.RetargetingTranslator.RetargetAttributes(_underlyingMethod.GetCustomAttributesToEmit(compilationState)); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); AddSynthesizedAttribute(ref attributes, Manager.Compilation.TrySynthesizeAttribute( WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); if (Manager.Compilation.Options.OptimizationLevel == OptimizationLevel.Debug) { AddSynthesizedAttribute(ref attributes, TrySynthesizeDebuggerDisplayAttribute()); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { // no attributes should be emitted }
internal override IEnumerable<CSharpAttributeData> GetCustomAttributesToEmit(ModuleCompilationState compilationState) { throw ExceptionUtilities.Unreachable; }
public void Bug530209() { var ilSource = @" .class public auto ansi beforefieldinit Class1 extends[mscorlib] System.Object { .field public static initonly valuetype[mscorlib]System.Decimal d1 .custom instance void[mscorlib] System.Runtime.CompilerServices.DecimalConstantAttribute::.ctor(uint8, uint8, uint32, uint32, uint32) = {uint8(0) uint8(128) uint32(0) uint32(0) uint32(7)} .custom instance void[mscorlib] System.Runtime.CompilerServices.DecimalConstantAttribute::.ctor(uint8, uint8, int32, int32, int32) = {uint8(0) uint8(128) int32(0) int32(0) int32(8)} .field public static initonly valuetype[mscorlib]System.DateTime d2 .custom instance void[mscorlib] System.Runtime.CompilerServices.DateTimeConstantAttribute::.ctor(int64) = {int64(634925952000000000)} .custom instance void[mscorlib] System.Runtime.CompilerServices.DateTimeConstantAttribute::.ctor(int64) = {int64(634925952000000001)} .method private specialname rtspecialname static void .cctor() cil managed { // Code size 33 (0x21) .maxstack 8 IL_0000: ldc.i4.s -7 IL_0002: conv.i8 IL_0003: newobj instance void [mscorlib]System.Decimal::.ctor(int64) IL_0008: stsfld valuetype[mscorlib]System.Decimal Class1::d1 IL_000d: ldc.i8 0x8cfb5ca13a30000 IL_0016: newobj instance void [mscorlib]System.DateTime::.ctor(int64) IL_001b: stsfld valuetype[mscorlib]System.DateTime Class1::d2 IL_0020: ret } // end of method Class1::.cctor .method public specialname rtspecialname instance void .ctor() cil managed { // Code size 7 (0x7) .maxstack 8 IL_0000: ldarg.0 IL_0001: call instance void [mscorlib]System.Object::.ctor() IL_0006: ret } // end of method Class1::.ctor .method public instance void M1([opt] valuetype[mscorlib] System.Decimal d1, [opt] valuetype[mscorlib] System.DateTime d2) cil managed { .param[1] .custom instance void [mscorlib]System.Runtime.CompilerServices.DecimalConstantAttribute::.ctor(uint8, uint8, uint32, uint32, uint32) = { uint8(0) uint8(128) uint32(0) uint32(0) uint32(7)} .custom instance void [mscorlib]System.Runtime.CompilerServices.DecimalConstantAttribute::.ctor(uint8, uint8, int32, int32, int32) = { uint8(0) uint8(128) int32(0) int32(0) int32(8)} .param[2] .custom instance void [mscorlib]System.Runtime.CompilerServices.DateTimeConstantAttribute::.ctor(int64) = { int64(634925952000000001)} .custom instance void [mscorlib]System.Runtime.CompilerServices.DateTimeConstantAttribute::.ctor(int64) = { int64(634925952000000000)} // Code size 1 (0x1) .maxstack 8 IL_0000: ret } // end of method Class1::M1 } // end of class Class1 "; var c1 = CreateCompilationWithMscorlib( @" public class Class1 { public const decimal d1 = -7; public void M1(decimal d1 = -7) {} }"); var class1 = c1.GetTypeByMetadataName("Class1"); var d1 = class1.GetMember<FieldSymbol>("d1"); var m1 = class1.GetMember<MethodSymbol>("M1"); var state = new ModuleCompilationState(); Assert.Empty(d1.GetAttributes()); Assert.Equal("System.Runtime.CompilerServices.DecimalConstantAttribute(0, 128, 0, 0, 7)", d1.GetCustomAttributesToEmit(state).Single().ToString()); Assert.Equal(d1.ConstantValue, -7m); Assert.Empty(m1.Parameters[0].GetAttributes()); Assert.Equal("System.Runtime.CompilerServices.DecimalConstantAttribute(0, 128, 0, 0, 7)", m1.Parameters[0].GetCustomAttributesToEmit(state).Single().ToString()); Assert.Equal(m1.Parameters[0].ExplicitDefaultValue, -7m); var c2 = CreateCompilationWithCustomILSource("", ilSource); class1 = c2.GetTypeByMetadataName("Class1"); d1 = class1.GetMember<FieldSymbol>("d1"); var d2 = class1.GetMember<FieldSymbol>("d2"); m1 = class1.GetMember<MethodSymbol>("M1"); Assert.Empty(d1.GetAttributes()); Assert.Equal("System.Runtime.CompilerServices.DecimalConstantAttribute(0, 128, 0, 0, 7)", d1.GetCustomAttributesToEmit(state).Single().ToString()); Assert.Equal(d1.ConstantValue, -7m); Assert.Equal(2, d2.GetAttributes().Length); Assert.Equal(2, d2.GetCustomAttributesToEmit(state).Count()); Assert.Null(d2.ConstantValue); Assert.Empty(m1.Parameters[0].GetAttributes()); Assert.Equal("System.Runtime.CompilerServices.DecimalConstantAttribute(0, 128, 0, 0, 7)", m1.Parameters[0].GetCustomAttributesToEmit(state).Single().ToString()); Assert.Equal(m1.Parameters[0].ExplicitDefaultValue, -7m); Assert.Empty(m1.Parameters[1].GetAttributes()); Assert.Equal("System.Runtime.CompilerServices.DateTimeConstantAttribute(634925952000000000)", m1.Parameters[1].GetCustomAttributesToEmit(state).Single().ToString()); Assert.Equal(m1.Parameters[1].ExplicitDefaultValue, new DateTime(2013, 1, 1)); var c3 = CreateCompilationWithCustomILSource("", ilSource); class1 = c3.GetTypeByMetadataName("Class1"); d1 = class1.GetMember<FieldSymbol>("d1"); d2 = class1.GetMember<FieldSymbol>("d2"); m1 = class1.GetMember<MethodSymbol>("M1"); Assert.Equal(d1.ConstantValue, -7m); Assert.Empty(d1.GetAttributes()); Assert.Equal("System.Runtime.CompilerServices.DecimalConstantAttribute(0, 128, 0, 0, 7)", d1.GetCustomAttributesToEmit(state).Single().ToString()); Assert.Null(d2.ConstantValue); Assert.Equal(2, d2.GetAttributes().Length); Assert.Equal(2, d2.GetCustomAttributesToEmit(state).Count()); Assert.Equal(m1.Parameters[0].ExplicitDefaultValue, -7m); Assert.Empty(m1.Parameters[0].GetAttributes()); Assert.Equal("System.Runtime.CompilerServices.DecimalConstantAttribute(0, 128, 0, 0, 7)", m1.Parameters[0].GetCustomAttributesToEmit(state).Single().ToString()); Assert.Equal(m1.Parameters[1].ExplicitDefaultValue, new DateTime(2013, 1, 1)); Assert.Empty(m1.Parameters[1].GetAttributes()); Assert.Equal("System.Runtime.CompilerServices.DateTimeConstantAttribute(634925952000000000)", m1.Parameters[1].GetCustomAttributesToEmit(state).Single().ToString()); }
internal override IEnumerable<CSharpAttributeData> GetCustomAttributesToEmit(ModuleCompilationState compilationState) { foreach (CSharpAttributeData attribute in GetAttributes()) { yield return attribute; } // Yield hidden attributes last, order might be important. foreach (CSharpAttributeData attribute in _lazyHiddenAttributes) { yield return attribute; } }
internal override abstract IEnumerable <CSharpAttributeData> GetCustomAttributesToEmit(ModuleCompilationState compilationState);
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); if (this.Type.ContainsDynamic()) { var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.Type, customModifiersCount: 0)); } }
internal override IEnumerable<CSharpAttributeData> GetCustomAttributesToEmit(ModuleCompilationState compilationState) { return GetAttributes(); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { // Emit [Dynamic] on synthesized parameter symbols when the original parameter was dynamic // in order to facilitate debugging. In the case the necessary attributes are missing // this is a no-op. Emitting an error here, or when the original parameter was bound, would // adversely effect the compilation or potentially change overload resolution. var compilation = this.DeclaringCompilation; if (Type.ContainsDynamic() && compilation.HasDynamicEmitAttributes() && compilation.GetSpecialType(SpecialType.System_Boolean).SpecialType == SpecialType.System_Boolean) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.Type, this.CustomModifiers.Length, this.RefKind)); } }
internal override IEnumerable <CSharpAttributeData> GetCustomAttributesToEmit(ModuleCompilationState compilationState) { foreach (CSharpAttributeData attribute in GetAttributes()) { yield return(attribute); } // Yield hidden attributes last, order might be important. if (FilterOutDecimalConstantAttribute()) { var containingPEModuleSymbol = this.containingType.ContainingPEModule; yield return(new PEAttributeData(containingPEModuleSymbol, containingPEModuleSymbol.Module.FindLastTargetAttribute(this.handle, AttributeDescription.DecimalConstantAttribute).Handle)); } }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder <SynthesizedAttributeData> attributes) { underlyingParameter.AddSynthesizedAttributes(compilationState, ref attributes); }
internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); if (this.IsExtensionMethod) { // No need to check if [Extension] attribute was explicitly set since // we'll issue CS1112 error in those cases and won't generate IL. var compilation = this.DeclaringCompilation; AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute( WellKnownMember.System_Runtime_CompilerServices_ExtensionAttribute__ctor)); } }
/// <remarks> /// These won't be returned by GetAttributes on source methods, but they /// will be returned by GetAttributes on metadata symbols. /// </remarks> internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder<SynthesizedAttributeData> attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); CSharpCompilation compilation = this.DeclaringCompilation; if (this.ContainsExtensionMethods) { // No need to check if [Extension] attribute was explicitly set since // we'll issue CS1112 error in those cases and won't generate IL. AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_ExtensionAttribute__ctor)); } if (this.Indexers.Any()) { string defaultMemberName = this.Indexers.First().MetadataName; // UNDONE: IndexerNameAttribute var defaultMemberNameConstant = new TypedConstant(compilation.GetSpecialType(SpecialType.System_String), TypedConstantKind.Primitive, defaultMemberName); AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute( WellKnownMember.System_Reflection_DefaultMemberAttribute__ctor, ImmutableArray.Create(defaultMemberNameConstant))); } NamedTypeSymbol baseType = this.BaseTypeNoUseSiteDiagnostics; if ((object)baseType != null && baseType.ContainsDynamic()) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(baseType, customModifiersCount: 0)); } }