Tue May 13 16:41:49 CEST 2003 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / metadata / class.h
index 4f6af697d8b103cb189af91c47a2eb44e3a6d0ea..47180f38be6846c0434c77d5bb7afeb9b15b4cb5 100644 (file)
@@ -7,16 +7,31 @@
 
 #define MONO_CLASS_IS_ARRAY(c) ((c)->rank)
 
+#define MONO_DEFAULT_SUPERTABLE_SIZE 6
+
 extern gboolean mono_print_vtable;
+typedef struct MonoVTable MonoVTable;
 
 typedef struct {
-       MonoType *type;
-       int       offset;
-       const char     *name;
-       const char     *data;
-       /* add marshal data, too */
+       MonoType        *type;
+       int              offset;
+       const char      *name;
+       const char      *data;
+       MonoClass       *parent;
 } MonoClassField;
 
+typedef struct {
+       MonoClassField *field;
+       guint32 offset;
+       MonoMarshalSpec *mspec;
+} MonoMarshalField;
+
+typedef struct {
+       guint32 native_size;
+       guint32 num_fields;
+       MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
+} MonoMarshalType;
+
 typedef struct {
        const char *name;
        MonoMethod *get;
@@ -35,11 +50,23 @@ typedef struct {
 
 struct _MonoClass {
        MonoImage *image;
-       guint32    type_token;
 
-       guint dummy           : 1; /* temorary hack */
-       guint inited          : 1;
+       /*
+        * relative numbering for fast type checking
+        */
+       unsigned int baseval;
+       unsigned int diffval;
+
+       /* The underlying type of the enum */
+       MonoType *enum_basetype;
+       /* element class for arrays and enum */
+       MonoClass *element_class; 
+       /* used for subtype checks */
+       MonoClass *cast_class; 
+       /* array dimension */
+       guint32    rank;          
 
+       guint inited          : 1;
        /* We use init_pending to detect cyclic calls to mono_class_init */
        guint init_pending    : 1;
 
@@ -54,17 +81,27 @@ struct _MonoClass {
        guint size_inited     : 1;
        guint valuetype       : 1; /* derives from System.ValueType */
        guint enumtype        : 1; /* derives from System.Enum */
+       guint blittable       : 1; /* class is blittable */
+       guint unicode         : 1; /* class uses unicode char when marshalled */
+       guint wastypebuilder  : 1; /* class was created at runtime from a TypeBuilder */
+       /* next byte */
+       guint min_align       : 4;
+       guint packing_size    : 4;
+       /* next byte */
        guint ghcimpl         : 1; /* class has its own GetHashCode impl */ 
+       guint has_finalize    : 1; /* class has its own Finalize impl */ 
        guint marshalbyref    : 1; /* class is a MarshalByRefObject */
        guint contextbound    : 1; /* class is a ContextBoundObject */
        guint delegate        : 1; /* class is a Delegate */
-       guint min_align       : 4;
+       guint gc_descr_inited : 1; /* gc_descr is initialized */
+       guint dummy           : 1; /* temporary hack */
 
        MonoClass  *parent;
        MonoClass  *nested_in;
        GList      *nested_classes;
        GList      *subclasses; /* list of all subclasses */
 
+       guint32    type_token;
        const char *name;
        const char *name_space;
        
@@ -74,6 +111,10 @@ struct _MonoClass {
         gint       *interface_offsets;   
        MonoClass **interfaces;
 
+       /* for fast subtype checks */
+       guint       idepth;
+       MonoClass **supertypes;
+
        /*
         * Computed object instance size, total.
         */
@@ -81,12 +122,6 @@ struct _MonoClass {
        int        class_size;
        int        vtable_size; /* number of slots */
 
-       /*
-        * relative numbering for fast type checking
-        */
-       unsigned int baseval;
-       unsigned int diffval;
-
        /*
         * From the TypeDef table
         */
@@ -96,6 +131,9 @@ struct _MonoClass {
                int count;
        } field, method, property, event;
 
+       /* loaded on demand */
+       MonoMarshalType *marshal_info;
+
        /*
         * Field information: Type and location from object base
         */
@@ -107,58 +145,97 @@ struct _MonoClass {
 
        MonoMethod **methods;
 
-       /* The underlying type of the enum */
-       MonoType *enum_basetype;
-       /* element class for arrays and enum */
-       MonoClass *element_class; 
-       /* array dimension */
-       guint32    rank;          
-
        /* used as the type of the this argument and when passing the arg by value */
        MonoType this_arg;
        MonoType byval_arg;
 
        void *reflection_info;
 
+       void *gc_descr;
+       guint64 gc_bitmap;
+
+       MonoMethod *ptr_to_str;
+       MonoMethod *str_to_ptr;
+
+       MonoVTable *cached_vtable;
         MonoMethod **vtable;   
 };
 
-typedef struct {
+struct MonoVTable {
        MonoClass  *klass;
+    /*
+        * According to comments in gc_gcj.h, this should be the second word in
+        * the vtable.
+        */
+       void *gc_descr;         
        MonoDomain *domain;  /* each object/vtable belongs to exactly one domain */
        guint       max_interface_id;
         gpointer   *interface_offsets;   
-        gpointer    data;
-        gpointer    vtable [0];        
-} MonoVTable;
+        gpointer    data; /* to store static class data */
+       guint remote          : 1; /* class is remotely activated */
+       /* do not add any fields after vtable, the structure is dynamically extended */
+        gpointer    vtable [MONO_ZERO_LEN_ARRAY];      
+};
+
+typedef struct {
+       gulong new_object_count;
+       gulong initialized_class_count;
+       gulong used_class_count;
+       gulong class_vtable_size;
+       gulong class_static_data_size;
+} MonoStats;
 
+extern MonoStats mono_stats;
 
 typedef gpointer (*MonoTrampoline)       (MonoMethod *method);
 
+typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token);
+
 MonoClass *
 mono_class_get             (MonoImage *image, guint32 type_token);
 
 void
 mono_class_init            (MonoClass *klass);
 
+void
+mono_class_layout_fields   (MonoClass *klass);
+
+void
+mono_class_setup_vtable    (MonoClass *klass, MonoMethod **overrides, int onum);
+
 MonoVTable *
-mono_class_vtable          (MonoDomain *domain, MonoClass *class);
+mono_class_vtable          (MonoDomain *domain, MonoClass *klass);
 
 MonoVTable *
-mono_class_proxy_vtable    (MonoDomain *domain, MonoClass *class);
+mono_class_proxy_vtable    (MonoDomain *domain, MonoClass *klass);
+
+void
+mono_class_setup_mono_type (MonoClass *klass);
 
 void
-mono_class_setup_mono_type (MonoClass *class);
+mono_class_setup_parent    (MonoClass *klass, MonoClass *parent);
 
 void
-mono_class_setup_parent    (MonoClass *class, MonoClass *parent);
+mono_class_setup_supertypes (MonoClass *klass);
 
 MonoClass *
 mono_class_from_name       (MonoImage *image, const char* name_space, const char *name);
 
+MonoClass *
+mono_class_from_name_case  (MonoImage *image, const char* name_space, const char *name);
+
+MonoClass * 
+mono_class_from_typeref    (MonoImage *image, guint32 type_token);
+
 MonoClassField*
 mono_field_from_memberref  (MonoImage *image, guint32 token, MonoClass **retklass);
 
+MonoClassField*
+mono_field_from_token      (MonoImage *image, guint32 token, MonoClass **retklass);
+
+MonoMethod**
+mono_class_get_overrides   (MonoImage *image, guint32 type_token, gint32 *num_overrides);
+
 MonoClass *
 mono_array_class_get       (MonoType *element_type, guint32 rank);
 
@@ -171,6 +248,9 @@ mono_class_get_field       (MonoClass *klass, guint32 field_token);
 MonoClassField *
 mono_class_get_field_from_name (MonoClass *klass, const char *name);
 
+MonoProperty*
+mono_class_get_property_from_name (MonoClass *klass, const char *name);
+
 gint32
 mono_array_element_size    (MonoClass *ac);
 
@@ -178,14 +258,30 @@ gint32
 mono_class_instance_size   (MonoClass *klass);
 
 gint32
-mono_class_value_size      (MonoClass *klass, guint32 *align);
+mono_class_array_element_size (MonoClass *klass);
 
 gint32
 mono_class_data_size       (MonoClass *klass);
 
+gint32
+mono_class_value_size      (MonoClass *klass, guint32 *align);
+
+gint32
+mono_class_native_size     (MonoClass *klass, guint32 *align);
+
+MonoMarshalType *
+mono_marshal_load_type_info (MonoClass* klass);
+
+gint32
+mono_class_min_align       (MonoClass *klass);
+
 MonoClass *
 mono_class_from_mono_type  (MonoType *type);
 
+gboolean
+mono_class_is_subclass_of (MonoClass *klass, MonoClass *klassc, 
+                                                  gboolean check_interfaces);
+
 gpointer
 mono_ldtoken               (MonoImage *image, guint32 token, MonoClass **retclass);
 
@@ -195,4 +291,13 @@ mono_install_trampoline (MonoTrampoline func);
 void
 mono_install_remoting_trampoline (MonoTrampoline func);
 
+gpointer
+mono_lookup_dynamic_token (MonoImage *image, guint32 token);
+
+void
+mono_install_lookup_dynamic_token (MonoLookupDynamicToken func);
+
+void    
+mono_install_get_config_dir(void);
+
 #endif /* _MONO_CLI_CLASS_H_ */