FieldAttr() 공개 정적인 메소드

public static FieldAttr ( Mono.CSharp.Modifiers mod_flags ) : FieldAttributes
mod_flags Mono.CSharp.Modifiers
리턴 FieldAttributes
예제 #1
0
파일: field.cs 프로젝트: Arsslensoft/VSharp
        public override bool Define()
        {
            if (!base.Define())
            {
                return(false);
            }
            // SYNC_MOD_CTRL
            if ((ModFlags & Modifiers.SYNC) == Modifiers.SYNC)
            {
                Report.Error(3661, Location, "A sync modifier cannot be used in field declaration. ");
            }

            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 f = new Field(Parent, d.GetFieldTypeExpression(this), 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);
        }
예제 #2
0
파일: field.cs 프로젝트: raj581/Marvin
        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)
            {
                ((TypeContainer)Parent).RegisterFieldForInitialization(this,
                                                                       new FieldInitializer(spec, initializer, this));
            }

            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 Field(Parent, t, ModFlags, new MemberName(d.Name.Value, d.Name.Location), OptAttributes);
                    if (d.Initializer != null)
                    {
                        f.initializer = d.Initializer;
                    }

                    Parent.PartialContainer.Fields.Insert(++index, f);
                }
            }

            return(true);
        }
예제 #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
            if ((ModFlags & Modifiers.BACKING_FIELD) == 0)
            {
                Parent.MemberCache.AddMember(spec);
            }

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

            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 Field(Parent, t, ModFlags, new MemberName(d.Name.Value, d.Name.Location), OptAttributes);
                    if (d.Initializer != null)
                    {
                        f.initializer = d.Initializer;
                    }

                    Parent.PartialContainer.Fields.Insert(++index, f);
                }
            }

/*
 *                      if ((ModFlags & (Modifiers.STATIC | Modifiers.READONLY | Modifiers.COMPILER_GENERATED)) == Modifiers.STATIC)
 *                              Console.WriteLine ("{0}: {1}", Location.ToString (), GetSignatureForError ());
 */
            return(true);
        }
예제 #4
0
        /// <summary>
        ///   Defines the constant in the @parent
        /// </summary>
        public override bool Define()
        {
            if (!base.Define())
            {
                return(false);
            }

            if (!member_type.IsConstantCompatible)
            {
                Error_InvalidConstantType(member_type, Location, Report);
            }

            FieldAttributes field_attr = FieldAttributes.Static | ModifiersExtensions.FieldAttr(ModFlags);

            // Decimals cannot be emitted into the constant blob.  So, convert to 'readonly'.
            if (member_type.BuiltinType == BuiltinTypeSpec.Type.Decimal)
            {
                field_attr |= FieldAttributes.InitOnly;
            }
            else
            {
                field_attr |= FieldAttributes.Literal;
            }

            FieldBuilder = Parent.TypeBuilder.DefineField(Name, MemberType.GetMetaInfo(), field_attr);
            spec         = new ConstSpec(Parent.Definition, this, MemberType, FieldBuilder, ModFlags, initializer);

            Parent.MemberCache.AddMember(spec);

            if ((field_attr & FieldAttributes.InitOnly) != 0)
            {
                Parent.PartialContainer.RegisterFieldForInitialization(this,
                                                                       new FieldInitializer(this, initializer, Location));
            }

            if (declarators != null)
            {
                foreach (var d in declarators)
                {
                    var t = new TypeExpression(d.Type, TypeExpression.Location);
                    var c = new Const(Parent, t, ModFlags & ~Modifiers.STATIC, new MemberName(d.Name.Value, d.Name.Location), OptAttributes);
                    c.initializer = d.Initializer;
                    if (d.Initializer is ConstInitializer)
                    {
                        ((ConstInitializer)d.Initializer).Field = c;
                    }
                    ((ConstInitializer)c.initializer).Name = d.Name.Value;
                    c.Define();
                    Parent.PartialContainer.Members.Add(c);
                }
            }

            return(true);
        }
예제 #5
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);
        }
예제 #6
0
            public FieldSpec DefineInitializedData(byte[] data, Location loc)
            {
                Struct size_type;

                if (!size_types.TryGetValue(data.Length, out size_type))
                {
                    //
                    // Build common type for this data length. We cannot use
                    // DefineInitializedData because it creates public type,
                    // and its name is not unique among modules
                    //
                    size_type = new Struct(this, new MemberName("$ArrayType=" + data.Length, loc), Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED, null);
                    size_type.CreateContainer();
                    size_type.DefineContainer();

                    size_types.Add(data.Length, size_type);

                    // It has to work even if StructLayoutAttribute does not exist
                    size_type.TypeBuilder.__SetLayout(1, data.Length);
                }

                var name = "$field-" + fields.ToString("X");

                ++fields;
                const Modifiers fmod     = Modifiers.STATIC | Modifiers.INTERNAL;
                var             fbuilder = TypeBuilder.DefineField(name, size_type.CurrentType.GetMetaInfo(), ModifiersExtensions.FieldAttr(fmod) | FieldAttributes.HasFieldRVA);

                fbuilder.__SetDataAndRVA(data);

                return(new FieldSpec(CurrentType, null, size_type.CurrentType, fbuilder, fmod));
            }
