mie: add strict-naming support to mie_name_map
in strict mode, the hint is taken as the required name. if a value already exists with the given name, the operation fails.
This commit is contained in:
@@ -84,7 +84,7 @@ struct mie_value *mie_func_generate_value_name(
|
||||
struct mie_func *func, struct mie_value *val, const char *hint)
|
||||
{
|
||||
struct mie_name *name
|
||||
= mie_name_map_put(func->f_names, &val->v_name, hint);
|
||||
= mie_name_map_put(func->f_names, &val->v_name, hint, 0);
|
||||
return b_unbox(struct mie_value, name, v_name);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
#include <blue/core/btree.h>
|
||||
#include <blue/core/queue.h>
|
||||
|
||||
enum mie_name_map_flags {
|
||||
MIE_NAME_MAP_STRICT = 0x01u,
|
||||
};
|
||||
|
||||
enum mie_name_map_entry_type {
|
||||
MIE_NAME_MAP_E_NONE = 0,
|
||||
MIE_NAME_MAP_E_NAME,
|
||||
@@ -38,6 +42,7 @@ extern struct mie_name_map *mie_name_map_create(void);
|
||||
extern void mie_name_map_destroy(struct mie_name_map *map);
|
||||
|
||||
extern struct mie_name *mie_name_map_put(
|
||||
struct mie_name_map *map, struct mie_name *entry, const char *hint);
|
||||
struct mie_name_map *map, struct mie_name *entry, const char *hint,
|
||||
enum mie_name_map_flags flags);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -106,7 +106,8 @@ enum b_status mie_module_put_data(
|
||||
struct mie_value *mie_module_generate_value_name(
|
||||
struct mie_module *mod, struct mie_value *val, const char *hint)
|
||||
{
|
||||
struct mie_name *name = mie_name_map_put(mod->m_names, &val->v_name, hint);
|
||||
struct mie_name *name
|
||||
= mie_name_map_put(mod->m_names, &val->v_name, hint, 0);
|
||||
return b_unbox(struct mie_value, name, v_name);
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,8 @@ static b_status put_name(struct mie_name_map *map, struct mie_name *name)
|
||||
}
|
||||
|
||||
struct mie_name *mie_name_map_put(
|
||||
struct mie_name_map *map, struct mie_name *entry, const char *hint)
|
||||
struct mie_name_map *map, struct mie_name *entry, const char *hint,
|
||||
enum mie_name_map_flags flags)
|
||||
{
|
||||
memset(entry, 0x0, sizeof *entry);
|
||||
entry->n_base.e_type = MIE_NAME_MAP_E_NAME;
|
||||
@@ -149,6 +150,12 @@ struct mie_name *mie_name_map_put(
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & MIE_NAME_MAP_STRICT) {
|
||||
/* the caller insists that `hint` be used as the name.
|
||||
* such a name already exists, so we can't help them */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* that name already exists, use a suffix to make the name unique.
|
||||
* alternately, no hint was specified, so it's up to us to generate the name */
|
||||
b_rope dot = B_ROPE_CHAR('.');
|
||||
|
||||
Reference in New Issue
Block a user