示例#1
0
        public FixedFieldSpec(ModuleContainer module, TypeSpec declaringType, IMemberDefinition definition, FieldInfo info, FieldSpec element, Modifiers modifiers)
            : base(declaringType, definition, PointerContainer.MakeType(module, element.MemberType), info, modifiers)
        {
            this.element = element;

            // It's never CLS-Compliant
            state &= ~StateFlags.CLSCompliant_Undetected;
        }
        public void Emit(OpCode opcode, FieldSpec field)
        {
            if (IsAnonymousStoreyMutateRequired)
            {
                field = field.Mutate(CurrentAnonymousMethod.Storey.Mutator);
            }

            ig.Emit(opcode, field.GetMetaInfo());
        }
示例#3
0
        public override bool Define()
        {
            if (!base.Define())
            {
                return(false);
            }

            MetaType[] required_modifier = null;
            if ((ModFlags & Modifiers.VOLATILE) != 0)
            {
                var mod = Module.PredefinedTypes.IsVolatile.Resolve();
                if (mod != null)
                {
                    required_modifier = new MetaType[] { mod.GetMetaInfo() }
                }
                ;
            }

            FieldBuilder = Parent.TypeBuilder.DefineField(
                Name, member_type.GetMetaInfo(), required_modifier, null, ModifiersExtensions.FieldAttr(ModFlags));

            spec = new FieldSpec(Parent.Definition, this, MemberType, FieldBuilder, ModFlags);

            //
            // Don't cache inaccessible fields except for struct where we
            // need them for definitive assignment checks
            //
            if ((ModFlags & Modifiers.BACKING_FIELD) == 0 || Parent.Kind == MemberKind.Struct)
            {
                Parent.MemberCache.AddMember(spec);
            }

            if (initializer != null)
            {
                Parent.RegisterFieldForInitialization(this, new FieldInitializer(this, initializer, TypeExpression.Location));
            }

            if (declarators != null)
            {
                foreach (var d in declarators)
                {
                    var t = new TypeExpression(MemberType, d.Name.Location);
                    var f = new Field(Parent, t, ModFlags, new MemberName(d.Name.Value, d.Name.Location), OptAttributes);
                    if (d.Initializer != null)
                    {
                        f.initializer = d.Initializer;
                    }

                    f.Define();
                    Parent.PartialContainer.Members.Add(f);
                }
            }

            return(true);
        }
示例#4
0
        public override bool Define()
        {
            if (!base.Define())
            {
                return(false);
            }

            if (!BuiltinTypeSpec.IsPrimitiveType(MemberType))
            {
                Report.Error(1663, Location,
                             "`{0}': Fixed size buffers type must be one of the following: bool, byte, short, int, long, char, sbyte, ushort, uint, ulong, float or double",
                             GetSignatureForError());
            }
            else if (declarators != null)
            {
                var t = new TypeExpression(MemberType, TypeExpression.Location);
                foreach (var d in declarators)
                {
                    var f = new FixedField(Parent, t, ModFlags, new MemberName(d.Name.Value, d.Name.Location), OptAttributes);
                    f.initializer = d.Initializer;
                    ((ConstInitializer)f.initializer).Name = d.Name.Value;
                    f.Define();
                    Parent.PartialContainer.Members.Add(f);
                }
            }

            // Create nested fixed buffer container
            string name = String.Format("<{0}>__FixedBuffer{1}", Name, GlobalCounter++);

            fixed_buffer_type = Parent.TypeBuilder.DefineNestedType(name,
                                                                    TypeAttributes.NestedPublic | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit,
                                                                    Compiler.BuiltinTypes.ValueType.GetMetaInfo());

            var ffield = fixed_buffer_type.DefineField(FixedElementName, MemberType.GetMetaInfo(), FieldAttributes.Public);

            FieldBuilder = Parent.TypeBuilder.DefineField(Name, fixed_buffer_type, ModifiersExtensions.FieldAttr(ModFlags));

            var element_spec = new FieldSpec(null, this, MemberType, ffield, ModFlags);

            spec = new FixedFieldSpec(Module, Parent.Definition, this, FieldBuilder, element_spec, ModFlags);

            Parent.MemberCache.AddMember(spec);
            return(true);
        }
