public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
#if false
			if (a.Type == pa.MarshalAs) {
				UnmanagedMarshal marshal = a.GetMarshal (this);
				if (marshal != null) {
					builder.SetMarshal (marshal);
				}
				return;
			}
#endif
			if (a.HasSecurityAttribute) {
				a.Error_InvalidSecurityParent ();
				return;
			}

			if (a.Type == pa.Dynamic) {
				a.Error_MisusedDynamicAttribute ();
				return;
			}

			builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
		}
Example #2
0
        public void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
        {
            if (a.IsValidSecurityAttribute())
            {
                a.ExtractSecurityPermissionSet(ctor, ref declarative_security);
                return;
            }

            if (a.Type == pa.AssemblyCulture)
            {
                string value = a.GetString();
                if (value == null || value.Length == 0)
                {
                    return;
                }

                if (Compiler.Settings.Target == Target.Exe)
                {
                    a.Error_AttributeEmitError("The executables cannot be satelite assemblies, remove the attribute or keep it empty");
                    return;
                }

                if (value == "neutral")
                {
                    value = "";
                }

                if (Compiler.Settings.Target == Target.Module)
                {
                    SetCustomAttribute(ctor, cdata);
                }
                else
                {
                    builder_extra.SetCulture(value, a.Location);
                }

                return;
            }

            if (a.Type == pa.AssemblyVersion)
            {
                string value = a.GetString();
                if (value == null || value.Length == 0)
                {
                    return;
                }

                var vinfo = IsValidAssemblyVersion(value, true);
                if (vinfo == null)
                {
                    a.Error_AttributeEmitError(string.Format("Specified version `{0}' is not valid", value));
                    return;
                }

                if (Compiler.Settings.Target == Target.Module)
                {
                    SetCustomAttribute(ctor, cdata);
                }
                else
                {
                    builder_extra.SetVersion(vinfo, a.Location);
                }

                return;
            }

            if (a.Type == pa.AssemblyAlgorithmId)
            {
                const int pos = 2;                 // skip CA header
                uint      alg = (uint)cdata [pos];
                alg |= ((uint)cdata [pos + 1]) << 8;
                alg |= ((uint)cdata [pos + 2]) << 16;
                alg |= ((uint)cdata [pos + 3]) << 24;

                if (Compiler.Settings.Target == Target.Module)
                {
                    SetCustomAttribute(ctor, cdata);
                }
                else
                {
                    builder_extra.SetAlgorithmId(alg, a.Location);
                }

                return;
            }

            if (a.Type == pa.AssemblyFlags)
            {
                const int pos   = 2;               // skip CA header
                uint      flags = (uint)cdata[pos];
                flags |= ((uint)cdata [pos + 1]) << 8;
                flags |= ((uint)cdata [pos + 2]) << 16;
                flags |= ((uint)cdata [pos + 3]) << 24;

                // Ignore set PublicKey flag if assembly is not strongnamed
                if ((flags & (uint)AssemblyNameFlags.PublicKey) != 0 && public_key == null)
                {
                    flags &= ~(uint)AssemblyNameFlags.PublicKey;
                }

                if (Compiler.Settings.Target == Target.Module)
                {
                    SetCustomAttribute(ctor, cdata);
                }
                else
                {
                    builder_extra.SetFlags(flags, a.Location);
                }

                return;
            }

            if (a.Type == pa.TypeForwarder)
            {
                TypeSpec t = a.GetArgumentType();
                if (t == null || TypeManager.HasElementType(t))
                {
                    Report.Error(735, a.Location, "Invalid type specified as an argument for TypeForwardedTo attribute");
                    return;
                }

                if (emitted_forwarders == null)
                {
                    emitted_forwarders = new Dictionary <ITypeDefinition, Attribute> ();
                }
                else if (emitted_forwarders.ContainsKey(t.MemberDefinition))
                {
                    Report.SymbolRelatedToPreviousError(emitted_forwarders[t.MemberDefinition].Location, null);
                    Report.Error(739, a.Location, "A duplicate type forward of type `{0}'",
                                 TypeManager.CSharpName(t));
                    return;
                }

                emitted_forwarders.Add(t.MemberDefinition, a);

                if (t.MemberDefinition.DeclaringAssembly == this)
                {
                    Report.SymbolRelatedToPreviousError(t);
                    Report.Error(729, a.Location, "Cannot forward type `{0}' because it is defined in this assembly",
                                 TypeManager.CSharpName(t));
                    return;
                }

                if (t.IsNested)
                {
                    Report.Error(730, a.Location, "Cannot forward type `{0}' because it is a nested type",
                                 TypeManager.CSharpName(t));
                    return;
                }

                builder_extra.AddTypeForwarder(t.GetDefinition(), a.Location);
                return;
            }

            if (a.Type == pa.Extension)
            {
                a.Error_MisusedExtensionAttribute();
                return;
            }

            if (a.Type == pa.InternalsVisibleTo)
            {
                string assembly_name = a.GetString();
                if (assembly_name.Length == 0)
                {
                    return;
                }
#if STATIC
                ParsedAssemblyName  aname;
                ParseAssemblyResult r = Fusion.ParseAssemblyName(assembly_name, out aname);
                if (r != ParseAssemblyResult.OK)
                {
                    Report.Warning(1700, 3, a.Location, "Assembly reference `{0}' is invalid and cannot be resolved",
                                   assembly_name);
                    return;
                }

                if (aname.Version != null || aname.Culture != null || aname.ProcessorArchitecture != ProcessorArchitecture.None)
                {
                    Report.Error(1725, a.Location,
                                 "Friend assembly reference `{0}' is invalid. InternalsVisibleTo declarations cannot have a version, culture or processor architecture specified",
                                 assembly_name);

                    return;
                }

                if (public_key != null && !aname.HasPublicKey)
                {
                    Report.Error(1726, a.Location,
                                 "Friend assembly reference `{0}' is invalid. Strong named assemblies must specify a public key in their InternalsVisibleTo declarations",
                                 assembly_name);
                    return;
                }
#endif
            }
            else if (a.Type == pa.RuntimeCompatibility)
            {
                wrap_non_exception_throws_custom = true;
            }
            else if (a.Type == pa.AssemblyFileVersion)
            {
                string value = a.GetString();
                if (string.IsNullOrEmpty(value) || IsValidAssemblyVersion(value, false) == null)
                {
                    Report.Warning(1607, 1, a.Location, "The version number `{0}' specified for `{1}' is invalid",
                                   value, a.Name);
                    return;
                }
            }


            SetCustomAttribute(ctor, cdata);
        }
        public override void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
        {
            if (a.Target == AttributeTargets.ReturnValue)
            {
                if (return_attributes == null)
                {
                    return_attributes = new ReturnParameter(this, InvokeBuilder.MethodBuilder, Location);
                }

                return_attributes.ApplyAttributeBuilder(a, ctor, cdata, pa);
                return;
            }

            base.ApplyAttributeBuilder(a, ctor, cdata, pa);
        }
        public virtual void ApplyAttributes(MethodBuilder mb, ConstructorBuilder cb, int index, PredefinedAttributes pa)
        {
            if (builder != null)
            {
                throw new InternalErrorException("builder already exists");
            }

            var pattrs = ParametersCompiled.GetParameterAttribute(modFlags);

            if (HasOptionalExpression)
            {
                pattrs |= ParameterAttributes.Optional;
            }

            if (mb == null)
            {
                builder = cb.DefineParameter(index, pattrs, Name);
            }
            else
            {
                builder = mb.DefineParameter(index, pattrs, Name);
            }

            if (OptAttributes != null)
            {
                OptAttributes.Emit();
            }

            if (HasDefaultValue)
            {
                //
                // Emit constant values for true constants only, the other
                // constant-like expressions will rely on default value expression
                //
                var      def_value = DefaultValue;
                Constant c         = def_value != null ? def_value.Child as Constant : default_expr as Constant;
                if (c != null)
                {
                    if (default_expr.Type == TypeManager.decimal_type)
                    {
                        pa.DecimalConstant.EmitAttribute(builder, (decimal)c.GetValue(), c.Location);
                    }
                    else
                    {
                        builder.SetConstant(c.GetValue());
                    }
                }
                else if (default_expr.Type.IsStruct)
                {
                    //
                    // Handles special case where default expression is used with value-type
                    //
                    // void Foo (S s = default (S)) {}
                    //
                    builder.SetConstant(null);
                }
            }

            if (parameter_type != null)
            {
                if (parameter_type == InternalType.Dynamic)
                {
                    pa.Dynamic.EmitAttribute(builder);
                }
                else if (parameter_type.HasDynamicElement)
                {
                    pa.Dynamic.EmitAttribute(builder, parameter_type, Location);
                }
            }
        }
