diff --git a/mie/include/mie/type/function.h b/mie/include/mie/type/function.h index cf0b91b..f4bdf6d 100644 --- a/mie/include/mie/type/function.h +++ b/mie/include/mie/type/function.h @@ -23,4 +23,6 @@ MIE_API void mie_function_type_build_id( size_t nr_in_types, const struct mie_type **out_types, size_t nr_out_types); +MIE_API bool mie_type_is_function(const struct mie_type *ty); + #endif diff --git a/mie/include/mie/type/storage.h b/mie/include/mie/type/storage.h index db29e3b..7b43945 100644 --- a/mie/include/mie/type/storage.h +++ b/mie/include/mie/type/storage.h @@ -14,9 +14,12 @@ struct mie_storage_type { MIE_API struct mie_storage_type *mie_storage_type_create(void); MIE_API void mie_storage_type_add_part( struct mie_storage_type *ty, const struct mie_type *part); +MIE_API size_t mie_storage_type_get_nr_parts(const struct mie_storage_type *ty); MIE_API void mie_storage_type_build_id( struct mie_id_builder *builder, const struct mie_type **parts, size_t nr_parts); +MIE_API bool mie_type_is_storage(const struct mie_type *ty); + #endif diff --git a/mie/include/mie/type/type.h b/mie/include/mie/type/type.h index 2c1d0f8..adaa078 100644 --- a/mie/include/mie/type/type.h +++ b/mie/include/mie/type/type.h @@ -47,4 +47,7 @@ MIE_API void mie_type_build_id( MIE_API void mie_type_generate_id( const struct mie_type *type, const mie_id *ns, mie_id *out); +MIE_API bool mie_type_is( + const struct mie_type *ty, const char *dialect_name, const char *type_name); + #endif diff --git a/mie/type/function.c b/mie/type/function.c index 781ddb2..6c169a9 100644 --- a/mie/type/function.c +++ b/mie/type/function.c @@ -4,6 +4,8 @@ #include #include +#define FUNCTION_TYPE_NAME "*function" + static void build_id(const struct mie_type *type, struct mie_id_builder *ctx) { const struct mie_function_type *function @@ -51,7 +53,7 @@ static enum mie_status type_print( } static struct mie_type_definition function_type = { - .ty_name = "*function", + .ty_name = FUNCTION_TYPE_NAME, .ty_data_size = sizeof(struct mie_type), .ty_build_id = build_id, .ty_print = type_print, @@ -104,3 +106,15 @@ void mie_function_type_build_id( } mie_id_builder_add_marker(ctx, MIE_ID_BUILDER_FUNCTION_OUT_END); } + +bool mie_type_is_function(const struct mie_type *ty) +{ + const struct mie_type_definition *ty_def = ty->ty_def; + + if (!ty_def) { + return false; + } + + return (!ty_def->ty_parent) + && !strcmp(ty_def->ty_name, FUNCTION_TYPE_NAME); +} diff --git a/mie/type/storage.c b/mie/type/storage.c index 205f686..82352eb 100644 --- a/mie/type/storage.c +++ b/mie/type/storage.c @@ -4,6 +4,8 @@ #include #include +#define STORAGE_TYPE_NAME "*storage" + static void build_id(const struct mie_type *type, struct mie_id_builder *ctx) { const struct mie_storage_type *storage @@ -33,7 +35,7 @@ static enum mie_status type_print( } static struct mie_type_definition storage_type = { - .ty_name = "*storage", + .ty_name = STORAGE_TYPE_NAME, .ty_data_size = sizeof(struct mie_type), .ty_build_id = build_id, .ty_print = type_print, @@ -59,6 +61,11 @@ void mie_storage_type_add_part( mie_vector_push_back(ty->st_parts, &part, NULL); } +size_t mie_storage_type_get_nr_parts(const struct mie_storage_type *ty) +{ + return MIE_VECTOR_COUNT(ty->st_parts); +} + void mie_storage_type_build_id( struct mie_id_builder *ctx, const struct mie_type **parts, size_t nr_parts) { @@ -68,3 +75,14 @@ void mie_storage_type_build_id( } mie_id_builder_add_marker(ctx, MIE_ID_BUILDER_STORAGE_END); } + +bool mie_type_is_storage(const struct mie_type *ty) +{ + const struct mie_type_definition *ty_def = ty->ty_def; + + if (!ty_def) { + return false; + } + + return (!ty_def->ty_parent) && !strcmp(ty_def->ty_name, STORAGE_TYPE_NAME); +} diff --git a/mie/type/type.c b/mie/type/type.c index abb6a11..d07de72 100644 --- a/mie/type/type.c +++ b/mie/type/type.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -44,3 +45,25 @@ void mie_type_generate_id(const struct mie_type *type, const mie_id *ns, mie_id mie_type_build_id(type, &ctx); mie_id_builder_end(&ctx, out); } + +bool mie_type_is( + const struct mie_type *ty, const char *dialect_name, const char *type_name) +{ + if (!ty->ty_def) { + return false; + } + + if (strcmp(ty->ty_def->ty_name, type_name) != 0) { + return false; + } + + if (!ty->ty_def->ty_parent) { + return false; + } + + if (strcmp(ty->ty_def->ty_parent->d_name, dialect_name) != 0) { + return false; + } + + return true; +}