const Vector<GDMonoField *> &GDMonoClass::get_all_fields() { if (fields_fetched) return fields_list; void *iter = NULL; MonoClassField *raw_field = NULL; while ((raw_field = mono_class_get_fields(mono_class, &iter)) != NULL) { StringName name = mono_field_get_name(raw_field); Map<StringName, GDMonoField *>::Element *match = fields.find(name); if (match) { fields_list.push_back(match->get()); } else { GDMonoField *field = memnew(GDMonoField(raw_field, this)); fields.insert(name, field); fields_list.push_back(field); } } fields_fetched = true; return fields_list; }
MonoClassField *CScriptClass::GetMonoField(const char *name) { MonoClass *pClass = (MonoClass *)m_pObject; MonoClassField *pCurField = nullptr; void *pIterator = 0; while (pClass != nullptr) { pCurField = mono_class_get_fields(pClass, &pIterator); if(pCurField == nullptr) { pClass = mono_class_get_parent(pClass); if(pClass == mono_get_object_class()) break; pIterator = 0; continue; } if(!strcmp(mono_field_get_name(pCurField), name)) return pCurField; } return nullptr; }
void mioClass::eachFields(const std::function<void(mioField&)> &f) { MonoClassField *field; gpointer iter = nullptr; while ((field = mono_class_get_fields(mclass, &iter))) { mioField mf = field; f(mf); } }
static void handle_type (MonoClass *klass, guint32 flags) { int i; guint32 missing; MonoCustomAttrInfo* cattrs; gpointer val = NULL, oldkey = NULL; MonoProperty* prop; MonoEvent* event; MonoMethod* method; MonoClassField* field; gpointer iter; if (g_hash_table_lookup_extended (type_table, klass, &oldkey, &val)) { missing = flags & ~(GPOINTER_TO_UINT (val)); } else { missing = flags; } if (!missing) return; g_hash_table_insert (type_table, klass, GUINT_TO_POINTER (missing)); if (verbose) g_print ("#processing klass: %s.%s\n", klass->name_space, klass->name); mono_class_init (klass); if (klass->parent) add_type (klass->parent); if (klass->nested_in) add_type (klass->nested_in); iter = NULL; while ((method = mono_class_get_methods (klass, &iter))) { if ((missing & TYPE_METHODS) || strcmp (method->name, ".cctor") == 0) add_types_from_method (method); } if (klass->enumtype) { add_field (mono_class_get_field_from_name (klass, "value__")); } if (force_enums || (missing & TYPE_FIELDS)) { iter = NULL; while ((field = mono_class_get_fields (klass, &iter))) add_field (field); } iter = NULL; while ((prop = mono_class_get_properties (klass, &iter))) { cattrs = mono_custom_attrs_from_property (klass, prop); handle_cattrs (cattrs); } iter = NULL; while ((event = mono_class_get_events (klass, &iter))) { cattrs = mono_custom_attrs_from_event (klass, event); handle_cattrs (cattrs); } for (i = 0; i < klass->interface_count; ++i) add_type (klass->interfaces [i]); cattrs = mono_custom_attrs_from_class (klass); handle_cattrs (cattrs); }
void mioClass::eachFieldsUpwards(const std::function<void(mioField&, mioClass&)> &f) { mioClass c = mclass; do { MonoClassField *field; gpointer iter = nullptr; while (field = mono_class_get_fields(c, &iter)) { mioField m = field; f(m, c); } c = c.getParent(); } while (c); }
Vector<MonoClassField *> GDMonoClass::get_enum_fields() { bool class_is_enum = mono_class_is_enum(mono_class); ERR_FAIL_COND_V(!class_is_enum, Vector<MonoClassField *>()); Vector<MonoClassField *> enum_fields; void *iter = NULL; MonoClassField *raw_field = NULL; while ((raw_field = mono_class_get_fields(get_mono_ptr(), &iter)) != NULL) { uint32_t field_flags = mono_field_get_flags(raw_field); // Enums have an instance field named value__ which holds the value of the enum. // Enum constants are static, so we will use this to ignore the value__ field. if (field_flags & MONO_FIELD_ATTR_PUBLIC && field_flags & MONO_FIELD_ATTR_STATIC) { enum_fields.push_back(raw_field); } } return enum_fields; }
void CPipeServer::EnumFieldsInClass() { void *c=(void *)ReadQword(); void *iter=NULL; void *field; do { field=mono_class_get_fields(c, &iter); WriteQword((UINT_PTR)field); if (field) { char *name; void *fieldtype=mono_field_get_type(field); WriteQword((UINT_PTR)fieldtype); WriteDword(mono_type_get_type(fieldtype)); WriteQword((UINT_PTR)mono_field_get_parent(field)); WriteDword((UINT_PTR)mono_field_get_offset(field)); WriteDword(mono_field_get_flags(field)); name=mono_field_get_name(field); WriteWord(strlen(name)); Write(name, strlen(name)); name=mono_type_get_name(fieldtype); if (name) { WriteWord(strlen(name)); Write(name, strlen(name)); g_free(name); } else WriteWord(0); } } while (field); }
static int memory_usage (MonoObject *obj, GHashTable *visited) { int total = 0; MonoClass *klass; MonoType *type; gpointer iter = NULL; MonoClassField *field; if (g_hash_table_lookup (visited, obj)) return 0; g_hash_table_insert (visited, obj, obj); klass = mono_object_get_class (obj); type = mono_class_get_type (klass); /* This is an array, so drill down into it */ if (type->type == MONO_TYPE_SZARRAY) total += memory_usage_array ((MonoArray *) obj, visited); while ((field = mono_class_get_fields (klass, &iter)) != NULL) { MonoType *ftype = mono_field_get_type (field); gpointer value; if ((ftype->attrs & (FIELD_ATTRIBUTE_STATIC | FIELD_ATTRIBUTE_HAS_FIELD_RVA)) != 0) continue; /* FIXME: There are probably other types we need to drill down into */ switch (ftype->type) { case MONO_TYPE_CLASS: case MONO_TYPE_OBJECT: mono_field_get_value (obj, field, &value); if (value != NULL) total += memory_usage ((MonoObject *) value, visited); break; case MONO_TYPE_STRING: mono_field_get_value (obj, field, &value); if (value != NULL) total += mono_object_get_size ((MonoObject *) value); break; case MONO_TYPE_SZARRAY: mono_field_get_value (obj, field, &value); if (value != NULL) { total += memory_usage_array ((MonoArray *) value, visited); total += mono_object_get_size ((MonoObject *) value); } break; default: /* printf ("Got type 0x%x\n", ftype->type); */ /* ignore, this will be included in mono_object_get_size () */ break; } } total += mono_object_get_size (obj); return total; }