Example #5
0
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.Type == pa.ComImport && !attributes.Contains (pa.Guid)) {
				a.Error_MissingGuidAttribute ();
				return;
			}

			base.ApplyAttributeBuilder (a, ctor, cdata, pa);
		}
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.Type == pa.CLSCompliant) {
				method.Compiler.Report.Warning (3023, 1, a.Location,
					"CLSCompliant attribute has no meaning when applied to return types. Try putting it on the method instead");
			}

			// This occurs after Warning -28
			if (builder == null)
				return;

			base.ApplyAttributeBuilder (a, ctor, cdata, pa);
		}
		public override void  ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index, PredefinedAttributes pa)
		{
			// Nothing to do
		}
Example #8
0
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.Type == pa.Conditional) {
				Error_ConditionalAttributeIsNotValid ();
				return;
			}

			base.ApplyAttributeBuilder (a, ctor, cdata, pa);
		}
Example #9
0
        public override void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
        {
            if (a.Target == AttributeTargets.ReturnValue)
            {
                CreateReturnBuilder();
                return_attributes.ApplyAttributeBuilder(a, ctor, cdata, pa);
                return;
            }

            if (a.IsValidSecurityAttribute())
            {
                a.ExtractSecurityPermissionSet(ctor, ref declarative_security);
                return;
            }

            base.ApplyAttributeBuilder(a, ctor, cdata, pa);
        }
Example #10
0
        public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa)
        {
            if (a.Target == AttributeTargets.ReturnValue)
            {
                if (return_attributes == null)
                {
                    return_attributes = new ReturnParameter(InvokeBuilder, Location);
                }

                return_attributes.ApplyAttributeBuilder(a, cb, pa);
                return;
            }

            base.ApplyAttributeBuilder(a, cb, pa);
        }
