gibaseinfo: Allow parent types to be specified for derived types

This doesn’t change the type hierarchy for now (i.e. it introduces no
functional changes), but it will allow us to add some intermediate types
into the `GIBaseInfo` hierarchy in an upcoming commit.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: #3216
This commit is contained in:
Philip Withnall 2024-01-17 14:32:23 +00:00
parent 71a19a6f65
commit 4d5b6599fc
2 changed files with 34 additions and 23 deletions

View File

@ -47,6 +47,7 @@ void gi_base_info_init_types (void);
GType gi_base_info_type_register_static (const char *type_name,
size_t instance_size,
GClassInitFunc class_init,
GType parent_type,
GTypeFlags type_flags);
G_END_DECLS

View File

@ -204,6 +204,8 @@ gi_base_info_get_type (void)
* @type_name: the name of the type
* @instance_size: size (in bytes) of the types instance struct
* @class_init: class init function for the type
* @parent_type: [type@GObject.Type] for the parent type; this will typically be
* `GI_TYPE_BASE_INFO`
* @type_flags: flags for the type
*
* Registers a new [type@GIRepository.BaseInfo] type for the given @type_name
@ -216,6 +218,7 @@ GType
gi_base_info_type_register_static (const char *type_name,
size_t instance_size,
GClassInitFunc class_init,
GType parent_type,
GTypeFlags type_flags)
{
GTypeInfo info;
@ -230,7 +233,7 @@ gi_base_info_type_register_static (const char *type_name,
info.instance_init = NULL;
info.value_table = NULL;
return g_type_register_static (GI_TYPE_BASE_INFO, type_name, &info, type_flags);
return g_type_register_static (parent_type, type_name, &info, type_flags);
}
static GType gi_base_info_types[GI_INFO_TYPE_N_TYPES];
@ -276,36 +279,43 @@ gi_base_info_init_types (void)
const char *type_name;
size_t instance_size;
GClassInitFunc class_init;
GIInfoType parent_info_type; /* 0 for GIBaseInfo */
GTypeFlags type_flags;
}
types[] =
{
{ GI_INFO_TYPE_CALLABLE, "GICallableInfo", sizeof (GICallableInfo), gi_callable_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_FUNCTION, "GIFunctionInfo", sizeof (GIFunctionInfo), gi_function_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_CALLBACK, "GICallbackInfo", sizeof (GICallbackInfo), gi_callback_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_REGISTERED_TYPE, "GIRegisteredTypeInfo", sizeof (GIRegisteredTypeInfo), gi_registered_type_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_STRUCT, "GIStructInfo", sizeof (GIStructInfo), gi_struct_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_UNION, "GIUnionInfo", sizeof (GIUnionInfo), gi_union_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_ENUM, "GIEnumInfo", sizeof (GIEnumInfo), gi_enum_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_OBJECT, "GIObjectInfo", sizeof (GIObjectInfo), gi_object_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_INTERFACE, "GIInterfaceInfo", sizeof (GIInterfaceInfo), gi_interface_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_CONSTANT, "GIConstantInfo", sizeof (GIConstantInfo), gi_constant_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_VALUE, "GIValueInfo", sizeof (GIValueInfo), gi_value_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_SIGNAL, "GISignalInfo", sizeof (GISignalInfo), gi_signal_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_VFUNC, "GIVFuncInfo", sizeof (GIVFuncInfo), gi_vfunc_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_PROPERTY, "GIPropertyInfo", sizeof (GIPropertyInfo), gi_property_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_FIELD, "GIFieldInfo", sizeof (GIFieldInfo), gi_field_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_ARG, "GIArgInfo", sizeof (GIArgInfo), gi_arg_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_TYPE, "GITypeInfo", sizeof (GITypeInfo), gi_type_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_UNRESOLVED, "GIUnresolvedInfo", sizeof (GIUnresolvedInfo), gi_unresolved_info_class_init, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_CALLABLE, "GICallableInfo", sizeof (GICallableInfo), gi_callable_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_FUNCTION, "GIFunctionInfo", sizeof (GIFunctionInfo), gi_function_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_CALLBACK, "GICallbackInfo", sizeof (GICallbackInfo), gi_callback_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_REGISTERED_TYPE, "GIRegisteredTypeInfo", sizeof (GIRegisteredTypeInfo), gi_registered_type_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_STRUCT, "GIStructInfo", sizeof (GIStructInfo), gi_struct_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_UNION, "GIUnionInfo", sizeof (GIUnionInfo), gi_union_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_ENUM, "GIEnumInfo", sizeof (GIEnumInfo), gi_enum_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_OBJECT, "GIObjectInfo", sizeof (GIObjectInfo), gi_object_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_INTERFACE, "GIInterfaceInfo", sizeof (GIInterfaceInfo), gi_interface_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_CONSTANT, "GIConstantInfo", sizeof (GIConstantInfo), gi_constant_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_VALUE, "GIValueInfo", sizeof (GIValueInfo), gi_value_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_SIGNAL, "GISignalInfo", sizeof (GISignalInfo), gi_signal_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_VFUNC, "GIVFuncInfo", sizeof (GIVFuncInfo), gi_vfunc_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_PROPERTY, "GIPropertyInfo", sizeof (GIPropertyInfo), gi_property_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_FIELD, "GIFieldInfo", sizeof (GIFieldInfo), gi_field_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_ARG, "GIArgInfo", sizeof (GIArgInfo), gi_arg_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_TYPE, "GITypeInfo", sizeof (GITypeInfo), gi_type_info_class_init, 0, G_TYPE_FLAG_NONE },
{ GI_INFO_TYPE_UNRESOLVED, "GIUnresolvedInfo", sizeof (GIUnresolvedInfo), gi_unresolved_info_class_init, 0, G_TYPE_FLAG_NONE },
};
for (size_t i = 0; i < G_N_ELEMENTS (types); i++)
{
GType registered_type = gi_base_info_type_register_static (g_intern_static_string (types[i].type_name),
types[i].instance_size,
types[i].class_init,
types[i].type_flags);
GType registered_type, parent_type;
parent_type = (types[i].parent_info_type == 0) ? GI_TYPE_BASE_INFO : gi_base_info_types[types[i].parent_info_type];
g_assert (parent_type != G_TYPE_INVALID);
registered_type = gi_base_info_type_register_static (g_intern_static_string (types[i].type_name),
types[i].instance_size,
types[i].class_init,
parent_type,
types[i].type_flags);
gi_base_info_types[types[i].info_type] = registered_type;
}