예제 #7
0
            public FieldSpec DefineInitializedData(byte[] data, Location loc)
            {
                Struct size_type;

                if (!size_types.TryGetValue(data.Length, out size_type))
                {
                    //
                    // Build common type for this data length. We cannot use
                    // DefineInitializedData because it creates public type,
                    // and its name is not unique among modules
                    //
                    size_type = new Struct(null, this, new MemberName("$ArrayType=" + data.Length, Location), Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED, null);
                    size_type.CreateType();
                    size_type.DefineType();

                    size_types.Add(data.Length, size_type);
                    var ctor = Module.PredefinedMembers.StructLayoutAttributeCtor.Resolve(Location);
                    if (ctor != null)
                    {
                        var argsEncoded = new AttributeEncoder();
                        argsEncoded.Encode((short)LayoutKind.Explicit);

                        var field_size = Module.PredefinedMembers.StructLayoutSize.Resolve(Location);
                        var pack       = Module.PredefinedMembers.StructLayoutPack.Resolve(Location);
                        if (field_size != null && pack != null)
                        {
                            argsEncoded.EncodeNamedArguments(
                                new[] { field_size, pack },
                                new[] { new IntConstant(Compiler.BuiltinTypes, (int)data.Length, Location), new IntConstant(Compiler.BuiltinTypes, 1, Location) }
                                );

                            size_type.TypeBuilder.SetCustomAttribute((ConstructorInfo)ctor.GetMetaInfo(), argsEncoded.ToArray());
                        }
                    }
                }

                var name = "$field-" + fields.ToString("X");

                ++fields;
                const Modifiers fmod     = Modifiers.STATIC | Modifiers.INTERNAL;
                var             fbuilder = TypeBuilder.DefineField(name, size_type.CurrentType.GetMetaInfo(), ModifiersExtensions.FieldAttr(fmod) | FieldAttributes.HasFieldRVA);

                fbuilder.__SetDataAndRVA(data);

                return(new FieldSpec(CurrentType, null, size_type.CurrentType, fbuilder, fmod));
            }
예제 #8
0
            public FieldSpec DefineInitializedData(byte[] data, Location loc)
            {
                Struct size_type;

                if (!size_types.TryGetValue(data.Length, out size_type))
                {
                    //
                    // Build common type for this data length. We cannot use
                    // DefineInitializedData because it creates public type,
                    // and its name is not unique among modules
                    //
                    size_type = new Struct(null, this, new MemberName("$ArrayType=" + data.Length, Location), Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED, null);
                    size_type.CreateType();
                    size_type.DefineType();

                    size_types.Add(data.Length, size_type);

                    var pa = Module.PredefinedAttributes.StructLayout;
                    if (pa.Constructor != null || pa.ResolveConstructor(Location, TypeManager.short_type))
                    {
                        var argsEncoded = new AttributeEncoder();
                        argsEncoded.Encode((short)LayoutKind.Explicit);

                        var field_size = pa.GetField("Size", TypeManager.int32_type, Location);
                        var pack       = pa.GetField("Pack", TypeManager.int32_type, Location);
                        if (field_size != null)
                        {
                            argsEncoded.EncodeNamedArguments(
                                new[] { field_size, pack },
                                new[] { new IntConstant((int)data.Length, Location), new IntConstant(1, Location) }
                                );
                        }

                        pa.EmitAttribute(size_type.TypeBuilder, argsEncoded);
                    }
                }

                var name = "$field-" + fields.ToString("X");

                ++fields;
                const Modifiers fmod     = Modifiers.STATIC | Modifiers.INTERNAL;
                var             fbuilder = TypeBuilder.DefineField(name, size_type.CurrentType.GetMetaInfo(), ModifiersExtensions.FieldAttr(fmod) | FieldAttributes.HasFieldRVA);

#if STATIC
                fbuilder.__SetDataAndRVA(data);
#else
                if (set_data == null)
                {
                    set_data = typeof(FieldBuilder).GetMethod("SetRVAData", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                }

                try
                {
                    set_data.Invoke(fbuilder, new object[] { data });
                }
                catch
                {
                    Report.RuntimeMissingSupport(loc, "SetRVAData");
                }
#endif

                return(new FieldSpec(CurrentType, null, size_type.CurrentType, fbuilder, fmod));
            }