Example #11
0
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (has_normal_indexers && a.Type == pa.DefaultMember) {
				Report.Error (646, a.Location, "Cannot specify the `DefaultMember' attribute on type containing an indexer");
				return;
			}

			if (a.Type == pa.Required) {
				Report.Error (1608, a.Location, "The RequiredAttribute attribute is not permitted on C# types");
				return;
			}

			TypeBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
		} 
Example #12
0
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.Target == AttributeTargets.Field) {
				BackingField.ApplyAttributeBuilder (a, ctor, cdata, pa);
				return;
			}

			base.ApplyAttributeBuilder (a, ctor, cdata, pa);
		}
Example #13
0
        public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa)
        {
            if (a.Type == pa.CLSCompliant)
            {
                if (CodeGen.Assembly.ClsCompliantAttribute == null)
                {
                    Report.Warning(3012, 1, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
                }
                else if (CodeGen.Assembly.IsClsCompliant != a.GetBoolean())
                {
                    Report.SymbolRelatedToPreviousError(CodeGen.Assembly.ClsCompliantAttribute.Location, CodeGen.Assembly.ClsCompliantAttribute.GetSignatureForError());
                    Report.Warning(3017, 1, a.Location, "You cannot specify the CLSCompliant attribute on a module that differs from the CLSCompliant attribute on the assembly");
                    return;
                }
            }

            Builder.SetCustomAttribute(cb);
        }
Example #14
0
		public void InitializePredefinedTypes ()
		{
			predefined_attributes = new PredefinedAttributes (this);
			predefined_types = new PredefinedTypes (this);
			predefined_members = new PredefinedMembers (this);

			OperatorsBinaryEqualityLifted = Binary.CreateEqualityLiftedOperatorsTable (this);
			OperatorsBinaryLifted = Binary.CreateStandardLiftedOperatorsTable (this);
		}
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			throw new NotSupportedException ();
		}
Example #16
0
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.Type == pa.CLSCompliant || a.Type == pa.Obsolete || a.Type == pa.Conditional) {
				Report.Error (1667, a.Location,
					"Attribute `{0}' is not valid on property or event accessors. It is valid on `{1}' declarations only",
					a.Type.GetSignatureForError (), a.GetValidTargets ());
				return;
			}

			if (a.IsValidSecurityAttribute ()) {
				a.ExtractSecurityPermissionSet (ctor, ref declarative_security);
				return;
			}

			if (a.Target == AttributeTargets.Method) {
				method_data.MethodBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
				return;
			}

			if (a.Target == AttributeTargets.ReturnValue) {
				if (return_attributes == null)
					return_attributes = new ReturnParameter (this, method_data.MethodBuilder, Location);

				return_attributes.ApplyAttributeBuilder (a, ctor, cdata, pa);
				return;
			}

			ApplyToExtraTarget (a, ctor, cdata, pa);
		}
Example #17
0
        public override void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
        {
            if (a.Target == AttributeTargets.ReturnValue)
            {
                if (return_attributes == null)
                {
                    return_attributes = new ReturnParameter(this, InvokeBuilder.MethodBuilder, Location);
                }

                return_attributes.ApplyAttributeBuilder(a, ctor, cdata, pa);
                return;
            }

            if (a.IsValidSecurityAttribute())
            {
                a.ExtractSecurityPermissionSet(ctor, ref declarative_security);
                return;
            }

            base.ApplyAttributeBuilder(a, ctor, cdata, pa);
        }
Example #18
0
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.Type == pa.Conditional) {
				if (IsExplicitImpl) {
					Error_ConditionalAttributeIsNotValid ();
					return;
				}

				if ((ModFlags & Modifiers.OVERRIDE) != 0) {
					Report.Error (243, Location, "Conditional not valid on `{0}' because it is an override method", GetSignatureForError ());
					return;
				}

				if (ReturnType.Kind != MemberKind.Void) {
					Report.Error (578, Location, "Conditional not valid on `{0}' because its return type is not void", GetSignatureForError ());
					return;
				}

				if (IsInterface) {
					Report.Error (582, Location, "Conditional not valid on interface members");
					return;
				}

				if (MethodData.implementing != null) {
					Report.SymbolRelatedToPreviousError (MethodData.implementing.DeclaringType);
					Report.Error (629, Location, "Conditional member `{0}' cannot implement interface member `{1}'",
						GetSignatureForError (), TypeManager.CSharpSignature (MethodData.implementing));
					return;
				}

				for (int i = 0; i < parameters.Count; ++i) {
					if ((parameters.FixedParameters [i].ModFlags & Parameter.Modifier.OUT) != 0) {
						Report.Error (685, Location, "Conditional method `{0}' cannot have an out parameter", GetSignatureForError ());
						return;
					}
				}
			}

			if (a.Type == pa.Extension) {
				a.Error_MisusedExtensionAttribute ();
				return;
			}

			base.ApplyAttributeBuilder (a, ctor, cdata, pa);
		}
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.Target == AttributeTargets.Field) {
				backing_field.ApplyAttributeBuilder (a, ctor, cdata, pa);
				return;
			}

			if (a.Target == AttributeTargets.Method) {
				int errors = Report.Errors;
				Add.ApplyAttributeBuilder (a, ctor, cdata, pa);
				if (errors == Report.Errors)
					Remove.ApplyAttributeBuilder (a, ctor, cdata, pa);
				return;
			}

			base.ApplyAttributeBuilder (a, ctor, cdata, pa);
		}
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if ((a.HasSecurityAttribute)) {
				a.Error_InvalidSecurityParent ();
				return;
			}

			EventBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
		}
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.Type == pa.IndexerName) {
				// Attribute was copied to container
				return;
			}

			base.ApplyAttributeBuilder (a, ctor, cdata, pa);
		}
