static int GetInfo(out MonoEnumInfo info)
 {
     info = new MonoEnumInfo();
     info.stuff();
     return(info.val);
 }
示例#2
0
        static unsafe void get_enum_info(TysosType enumType, out MonoEnumInfo info)
        {
            MonoEnumInfo ret = new MonoEnumInfo();

            ret.utype = GetUnderlyingEnumType(enumType);

            if (!ret.utype.Equals(typeof(int)))
            {
                throw new Exception("get_enum_info: currently only enums with an underlying type of int are supported");
            }

            var ets = enumType.tspec;

            /* Iterate through methods looking for requested
             *    one */
            var first_fdef = ets.m.GetIntEntry(metadata.MetadataStream.tid_TypeDef,
                                               ets.tdrow, 4);
            var last_fdef = ets.m.GetLastFieldDef(ets.tdrow);

            // First iterate to get number of satic fields
            int static_fields = 0;

            for (uint fdef_row = first_fdef; fdef_row < last_fdef; fdef_row++)
            {
                var flags = ets.m.GetIntEntry(metadata.MetadataStream.tid_Field,
                                              (int)fdef_row, 0);
                if ((flags & 0x10) == 0x10)
                {
                    static_fields++;
                }
            }

            ret.names = new string[static_fields];
            int[] values = new int[static_fields];

            System.Diagnostics.Debugger.Log(0, "libsupcs", "Enum.get_enum_info: found " + static_fields.ToString() + " entries");

            static_fields = 0;
            // Iterate again to get the details
            for (uint fdef_row = first_fdef; fdef_row < last_fdef; fdef_row++)
            {
                var flags = ets.m.GetIntEntry(metadata.MetadataStream.tid_Field,
                                              (int)fdef_row, 0);
                if ((flags & 0x10) == 0x10)
                {
                    var name = ets.m.GetStringEntry(metadata.MetadataStream.tid_Field,
                                                    (int)fdef_row, 1);
                    ret.names[static_fields] = name;

                    System.Diagnostics.Debugger.Log(0, "libsupcs", "Enum.get_enum_info: field: " + name);

                    var const_row = ets.m.const_field_owners[fdef_row];
                    if (const_row != 0)
                    {
                        var const_offset = (int)ets.m.GetIntEntry(metadata.MetadataStream.tid_Constant,
                                                                  const_row, 2);

                        ets.m.SigReadUSCompressed(ref const_offset);
                        var const_val = ets.m.sh_blob.di.ReadInt(const_offset);
                        values[static_fields] = const_val;

                        System.Diagnostics.Debugger.Log(0, "libsupcs", "Enum.get_enum_info: value: " + const_val.ToString());
                    }

                    static_fields++;
                }
            }

            ret.values = values;
            info       = ret;
        }
        static int GetInfo (out MonoEnumInfo info) {
		info = new MonoEnumInfo ();
                info.stuff();
                return info.val;
        }
示例#4
0
        void get_fields()
        {
            if (fields != null)
                return;

            foreach (Cecil.CustomAttribute cattr in type.CustomAttributes) {
                if (cattr.Constructor.DeclaringType.FullName == "System.FlagsAttribute") {
                    is_flags = true;
                    break;
                }
            }

            int num_fields = 0, num_sfields = 0;

            foreach (Cecil.FieldDefinition field in type.Fields) {
                if (field.IsStatic)
                    num_sfields++;
                else
                    num_fields++;
            }

            fields = new MonoEnumInfo [num_fields];
            static_fields = new MonoEnumInfo [num_sfields];

            int pos = 0, spos = 0, i = 0;
            foreach (Cecil.FieldDefinition field in type.Fields) {
                TargetType ftype = File.MonoLanguage.LookupMonoType (field.FieldType);
                if (field.IsStatic) {
                    static_fields [spos] = new MonoEnumInfo (
                        this, ftype, spos, i, field);
                    spos++;
                } else {
                    if (field.Name != "value__")
                        throw new InternalError ("Mono enum type has instance field with name other than 'value__'.");
                    fields [pos] = new MonoEnumInfo (this, ftype, pos, i, field);
                    pos++;
                }

                i++;
            }
            if (pos > 1)
                throw new InternalError ("Mono enum type has more than one instance field.");
        }