core: type: check if a class tries to implement an interface it doesn't extend or inherit
This commit is contained in:
15
core/error.c
15
core/error.c
@@ -719,10 +719,25 @@ static const struct b_error_definition builtin_errors[] = {
|
|||||||
"Class initialisation failure"),
|
"Class initialisation failure"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct b_error_msg builtin_msg[] = {
|
||||||
|
B_ERROR_MSG(B_MSG_TYPE_REGISTRATION_FAILURE, "Type registration failed"),
|
||||||
|
B_ERROR_MSG(B_MSG_CLASS_INIT_FAILURE, "Class initialisation failed"),
|
||||||
|
B_ERROR_MSG_TEMPLATE(
|
||||||
|
B_MSG_CLASS_SPECIFIES_UNKNOWN_INTERFACE,
|
||||||
|
"Class @[class_name] specifies an implementation for interface "
|
||||||
|
"@[interface_name] that it does not extend or inherit",
|
||||||
|
B_ERROR_TEMPLATE_PARAM(
|
||||||
|
"class_name", B_ERROR_TEMPLATE_PARAM_STRING, "%s"),
|
||||||
|
B_ERROR_TEMPLATE_PARAM(
|
||||||
|
"interface_name", B_ERROR_TEMPLATE_PARAM_STRING, "%s")),
|
||||||
|
};
|
||||||
|
|
||||||
static const struct b_error_vendor builtin_vendor = {
|
static const struct b_error_vendor builtin_vendor = {
|
||||||
.v_name = "Blue",
|
.v_name = "Blue",
|
||||||
.v_error_definitions = builtin_errors,
|
.v_error_definitions = builtin_errors,
|
||||||
.v_error_definitions_length = sizeof builtin_errors,
|
.v_error_definitions_length = sizeof builtin_errors,
|
||||||
|
.v_msg = builtin_msg,
|
||||||
|
.v_msg_length = sizeof builtin_msg,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void get_error_id(
|
static void get_error_id(
|
||||||
|
|||||||
@@ -20,7 +20,14 @@
|
|||||||
#define B_TYPE_CLASS_INTERFACE_BEGIN(interface_name, interface_id) \
|
#define B_TYPE_CLASS_INTERFACE_BEGIN(interface_name, interface_id) \
|
||||||
interface_name##_class *__B_IFACE_I1(iface, __LINE__) \
|
interface_name##_class *__B_IFACE_I1(iface, __LINE__) \
|
||||||
= b_class_get_interface(p, interface_id); \
|
= b_class_get_interface(p, interface_id); \
|
||||||
if (__B_IFACE_I1(iface, __LINE__)) { \
|
if (!__B_IFACE_I1(iface, __LINE__)) { \
|
||||||
|
b_throw_error_with_msg_template( \
|
||||||
|
B_ERRORS_BUILTIN, B_ERR_CLASS_INIT_FAILURE, \
|
||||||
|
B_MSG_CLASS_SPECIFIES_UNKNOWN_INTERFACE, \
|
||||||
|
B_ERROR_PARAM("class_name", b_class_get_name(p)), \
|
||||||
|
B_ERROR_PARAM("interface_name", #interface_name)); \
|
||||||
|
exit(-1); \
|
||||||
|
} else { \
|
||||||
interface_name##_class *iface = __B_IFACE_I1(iface, __LINE__);
|
interface_name##_class *iface = __B_IFACE_I1(iface, __LINE__);
|
||||||
#define B_TYPE_CLASS_INTERFACE_END(interface_name, interface_id) }
|
#define B_TYPE_CLASS_INTERFACE_END(interface_name, interface_id) }
|
||||||
#define B_INTERFACE_ENTRY(slot) iface->slot
|
#define B_INTERFACE_ENTRY(slot) iface->slot
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ typedef enum b_status_msg {
|
|||||||
/* blue-object specific messages */
|
/* blue-object specific messages */
|
||||||
B_MSG_TYPE_REGISTRATION_FAILURE,
|
B_MSG_TYPE_REGISTRATION_FAILURE,
|
||||||
B_MSG_CLASS_INIT_FAILURE,
|
B_MSG_CLASS_INIT_FAILURE,
|
||||||
|
B_MSG_CLASS_SPECIFIES_UNKNOWN_INTERFACE,
|
||||||
} b_status_msg;
|
} b_status_msg;
|
||||||
|
|
||||||
BLUE_API const char *b_status_to_string(b_status status);
|
BLUE_API const char *b_status_to_string(b_status status);
|
||||||
|
|||||||
Reference in New Issue
Block a user