Example #22
0
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.Type == pa.AttributeUsage) {
				if (!BaseType.IsAttribute && spec.BuiltinType != BuiltinTypeSpec.Type.Attribute) {
					Report.Error (641, a.Location, "Attribute `{0}' is only valid on classes derived from System.Attribute", a.GetSignatureForError ());
				}
			}

			if (a.Type == pa.Conditional && !BaseType.IsAttribute) {
				Report.Error (1689, a.Location, "Attribute `System.Diagnostics.ConditionalAttribute' is only valid on methods or attribute classes");
				return;
			}

			if (a.Type == pa.ComImport && !attributes.Contains (pa.Guid)) {
				a.Error_MissingGuidAttribute ();
				return;
			}

			if (a.Type == pa.Extension) {
				a.Error_MisusedExtensionAttribute ();
				return;
			}

			if (a.Type.IsConditionallyExcluded (this))
				return;

			base.ApplyAttributeBuilder (a, ctor, cdata, pa);
		}
			protected override void ApplyToExtraTarget (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
			{
				if (a.Target == AttributeTargets.Parameter) {
					parameters[0].ApplyAttributeBuilder (a, ctor, cdata, pa);
					return;
				}

				base.ApplyAttributeBuilder (a, ctor, cdata, pa);
			}
Example #24
0
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.Target == AttributeTargets.Assembly) {
				assembly.ApplyAttributeBuilder (a, ctor, cdata, pa);
				return;
			}

			if (a.Type == pa.DefaultCharset) {
				switch (a.GetCharSetValue ()) {
				case CharSet.Ansi:
				case CharSet.None:
					break;
				case CharSet.Auto:
					DefaultCharSet = CharSet.Auto;
					DefaultCharSetType = TypeAttributes.AutoClass;
					break;
				case CharSet.Unicode:
					DefaultCharSet = CharSet.Unicode;
					DefaultCharSetType = TypeAttributes.UnicodeClass;
					break;
				default:
					Report.Error (1724, a.Location, "Value specified for the argument to `{0}' is not valid",
						a.GetSignatureForError ());
					break;
				}
			} else if (a.Type == pa.CLSCompliant) {
				Attribute cls = DeclaringAssembly.CLSCompliantAttribute;
				if (cls == null) {
					Report.Warning (3012, 1, a.Location,
						"You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
				} else if (DeclaringAssembly.IsCLSCompliant != a.GetBoolean ()) {
					Report.SymbolRelatedToPreviousError (cls.Location, cls.GetSignatureForError ());
					Report.Warning (3017, 1, a.Location,
						"You cannot specify the CLSCompliant attribute on a module that differs from the CLSCompliant attribute on the assembly");
					return;
				}
			}

			builder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
		}
			public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
			{
				if (a.Type == pa.MethodImpl) {
					method.is_external_implementation = a.IsInternalCall ();
				}

				base.ApplyAttributeBuilder (a, ctor, cdata, pa);
			}
        public override void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
        {
            if (a.Type == pa.CLSCompliant)
            {
                method.Compiler.Report.Warning(3023, 1, a.Location,
                                               "CLSCompliant attribute has no meaning when applied to return types. Try putting it on the method instead");
            }

            // This occurs after Warning -28
            if (builder == null)
            {
                return;
            }

            base.ApplyAttributeBuilder(a, ctor, cdata, pa);
        }
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.HasSecurityAttribute) {
				a.Error_InvalidSecurityParent ();
				return;
			}

			if (a.Type == pa.Dynamic) {
				a.Error_MisusedDynamicAttribute ();
				return;
			}

			PropertyBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
		}
Example #28
0
        public override void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
        {
            if (a.Type == pa.FieldOffset)
            {
                status |= Status.HAS_OFFSET;

                if (!Parent.PartialContainer.HasExplicitLayout)
                {
                    Report.Error(636, Location, "The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)");
                    return;
                }

                if ((ModFlags & Modifiers.STATIC) != 0 || this is Const)
                {
                    Report.Error(637, Location, "The FieldOffset attribute is not allowed on static or const fields");
                    return;
                }
            }

            if (a.Type == pa.FixedBuffer)
            {
                Report.Error(1716, Location, "Do not use 'System.Runtime.CompilerServices.FixedBuffer' attribute. Use the 'fixed' field modifier instead");
                return;
            }

#if false
            if (a.Type == pa.MarshalAs)
            {
                UnmanagedMarshal marshal = a.GetMarshal(this);
                if (marshal != null)
                {
                    FieldBuilder.SetMarshal(marshal);
                }
                return;
            }
#endif
            if ((a.HasSecurityAttribute))
            {
                a.Error_InvalidSecurityParent();
                return;
            }

            if (a.Type == pa.Dynamic)
            {
                a.Error_MisusedDynamicAttribute();
                return;
            }

            FieldBuilder.SetCustomAttribute((ConstructorInfo)ctor.GetMetaInfo(), cdata);
        }
