type: add functions to determine what kind of type a type is
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <mie/dialect/dialect.h>
|
||||
#include <mie/type/function.h>
|
||||
#include <mie/type/storage.h>
|
||||
#include <mie/type/type-definition.h>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user