Beispiel #1
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);
                int index = Parent.PartialContainer.Fields.IndexOf(this);
                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;
                    Parent.PartialContainer.Fields.Insert(++index, 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);
        }
Beispiel #2
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);
				int index = Parent.PartialContainer.Fields.IndexOf (this);
				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;
					Parent.PartialContainer.Fields.Insert (++index, 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;
		}
Beispiel #3
0
        public override bool Define()
        {
            if (!base.Define ())
                return false;

            if (!TypeManager.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 ());
            }

            // Create nested fixed buffer container
            string name = String.Format ("<{0}>__FixedBuffer{1}", Name, GlobalCounter++);
            fixed_buffer_type = Parent.TypeBuilder.DefineNestedType (name, Parent.Module.DefaultCharSetType |
                TypeAttributes.NestedPublic | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit, TypeManager.value_type.GetMetaInfo ());

            fixed_buffer_type.DefineField (FixedElementName, MemberType.GetMetaInfo (), FieldAttributes.Public);
            RootContext.RegisterCompilerGeneratedType (fixed_buffer_type);

            FieldBuilder = Parent.TypeBuilder.DefineField (Name, fixed_buffer_type, ModifiersExtensions.FieldAttr (ModFlags));
            var element_spec = new FieldSpec (null, this, MemberType, FieldBuilder, ModFlags);
            spec = new FixedFieldSpec (Parent.Definition, this, FieldBuilder, element_spec, ModFlags);

            Parent.MemberCache.AddMember (spec);
            return true;
        }