Example #29
0
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.Target == AttributeTargets.ReturnValue) {
				if (return_attributes == null)
					return_attributes = new ReturnParameter (this, InvokeBuilder.MethodBuilder, Location);

				return_attributes.ApplyAttributeBuilder (a, ctor, cdata, pa);
				return;
			}

			base.ApplyAttributeBuilder (a, ctor, cdata, pa);
		}
Example #30
0
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.Type == pa.FieldOffset) {
				status |= Status.HAS_OFFSET;

				if (!Parent.PartialContainer.HasExplicitLayout) {
					Report.Error (636, Location, "The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)");
					return;
				}

				if ((ModFlags & Modifiers.STATIC) != 0 || this is Const) {
					Report.Error (637, Location, "The FieldOffset attribute is not allowed on static or const fields");
					return;
				}
			}

			if (a.Type == pa.FixedBuffer) {
				Report.Error (1716, Location, "Do not use 'System.Runtime.CompilerServices.FixedBuffer' attribute. Use the 'fixed' field modifier instead");
				return;
			}

#if false
			if (a.Type == pa.MarshalAs) {
				UnmanagedMarshal marshal = a.GetMarshal (this);
				if (marshal != null) {
					FieldBuilder.SetMarshal (marshal);
				}
				return;
			}
#endif
			if ((a.HasSecurityAttribute)) {
				a.Error_InvalidSecurityParent ();
				return;
			}

			if (a.Type == pa.Dynamic) {
				a.Error_MisusedDynamicAttribute ();
				return;
			}

			FieldBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
		}
Example #31
0
        public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa)
        {
#if !NET_2_0
            if (a.Type == pa.MarshalAs)
            {
                UnmanagedMarshal marshal = a.GetMarshal(this);
                if (marshal != null)
                {
                    builder.SetMarshal(marshal);
                }
                return;
            }
#endif
            if (a.HasSecurityAttribute)
            {
                a.Error_InvalidSecurityParent();
                return;
            }

            builder.SetCustomAttribute(cb);
        }
Example #32
0
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.IsValidSecurityAttribute ()) {
				a.ExtractSecurityPermissionSet (ctor, ref declarative_security);
				return;
			}

			if (a.Type == pa.MethodImpl) {
				is_external_implementation = a.IsInternalCall ();
			}

			ConstructorBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
		}
Example #33
0
        public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa)
        {
            Report Report = RootContext.ToplevelTypes.Compiler.Report;

            if (a.Type == pa.In && ModFlags == Modifier.OUT)
            {
                Report.Error(36, a.Location, "An out parameter cannot have the `In' attribute");
                return;
            }

            if (a.Type == pa.ParamArray)
            {
                Report.Error(674, a.Location, "Do not use `System.ParamArrayAttribute'. Use the `params' keyword instead");
                return;
            }

            if (a.Type == PredefinedAttributes.Get.Out && (ModFlags & Modifier.REF) == Modifier.REF &&
                !OptAttributes.Contains(pa.In))
            {
                Report.Error(662, a.Location,
                             "Cannot specify only `Out' attribute on a ref parameter. Use both `In' and `Out' attributes or neither");
                return;
            }

            if (a.Type == pa.CLSCompliant)
            {
                Report.Warning(3022, 1, a.Location, "CLSCompliant attribute has no meaning when applied to parameters. Try putting it on the method instead");
            }

            if (HasDefaultValue && (a.Type == pa.DefaultParameterValue || a.Type == pa.OptionalParameter))
            {
                Report.Error(1745, a.Location,
                             "Cannot specify `{0}' attribute on optional parameter `{1}'",
                             TypeManager.CSharpName(a.Type).Replace("Attribute", ""), Name);
                return;
            }

            if (a.Type == pa.DefaultParameterValue)
            {
                object val = a.GetParameterDefaultValue();
                if (val != null)
                {
                    Type t = val.GetType();
                    if (t.IsArray || TypeManager.IsSubclassOf(t, TypeManager.type_type))
                    {
                        if (parameter_type == TypeManager.object_type)
                        {
                            if (!t.IsArray)
                            {
                                t = TypeManager.type_type;
                            }

                            Report.Error(1910, a.Location, "Argument of type `{0}' is not applicable for the DefaultParameterValue attribute",
                                         TypeManager.CSharpName(t));
                        }
                        else
                        {
                            Report.Error(1909, a.Location, "The DefaultParameterValue attribute is not applicable on parameters of type `{0}'",
                                         TypeManager.CSharpName(parameter_type));;
                        }
                        return;
                    }
                }

                if (parameter_type == TypeManager.object_type ||
                    (val == null && !TypeManager.IsGenericParameter(parameter_type) && TypeManager.IsReferenceType(parameter_type)) ||
                    (val != null && TypeManager.TypeToCoreType(val.GetType()) == parameter_type))
                {
                    builder.SetConstant(val);
                }
                else
                {
                    Report.Error(1908, a.Location, "The type of the default value should match the type of the parameter");
                }
                return;
            }

            base.ApplyAttributeBuilder(a, cb, pa);
        }
Example #34
0
		protected virtual void ApplyToExtraTarget (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			throw new NotSupportedException ("You forgot to define special attribute target handling");
		}
Example #35
0
        public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa)
        {
            if (a.Type == pa.CLSCompliant)
            {
                RootContext.ToplevelTypes.Compiler.Report.Warning(3023, 1, a.Location,
                                                                  "CLSCompliant attribute has no meaning when applied to return types. Try putting it on the method instead");
            }

            // This occurs after Warning -28
            if (builder == null)
            {
                return;
            }

            base.ApplyAttributeBuilder(a, cb, pa);
        }
Example #36
0
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.Target == AttributeTargets.ReturnValue) {
				if (return_attributes == null)
					return_attributes = new ReturnParameter (this, MethodBuilder, Location);

				return_attributes.ApplyAttributeBuilder (a, ctor, cdata, pa);
				return;
			}

			if (a.Type == pa.MethodImpl) {
				if ((ModFlags & Modifiers.ASYNC) != 0 && (a.GetMethodImplOptions () & MethodImplOptions.Synchronized) != 0) {
					Report.Error (4015, a.Location, "`{0}': Async methods cannot use `MethodImplOptions.Synchronized'",
						GetSignatureForError ());
				}

				is_external_implementation = a.IsInternalCall ();
			} else if (a.Type == pa.DllImport) {
				const Modifiers extern_static = Modifiers.EXTERN | Modifiers.STATIC;
				if ((ModFlags & extern_static) != extern_static) {
					Report.Error (601, a.Location, "The DllImport attribute must be specified on a method marked `static' and `extern'");
				}

				if (MemberName.IsGeneric || Parent.IsGenericOrParentIsGeneric) {
					Report.Error (7042, a.Location, 
						"The DllImport attribute cannot be applied to a method that is generic or contained in a generic type");
				}

				is_external_implementation = true;
			}

			if (a.IsValidSecurityAttribute ()) {
				a.ExtractSecurityPermissionSet (ctor, ref declarative_security);
				return;
			}

			if (MethodBuilder != null)
				MethodBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
		}
Example #37
0
 public void InitializePredefinedTypes()
 {
     predefined_attributes = new PredefinedAttributes(this);
     predefined_types      = new PredefinedTypes(this);
     predefined_members    = new PredefinedMembers(this);
 }
		public override void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index, PredefinedAttributes pa)
		{
			base.ApplyAttributes (mb, cb, index, pa);
			pa.ParamArray.EmitAttribute (builder);
		}
