RzType add new APIs
- rz_base_type_clone_into - rz_base_type_clone
This commit is contained in:
parent
067c32ad18
commit
ec2cff8451
2 changed files with 52 additions and 1 deletions
|
|
@ -253,7 +253,10 @@ RZ_API void rz_type_db_reload(RzTypeDB *typedb, const char *dir_prefix);
|
|||
RZ_API void rz_type_db_purge(RzTypeDB *typedb);
|
||||
|
||||
// Base types
|
||||
|
||||
RZ_API bool rz_base_type_clone_into(
|
||||
RZ_NONNULL RZ_BORROW RZ_OUT RzBaseType *dst,
|
||||
RZ_NONNULL RZ_BORROW RZ_IN RzBaseType *src);
|
||||
RZ_API RZ_OWN RzBaseType *rz_base_type_clone(RZ_NULLABLE RZ_BORROW RzBaseType *b);
|
||||
RZ_API void rz_type_base_type_free(RzBaseType *type);
|
||||
RZ_API RZ_OWN RzBaseType *rz_type_base_type_new(RzBaseTypeKind kind);
|
||||
RZ_API RZ_BORROW const char *rz_type_base_type_kind_as_string(RzBaseTypeKind kind);
|
||||
|
|
|
|||
|
|
@ -124,6 +124,54 @@ RZ_API RZ_OWN RzList /*<RzBaseType *>*/ *rz_type_db_get_base_types(const RzTypeD
|
|||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Copy RzBaseType \p src into another RzBaseType \p dst
|
||||
* \param dst the destination RzBaseType
|
||||
* \param src the source RzBaseType
|
||||
* \return true if the copy was successful, false otherwise
|
||||
*/
|
||||
RZ_API bool rz_base_type_clone_into(
|
||||
RZ_NONNULL RZ_BORROW RZ_OUT RzBaseType *dst,
|
||||
RZ_NONNULL RZ_BORROW RZ_IN RzBaseType *src) {
|
||||
rz_return_val_if_fail(src && dst, false);
|
||||
rz_mem_copy(dst, sizeof(RzBaseType), src, sizeof(RzBaseType));
|
||||
dst->name = rz_str_new(src->name);
|
||||
dst->type = src->type ? rz_type_clone(src->type) : NULL;
|
||||
|
||||
switch (src->kind) {
|
||||
case RZ_BASE_TYPE_KIND_ENUM:
|
||||
rz_vector_clone_into(&dst->enum_data.cases, &src->enum_data.cases);
|
||||
break;
|
||||
case RZ_BASE_TYPE_KIND_STRUCT:
|
||||
rz_vector_clone_into(&dst->struct_data.members, &src->struct_data.members);
|
||||
break;
|
||||
case RZ_BASE_TYPE_KIND_UNION:
|
||||
rz_vector_clone_into(&dst->union_data.members, &src->union_data.members);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Copy the RzBaseType \p b and all its members
|
||||
* \param b the RzBaseType to copy
|
||||
* \return a copy of \p b
|
||||
*/
|
||||
RZ_API RZ_OWN RzBaseType *rz_base_type_clone(RZ_NULLABLE RZ_BORROW RzBaseType *b) {
|
||||
if (!b) {
|
||||
return NULL;
|
||||
}
|
||||
RzBaseType *type = RZ_NEW0(RzBaseType);
|
||||
if (!type) {
|
||||
return NULL;
|
||||
}
|
||||
if (!rz_base_type_clone_into(type, b)) {
|
||||
return NULL;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Frees the RzBaseType instance and all of its members
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue