示例#1
0
			public void AddAttributeSection(AstNode parent, Attributable a)
			{
				if (a == null || a.OptAttributes == null)
					return;
				AddAttributeSection(parent, a.OptAttributes);
			}
示例#2
0
		public void AttachTo (Attributable attributable)
		{
			foreach (Attribute a in Attrs)
				a.AttachTo (attributable);
		}
示例#3
0
		public virtual void AttachTo (Attributable owner)
		{
			if (this.owners == null) {
				this.owners = new Attributable[1] { owner };
				return;
			}

			// When the same attribute is attached to multiple fiels
			// we use this extra_owners as a list of owners. The attribute
			// then can be removed because will be emitted when first owner
			// is served
			Attributable[] new_array = new Attributable [this.owners.Length + 1];
			owners.CopyTo (new_array, 0);
			new_array [owners.Length] = owner;
			this.owners = new_array;
			owner.OptAttributes = null;
		}
示例#4
0
		//
		// Theoretically, we can get rid of this, since FieldBuilder.SetCustomAttribute()
		// and ParameterBuilder.SetCustomAttribute() are supposed to handle this attribute.
		// However, we can't, since it appears that the .NET 1.1 SRE hangs when given a MarshalAsAttribute.
		//
#if !NET_2_0
		public UnmanagedMarshal GetMarshal (Attributable attr)
		{
			UnmanagedType UnmanagedType;
			if (!RootContext.StdLib || pos_values [0].GetType () != typeof (UnmanagedType))
				UnmanagedType = (UnmanagedType) System.Enum.ToObject (typeof (UnmanagedType), pos_values [0]);
			else
				UnmanagedType = (UnmanagedType) pos_values [0];

			object value = GetFieldValue ("SizeParamIndex");
			if (value != null && UnmanagedType != UnmanagedType.LPArray) {
				Error_AttributeEmitError ("SizeParamIndex field is not valid for the specified unmanaged type");
				return null;
			}

			object o = GetFieldValue ("ArraySubType");
			UnmanagedType array_sub_type = o == null ? (UnmanagedType) 0x50 /* NATIVE_MAX */ : (UnmanagedType) o;

			switch (UnmanagedType) {
			case UnmanagedType.CustomMarshaler: {
				MethodInfo define_custom = typeof (UnmanagedMarshal).GetMethod ("DefineCustom",
					BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if (define_custom == null) {
					Report.RuntimeMissingSupport (Location, "set marshal info");
					return null;
				}
				
				object [] args = new object [4];
				args [0] = GetFieldValue ("MarshalTypeRef");
				args [1] = GetFieldValue ("MarshalCookie");
				args [2] = GetFieldValue ("MarshalType");
				args [3] = Guid.Empty;
				return (UnmanagedMarshal) define_custom.Invoke (null, args);
			}
			case UnmanagedType.LPArray: {
				object size_const = GetFieldValue ("SizeConst");
				object size_param_index = GetFieldValue ("SizeParamIndex");

				if ((size_const != null) || (size_param_index != null)) {
					MethodInfo define_array = typeof (UnmanagedMarshal).GetMethod ("DefineLPArrayInternal",
						BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (define_array == null) {
						Report.RuntimeMissingSupport (Location, "set marshal info");
						return null;
					}
				
					object [] args = new object [3];
					args [0] = array_sub_type;
					args [1] = size_const == null ? -1 : size_const;
					args [2] = size_param_index == null ? -1 : size_param_index;
					return (UnmanagedMarshal) define_array.Invoke (null, args);
				}
				else
					return UnmanagedMarshal.DefineLPArray (array_sub_type);
			}
			case UnmanagedType.SafeArray:
				return UnmanagedMarshal.DefineSafeArray (array_sub_type);

			case UnmanagedType.ByValArray:
				FieldBase fm = attr as FieldBase;
				if (fm == null) {
					Error_AttributeEmitError ("Specified unmanaged type is only valid on fields");
					return null;
				}
				return UnmanagedMarshal.DefineByValArray ((int) GetFieldValue ("SizeConst"));

			case UnmanagedType.ByValTStr:
				return UnmanagedMarshal.DefineByValTStr ((int) GetFieldValue ("SizeConst"));

			default:
				return UnmanagedMarshal.DefineUnmanagedMarshal (UnmanagedType);
			}
		}
示例#5
0
		public override void AttachTo (Attributable owner)
		{
			if (ExplicitTarget == "assembly") {
				owners [0] = CodeGen.Assembly;
				return;
			}
			if (ExplicitTarget == "module") {
				owners [0] = CodeGen.Module;
				return;
			}
			throw new NotImplementedException ("Unknown global explicit target " + ExplicitTarget);
		}
示例#6
0
		//
		// When the same attribute is attached to multiple fiels
		// we use @target field as a list of targets. The attribute
		// has to be resolved only once but emitted for each target.
		//
		public virtual void AttachTo (Attributable target, IMemberContext context)
		{
			if (this.targets == null) {
				this.targets = new Attributable[] { target };
				this.context = context;
				return;
			}

			// Resize target array
			Attributable[] new_array = new Attributable [this.targets.Length + 1];
			targets.CopyTo (new_array, 0);
			new_array [targets.Length] = target;
			this.targets = new_array;

			// No need to update context, different targets cannot have
			// different contexts, it's enough to remove same attributes
			// from secondary members.

			target.OptAttributes = null;
		}
示例#7
0
		public void AttachTo (Attributable attributable, IMemberContext context)
		{
			foreach (Attribute a in Attrs)
				a.AttachTo (attributable, context);
		}
示例#8
0
		public override void AttachTo (Attributable target, IMemberContext context)
		{
			if (ExplicitTarget == "assembly") {
				base.AttachTo (CodeGen.Assembly, context);
				return;
			}

			if (ExplicitTarget == "module") {
				base.AttachTo (RootContext.ToplevelTypes, context);
				return;
			}

			throw new NotImplementedException ("Unknown global explicit target " + ExplicitTarget);
		}
			public void AddAttributeSection (AstNode parent, Attributable a)
			{
				if (a.OptAttributes == null)
					return;
				foreach (var attr in a.OptAttributes.Sections) {
					parent.AddChild (ConvertAttributeSection (attr), AttributedNode.AttributeRole);
				}
			}
示例#10
0
			public void AddAttributeSection (AttributedNode parent, Attributable a)
			{
				if (a.OptAttributes != null && a.OptAttributes.Attrs != null) 
					parent.AddChild (ConvertAttributeSection (a.OptAttributes), AttributedNode.AttributeRole);
			}