Example #39
0
        public override void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
        {
            if (a.Target == AttributeTargets.Assembly)
            {
                assembly.ApplyAttributeBuilder(a, ctor, cdata, pa);
                return;
            }

            if (a.Type == pa.DefaultCharset)
            {
                switch (a.GetCharSetValue())
                {
                case CharSet.Ansi:
                case CharSet.None:
                    break;

                case CharSet.Auto:
                    DefaultCharSet     = CharSet.Auto;
                    DefaultCharSetType = TypeAttributes.AutoClass;
                    break;

                case CharSet.Unicode:
                    DefaultCharSet     = CharSet.Unicode;
                    DefaultCharSetType = TypeAttributes.UnicodeClass;
                    break;

                default:
                    Report.Error(1724, a.Location, "Value specified for the argument to `{0}' is not valid",
                                 a.GetSignatureForError());
                    break;
                }
            }
            else if (a.Type == pa.CLSCompliant)
            {
                Attribute cls = DeclaringAssembly.CLSCompliantAttribute;
                if (cls == null)
                {
                    Report.Warning(3012, 1, a.Location,
                                   "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
                }
                else if (DeclaringAssembly.IsCLSCompliant != a.GetBoolean())
                {
                    Report.SymbolRelatedToPreviousError(cls.Location, cls.GetSignatureForError());
                    Report.Warning(3017, 1, a.Location,
                                   "You cannot specify the CLSCompliant attribute on a module that differs from the CLSCompliant attribute on the assembly");
                    return;
                }
            }

            builder.SetCustomAttribute((ConstructorInfo)ctor.GetMetaInfo(), cdata);
        }
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.Type == pa.In && ModFlags == Modifier.OUT) {
				a.Report.Error (36, a.Location, "An out parameter cannot have the `In' attribute");
				return;
			}

			if (a.Type == pa.ParamArray) {
				a.Report.Error (674, a.Location, "Do not use `System.ParamArrayAttribute'. Use the `params' keyword instead");
				return;
			}

			if (a.Type == pa.Out && (ModFlags & Modifier.REF) != 0 &&
			    !OptAttributes.Contains (pa.In)) {
				a.Report.Error (662, a.Location,
					"Cannot specify only `Out' attribute on a ref parameter. Use both `In' and `Out' attributes or neither");
				return;
			}

			if (a.Type == pa.CLSCompliant) {
				a.Report.Warning (3022, 1, a.Location, "CLSCompliant attribute has no meaning when applied to parameters. Try putting it on the method instead");
			} else if (a.Type == pa.DefaultParameterValue || a.Type == pa.OptionalParameter) {
				if (HasOptionalExpression) {
					a.Report.Error (1745, a.Location,
						"Cannot specify `{0}' attribute on optional parameter `{1}'",
						TypeManager.CSharpName (a.Type).Replace ("Attribute", ""), Name);
				}

				if (a.Type == pa.DefaultParameterValue)
					return;
			} else if (a.Type == pa.CallerMemberNameAttribute) {
				if ((modFlags & Modifier.CallerMemberName) == 0) {
					a.Report.Error (4022, a.Location,
						"The CallerMemberName attribute can only be applied to parameters with default value");
				}
			} else if (a.Type == pa.CallerLineNumberAttribute) {
				if ((modFlags & Modifier.CallerLineNumber) == 0) {
					a.Report.Error (4020, a.Location,
						"The CallerLineNumber attribute can only be applied to parameters with default value");
				}
			} else if (a.Type == pa.CallerFilePathAttribute) {
				if ((modFlags & Modifier.CallerFilePath) == 0) {
					a.Report.Error (4021, a.Location,
						"The CallerFilePath attribute can only be applied to parameters with default value");
				}
			}

			base.ApplyAttributeBuilder (a, ctor, cdata, pa);
		}
 public override void ApplyAttributes(MethodBuilder mb, ConstructorBuilder cb, int index, PredefinedAttributes pa)
 {
     base.ApplyAttributes(mb, cb, index, pa);
     pa.ParamArray.EmitAttribute(builder);
 }
		public virtual void ApplyAttributes (MethodBuilder mb, ConstructorBuilder cb, int index, PredefinedAttributes pa)
		{
			if (builder != null)
				throw new InternalErrorException ("builder already exists");

			var pattrs = ParametersCompiled.GetParameterAttribute (modFlags);
			if (HasOptionalExpression)
				pattrs |= ParameterAttributes.Optional;

			if (mb == null)
				builder = cb.DefineParameter (index, pattrs, Name);
			else
				builder = mb.DefineParameter (index, pattrs, Name);

			if (OptAttributes != null)
				OptAttributes.Emit ();

			if (HasDefaultValue) {
				//
				// Emit constant values for true constants only, the other
				// constant-like expressions will rely on default value expression
				//
				var def_value = DefaultValue;
				Constant c = def_value != null ? def_value.Child as Constant : default_expr as Constant;
				if (c != null) {
					if (c.Type.BuiltinType == BuiltinTypeSpec.Type.Decimal) {
						pa.DecimalConstant.EmitAttribute (builder, (decimal) c.GetValue (), c.Location);
					} else {
						builder.SetConstant (c.GetValue ());
					}
				} else if (default_expr.Type.IsStruct) {
					//
					// Handles special case where default expression is used with value-type
					//
					// void Foo (S s = default (S)) {}
					//
					builder.SetConstant (null);
				}
			}

			if (parameter_type != null) {
				if (parameter_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
					pa.Dynamic.EmitAttribute (builder);
				} else if (parameter_type.HasDynamicElement) {
					pa.Dynamic.EmitAttribute (builder, parameter_type, Location);
				}
			}
		}
 public override void  ApplyAttributes(MethodBuilder mb, ConstructorBuilder cb, int index, PredefinedAttributes pa)
 {
     // Nothing to do
 }
Example #44
0
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.IsValidSecurityAttribute ()) {
				a.ExtractSecurityPermissionSet (ctor, ref declarative_security);
				return;
			}

			if (a.Type == pa.StructLayout) {
				PartialContainer.HasStructLayout = true;
				if (a.IsExplicitLayoutKind ())
					PartialContainer.HasExplicitLayout = true;
			}

			if (a.Type == pa.Dynamic) {
				a.Error_MisusedDynamicAttribute ();
				return;
			}

			base.ApplyAttributeBuilder (a, ctor, cdata, pa);
		}
        public override void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
        {
            if (a.Type == pa.In && ModFlags == Modifier.OUT)
            {
                a.Report.Error(36, a.Location, "An out parameter cannot have the `In' attribute");
                return;
            }

            if (a.Type == pa.ParamArray)
            {
                a.Report.Error(674, a.Location, "Do not use `System.ParamArrayAttribute'. Use the `params' keyword instead");
                return;
            }

            if (a.Type == pa.Out && (ModFlags & Modifier.REF) == Modifier.REF &&
                !OptAttributes.Contains(pa.In))
            {
                a.Report.Error(662, a.Location,
                               "Cannot specify only `Out' attribute on a ref parameter. Use both `In' and `Out' attributes or neither");
                return;
            }

            if (a.Type == pa.CLSCompliant)
            {
                a.Report.Warning(3022, 1, a.Location, "CLSCompliant attribute has no meaning when applied to parameters. Try putting it on the method instead");
            }

            if (a.Type == pa.DefaultParameterValue || a.Type == pa.OptionalParameter)
            {
                if (HasOptionalExpression)
                {
                    a.Report.Error(1745, a.Location,
                                   "Cannot specify `{0}' attribute on optional parameter `{1}'",
                                   TypeManager.CSharpName(a.Type).Replace("Attribute", ""), Name);
                }

                if (a.Type == pa.DefaultParameterValue)
                {
                    return;
                }
            }

            base.ApplyAttributeBuilder(a, ctor, cdata, pa);
        }
