schema CHANGE refactor lys_module structure
- share some of the data between parsed (lysp_module) and compiled
(lysc_module) structures. It should optimize processing and make usage
more simple
- separate lysp_submodule - so far the submodules were same as parsed
modules (using a bit to differentiate). Since the lys_module structure
was optimized more for use with the data (so more focused on the
compiled schema), the lysp_module is now more interconnected with the
lys_module structure, but this cannot be done in submodules. Therefore,
the lysp_submodule was created sharing most of the members with
lysp_module (to unify parsing process) but adding some other members
which are placed into lys_module in case of lysp_module structure.
- except of the moving some of the members of lysp_module/lysc_module
into lys_module structure, the change does not affect the compiled
structures.
diff --git a/src/context.c b/src/context.c
index 66b62e5..59fa438 100644
--- a/src/context.c
+++ b/src/context.c
@@ -208,7 +208,7 @@
for (i = 0; i < ((options & LY_CTX_NOYANGLIBRARY) ? (LY_INTERNAL_MODS_COUNT - 2) : LY_INTERNAL_MODS_COUNT); i++) {
module = (struct lys_module *)lys_parse_mem(ctx, internal_modules[i].data, internal_modules[i].format);
LY_CHECK_ERR_GOTO(!module, rc = ly_errcode(ctx), error);
- module->parsed->implemented = internal_modules[i].implemented;
+ module->implemented = internal_modules[i].implemented;
}
*new_ctx = ctx;
@@ -282,8 +282,7 @@
*
* @param[in] ctx Context where to iterate.
* @param[in] key Key value to search for.
- * @param[in] key_offset Key's offset in struct lysp_module and struct lysc_module to get value from the context's
- * modules to match with the key.
+ * @param[in] key_offset Key's offset in struct lys_module to get value from the context's modules to match with the key.
* @param[in,out] Iterator to pass between the function calls. On the first call, the variable is supposed to be
* initiated to 0. After each call returning a module, the value is greater by 1 than the index of the returned
* module in the context.
@@ -297,11 +296,7 @@
for (; *index < ctx->list.count; ++(*index)) {
mod = ctx->list.objs[*index];
- if (mod->compiled) {
- value = *(const char**)(((int8_t*)(mod->compiled)) + key_offset);
- } else {
- value = *(const char**)(((int8_t*)(mod->parsed)) + key_offset);
- }
+ value = *(const char**)(((int8_t*)(mod)) + key_offset);
if (!strcmp(key, value)) {
/* increment index for the next run */
++(*index);
@@ -316,7 +311,7 @@
* @brief Unifying function for ly_ctx_get_module() and ly_ctx_get_module_ns()
* @param[in] ctx Context where to search.
* @param[in] key Name or Namespace as a search key.
- * @param[in] key_offset Key's offset in struct lysp_module to get value from the context's modules to match with the key.
+ * @param[in] key_offset Key's offset in struct lys_module to get value from the context's modules to match with the key.
* @param[in] revision Revision date to match. If NULL, the matching module must have no revision. To search for the latest
* revision module, use ly_ctx_get_module_latest_by().
* @return Matching module if any.
@@ -349,21 +344,21 @@
ly_ctx_get_module_ns(const struct ly_ctx *ctx, const char *ns, const char *revision)
{
LY_CHECK_ARG_RET(ctx, ctx, ns, NULL);
- return ly_ctx_get_module_by(ctx, ns, offsetof(struct lysp_module, ns), revision);
+ return ly_ctx_get_module_by(ctx, ns, offsetof(struct lys_module, ns), revision);
}
API const struct lys_module *
ly_ctx_get_module(const struct ly_ctx *ctx, const char *name, const char *revision)
{
LY_CHECK_ARG_RET(ctx, ctx, name, NULL);
- return ly_ctx_get_module_by(ctx, name, offsetof(struct lysp_module, name), revision);
+ return ly_ctx_get_module_by(ctx, name, offsetof(struct lys_module, name), revision);
}
/**
* @brief Unifying function for ly_ctx_get_module_latest() and ly_ctx_get_module_latest_ns()
* @param[in] ctx Context where to search.
* @param[in] key Name or Namespace as a search key.
- * @param[in] key_offset Key's offset in struct lysp_module to get value from the context's modules to match with the key.
+ * @param[in] key_offset Key's offset in struct lys_module to get value from the context's modules to match with the key.
* @return Matching module if any.
*/
static const struct lys_module *
@@ -373,7 +368,7 @@
unsigned int index = 0;
while ((mod = ly_ctx_get_module_by_iter(ctx, key, key_offset, &index))) {
- if ((mod->compiled && mod->compiled->latest_revision) || (!mod->compiled && mod->parsed->latest_revision)) {
+ if (mod->latest_revision) {
return mod;
}
}
@@ -385,21 +380,21 @@
ly_ctx_get_module_latest(const struct ly_ctx *ctx, const char *name)
{
LY_CHECK_ARG_RET(ctx, ctx, name, NULL);
- return ly_ctx_get_module_latest_by(ctx, name, offsetof(struct lysp_module, name));
+ return ly_ctx_get_module_latest_by(ctx, name, offsetof(struct lys_module, name));
}
const struct lys_module *
ly_ctx_get_module_latest_ns(const struct ly_ctx *ctx, const char *ns)
{
LY_CHECK_ARG_RET(ctx, ctx, ns, NULL);
- return ly_ctx_get_module_latest_by(ctx, ns, offsetof(struct lysp_module, ns));
+ return ly_ctx_get_module_latest_by(ctx, ns, offsetof(struct lys_module, ns));
}
/**
* @brief Unifying function for ly_ctx_get_module_implemented() and ly_ctx_get_module_implemented_ns()
* @param[in] ctx Context where to search.
* @param[in] key Name or Namespace as a search key.
- * @param[in] key_offset Key's offset in struct lysp_module to get value from the context's modules to match with the key.
+ * @param[in] key_offset Key's offset in struct lys_module to get value from the context's modules to match with the key.
* @return Matching module if any.
*/
static const struct lys_module *
@@ -409,7 +404,7 @@
unsigned int index = 0;
while ((mod = ly_ctx_get_module_by_iter(ctx, key, key_offset, &index))) {
- if ((mod->compiled && mod->compiled->implemented) || (!mod->compiled && mod->parsed->implemented)) {
+ if (mod->implemented) {
return mod;
}
}
@@ -421,17 +416,17 @@
ly_ctx_get_module_implemented(const struct ly_ctx *ctx, const char *name)
{
LY_CHECK_ARG_RET(ctx, ctx, name, NULL);
- return ly_ctx_get_module_implemented_by(ctx, name, offsetof(struct lysp_module, name));
+ return ly_ctx_get_module_implemented_by(ctx, name, offsetof(struct lys_module, name));
}
API const struct lys_module *
ly_ctx_get_module_implemented_ns(const struct ly_ctx *ctx, const char *ns)
{
LY_CHECK_ARG_RET(ctx, ctx, ns, NULL);
- return ly_ctx_get_module_implemented_by(ctx, ns, offsetof(struct lysp_module, ns));
+ return ly_ctx_get_module_implemented_by(ctx, ns, offsetof(struct lys_module, ns));
}
-struct lysp_module *
+struct lysp_submodule *
ly_ctx_get_submodule(const struct ly_ctx *ctx, const char *module, const char *submodule, const char *revision)
{
const struct lys_module *mod;
@@ -445,7 +440,7 @@
if (!mod->parsed) {
continue;
}
- if (module && strcmp(module, mod->parsed->name)) {
+ if (module && strcmp(module, mod->name)) {
continue;
}
@@ -474,18 +469,13 @@
for (u = 0; u < ctx->list.count; ++u) {
mod = ctx->list.objs[u];
- if (mod->compiled && mod->compiled->latest_revision == 2) {
- mod->compiled->latest_revision = 1;
+ if (mod->latest_revision == 2) {
+ mod->latest_revision = 1;
}
- if (mod->parsed) {
- if (mod->parsed->latest_revision == 2) {
- mod->parsed->latest_revision = 1;
- }
- if (mod->parsed->includes) {
- for (v = 0; v < LY_ARRAY_SIZE(mod->parsed->includes); ++v) {
- if (mod->parsed->includes[v].submodule->latest_revision == 2) {
- mod->parsed->includes[v].submodule->latest_revision = 1;
- }
+ if (mod->parsed && mod->parsed->includes) {
+ for (v = 0; v < LY_ARRAY_SIZE(mod->parsed->includes); ++v) {
+ if (mod->parsed->includes[v].submodule->latest_revision == 2) {
+ mod->parsed->includes[v].submodule->latest_revision = 1;
}
}
}