示例#5
0
		public override bool Define ()
		{
			if (!base.Define ())
				return false;

			MetaType[] required_modifier = null;
			if ((ModFlags & Modifiers.VOLATILE) != 0) {
				var mod = Module.PredefinedTypes.IsVolatile.Resolve ();
				if (mod != null)
					required_modifier = new MetaType[] { mod.GetMetaInfo () };
			}

			FieldBuilder = Parent.TypeBuilder.DefineField (
				Name, member_type.GetMetaInfo (), required_modifier, null, ModifiersExtensions.FieldAttr (ModFlags));

			spec = new FieldSpec (Parent.Definition, this, MemberType, FieldBuilder, ModFlags);

			//
			// Don't cache inaccessible fields except for struct where we
			// need them for definitive assignment checks
			//
			if ((ModFlags & Modifiers.BACKING_FIELD) == 0 || Parent.Kind == MemberKind.Struct) {
				Parent.MemberCache.AddMember (spec);
			}

			if (initializer != null) {
				Parent.RegisterFieldForInitialization (this, new FieldInitializer (this, initializer, TypeExpression.Location));
			}

			if (declarators != null) {
				foreach (var d in declarators) {
					var t = new TypeExpression (MemberType, d.Name.Location);
					var f = new Field (Parent, t, ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
					if (d.Initializer != null)
						f.initializer = d.Initializer;

					f.Define ();
					Parent.PartialContainer.Members.Add (f);
				}
			}

			return true;
		}
示例#6
0
		public FixedFieldSpec (TypeSpec declaringType, IMemberDefinition definition, FieldInfo info, FieldSpec element, Modifiers modifiers)
			: base (declaringType, definition, element.MemberType, info, modifiers)
		{
			this.element = element;

			// It's never CLS-Compliant
			state &= ~StateFlags.CLSCompliant_Undetected;
		}
示例#7
0
		public override bool Define ()
		{
			if (!base.Define ())
				return false;

			if (!BuiltinTypeSpec.IsPrimitiveType (MemberType)) {
				Report.Error (1663, Location,
					"`{0}': Fixed size buffers type must be one of the following: bool, byte, short, int, long, char, sbyte, ushort, uint, ulong, float or double",
					GetSignatureForError ());
			} else if (declarators != null) {
				var t = new TypeExpression (MemberType, TypeExpression.Location);
				foreach (var d in declarators) {
					var f = new FixedField (Parent, t, ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
					f.initializer = d.Initializer;
					((ConstInitializer) f.initializer).Name = d.Name.Value;
					f.Define ();
					Parent.PartialContainer.Members.Add (f);
				}
			}
			
			// Create nested fixed buffer container
			string name = String.Format ("<{0}>__FixedBuffer{1}", Name, GlobalCounter++);
			fixed_buffer_type = Parent.TypeBuilder.DefineNestedType (name,
				TypeAttributes.NestedPublic | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit,
				Compiler.BuiltinTypes.ValueType.GetMetaInfo ());

			var ffield = fixed_buffer_type.DefineField (FixedElementName, MemberType.GetMetaInfo (), FieldAttributes.Public);
			
			FieldBuilder = Parent.TypeBuilder.DefineField (Name, fixed_buffer_type, ModifiersExtensions.FieldAttr (ModFlags));

			var element_spec = new FieldSpec (null, this, MemberType, ffield, ModFlags);
			spec = new FixedFieldSpec (Parent.Definition, this, FieldBuilder, element_spec, ModFlags);

			Parent.MemberCache.AddMember (spec);
			return true;
		}
		public void Emit (OpCode opcode, FieldSpec field)
		{
			if (IsAnonymousStoreyMutateRequired)
				field = field.Mutate (CurrentAnonymousMethod.Storey.Mutator);

			ig.Emit (opcode, field.GetMetaInfo ());
		}