Example #46
0
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			base.ApplyAttributeBuilder (a, ctor, cdata, pa);

			//
			// When struct constains fixed fixed and struct layout has explicitly
			// set CharSet, its value has to be propagated to compiler generated
			// fixed types
			//
			if (a.Type == pa.StructLayout) {
				var value = a.GetNamedValue ("CharSet");
				if (value == null)
					return;

				for (int i = 0; i < Members.Count; ++i) {
					FixedField ff = Members [i] as FixedField;
					if (ff == null)
						continue;

					ff.CharSet = (CharSet) System.Enum.Parse (typeof (CharSet), value.GetValue ().ToString ());
				}
			}
		}
        public override void ApplyAttributeBuilder(Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
        {
#if false
            if (a.Type == pa.MarshalAs)
            {
                UnmanagedMarshal marshal = a.GetMarshal(this);
                if (marshal != null)
                {
                    builder.SetMarshal(marshal);
                }
                return;
            }
#endif
            if (a.HasSecurityAttribute)
            {
                a.Error_InvalidSecurityParent();
                return;
            }

            if (a.Type == pa.Dynamic)
            {
                a.Error_MisusedDynamicAttribute();
                return;
            }

            builder.SetCustomAttribute((ConstructorInfo)ctor.GetMetaInfo(), cdata);
        }
Example #48
0
		public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
		{
			if (a.Target == AttributeTargets.Method) {
				foreach (var m in members) {
					var c = m as Constructor;
					if (c == null)
						continue;

					if (c.IsPrimaryConstructor) {
						c.ApplyAttributeBuilder (a, ctor, cdata, pa);
						return;
					}
				}

				throw new InternalErrorException ();
			}

			if (has_normal_indexers && a.Type == pa.DefaultMember) {
				Report.Error (646, a.Location, "Cannot specify the `DefaultMember' attribute on type containing an indexer");
				return;
			}

			if (a.Type == pa.Required) {
				Report.Error (1608, a.Location, "The RequiredAttribute attribute is not permitted on C# types");
				return;
			}

			TypeBuilder.SetCustomAttribute ((ConstructorInfo) ctor.GetMetaInfo (), cdata);
		} 
Example #49
0
        public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa)
        {
            if (a.IsValidSecurityAttribute())
            {
                if (declarative_security == null)
                {
                    declarative_security = new ListDictionary();
                }

                a.ExtractSecurityPermissionSet(declarative_security);
                return;
            }

            if (a.Type == pa.AssemblyCulture)
            {
                string value = a.GetString();
                if (value == null || value.Length == 0)
                {
                    return;
                }

                if (RootContext.Target == Target.Exe)
                {
                    a.Error_AttributeEmitError("The executables cannot be satelite assemblies, remove the attribute or keep it empty");
                    return;
                }
            }

            if (a.Type == pa.AssemblyVersion)
            {
                string value = a.GetString();
                if (value == null || value.Length == 0)
                {
                    return;
                }

                value = value.Replace('*', '0');

                if (!IsValidAssemblyVersion(value))
                {
                    a.Error_AttributeEmitError(string.Format("Specified version `{0}' is not valid", value));
                    return;
                }
            }

            if (a.Type == pa.InternalsVisibleTo && !CheckInternalsVisibleAttribute(a))
            {
                return;
            }

            if (a.Type == pa.TypeForwarder)
            {
                Type t = a.GetArgumentType();
                if (t == null || TypeManager.HasElementType(t))
                {
                    Report.Error(735, a.Location, "Invalid type specified as an argument for TypeForwardedTo attribute");
                    return;
                }

                t = TypeManager.DropGenericTypeArguments(t);
                if (emitted_forwarders == null)
                {
                    emitted_forwarders = new ListDictionary();
                }
                else if (emitted_forwarders.Contains(t))
                {
                    Report.SymbolRelatedToPreviousError(((Attribute)emitted_forwarders[t]).Location, null);
                    Report.Error(739, a.Location, "A duplicate type forward of type `{0}'",
                                 TypeManager.CSharpName(t));
                    return;
                }

                emitted_forwarders.Add(t, a);

                if (TypeManager.LookupDeclSpace(t) != null)
                {
                    Report.SymbolRelatedToPreviousError(t);
                    Report.Error(729, a.Location, "Cannot forward type `{0}' because it is defined in this assembly",
                                 TypeManager.CSharpName(t));
                    return;
                }

                if (t.DeclaringType != null)
                {
                    Report.Error(730, a.Location, "Cannot forward type `{0}' because it is a nested type",
                                 TypeManager.CSharpName(t));
                    return;
                }

                if (add_type_forwarder == null)
                {
                    add_type_forwarder = typeof(AssemblyBuilder).GetMethod("AddTypeForwarder",
                                                                           BindingFlags.NonPublic | BindingFlags.Instance);

                    if (add_type_forwarder == null)
                    {
                        Report.RuntimeMissingSupport(a.Location, "TypeForwardedTo attribute");
                        return;
                    }
                }

                add_type_forwarder.Invoke(Builder, new object[] { t });
                return;
            }

            if (a.Type == pa.Extension)
            {
                a.Error_MisusedExtensionAttribute();
                return;
            }

            Builder.SetCustomAttribute(cb);
        }