internal override void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments <AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments) { Debug.Assert((object)arguments.AttributeSyntaxOpt != null); var diagnostics = (BindingDiagnosticBag)arguments.Diagnostics; var attribute = arguments.Attribute; Debug.Assert(!attribute.HasErrors); Debug.Assert(arguments.SymbolPart == AttributeLocation.None); if (attribute.IsTargetAttribute(this, AttributeDescription.SpecialNameAttribute)) { arguments.GetOrCreateData <FieldWellKnownAttributeData>().HasSpecialNameAttribute = true; } else if (attribute.IsTargetAttribute(this, AttributeDescription.NonSerializedAttribute)) { arguments.GetOrCreateData <FieldWellKnownAttributeData>().HasNonSerializedAttribute = true; } else if (attribute.IsTargetAttribute(this, AttributeDescription.FieldOffsetAttribute)) { if (this.IsStatic || this.IsConst) { // CS0637: The FieldOffset attribute is not allowed on static or const fields diagnostics.Add(ErrorCode.ERR_StructOffsetOnBadField, arguments.AttributeSyntaxOpt.Name.Location, arguments.AttributeSyntaxOpt.GetErrorDisplayName()); } else { int offset = attribute.CommonConstructorArguments[0].DecodeValue <int>(SpecialType.System_Int32); if (offset < 0) { // Dev10 reports CS0647: "Error emitting attribute ..." CSharpSyntaxNode attributeArgumentSyntax = attribute.GetAttributeArgumentSyntax(0, arguments.AttributeSyntaxOpt); diagnostics.Add(ErrorCode.ERR_InvalidAttributeArgument, attributeArgumentSyntax.Location, arguments.AttributeSyntaxOpt.GetErrorDisplayName()); offset = 0; } // Set field offset even if the attribute specifies an invalid value, so that // post-validation knows that the attribute is applied and reports better errors. arguments.GetOrCreateData <FieldWellKnownAttributeData>().SetFieldOffset(offset); } } else if (attribute.IsTargetAttribute(this, AttributeDescription.MarshalAsAttribute)) { MarshalAsAttributeDecoder <FieldWellKnownAttributeData, AttributeSyntax, CSharpAttributeData, AttributeLocation> .Decode(ref arguments, AttributeTargets.Field, MessageProvider.Instance); } else if (ReportExplicitUseOfReservedAttributes(in arguments, ReservedAttributes.DynamicAttribute | ReservedAttributes.IsReadOnlyAttribute | ReservedAttributes.IsUnmanagedAttribute | ReservedAttributes.IsByRefLikeAttribute | ReservedAttributes.TupleElementNamesAttribute | ReservedAttributes.NullableAttribute | ReservedAttributes.NativeIntegerAttribute)) { }
internal sealed override void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments <AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments) { Debug.Assert((object)arguments.AttributeSyntaxOpt != null); var attribute = arguments.Attribute; Debug.Assert(!attribute.HasErrors); Debug.Assert(arguments.SymbolPart == AttributeLocation.None); if (attribute.IsTargetAttribute(this, AttributeDescription.SpecialNameAttribute)) { arguments.GetOrCreateData <CommonFieldWellKnownAttributeData>().HasSpecialNameAttribute = true; } else if (attribute.IsTargetAttribute(this, AttributeDescription.NonSerializedAttribute)) { arguments.GetOrCreateData <CommonFieldWellKnownAttributeData>().HasNonSerializedAttribute = true; } else if (attribute.IsTargetAttribute(this, AttributeDescription.FieldOffsetAttribute)) { if (this.IsStatic || this.IsConst) { // CS0637: The FieldOffset attribute is not allowed on static or const fields arguments.Diagnostics.Add(ErrorCode.ERR_StructOffsetOnBadField, arguments.AttributeSyntaxOpt.Name.Location, arguments.AttributeSyntaxOpt.GetErrorDisplayName()); } else { int offset = attribute.CommonConstructorArguments[0].DecodeValue <int>(SpecialType.System_Int32); if (offset < 0) { // Dev10 reports CS0647: "Error emitting attribute ..." CSharpSyntaxNode attributeArgumentSyntax = attribute.GetAttributeArgumentSyntax(0, arguments.AttributeSyntaxOpt); arguments.Diagnostics.Add(ErrorCode.ERR_InvalidAttributeArgument, attributeArgumentSyntax.Location, arguments.AttributeSyntaxOpt.GetErrorDisplayName()); offset = 0; } // Set field offset even if the attribute specifies an invalid value, so that // post-validation knows that the attribute is applied and reports better errors. arguments.GetOrCreateData <CommonFieldWellKnownAttributeData>().SetFieldOffset(offset); } } else if (attribute.IsTargetAttribute(this, AttributeDescription.MarshalAsAttribute)) { MarshalAsAttributeDecoder <CommonFieldWellKnownAttributeData, AttributeSyntax, CSharpAttributeData, AttributeLocation> .Decode(ref arguments, AttributeTargets.Field, MessageProvider.Instance); } else if (attribute.IsTargetAttribute(this, AttributeDescription.FixedBufferAttribute)) { // error CS1716: Do not use 'System.Runtime.CompilerServices.FixedBuffer' attribute. Use the 'fixed' field modifier instead. arguments.Diagnostics.Add(ErrorCode.ERR_DoNotUseFixedBufferAttr, arguments.AttributeSyntaxOpt.Name.Location); } else if (attribute.IsTargetAttribute(this, AttributeDescription.DynamicAttribute)) { // DynamicAttribute should not be set explicitly. arguments.Diagnostics.Add(ErrorCode.ERR_ExplicitDynamicAttr, arguments.AttributeSyntaxOpt.Location); } else if (attribute.IsTargetAttribute(this, AttributeDescription.DateTimeConstantAttribute)) { VerifyConstantValueMatches(attribute.DecodeDateTimeConstantValue(), ref arguments); } else if (attribute.IsTargetAttribute(this, AttributeDescription.DecimalConstantAttribute)) { VerifyConstantValueMatches(attribute.DecodeDecimalConstantValue(), ref arguments); } }
internal override void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments <AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments) { Debug.Assert((object)arguments.AttributeSyntaxOpt != null); var attribute = arguments.Attribute; Debug.Assert(!attribute.HasErrors); Debug.Assert(arguments.SymbolPart == AttributeLocation.None); if (attribute.IsTargetAttribute(this, AttributeDescription.DefaultParameterValueAttribute)) { // Attribute decoded and constant value stored during EarlyDecodeWellKnownAttribute. DecodeDefaultParameterValueAttribute(AttributeDescription.DefaultParameterValueAttribute, ref arguments); } else if (attribute.IsTargetAttribute(this, AttributeDescription.DecimalConstantAttribute)) { // Attribute decoded and constant value stored during EarlyDecodeWellKnownAttribute. DecodeDefaultParameterValueAttribute(AttributeDescription.DecimalConstantAttribute, ref arguments); } else if (attribute.IsTargetAttribute(this, AttributeDescription.DateTimeConstantAttribute)) { // Attribute decoded and constant value stored during EarlyDecodeWellKnownAttribute. DecodeDefaultParameterValueAttribute(AttributeDescription.DateTimeConstantAttribute, ref arguments); } else if (attribute.IsTargetAttribute(this, AttributeDescription.OptionalAttribute)) { Debug.Assert(this.lazyHasOptionalAttribute == ThreeState.True); if (HasDefaultArgumentSyntax) { // error CS1745: Cannot specify default parameter value in conjunction with DefaultParameterAttribute or OptionalAttribute arguments.Diagnostics.Add(ErrorCode.ERR_DefaultValueUsedWithAttributes, arguments.AttributeSyntaxOpt.Name.Location); } } else if (attribute.IsTargetAttribute(this, AttributeDescription.ParamArrayAttribute)) { // error CS0674: Do not use 'System.ParamArrayAttribute'. Use the 'params' keyword instead. arguments.Diagnostics.Add(ErrorCode.ERR_ExplicitParamArray, arguments.AttributeSyntaxOpt.Name.Location); } else if (attribute.IsTargetAttribute(this, AttributeDescription.InAttribute)) { if (this.RefKind == RefKind.Out) { // error CS0036: An out parameter cannot have the In attribute arguments.Diagnostics.Add(ErrorCode.ERR_InAttrOnOutParam, arguments.AttributeSyntaxOpt.Name.Location); } else { arguments.GetOrCreateData <CommonParameterWellKnownAttributeData>().HasInAttribute = true; } } else if (attribute.IsTargetAttribute(this, AttributeDescription.OutAttribute)) { arguments.GetOrCreateData <CommonParameterWellKnownAttributeData>().HasOutAttribute = true; } else if (attribute.IsTargetAttribute(this, AttributeDescription.MarshalAsAttribute)) { MarshalAsAttributeDecoder <CommonParameterWellKnownAttributeData, AttributeSyntax, CSharpAttributeData, AttributeLocation> .Decode(ref arguments, AttributeTargets.Parameter, MessageProvider.Instance); } else if (attribute.IsTargetAttribute(this, AttributeDescription.IDispatchConstantAttribute)) { arguments.GetOrCreateData <CommonParameterWellKnownAttributeData>().HasIDispatchConstantAttribute = true; } else if (attribute.IsTargetAttribute(this, AttributeDescription.IUnknownConstantAttribute)) { arguments.GetOrCreateData <CommonParameterWellKnownAttributeData>().HasIUnknownConstantAttribute = true; } else if (attribute.IsTargetAttribute(this, AttributeDescription.CallerLineNumberAttribute)) { ValidateCallerLineNumberAttribute(arguments.AttributeSyntaxOpt, arguments.Diagnostics); } else if (attribute.IsTargetAttribute(this, AttributeDescription.CallerFilePathAttribute)) { ValidateCallerFilePathAttribute(arguments.AttributeSyntaxOpt, arguments.Diagnostics); } else if (attribute.IsTargetAttribute(this, AttributeDescription.CallerMemberNameAttribute)) { ValidateCallerMemberNameAttribute(arguments.AttributeSyntaxOpt, arguments.Diagnostics); } else if (attribute.IsTargetAttribute(this, AttributeDescription.DynamicAttribute)) { // DynamicAttribute should not be set explicitly. arguments.Diagnostics.Add(ErrorCode.ERR_ExplicitDynamicAttr, arguments.AttributeSyntaxOpt.Location); } }