hide ec_node structure
authorOlivier Matz <zer0@droids-corp.org>
Wed, 9 Oct 2019 18:45:02 +0000 (20:45 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Wed, 9 Oct 2019 18:45:02 +0000 (20:45 +0200)
24 files changed:
include/ecoli_node.h
src/ecoli_node.c
src/ecoli_node_any.c
src/ecoli_node_bypass.c
src/ecoli_node_cmd.c
src/ecoli_node_cond.c
src/ecoli_node_dynamic.c
src/ecoli_node_empty.c
src/ecoli_node_expr.c
src/ecoli_node_file.c
src/ecoli_node_int.c
src/ecoli_node_many.c
src/ecoli_node_none.c
src/ecoli_node_once.c
src/ecoli_node_option.c
src/ecoli_node_or.c
src/ecoli_node_re.c
src/ecoli_node_re_lex.c
src/ecoli_node_seq.c
src/ecoli_node_sh_lex.c
src/ecoli_node_space.c
src/ecoli_node_str.c
src/ecoli_node_subset.c
src/ecoli_parse.c

index 894e64f..38e25e4 100644 (file)
@@ -158,20 +158,6 @@ enum ec_node_free_state {
        EC_NODE_FREE_STATE_FREEING,
 };
 
-struct ec_node {
-       const struct ec_node_type *type;
-       struct ec_config *config;    /**< Generic configuration. */
-       char *id;
-       char *desc;
-       struct ec_dict *attrs;
-       unsigned int refcnt;
-       struct {
-               enum ec_node_free_state state; /**< State of loop detection */
-               unsigned int refcnt;    /**< Number of reachable references
-                                        *   starting from node beeing freed */
-       } free; /**< Freeing state: used for loop detection */
-};
-
 /* create a new node when the type is known, typically called from the node
  * code */
 struct ec_node *ec_node_from_type(const struct ec_node_type *type, const char *id);
@@ -209,6 +195,18 @@ struct ec_node *ec_node_find(struct ec_node *node, const char *id);
 int ec_node_check_type(const struct ec_node *node,
                const struct ec_node_type *type);
 
+const char *ec_node_get_type_name(const struct ec_node *node);
+
+/**
+ * Get the pointer to the node private area.
+ *
+ * @param node
+ *   The grammar node.
+ * @return
+ *   The pointer to the node private area.
+ */
+void *ec_node_priv(const struct ec_node *node);
+
 #endif
 
  /** @} */
index 07ef9e5..935f4e6 100644 (file)
 
 EC_LOG_TYPE_REGISTER(node);
 
+struct ec_node {
+       const struct ec_node_type *type;
+       struct ec_config *config;    /**< Generic configuration. */
+       char *id;
+       char *desc;
+       struct ec_dict *attrs;
+       unsigned int refcnt;
+       struct {
+               enum ec_node_free_state state; /**< State of loop detection */
+               unsigned int refcnt;    /**< Number of reachable references
+                                        *   starting from node beeing freed */
+       } free; /**< Freeing state: used for loop detection */
+};
+
 static struct ec_node_type_list node_type_list =
        TAILQ_HEAD_INITIALIZER(node_type_list);
 
@@ -44,8 +58,6 @@ ec_node_type_lookup(const char *name)
 
 int ec_node_type_register(struct ec_node_type *type)
 {
-       EC_CHECK_ARG(type->size >= sizeof(struct ec_node), -1, EINVAL);
-
        if (ec_node_type_lookup(type->name) != NULL) {
                errno = EEXIST;
                return -1;
@@ -75,7 +87,7 @@ struct ec_node *ec_node_from_type(const struct ec_node_type *type, const char *i
                goto fail;
        }
 
-       node = ec_calloc(1, type->size);
+       node = ec_calloc(1, sizeof(*node) + type->size);
        if (node == NULL)
                goto fail;
 
@@ -428,6 +440,18 @@ int ec_node_check_type(const struct ec_node *node,
        return 0;
 }
 
+const char *ec_node_get_type_name(const struct ec_node *node)
+{
+       return node->type->name;
+}
+
+void *ec_node_priv(const struct ec_node *node)
+{
+       if (node == NULL)
+               return NULL;
+       return (void *)(node + 1);
+}
+
 /* LCOV_EXCL_START */
 static int ec_node_testcase(void)
 {
index 88ac542..8efbec4 100644 (file)
 EC_LOG_TYPE_REGISTER(node_any);
 
 struct ec_node_any {
-       struct ec_node gen;
        char *attr_name;
 };
 
-static int ec_node_any_parse(const struct ec_node *gen_node,
+static int ec_node_any_parse(const struct ec_node *node,
                        struct ec_parse *state,
                        const struct ec_strvec *strvec)
 {
-       struct ec_node_any *node = (struct ec_node_any *)gen_node;
+       struct ec_node_any *priv = ec_node_priv(node);
        const struct ec_dict *attrs;
 
        (void)state;
 
        if (ec_strvec_len(strvec) == 0)
                return EC_PARSE_NOMATCH;
-       if (node->attr_name != NULL) {
+       if (priv->attr_name != NULL) {
                attrs = ec_strvec_get_attrs(strvec, 0);
-               if (attrs == NULL || !ec_dict_has_key(attrs, node->attr_name))
+               if (attrs == NULL || !ec_dict_has_key(attrs, priv->attr_name))
                        return EC_PARSE_NOMATCH;
        }
 
        return 1;
 }
 
-static void ec_node_any_free_priv(struct ec_node *gen_node)
+static void ec_node_any_free_priv(struct ec_node *node)
 {
-       struct ec_node_any *node = (struct ec_node_any *)gen_node;
+       struct ec_node_any *priv = ec_node_priv(node);
 
-       ec_free(node->attr_name);
+       ec_free(priv->attr_name);
 }
 
 static const struct ec_config_schema ec_node_any_schema[] = {
@@ -63,10 +62,10 @@ static const struct ec_config_schema ec_node_any_schema[] = {
        },
 };
 
-static int ec_node_any_set_config(struct ec_node *gen_node,
+static int ec_node_any_set_config(struct ec_node *node,
                                const struct ec_config *config)
 {
-       struct ec_node_any *node = (struct ec_node_any *)gen_node;
+       struct ec_node_any *priv = ec_node_priv(node);
        const struct ec_config *value = NULL;
        char *s = NULL;
 
@@ -77,8 +76,8 @@ static int ec_node_any_set_config(struct ec_node *gen_node,
                        goto fail;
        }
 
-       ec_free(node->attr_name);
-       node->attr_name = s;
+       ec_free(priv->attr_name);
+       priv->attr_name = s;
 
        return 0;
 
@@ -103,11 +102,11 @@ struct ec_node *
 ec_node_any(const char *id, const char *attr)
 {
        struct ec_config *config = NULL;
-       struct ec_node *gen_node = NULL;
+       struct ec_node *node = NULL;
        int ret;
 
-       gen_node = ec_node_from_type(&ec_node_any_type, id);
-       if (gen_node == NULL)
+       node = ec_node_from_type(&ec_node_any_type, id);
+       if (node == NULL)
                return NULL;
 
        config = ec_config_dict();
@@ -118,16 +117,16 @@ ec_node_any(const char *id, const char *attr)
        if (ret < 0)
                goto fail;
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL;
        if (ret < 0)
                goto fail;
 
-       return gen_node;
+       return node;
 
 fail:
        ec_config_free(config);
-       ec_node_free(gen_node);
+       ec_node_free(node);
        return NULL;
 }
 
index ba9b89c..de70450 100644 (file)
 EC_LOG_TYPE_REGISTER(node_bypass);
 
 struct ec_node_bypass {
-       struct ec_node gen;
        struct ec_node *child;
 };
 
 static int
-ec_node_bypass_parse(const struct ec_node *gen_node,
+ec_node_bypass_parse(const struct ec_node *node,
                struct ec_parse *state,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_bypass *node = (struct ec_node_bypass *)gen_node;
+       struct ec_node_bypass *priv = ec_node_priv(node);
 
-       return ec_node_parse_child(node->child, state, strvec);
+       return ec_node_parse_child(priv->child, state, strvec);
 }
 
 static int
-ec_node_bypass_complete(const struct ec_node *gen_node,
+ec_node_bypass_complete(const struct ec_node *node,
                        struct ec_comp *comp,
                        const struct ec_strvec *strvec)
 {
-       struct ec_node_bypass *node = (struct ec_node_bypass *)gen_node;
+       struct ec_node_bypass *priv = ec_node_priv(node);
 
-       return ec_node_complete_child(node->child, comp, strvec);
+       return ec_node_complete_child(priv->child, comp, strvec);
 }
 
-static void ec_node_bypass_free_priv(struct ec_node *gen_node)
+static void ec_node_bypass_free_priv(struct ec_node *node)
 {
-       struct ec_node_bypass *node = (struct ec_node_bypass *)gen_node;
+       struct ec_node_bypass *priv = ec_node_priv(node);
 
-       ec_node_free(node->child);
+       ec_node_free(priv->child);
 }
 
 static size_t
-ec_node_bypass_get_children_count(const struct ec_node *gen_node)
+ec_node_bypass_get_children_count(const struct ec_node *node)
 {
-       struct ec_node_bypass *node = (struct ec_node_bypass *)gen_node;
+       struct ec_node_bypass *priv = ec_node_priv(node);
 
-       if (node->child)
+       if (priv->child)
                return 1;
        return 0;
 }
 
 static int
-ec_node_bypass_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_bypass_get_child(const struct ec_node *node, size_t i,
        struct ec_node **child, unsigned int *refs)
 {
-       struct ec_node_bypass *node = (struct ec_node_bypass *)gen_node;
+       struct ec_node_bypass *priv = ec_node_priv(node);
 
        if (i >= 1)
                return -1;
 
-       *child = node->child;
+       *child = priv->child;
        *refs = 2;
        return 0;
 }
@@ -89,10 +88,10 @@ static const struct ec_config_schema ec_node_bypass_schema[] = {
        },
 };
 
-static int ec_node_bypass_set_config(struct ec_node *gen_node,
+static int ec_node_bypass_set_config(struct ec_node *node,
                                const struct ec_config *config)
 {
-       struct ec_node_bypass *node = (struct ec_node_bypass *)gen_node;
+       struct ec_node_bypass *priv = ec_node_priv(node);
        const struct ec_config *child;
 
        child = ec_config_dict_get(config, "child");
@@ -103,9 +102,9 @@ static int ec_node_bypass_set_config(struct ec_node *gen_node,
                goto fail;
        }
 
-       if (node->child != NULL)
-               ec_node_free(node->child);
-       node->child = ec_node_clone(child->node);
+       if (priv->child != NULL)
+               ec_node_free(priv->child);
+       priv->child = ec_node_clone(child->node);
 
        return 0;
 
@@ -128,16 +127,16 @@ static struct ec_node_type ec_node_bypass_type = {
 EC_NODE_TYPE_REGISTER(ec_node_bypass_type);
 
 int
-ec_node_bypass_set_child(struct ec_node *gen_node, struct ec_node *child)
+ec_node_bypass_set_child(struct ec_node *node, struct ec_node *child)
 {
        const struct ec_config *cur_config = NULL;
        struct ec_config *config = NULL;
        int ret;
 
-       if (ec_node_check_type(gen_node, &ec_node_bypass_type) < 0)
+       if (ec_node_check_type(node, &ec_node_bypass_type) < 0)
                goto fail;
 
-       cur_config = ec_node_get_config(gen_node);
+       cur_config = ec_node_get_config(node);
        if (cur_config == NULL)
                config = ec_config_dict();
        else
@@ -151,7 +150,7 @@ ec_node_bypass_set_child(struct ec_node *gen_node, struct ec_node *child)
        }
        child = NULL; /* freed */
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL; /* freed */
        if (ret < 0)
                goto fail;
@@ -166,19 +165,19 @@ fail:
 
 struct ec_node *ec_node_bypass(const char *id, struct ec_node *child)
 {
-       struct ec_node *gen_node = NULL;
+       struct ec_node *node = NULL;
 
        if (child == NULL)
                goto fail;
 
-       gen_node = ec_node_from_type(&ec_node_bypass_type, id);
-       if (gen_node == NULL)
+       node = ec_node_from_type(&ec_node_bypass_type, id);
+       if (node == NULL)
                goto fail;
 
-       ec_node_bypass_set_child(gen_node, child);
+       ec_node_bypass_set_child(node, child);
        child = NULL;
 
-       return gen_node;
+       return node;
 
 fail:
        ec_node_free(child);
index ddda655..b6b0720 100644 (file)
@@ -39,7 +39,6 @@ static struct ec_node *ec_node_cmd_parser; /* the expression parser. */
 static struct ec_node *ec_node_cmd_expr;   /* the expr parser without lexer. */
 
 struct ec_node_cmd {
-       struct ec_node gen;
        char *cmd_str;           /* the command string. */
        struct ec_node *cmd;     /* the command node. */
        struct ec_node **table;  /* table of node referenced in command. */
@@ -160,7 +159,7 @@ ec_node_cmd_eval_bin_op(void **result, void *userctx, void *operand1,
        }
 
        if (ec_strvec_len(vec) == 0) {
-               if (!strcmp(in1->type->name, "seq")) {
+               if (!strcmp(ec_node_get_type_name(in1), "seq")) {
                        if (ec_node_seq_add(in1, ec_node_clone(in2)) < 0)
                                return -1;
                        ec_node_free(in2);
@@ -175,12 +174,12 @@ ec_node_cmd_eval_bin_op(void **result, void *userctx, void *operand1,
                        *result = out;
                }
        } else if (!strcmp(ec_strvec_val(vec, 0), "|")) {
-               if (!strcmp(in2->type->name, "or")) {
+               if (!strcmp(ec_node_get_type_name(in2), "or")) {
                        if (ec_node_or_add(in2, ec_node_clone(in1)) < 0)
                                return -1;
                        ec_node_free(in1);
                        *result = in2;
-               } else if (!strcmp(in1->type->name, "or")) {
+               } else if (!strcmp(ec_node_get_type_name(in1), "or")) {
                        if (ec_node_or_add(in1, ec_node_clone(in2)) < 0)
                                return -1;
                        ec_node_free(in2);
@@ -195,12 +194,12 @@ ec_node_cmd_eval_bin_op(void **result, void *userctx, void *operand1,
                        *result = out;
                }
        } else if (!strcmp(ec_strvec_val(vec, 0), ",")) {
-               if (!strcmp(in2->type->name, "subset")) {
+               if (!strcmp(ec_node_get_type_name(in2), "subset")) {
                        if (ec_node_subset_add(in2, ec_node_clone(in1)) < 0)
                                return -1;
                        ec_node_free(in1);
                        *result = in2;
-               } else if (!strcmp(in1->type->name, "subset")) {
+               } else if (!strcmp(ec_node_get_type_name(in1), "subset")) {
                        if (ec_node_subset_add(in1, ec_node_clone(in2)) < 0)
                                return -1;
                        ec_node_free(in2);
@@ -392,38 +391,38 @@ fail:
 }
 
 static int
-ec_node_cmd_parse(const struct ec_node *gen_node, struct ec_parse *state,
+ec_node_cmd_parse(const struct ec_node *node, struct ec_parse *state,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_cmd *node = (struct ec_node_cmd *)gen_node;
+       struct ec_node_cmd *priv = ec_node_priv(node);
 
-       return ec_node_parse_child(node->cmd, state, strvec);
+       return ec_node_parse_child(priv->cmd, state, strvec);
 }
 
 static int
-ec_node_cmd_complete(const struct ec_node *gen_node,
+ec_node_cmd_complete(const struct ec_node *node,
                struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_cmd *node = (struct ec_node_cmd *)gen_node;
+       struct ec_node_cmd *priv = ec_node_priv(node);
 
-       return ec_node_complete_child(node->cmd, comp, strvec);
+       return ec_node_complete_child(priv->cmd, comp, strvec);
 }
 
-static void ec_node_cmd_free_priv(struct ec_node *gen_node)
+static void ec_node_cmd_free_priv(struct ec_node *node)
 {
-       struct ec_node_cmd *node = (struct ec_node_cmd *)gen_node;
+       struct ec_node_cmd *priv = ec_node_priv(node);
        size_t i;
 
-       ec_free(node->cmd_str);
-       node->cmd_str = NULL;
-       ec_node_free(node->cmd);
-       node->cmd = NULL;
-       for (i = 0; i < node->len; i++)
-               ec_node_free(node->table[i]);
-       ec_free(node->table);
-       node->table = NULL;
-       node->len = 0;
+       ec_free(priv->cmd_str);
+       priv->cmd_str = NULL;
+       ec_node_free(priv->cmd);
+       priv->cmd = NULL;
+       for (i = 0; i < priv->len; i++)
+               ec_node_free(priv->table[i]);
+       ec_free(priv->table);
+       priv->table = NULL;
+       priv->len = 0;
 }
 
 static const struct ec_config_schema ec_node_cmd_subschema[] = {
@@ -458,10 +457,10 @@ static const struct ec_config_schema ec_node_cmd_schema[] = {
        },
 };
 
-static int ec_node_cmd_set_config(struct ec_node *gen_node,
+static int ec_node_cmd_set_config(struct ec_node *node,
                                const struct ec_config *config)
 {
-       struct ec_node_cmd *node = (struct ec_node_cmd *)gen_node;
+       struct ec_node_cmd *priv = ec_node_priv(node);
        const struct ec_config *expr = NULL;
        struct ec_node *cmd = NULL;
        struct ec_node **table = NULL;
@@ -490,15 +489,15 @@ static int ec_node_cmd_set_config(struct ec_node *gen_node,
                goto fail;
 
        /* ok, store the config */
-       ec_node_free(node->cmd);
-       node->cmd = cmd;
-       ec_free(node->cmd_str);
-       node->cmd_str = cmd_str;
-       for (i = 0; i < node->len; i++)
-               ec_node_free(node->table[i]);
-       ec_free(node->table);
-       node->table = table;
-       node->len = len;
+       ec_node_free(priv->cmd);
+       priv->cmd = cmd;
+       ec_free(priv->cmd_str);
+       priv->cmd_str = cmd_str;
+       for (i = 0; i < priv->len; i++)
+               ec_node_free(priv->table[i]);
+       ec_free(priv->table);
+       priv->table = table;
+       priv->len = len;
 
        return 0;
 
@@ -512,25 +511,25 @@ fail:
 }
 
 static size_t
-ec_node_cmd_get_children_count(const struct ec_node *gen_node)
+ec_node_cmd_get_children_count(const struct ec_node *node)
 {
-       struct ec_node_cmd *node = (struct ec_node_cmd *)gen_node;
+       struct ec_node_cmd *priv = ec_node_priv(node);
 
-       if (node->cmd == NULL)
+       if (priv->cmd == NULL)
                return 0;
        return 1;
 }
 
 static int
-ec_node_cmd_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_cmd_get_child(const struct ec_node *node, size_t i,
                struct ec_node **child, unsigned int *refs)
 {
-       struct ec_node_cmd *node = (struct ec_node_cmd *)gen_node;
+       struct ec_node_cmd *priv = ec_node_priv(node);
 
        if (i > 0)
                return -1;
 
-       *child = node->cmd;
+       *child = priv->cmd;
        *refs = 1;
        return 0;
 }
@@ -552,7 +551,7 @@ EC_NODE_TYPE_REGISTER(ec_node_cmd_type);
 struct ec_node *__ec_node_cmd(const char *id, const char *cmd, ...)
 {
        struct ec_config *config = NULL, *children = NULL;
-       struct ec_node *gen_node = NULL;
+       struct ec_node *node = NULL;
        va_list ap;
        int ret;
 
@@ -563,8 +562,8 @@ struct ec_node *__ec_node_cmd(const char *id, const char *cmd, ...)
        if (children == NULL)
                goto fail;
 
-       gen_node = ec_node_from_type(&ec_node_cmd_type, id);
-       if (gen_node == NULL)
+       node = ec_node_from_type(&ec_node_cmd_type, id);
+       if (node == NULL)
                goto fail;
 
        config = ec_config_dict();
@@ -580,15 +579,15 @@ struct ec_node *__ec_node_cmd(const char *id, const char *cmd, ...)
        }
        children = NULL;
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL; /* freed */
        if (ret < 0)
                goto fail;
 
-       return gen_node;
+       return node;
 
 fail:
-       ec_node_free(gen_node); /* will also free added children */
+       ec_node_free(node); /* will also free added children */
        ec_config_free(children);
        ec_config_free(config);
 
index 9c7c071..46d62bd 100644 (file)
@@ -42,7 +42,6 @@ static struct ec_node *ec_node_cond_parser; /* the expression parser. */
 static struct ec_dict *ec_node_cond_functions; /* functions dictionary */
 
 struct ec_node_cond {
-       struct ec_node gen;
        char *cond_str;                /* the condition string. */
        struct ec_parse *parsed_cond;  /* the parsed condition. */
        struct ec_node *child;         /* the child node. */
@@ -703,18 +702,18 @@ validate_condition(const struct ec_parse *cond, const struct ec_parse *state)
 }
 
 static int
-ec_node_cond_parse(const struct ec_node *gen_node, struct ec_parse *state,
+ec_node_cond_parse(const struct ec_node *node, struct ec_parse *state,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_cond *node = (struct ec_node_cond *)gen_node;
+       struct ec_node_cond *priv = ec_node_priv(node);
        struct ec_parse *child;
        int ret, valid;
 
-       ret = ec_node_parse_child(node->child, state, strvec);
+       ret = ec_node_parse_child(priv->child, state, strvec);
        if (ret <= 0)
                return ret;
 
-       valid = validate_condition(node->parsed_cond, state);
+       valid = validate_condition(priv->parsed_cond, state);
        if (valid < 0)
                return valid;
 
@@ -729,27 +728,27 @@ ec_node_cond_parse(const struct ec_node *gen_node, struct ec_parse *state,
 }
 
 static int
-ec_node_cond_complete(const struct ec_node *gen_node,
+ec_node_cond_complete(const struct ec_node *node,
                struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_cond *node = (struct ec_node_cond *)gen_node;
+       struct ec_node_cond *priv = ec_node_priv(node);
 
        // XXX eval condition
        // XXX before or after completing ? configurable ?
 
-       return ec_node_complete_child(node->child, comp, strvec);
+       return ec_node_complete_child(priv->child, comp, strvec);
 }
 
-static void ec_node_cond_free_priv(struct ec_node *gen_node)
+static void ec_node_cond_free_priv(struct ec_node *node)
 {
-       struct ec_node_cond *node = (struct ec_node_cond *)gen_node;
+       struct ec_node_cond *priv = ec_node_priv(node);
 
-       ec_free(node->cond_str);
-       node->cond_str = NULL;
-       ec_parse_free(node->parsed_cond);
-       node->parsed_cond = NULL;
-       ec_node_free(node->child);
+       ec_free(priv->cond_str);
+       priv->cond_str = NULL;
+       ec_parse_free(priv->parsed_cond);
+       priv->parsed_cond = NULL;
+       ec_node_free(priv->child);
 }
 
 static const struct ec_config_schema ec_node_cond_schema[] = {
@@ -768,10 +767,10 @@ static const struct ec_config_schema ec_node_cond_schema[] = {
        },
 };
 
-static int ec_node_cond_set_config(struct ec_node *gen_node,
+static int ec_node_cond_set_config(struct ec_node *node,
                                const struct ec_config *config)
 {
-       struct ec_node_cond *node = (struct ec_node_cond *)gen_node;
+       struct ec_node_cond *priv = ec_node_priv(node);
        const struct ec_config *cond = NULL;
        struct ec_parse *parsed_cond = NULL;
        const struct ec_config *child;
@@ -797,12 +796,12 @@ static int ec_node_cond_set_config(struct ec_node *gen_node,
                goto fail;
 
        /* ok, store the config */
-       ec_parse_free(node->parsed_cond);
-       node->parsed_cond = parsed_cond;
-       ec_free(node->cond_str);
-       node->cond_str = cond_str;
-       ec_node_free(node->child);
-       node->child = ec_node_clone(child->node);
+       ec_parse_free(priv->parsed_cond);
+       priv->parsed_cond = parsed_cond;
+       ec_free(priv->cond_str);
+       priv->cond_str = cond_str;
+       ec_node_free(priv->child);
+       priv->child = ec_node_clone(child->node);
 
        return 0;
 
@@ -813,25 +812,25 @@ fail:
 }
 
 static size_t
-ec_node_cond_get_children_count(const struct ec_node *gen_node)
+ec_node_cond_get_children_count(const struct ec_node *node)
 {
-       struct ec_node_cond *node = (struct ec_node_cond *)gen_node;
+       struct ec_node_cond *priv = ec_node_priv(node);
 
-       if (node->child == NULL)
+       if (priv->child == NULL)
                return 0;
        return 1;
 }
 
 static int
-ec_node_cond_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_cond_get_child(const struct ec_node *node, size_t i,
                struct ec_node **child, unsigned int *refs)
 {
-       struct ec_node_cond *node = (struct ec_node_cond *)gen_node;
+       struct ec_node_cond *priv = ec_node_priv(node);
 
        if (i > 0)
                return -1;
 
-       *child = node->child;
+       *child = priv->child;
        *refs = 1;
        return 0;
 }
@@ -854,14 +853,14 @@ struct ec_node *ec_node_cond(const char *id, const char *cmd,
                        struct ec_node *child)
 {
        struct ec_config *config = NULL;
-       struct ec_node *gen_node = NULL;
+       struct ec_node *node = NULL;
        int ret;
 
        if (child == NULL)
                return NULL;
 
-       gen_node = ec_node_from_type(&ec_node_cond_type, id);
-       if (gen_node == NULL)
+       node = ec_node_from_type(&ec_node_cond_type, id);
+       if (node == NULL)
                goto fail;
 
        config = ec_config_dict();
@@ -877,15 +876,15 @@ struct ec_node *ec_node_cond(const char *id, const char *cmd,
        }
        child = NULL;
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL; /* freed */
        if (ret < 0)
                goto fail;
 
-       return gen_node;
+       return node;
 
 fail:
-       ec_node_free(gen_node);
+       ec_node_free(node);
        ec_node_free(child);
        ec_config_free(config);
 
index a7130aa..2b79f7a 100644 (file)
 EC_LOG_TYPE_REGISTER(node_dynamic);
 
 struct ec_node_dynamic {
-       struct ec_node gen;
        ec_node_dynamic_build_t build;
        void *opaque;
 };
 
 static int
-ec_node_dynamic_parse(const struct ec_node *gen_node,
+ec_node_dynamic_parse(const struct ec_node *node,
                struct ec_parse *parse,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_dynamic *node = (struct ec_node_dynamic *)gen_node;
+       struct ec_node_dynamic *priv = ec_node_priv(node);
        struct ec_node *child = NULL;
        void (*node_free)(struct ec_node *) = ec_node_free;
        char key[64];
        int ret = -1;
 
-       child = node->build(parse, node->opaque);
+       child = priv->build(parse, priv->opaque);
        if (child == NULL)
                goto fail;
 
@@ -62,11 +61,11 @@ fail:
 }
 
 static int
-ec_node_dynamic_complete(const struct ec_node *gen_node,
+ec_node_dynamic_complete(const struct ec_node *node,
                struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_dynamic *node = (struct ec_node_dynamic *)gen_node;
+       struct ec_node_dynamic *priv = ec_node_priv(node);
        struct ec_parse *parse;
        struct ec_node *child = NULL;
        void (*node_free)(struct ec_node *) = ec_node_free;
@@ -74,7 +73,7 @@ ec_node_dynamic_complete(const struct ec_node *gen_node,
        int ret = -1;
 
        parse = ec_comp_get_state(comp);
-       child = node->build(parse, node->opaque);
+       child = priv->build(parse, priv->opaque);
        if (child == NULL)
                goto fail;
 
@@ -105,26 +104,26 @@ static struct ec_node_type ec_node_dynamic_type = {
 struct ec_node *
 ec_node_dynamic(const char *id, ec_node_dynamic_build_t build, void *opaque)
 {
-       struct ec_node *gen_node = NULL;
-       struct ec_node_dynamic *node;
+       struct ec_node *node = NULL;
+       struct ec_node_dynamic *priv;
 
        if (build == NULL) {
                errno = EINVAL;
                goto fail;
        }
 
-       gen_node = ec_node_from_type(&ec_node_dynamic_type, id);
-       if (gen_node == NULL)
+       node = ec_node_from_type(&ec_node_dynamic_type, id);
+       if (node == NULL)
                goto fail;
 
-       node = (struct ec_node_dynamic *)gen_node;
-       node->build = build;
-       node->opaque = opaque;
+       priv = ec_node_priv(node);
+       priv->build = build;
+       priv->opaque = opaque;
 
-       return gen_node;
+       return node;
 
 fail:
-       ec_node_free(gen_node);
+       ec_node_free(node);
        return NULL;
 
 }
@@ -144,7 +143,7 @@ build_counter(struct ec_parse *parse, void *opaque)
        for (iter = root; iter != NULL;
             iter = EC_PARSE_ITER_NEXT(root, iter, 1)) {
                node = ec_parse_get_node(iter);
-               if (node->id && !strcmp(node->id, "my-id"))
+               if (!strcmp(ec_node_id(node), "my-id"))
                        count++;
        }
        snprintf(buf, sizeof(buf), "count-%u", count);
index 6ce76e8..af3bae1 100644 (file)
 EC_LOG_TYPE_REGISTER(node_empty);
 
 struct ec_node_empty {
-       struct ec_node gen;
 };
 
-static int ec_node_empty_parse(const struct ec_node *gen_node,
+static int ec_node_empty_parse(const struct ec_node *node,
                        struct ec_parse *state,
                        const struct ec_strvec *strvec)
 {
-       (void)gen_node;
+       (void)node;
        (void)state;
        (void)strvec;
        return 0;
index 3b47d8c..2ca0ed3 100644 (file)
@@ -26,8 +26,6 @@
 EC_LOG_TYPE_REGISTER(node_expr);
 
 struct ec_node_expr {
-       struct ec_node gen;
-
        /* the built node */
        struct ec_node *child;
 
@@ -44,77 +42,77 @@ struct ec_node_expr {
        unsigned int paren_len;
 };
 
-static int ec_node_expr_parse(const struct ec_node *gen_node,
+static int ec_node_expr_parse(const struct ec_node *node,
                        struct ec_parse *state,
                        const struct ec_strvec *strvec)
 {
-       struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+       struct ec_node_expr *priv = ec_node_priv(node);
 
-       if (node->child == NULL) {
+       if (priv->child == NULL) {
                errno = ENOENT;
                return -1;
        }
 
-       return ec_node_parse_child(node->child, state, strvec);
+       return ec_node_parse_child(priv->child, state, strvec);
 }
 
 static int
-ec_node_expr_complete(const struct ec_node *gen_node,
+ec_node_expr_complete(const struct ec_node *node,
                struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+       struct ec_node_expr *priv = ec_node_priv(node);
 
-       if (node->child == NULL) {
+       if (priv->child == NULL) {
                errno = ENOENT;
                return -1;
        }
 
-       return ec_node_complete_child(node->child, comp, strvec);
+       return ec_node_complete_child(priv->child, comp, strvec);
 }
 
-static void ec_node_expr_free_priv(struct ec_node *gen_node)
+static void ec_node_expr_free_priv(struct ec_node *node)
 {
-       struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+       struct ec_node_expr *priv = ec_node_priv(node);
        unsigned int i;
 
-       ec_node_free(node->child);
-       ec_node_free(node->val_node);
-
-       for (i = 0; i < node->bin_ops_len; i++)
-               ec_node_free(node->bin_ops[i]);
-       ec_free(node->bin_ops);
-       for (i = 0; i < node->pre_ops_len; i++)
-               ec_node_free(node->pre_ops[i]);
-       ec_free(node->pre_ops);
-       for (i = 0; i < node->post_ops_len; i++)
-               ec_node_free(node->post_ops[i]);
-       ec_free(node->post_ops);
-       for (i = 0; i < node->paren_len; i++) {
-               ec_node_free(node->open_ops[i]);
-               ec_node_free(node->close_ops[i]);
+       ec_node_free(priv->child);
+       ec_node_free(priv->val_node);
+
+       for (i = 0; i < priv->bin_ops_len; i++)
+               ec_node_free(priv->bin_ops[i]);
+       ec_free(priv->bin_ops);
+       for (i = 0; i < priv->pre_ops_len; i++)
+               ec_node_free(priv->pre_ops[i]);
+       ec_free(priv->pre_ops);
+       for (i = 0; i < priv->post_ops_len; i++)
+               ec_node_free(priv->post_ops[i]);
+       ec_free(priv->post_ops);
+       for (i = 0; i < priv->paren_len; i++) {
+               ec_node_free(priv->open_ops[i]);
+               ec_node_free(priv->close_ops[i]);
        }
-       ec_free(node->open_ops);
-       ec_free(node->close_ops);
+       ec_free(priv->open_ops);
+       ec_free(priv->close_ops);
 }
 
-static int ec_node_expr_build(struct ec_node_expr *node)
+static int ec_node_expr_build(struct ec_node_expr *priv)
 {
        struct ec_node *term = NULL, *expr = NULL, *next = NULL,
                *pre_op = NULL, *post_op = NULL, *ref = NULL,
                *post = NULL;
        unsigned int i;
 
-       ec_node_free(node->child);
-       node->child = NULL;
+       ec_node_free(priv->child);
+       priv->child = NULL;
 
-       if (node->val_node == NULL) {
+       if (priv->val_node == NULL) {
                errno = EINVAL;
                return -1;
        }
 
-       if (node->bin_ops_len == 0 && node->pre_ops_len == 0 &&
-                       node->post_ops_len == 0) {
+       if (priv->bin_ops_len == 0 && priv->pre_ops_len == 0 &&
+                       priv->post_ops_len == 0) {
                errno = EINVAL;
                return -1;
        }
@@ -142,8 +140,8 @@ static int ec_node_expr_build(struct ec_node_expr *node)
        pre_op = ec_node("or", "pre-op");
        if (pre_op == NULL)
                goto fail;
-       for (i = 0; i < node->pre_ops_len; i++) {
-               if (ec_node_or_add(pre_op, ec_node_clone(node->pre_ops[i])) < 0)
+       for (i = 0; i < priv->pre_ops_len; i++) {
+               if (ec_node_or_add(pre_op, ec_node_clone(priv->pre_ops[i])) < 0)
                        goto fail;
        }
 
@@ -151,26 +149,26 @@ static int ec_node_expr_build(struct ec_node_expr *node)
        post_op = ec_node("or", "post-op");
        if (post_op == NULL)
                goto fail;
-       for (i = 0; i < node->post_ops_len; i++) {
-               if (ec_node_or_add(post_op, ec_node_clone(node->post_ops[i])) < 0)
+       for (i = 0; i < priv->post_ops_len; i++) {
+               if (ec_node_or_add(post_op, ec_node_clone(priv->post_ops[i])) < 0)
                        goto fail;
        }
 
        post = ec_node("or", "post");
        if (post == NULL)
                goto fail;
-       if (ec_node_or_add(post, ec_node_clone(node->val_node)) < 0)
+       if (ec_node_or_add(post, ec_node_clone(priv->val_node)) < 0)
                goto fail;
        if (ec_node_or_add(post,
                EC_NODE_SEQ(EC_NO_ID,
                        ec_node_clone(pre_op),
                        ec_node_clone(ref))) < 0)
                goto fail;
-       for (i = 0; i < node->paren_len; i++) {
+       for (i = 0; i < priv->paren_len; i++) {
                if (ec_node_or_add(post, EC_NODE_SEQ(EC_NO_ID,
-                                       ec_node_clone(node->open_ops[i]),
+                                       ec_node_clone(priv->open_ops[i]),
                                        ec_node_clone(ref),
-                                       ec_node_clone(node->close_ops[i]))) < 0)
+                                       ec_node_clone(priv->close_ops[i]))) < 0)
                        goto fail;
        }
        term = EC_NODE_SEQ("term",
@@ -180,12 +178,12 @@ static int ec_node_expr_build(struct ec_node_expr *node)
        if (term == NULL)
                goto fail;
 
-       for (i = 0; i < node->bin_ops_len; i++) {
+       for (i = 0; i < priv->bin_ops_len; i++) {
                next = EC_NODE_SEQ("next",
                        ec_node_clone(term),
                        ec_node_many(EC_NO_ID,
                                EC_NODE_SEQ(EC_NO_ID,
-                                       ec_node_clone(node->bin_ops[i]),
+                                       ec_node_clone(priv->bin_ops[i]),
                                        ec_node_clone(term)
                                ),
                                0, 0
@@ -212,7 +210,7 @@ static int ec_node_expr_build(struct ec_node_expr *node)
        ec_node_free(ref);
        ref = NULL;
 
-       node->child = expr;
+       priv->child = expr;
 
        return 0;
 
@@ -228,25 +226,25 @@ fail:
 }
 
 static size_t
-ec_node_expr_get_children_count(const struct ec_node *gen_node)
+ec_node_expr_get_children_count(const struct ec_node *node)
 {
-       struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+       struct ec_node_expr *priv = ec_node_priv(node);
 
-       if (node->child)
+       if (priv->child)
                return 1;
        return 0;
 }
 
 static int
-ec_node_expr_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_expr_get_child(const struct ec_node *node, size_t i,
                struct ec_node **child, unsigned int *refs)
 {
-       struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+       struct ec_node_expr *priv = ec_node_priv(node);
 
        if (i >= 1)
                return -1;
 
-       *child = node->child;
+       *child = priv->child;
        *refs = 1;
        return 0;
 }
@@ -263,11 +261,11 @@ static struct ec_node_type ec_node_expr_type = {
 
 EC_NODE_TYPE_REGISTER(ec_node_expr_type);
 
-int ec_node_expr_set_val_node(struct ec_node *gen_node, struct ec_node *val_node)
+int ec_node_expr_set_val_node(struct ec_node *node, struct ec_node *val_node)
 {
-       struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+       struct ec_node_expr *priv = ec_node_priv(node);
 
-       if (ec_node_check_type(gen_node, &ec_node_expr_type) < 0)
+       if (ec_node_check_type(node, &ec_node_expr_type) < 0)
                goto fail;
 
        if (val_node == NULL) {
@@ -275,9 +273,9 @@ int ec_node_expr_set_val_node(struct ec_node *gen_node, struct ec_node *val_node
                goto fail;
        }
 
-       ec_node_free(node->val_node);
-       node->val_node = val_node;
-       ec_node_expr_build(node);
+       ec_node_free(priv->val_node);
+       priv->val_node = val_node;
+       ec_node_expr_build(priv);
 
        return 0;
 
@@ -287,12 +285,12 @@ fail:
 }
 
 /* add a binary operator */
-int ec_node_expr_add_bin_op(struct ec_node *gen_node, struct ec_node *op)
+int ec_node_expr_add_bin_op(struct ec_node *node, struct ec_node *op)
 {
-       struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+       struct ec_node_expr *priv = ec_node_priv(node);
        struct ec_node **bin_ops;
 
-       if (ec_node_check_type(gen_node, &ec_node_expr_type) < 0)
+       if (ec_node_check_type(node, &ec_node_expr_type) < 0)
                goto fail;
 
        if (node == NULL || op == NULL) {
@@ -300,15 +298,15 @@ int ec_node_expr_add_bin_op(struct ec_node *gen_node, struct ec_node *op)
                goto fail;
        }
 
-       bin_ops = ec_realloc(node->bin_ops,
-               (node->bin_ops_len + 1) * sizeof(*node->bin_ops));
+       bin_ops = ec_realloc(priv->bin_ops,
+               (priv->bin_ops_len + 1) * sizeof(*priv->bin_ops));
        if (bin_ops == NULL)
                goto fail;;
 
-       node->bin_ops = bin_ops;
-       bin_ops[node->bin_ops_len] = op;
-       node->bin_ops_len++;
-       ec_node_expr_build(node);
+       priv->bin_ops = bin_ops;
+       bin_ops[priv->bin_ops_len] = op;
+       priv->bin_ops_len++;
+       ec_node_expr_build(priv);
 
        return 0;
 
@@ -318,12 +316,12 @@ fail:
 }
 
 /* add a unary pre-operator */
-int ec_node_expr_add_pre_op(struct ec_node *gen_node, struct ec_node *op)
+int ec_node_expr_add_pre_op(struct ec_node *node, struct ec_node *op)
 {
-       struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+       struct ec_node_expr *priv = ec_node_priv(node);
        struct ec_node **pre_ops;
 
-       if (ec_node_check_type(gen_node, &ec_node_expr_type) < 0)
+       if (ec_node_check_type(node, &ec_node_expr_type) < 0)
                goto fail;
 
        if (node == NULL || op == NULL) {
@@ -331,15 +329,15 @@ int ec_node_expr_add_pre_op(struct ec_node *gen_node, struct ec_node *op)
                goto fail;
        }
 
-       pre_ops = ec_realloc(node->pre_ops,
-               (node->pre_ops_len + 1) * sizeof(*node->pre_ops));
+       pre_ops = ec_realloc(priv->pre_ops,
+               (priv->pre_ops_len + 1) * sizeof(*priv->pre_ops));
        if (pre_ops == NULL)
                goto fail;
 
-       node->pre_ops = pre_ops;
-       pre_ops[node->pre_ops_len] = op;
-       node->pre_ops_len++;
-       ec_node_expr_build(node);
+       priv->pre_ops = pre_ops;
+       pre_ops[priv->pre_ops_len] = op;
+       priv->pre_ops_len++;
+       ec_node_expr_build(priv);
 
        return 0;
 
@@ -349,12 +347,12 @@ fail:
 }
 
 /* add a unary post-operator */
-int ec_node_expr_add_post_op(struct ec_node *gen_node, struct ec_node *op)
+int ec_node_expr_add_post_op(struct ec_node *node, struct ec_node *op)
 {
-       struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+       struct ec_node_expr *priv = ec_node_priv(node);
        struct ec_node **post_ops;
 
-       if (ec_node_check_type(gen_node, &ec_node_expr_type) < 0)
+       if (ec_node_check_type(node, &ec_node_expr_type) < 0)
                goto fail;
 
        if (node == NULL || op == NULL) {
@@ -362,15 +360,15 @@ int ec_node_expr_add_post_op(struct ec_node *gen_node, struct ec_node *op)
                goto fail;
        }
 
-       post_ops = ec_realloc(node->post_ops,
-               (node->post_ops_len + 1) * sizeof(*node->post_ops));
+       post_ops = ec_realloc(priv->post_ops,
+               (priv->post_ops_len + 1) * sizeof(*priv->post_ops));
        if (post_ops == NULL)
                goto fail;
 
-       node->post_ops = post_ops;
-       post_ops[node->post_ops_len] = op;
-       node->post_ops_len++;
-       ec_node_expr_build(node);
+       priv->post_ops = post_ops;
+       post_ops[priv->post_ops_len] = op;
+       priv->post_ops_len++;
+       ec_node_expr_build(priv);
 
        return 0;
 
@@ -380,13 +378,13 @@ fail:
 }
 
 /* add parenthesis symbols */
-int ec_node_expr_add_parenthesis(struct ec_node *gen_node,
+int ec_node_expr_add_parenthesis(struct ec_node *node,
        struct ec_node *open, struct ec_node *close)
 {
-       struct ec_node_expr *node = (struct ec_node_expr *)gen_node;
+       struct ec_node_expr *priv = ec_node_priv(node);
        struct ec_node **open_ops, **close_ops;
 
-       if (ec_node_check_type(gen_node, &ec_node_expr_type) < 0)
+       if (ec_node_check_type(node, &ec_node_expr_type) < 0)
                goto fail;
 
        if (node == NULL || open == NULL || close == NULL) {
@@ -394,21 +392,21 @@ int ec_node_expr_add_parenthesis(struct ec_node *gen_node,
                goto fail;
        }
 
-       open_ops = ec_realloc(node->open_ops,
-               (node->paren_len + 1) * sizeof(*node->open_ops));
+       open_ops = ec_realloc(priv->open_ops,
+               (priv->paren_len + 1) * sizeof(*priv->open_ops));
        if (open_ops == NULL)
                goto fail;
-       close_ops = ec_realloc(node->close_ops,
-               (node->paren_len + 1) * sizeof(*node->close_ops));
+       close_ops = ec_realloc(priv->close_ops,
+               (priv->paren_len + 1) * sizeof(*priv->close_ops));
        if (close_ops == NULL)
                goto fail;
 
-       node->open_ops = open_ops;
-       node->close_ops = close_ops;
-       open_ops[node->paren_len] = open;
-       close_ops[node->paren_len] = close;
-       node->paren_len++;
-       ec_node_expr_build(node);
+       priv->open_ops = open_ops;
+       priv->close_ops = close_ops;
+       open_ops[priv->paren_len] = open;
+       close_ops[priv->paren_len] = close;
+       priv->paren_len++;
+       ec_node_expr_build(priv);
 
        return 0;
 
@@ -428,34 +426,34 @@ enum expr_node_type {
        PAREN_CLOSE,
 };
 
-static enum expr_node_type get_node_type(const struct ec_node *expr_gen_node,
+static enum expr_node_type get_node_type(const struct ec_node *expr_node,
        const struct ec_node *check)
 {
-       struct ec_node_expr *expr_node = (struct ec_node_expr *)expr_gen_node;
+       struct ec_node_expr *expr_priv = ec_node_priv(expr_node);
        size_t i;
 
-       if (check == expr_node->val_node)
+       if (check == expr_priv->val_node)
                return VAL;
 
-       for (i = 0; i < expr_node->bin_ops_len; i++) {
-               if (check == expr_node->bin_ops[i])
+       for (i = 0; i < expr_priv->bin_ops_len; i++) {
+               if (check == expr_priv->bin_ops[i])
                        return BIN_OP;
        }
-       for (i = 0; i < expr_node->pre_ops_len; i++) {
-               if (check == expr_node->pre_ops[i])
+       for (i = 0; i < expr_priv->pre_ops_len; i++) {
+               if (check == expr_priv->pre_ops[i])
                        return PRE_OP;
        }
-       for (i = 0; i < expr_node->post_ops_len; i++) {
-               if (check == expr_node->post_ops[i])
+       for (i = 0; i < expr_priv->post_ops_len; i++) {
+               if (check == expr_priv->post_ops[i])
                        return POST_OP;
        }
 
-       for (i = 0; i < expr_node->paren_len; i++) {
-               if (check == expr_node->open_ops[i])
+       for (i = 0; i < expr_priv->paren_len; i++) {
+               if (check == expr_priv->open_ops[i])
                        return PAREN_OPEN;
        }
-       for (i = 0; i < expr_node->paren_len; i++) {
-               if (check == expr_node->close_ops[i])
+       for (i = 0; i < expr_priv->paren_len; i++) {
+               if (check == expr_priv->close_ops[i])
                        return PAREN_CLOSE;
        }
 
@@ -521,7 +519,7 @@ static int merge_results(void *userctx,
 static int eval_expression(struct result *result,
        void *userctx,
        const struct ec_node_expr_eval_ops *ops,
-       const struct ec_node *expr_gen_node,
+       const struct ec_node *expr_node,
        const struct ec_parse *parse)
 
 {
@@ -533,7 +531,7 @@ static int eval_expression(struct result *result,
        memset(result, 0, sizeof(*result));
        memset(&child_result, 0, sizeof(child_result));
 
-       type = get_node_type(expr_gen_node, ec_parse_get_node(parse));
+       type = get_node_type(expr_node, ec_parse_get_node(parse));
        if (type == VAL) {
                if (ops->eval_var(&result->val, userctx, parse) < 0)
                        goto fail;
@@ -545,7 +543,7 @@ static int eval_expression(struct result *result,
 
        EC_PARSE_FOREACH_CHILD(child, parse) {
 
-               type = get_node_type(expr_gen_node, ec_parse_get_node(child));
+               type = get_node_type(expr_node, ec_parse_get_node(child));
                if (type == PAREN_OPEN) {
                        open = child;
                        continue;
@@ -555,7 +553,7 @@ static int eval_expression(struct result *result,
                }
 
                if (eval_expression(&child_result, userctx, ops,
-                       expr_gen_node, child) < 0)
+                       expr_node, child) < 0)
                        goto fail;
 
                if (merge_results(userctx, ops, result, &child_result) < 0)
index 001dcb6..9c4f4f5 100644 (file)
@@ -24,8 +24,6 @@
 EC_LOG_TYPE_REGISTER(node_file);
 
 struct ec_node_file {
-       struct ec_node gen;
-
        /* below functions pointers are only useful for test */
        int (*lstat)(const char *pathname, struct stat *buf);
        DIR *(*opendir)(const char *name);
@@ -37,11 +35,11 @@ struct ec_node_file {
 };
 
 static int
-ec_node_file_parse(const struct ec_node *gen_node,
+ec_node_file_parse(const struct ec_node *node,
                struct ec_parse *state,
                const struct ec_strvec *strvec)
 {
-       (void)gen_node;
+       (void)node;
        (void)state;
 
        if (ec_strvec_len(strvec) == 0)
@@ -99,11 +97,11 @@ static int split_path(const char *path, char **dname_p, char **bname_p)
 }
 
 static int
-ec_node_file_complete(const struct ec_node *gen_node,
+ec_node_file_complete(const struct ec_node *node,
                struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_file *node = (struct ec_node_file *)gen_node;
+       struct ec_node_file *priv = ec_node_priv(node);
        char *dname = NULL, *bname = NULL, *effective_dir;
        struct ec_comp_item *item = NULL;
        enum ec_comp_type type;
@@ -150,12 +148,12 @@ ec_node_file_complete(const struct ec_node *gen_node,
        else
                effective_dir = dname;
 
-       if (node->lstat(effective_dir, &st) < 0)
+       if (priv->lstat(effective_dir, &st) < 0)
                goto fail;
        if (!S_ISDIR(st.st_mode))
                goto out;
 
-       dir = node->opendir(effective_dir);
+       dir = priv->opendir(effective_dir);
        if (dir == NULL)
                goto fail;
 
@@ -164,7 +162,7 @@ ec_node_file_complete(const struct ec_node *gen_node,
                int save_errno = errno;
 
                errno = 0;
-               de = node->readdir(dir);
+               de = priv->readdir(dir);
                if (de == NULL) {
                        if (errno == 0) {
                                errno = save_errno;
@@ -183,11 +181,11 @@ ec_node_file_complete(const struct ec_node *gen_node,
                if (de->d_type == DT_DIR) {
                        is_dir = 1;
                } else if (de->d_type == DT_UNKNOWN) {
-                       int dir_fd = node->dirfd(dir);
+                       int dir_fd = priv->dirfd(dir);
 
                        if (dir_fd < 0)
                                goto fail;
-                       if (node->fstatat(dir_fd, de->d_name, &st2, 0) < 0)
+                       if (priv->fstatat(dir_fd, de->d_name, &st2, 0) < 0)
                                goto fail;
                        if (S_ISDIR(st2.st_mode))
                                is_dir = 1;
@@ -212,7 +210,7 @@ ec_node_file_complete(const struct ec_node *gen_node,
                        if (ec_asprintf(&disp_str, "%s", de->d_name) < 0)
                                goto fail;
                }
-               if (ec_comp_add_item(comp, gen_node, &item,
+               if (ec_comp_add_item(comp, node, &item,
                                                type, input, comp_str) < 0)
                        goto out;
 
@@ -233,7 +231,7 @@ out:
        ec_free(dname);
        ec_free(bname);
        if (dir != NULL)
-               node->closedir(dir);
+               priv->closedir(dir);
 
        return 0;
 
@@ -243,21 +241,21 @@ fail:
        ec_free(dname);
        ec_free(bname);
        if (dir != NULL)
-               node->closedir(dir);
+               priv->closedir(dir);
 
        return -1;
 }
 
 static int
-ec_node_file_init_priv(struct ec_node *gen_node)
+ec_node_file_init_priv(struct ec_node *node)
 {
-       struct ec_node_file *node = (struct ec_node_file *)gen_node;
+       struct ec_node_file *priv = ec_node_priv(node);
 
-       node->lstat = lstat;
-       node->opendir = opendir;
-       node->readdir = readdir;
-       node->dirfd = dirfd;
-       node->fstatat = fstatat;
+       priv->lstat = lstat;
+       priv->opendir = opendir;
+       priv->readdir = readdir;
+       priv->dirfd = dirfd;
+       priv->fstatat = fstatat;
 
        return 0;
 }
@@ -363,16 +361,16 @@ test_fstatat(int dirfd, const char *pathname, struct stat *buf,
 }
 
 static int
-ec_node_file_override_functions(struct ec_node *gen_node)
+ec_node_file_override_functions(struct ec_node *node)
 {
-       struct ec_node_file *node = (struct ec_node_file *)gen_node;
-
-       node->lstat = test_lstat;
-       node->opendir = test_opendir;
-       node->readdir = test_readdir;
-       node->closedir = test_closedir;
-       node->dirfd = test_dirfd;
-       node->fstatat = test_fstatat;
+       struct ec_node_file *priv = ec_node_priv(node);
+
+       priv->lstat = test_lstat;
+       priv->opendir = test_opendir;
+       priv->readdir = test_readdir;
+       priv->closedir = test_closedir;
+       priv->dirfd = test_dirfd;
+       priv->fstatat = test_fstatat;
 
        return 0;
 }
index 80f2fd5..0fdca0b 100644 (file)
@@ -26,7 +26,6 @@ EC_LOG_TYPE_REGISTER(node_int);
 
 /* common to int and uint */
 struct ec_node_int_uint {
-       struct ec_node gen;
        bool is_signed;
        bool check_min;
        bool check_max;
@@ -41,45 +40,45 @@ struct ec_node_int_uint {
        unsigned int base;
 };
 
-static int parse_llint(struct ec_node_int_uint *node, const char *str,
+static int parse_llint(struct ec_node_int_uint *priv, const char *str,
        int64_t *val)
 {
        int64_t min, max;
 
-       if (node->check_min)
-               min = node->min;
+       if (priv->check_min)
+               min = priv->min;
        else
                min = LLONG_MIN;
-       if (node->check_max)
-               max = node->max;
+       if (priv->check_max)
+               max = priv->max;
        else
                max = LLONG_MAX;
 
-       return ec_str_parse_llint(str, node->base, min, max, val);
+       return ec_str_parse_llint(str, priv->base, min, max, val);
 }
 
-static int parse_ullint(struct ec_node_int_uint *node, const char *str,
+static int parse_ullint(struct ec_node_int_uint *priv, const char *str,
                        uint64_t *val)
 {
        uint64_t min, max;
 
-       if (node->check_min)
-               min = node->min;
+       if (priv->check_min)
+               min = priv->min;
        else
                min = 0;
-       if (node->check_max)
-               max = node->max;
+       if (priv->check_max)
+               max = priv->max;
        else
                max = ULLONG_MAX;
 
-       return ec_str_parse_ullint(str, node->base, min, max, val);
+       return ec_str_parse_ullint(str, priv->base, min, max, val);
 }
 
-static int ec_node_int_uint_parse(const struct ec_node *gen_node,
+static int ec_node_int_uint_parse(const struct ec_node *node,
                        struct ec_parse *state,
                        const struct ec_strvec *strvec)
 {
-       struct ec_node_int_uint *node = (struct ec_node_int_uint *)gen_node;
+       struct ec_node_int_uint *priv = ec_node_priv(node);
        const char *str;
        uint64_t u64;
        int64_t i64;
@@ -90,22 +89,22 @@ static int ec_node_int_uint_parse(const struct ec_node *gen_node,
                return EC_PARSE_NOMATCH;
 
        str = ec_strvec_val(strvec, 0);
-       if (node->is_signed) {
-               if (parse_llint(node, str, &i64) < 0)
+       if (priv->is_signed) {
+               if (parse_llint(priv, str, &i64) < 0)
                        return EC_PARSE_NOMATCH;
        } else {
-               if (parse_ullint(node, str, &u64) < 0)
+               if (parse_ullint(priv, str, &u64) < 0)
                        return EC_PARSE_NOMATCH;
        }
        return 1;
 }
 
 static int
-ec_node_uint_init_priv(struct ec_node *gen_node)
+ec_node_uint_init_priv(struct ec_node *node)
 {
-       struct ec_node_int_uint *node = (struct ec_node_int_uint *)gen_node;
+       struct ec_node_int_uint *priv = ec_node_priv(node);
 
-       node->is_signed = true;
+       priv->is_signed = true;
 
        return 0;
 }
@@ -131,10 +130,10 @@ static const struct ec_config_schema ec_node_int_schema[] = {
        },
 };
 
-static int ec_node_int_set_config(struct ec_node *gen_node,
+static int ec_node_int_set_config(struct ec_node *node,
                                const struct ec_config *config)
 {
-       struct ec_node_int_uint *node = (struct ec_node_int_uint *)gen_node;
+       struct ec_node_int_uint *priv = ec_node_priv(node);
        const struct ec_config *min_value = NULL;
        const struct ec_config *max_value = NULL;
        const struct ec_config *base_value = NULL;
@@ -150,21 +149,21 @@ static int ec_node_int_set_config(struct ec_node *gen_node,
        }
 
        if (min_value != NULL) {
-               node->check_min = true;
-               node->min = min_value->i64;
+               priv->check_min = true;
+               priv->min = min_value->i64;
        } else {
-               node->check_min = false;
+               priv->check_min = false;
        }
        if (max_value != NULL) {
-               node->check_max = true;
-               node->max = max_value->i64;
+               priv->check_max = true;
+               priv->max = max_value->i64;
        } else {
-               node->check_min = false;
+               priv->check_min = false;
        }
        if (base_value != NULL)
-               node->base = base_value->u64;
+               priv->base = base_value->u64;
        else
-               node->base = 0;
+               priv->base = 0;
 
        return 0;
 
@@ -189,11 +188,11 @@ struct ec_node *ec_node_int(const char *id, int64_t min,
        int64_t max, unsigned int base)
 {
        struct ec_config *config = NULL;
-       struct ec_node *gen_node = NULL;
+       struct ec_node *node = NULL;
        int ret;
 
-       gen_node = ec_node_from_type(&ec_node_int_type, id);
-       if (gen_node == NULL)
+       node = ec_node_from_type(&ec_node_int_type, id);
+       if (node == NULL)
                return NULL;
 
        config = ec_config_dict();
@@ -210,16 +209,16 @@ struct ec_node *ec_node_int(const char *id, int64_t min,
        if (ret < 0)
                goto fail;
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL;
        if (ret < 0)
                goto fail;
 
-       return gen_node;
+       return node;
 
 fail:
        ec_config_free(config);
-       ec_node_free(gen_node);
+       ec_node_free(node);
        return NULL;
 }
 
@@ -244,10 +243,10 @@ static const struct ec_config_schema ec_node_uint_schema[] = {
        },
 };
 
-static int ec_node_uint_set_config(struct ec_node *gen_node,
+static int ec_node_uint_set_config(struct ec_node *node,
                                const struct ec_config *config)
 {
-       struct ec_node_int_uint *node = (struct ec_node_int_uint *)gen_node;
+       struct ec_node_int_uint *priv = ec_node_priv(node);
        const struct ec_config *min_value = NULL;
        const struct ec_config *max_value = NULL;
        const struct ec_config *base_value = NULL;
@@ -263,21 +262,21 @@ static int ec_node_uint_set_config(struct ec_node *gen_node,
        }
 
        if (min_value != NULL) {
-               node->check_min = true;
-               node->min = min_value->u64;
+               priv->check_min = true;
+               priv->min = min_value->u64;
        } else {
-               node->check_min = false;
+               priv->check_min = false;
        }
        if (max_value != NULL) {
-               node->check_max = true;
-               node->max = max_value->u64;
+               priv->check_max = true;
+               priv->max = max_value->u64;
        } else {
-               node->check_min = false;
+               priv->check_min = false;
        }
        if (base_value != NULL)
-               node->base = base_value->u64;
+               priv->base = base_value->u64;
        else
-               node->base = 0;
+               priv->base = 0;
 
        return 0;
 
@@ -301,11 +300,11 @@ struct ec_node *ec_node_uint(const char *id, uint64_t min,
        uint64_t max, unsigned int base)
 {
        struct ec_config *config = NULL;
-       struct ec_node *gen_node = NULL;
+       struct ec_node *node = NULL;
        int ret;
 
-       gen_node = ec_node_from_type(&ec_node_uint_type, id);
-       if (gen_node == NULL)
+       node = ec_node_from_type(&ec_node_uint_type, id);
+       if (node == NULL)
                return NULL;
 
        config = ec_config_dict();
@@ -322,46 +321,46 @@ struct ec_node *ec_node_uint(const char *id, uint64_t min,
        if (ret < 0)
                goto fail;
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL;
        if (ret < 0)
                goto fail;
 
-       return gen_node;
+       return node;
 
 fail:
        ec_config_free(config);
-       ec_node_free(gen_node);
+       ec_node_free(node);
        return NULL;
 }
 
-int ec_node_int_getval(const struct ec_node *gen_node, const char *str,
+int ec_node_int_getval(const struct ec_node *node, const char *str,
                        int64_t *result)
 {
-       struct ec_node_int_uint *node = (struct ec_node_int_uint *)gen_node;
+       struct ec_node_int_uint *priv = ec_node_priv(node);
        int ret;
 
-       ret = ec_node_check_type(gen_node, &ec_node_int_type);
+       ret = ec_node_check_type(node, &ec_node_int_type);
        if (ret < 0)
                return ret;
 
-       if (parse_llint(node, str, result) < 0)
+       if (parse_llint(priv, str, result) < 0)
                return -1;
 
        return 0;
 }
 
-int ec_node_uint_getval(const struct ec_node *gen_node, const char *str,
+int ec_node_uint_getval(const struct ec_node *node, const char *str,
                        uint64_t *result)
 {
-       struct ec_node_int_uint *node = (struct ec_node_int_uint *)gen_node;
+       struct ec_node_int_uint *priv = ec_node_priv(node);
        int ret;
 
-       ret = ec_node_check_type(gen_node, &ec_node_uint_type);
+       ret = ec_node_check_type(node, &ec_node_uint_type);
        if (ret < 0)
                return ret;
 
-       if (parse_ullint(node, str, result) < 0)
+       if (parse_ullint(priv, str, result) < 0)
                return -1;
 
        return 0;
index 0850ae7..91a5fbf 100644 (file)
 EC_LOG_TYPE_REGISTER(node_many);
 
 struct ec_node_many {
-       struct ec_node gen;
        unsigned int min;
        unsigned int max;
        struct ec_node *child;
 };
 
-static int ec_node_many_parse(const struct ec_node *gen_node,
+static int ec_node_many_parse(const struct ec_node *node,
                        struct ec_parse *state,
                        const struct ec_strvec *strvec)
 {
-       struct ec_node_many *node = (struct ec_node_many *)gen_node;
+       struct ec_node_many *priv = ec_node_priv(node);
        struct ec_parse *child_parse;
        struct ec_strvec *childvec = NULL;
        size_t off = 0, count;
        int ret;
 
-       for (count = 0; node->max == 0 || count < node->max; count++) {
+       for (count = 0; priv->max == 0 || count < priv->max; count++) {
                childvec = ec_strvec_ndup(strvec, off,
                        ec_strvec_len(strvec) - off);
                if (childvec == NULL)
                        goto fail;
 
-               ret = ec_node_parse_child(node->child, state, childvec);
+               ret = ec_node_parse_child(priv->child, state, childvec);
                if (ret < 0)
                        goto fail;
 
@@ -67,7 +66,7 @@ static int ec_node_many_parse(const struct ec_node *gen_node,
                off += ret;
        }
 
-       if (count < node->min) {
+       if (count < priv->min) {
                ec_parse_free_children(state);
                return EC_PARSE_NOMATCH;
        }
@@ -80,7 +79,7 @@ fail:
 }
 
 static int
-__ec_node_many_complete(struct ec_node_many *node, unsigned int max,
+__ec_node_many_complete(struct ec_node_many *priv, unsigned int max,
                        struct ec_comp *comp,
                        const struct ec_strvec *strvec)
 {
@@ -90,7 +89,7 @@ __ec_node_many_complete(struct ec_node_many *node, unsigned int max,
        int ret;
 
        /* first, try to complete with the child node */
-       ret = ec_node_complete_child(node->child, comp, strvec);
+       ret = ec_node_complete_child(priv->child, comp, strvec);
        if (ret < 0)
                goto fail;
 
@@ -109,7 +108,7 @@ __ec_node_many_complete(struct ec_node_many *node, unsigned int max,
                if (childvec == NULL)
                        goto fail;
 
-               ret = ec_node_parse_child(node->child, parse, childvec);
+               ret = ec_node_parse_child(priv->child, parse, childvec);
                if (ret < 0)
                        goto fail;
 
@@ -128,7 +127,7 @@ __ec_node_many_complete(struct ec_node_many *node, unsigned int max,
                        goto fail;
                }
 
-               ret = __ec_node_many_complete(node, max, comp, childvec);
+               ret = __ec_node_many_complete(priv, max, comp, childvec);
                ec_parse_del_last_child(parse);
                ec_strvec_free(childvec);
                childvec = NULL;
@@ -145,43 +144,43 @@ fail:
 }
 
 static int
-ec_node_many_complete(const struct ec_node *gen_node,
+ec_node_many_complete(const struct ec_node *node,
                struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_many *node = (struct ec_node_many *)gen_node;
+       struct ec_node_many *priv = ec_node_priv(node);
 
-       return __ec_node_many_complete(node, node->max, comp,
+       return __ec_node_many_complete(priv, priv->max, comp,
                                strvec);
 }
 
-static void ec_node_many_free_priv(struct ec_node *gen_node)
+static void ec_node_many_free_priv(struct ec_node *node)
 {
-       struct ec_node_many *node = (struct ec_node_many *)gen_node;
+       struct ec_node_many *priv = ec_node_priv(node);
 
-       ec_node_free(node->child);
+       ec_node_free(priv->child);
 }
 
 static size_t
-ec_node_many_get_children_count(const struct ec_node *gen_node)
+ec_node_many_get_children_count(const struct ec_node *node)
 {
-       struct ec_node_many *node = (struct ec_node_many *)gen_node;
+       struct ec_node_many *priv = ec_node_priv(node);
 
-       if (node->child)
+       if (priv->child)
                return 1;
        return 0;
 }
 
 static int
-ec_node_many_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_many_get_child(const struct ec_node *node, size_t i,
                struct ec_node **child, unsigned int *refs)
 {
-       struct ec_node_many *node = (struct ec_node_many *)gen_node;
+       struct ec_node_many *priv = ec_node_priv(node);
 
        if (i >= 1)
                return -1;
 
-       *child = node->child;
+       *child = priv->child;
        *refs = 2;
        return 0;
 }
@@ -208,10 +207,10 @@ static const struct ec_config_schema ec_node_many_schema[] = {
        },
 };
 
-static int ec_node_many_set_config(struct ec_node *gen_node,
+static int ec_node_many_set_config(struct ec_node *node,
                                const struct ec_config *config)
 {
-       struct ec_node_many *node = (struct ec_node_many *)gen_node;
+       struct ec_node_many *priv = ec_node_priv(node);
        const struct ec_config *child, *min, *max;
 
        child = ec_config_dict_get(config, "child");
@@ -234,17 +233,17 @@ static int ec_node_many_set_config(struct ec_node *gen_node,
                goto fail;
        }
 
-       if (node->child != NULL)
-               ec_node_free(node->child);
-       node->child = ec_node_clone(child->node);
+       if (priv->child != NULL)
+               ec_node_free(priv->child);
+       priv->child = ec_node_clone(child->node);
        if (min == NULL)
-               node->min = 0;
+               priv->min = 0;
        else
-               node->min = min->u64;
+               priv->min = min->u64;
        if (max == NULL)
-               node->max = 0;
+               priv->max = 0;
        else
-               node->max = max->u64;
+               priv->max = max->u64;
 
        return 0;
 
@@ -267,17 +266,17 @@ static struct ec_node_type ec_node_many_type = {
 EC_NODE_TYPE_REGISTER(ec_node_many_type);
 
 int
-ec_node_many_set_params(struct ec_node *gen_node, struct ec_node *child,
+ec_node_many_set_params(struct ec_node *node, struct ec_node *child,
        unsigned int min, unsigned int max)
 {
        const struct ec_config *cur_config = NULL;
        struct ec_config *config = NULL;
        int ret;
 
-       if (ec_node_check_type(gen_node, &ec_node_many_type) < 0)
+       if (ec_node_check_type(node, &ec_node_many_type) < 0)
                goto fail;
 
-       cur_config = ec_node_get_config(gen_node);
+       cur_config = ec_node_get_config(node);
        if (cur_config == NULL)
                config = ec_config_dict();
        else
@@ -296,7 +295,7 @@ ec_node_many_set_params(struct ec_node *gen_node, struct ec_node *child,
        if (ec_config_dict_set(config, "max", ec_config_u64(max)) < 0)
                goto fail;
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL; /* freed */
        if (ret < 0)
                goto fail;
@@ -312,25 +311,25 @@ fail:
 struct ec_node *ec_node_many(const char *id, struct ec_node *child,
        unsigned int min, unsigned int max)
 {
-       struct ec_node *gen_node = NULL;
+       struct ec_node *node = NULL;
 
        if (child == NULL)
                return NULL;
 
-       gen_node = ec_node_from_type(&ec_node_many_type, id);
-       if (gen_node == NULL)
+       node = ec_node_from_type(&ec_node_many_type, id);
+       if (node == NULL)
                goto fail;
 
-       if (ec_node_many_set_params(gen_node, child, min, max) < 0) {
+       if (ec_node_many_set_params(node, child, min, max) < 0) {
                child = NULL;
                goto fail;
        }
        child = NULL;
 
-       return gen_node;
+       return node;
 
 fail:
-       ec_node_free(gen_node);
+       ec_node_free(node);
        ec_node_free(child);
        return NULL;
 }
index dba9ebf..eadcd4c 100644 (file)
 EC_LOG_TYPE_REGISTER(node_none);
 
 struct ec_node_none {
-       struct ec_node gen;
 };
 
-static int ec_node_none_parse(const struct ec_node *gen_node,
+static int ec_node_none_parse(const struct ec_node *node,
                        struct ec_parse *state,
                        const struct ec_strvec *strvec)
 {
-       (void)gen_node;
+       (void)node;
        (void)state;
        (void)strvec;
 
@@ -34,11 +33,11 @@ static int ec_node_none_parse(const struct ec_node *gen_node,
 }
 
 static int
-ec_node_none_complete(const struct ec_node *gen_node,
+ec_node_none_complete(const struct ec_node *node,
                        struct ec_comp *comp,
                        const struct ec_strvec *strvec)
 {
-       (void)gen_node;
+       (void)node;
        (void)comp;
        (void)strvec;
 
index 989c710..4662a66 100644 (file)
@@ -25,7 +25,6 @@
 EC_LOG_TYPE_REGISTER(node_once);
 
 struct ec_node_once {
-       struct ec_node gen;
        struct ec_node *child;
 };
 
@@ -48,29 +47,29 @@ count_node(struct ec_parse *parse, const struct ec_node *node)
 }
 
 static int
-ec_node_once_parse(const struct ec_node *gen_node,
+ec_node_once_parse(const struct ec_node *node,
                struct ec_parse *state,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_once *node = (struct ec_node_once *)gen_node;
+       struct ec_node_once *priv = ec_node_priv(node);
        unsigned int count;
 
        /* count the number of occurences of the node: if already parsed,
         * do not match
         */
-       count = count_node(ec_parse_get_root(state), node->child);
+       count = count_node(ec_parse_get_root(state), priv->child);
        if (count > 0)
                return EC_PARSE_NOMATCH;
 
-       return ec_node_parse_child(node->child, state, strvec);
+       return ec_node_parse_child(priv->child, state, strvec);
 }
 
 static int
-ec_node_once_complete(const struct ec_node *gen_node,
+ec_node_once_complete(const struct ec_node *node,
                struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_once *node = (struct ec_node_once *)gen_node;
+       struct ec_node_once *priv = ec_node_priv(node);
        struct ec_parse *parse = ec_comp_get_state(comp);
        unsigned int count;
        int ret;
@@ -78,44 +77,44 @@ ec_node_once_complete(const struct ec_node *gen_node,
        /* count the number of occurences of the node: if already parsed,
         * do not match
         */
-       count = count_node(ec_parse_get_root(parse), node->child);
+       count = count_node(ec_parse_get_root(parse), priv->child);
        if (count > 0)
                return 0;
 
-       ret = ec_node_complete_child(node->child, comp, strvec);
+       ret = ec_node_complete_child(priv->child, comp, strvec);
        if (ret < 0)
                return ret;
 
        return 0;
 }
 
-static void ec_node_once_free_priv(struct ec_node *gen_node)
+static void ec_node_once_free_priv(struct ec_node *node)
 {
-       struct ec_node_once *node = (struct ec_node_once *)gen_node;
+       struct ec_node_once *priv = ec_node_priv(node);
 
-       ec_node_free(node->child);
+       ec_node_free(priv->child);
 }
 
 static size_t
-ec_node_once_get_children_count(const struct ec_node *gen_node)
+ec_node_once_get_children_count(const struct ec_node *node)
 {
-       struct ec_node_once *node = (struct ec_node_once *)gen_node;
+       struct ec_node_once *priv = ec_node_priv(node);
 
-       if (node->child)
+       if (priv->child)
                return 1;
        return 0;
 }
 
 static int
-ec_node_once_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_once_get_child(const struct ec_node *node, size_t i,
                struct ec_node **child, unsigned int *refs)
 {
-       struct ec_node_once *node = (struct ec_node_once *)gen_node;
+       struct ec_node_once *priv = ec_node_priv(node);
 
        if (i >= 1)
                return -1;
 
-       *child = node->child;
+       *child = priv->child;
        *refs = 2;
        return 0;
 }
@@ -131,10 +130,10 @@ static const struct ec_config_schema ec_node_once_schema[] = {
        },
 };
 
-static int ec_node_once_set_config(struct ec_node *gen_node,
+static int ec_node_once_set_config(struct ec_node *node,
                                const struct ec_config *config)
 {
-       struct ec_node_once *node = (struct ec_node_once *)gen_node;
+       struct ec_node_once *priv = ec_node_priv(node);
        const struct ec_config *child;
 
        child = ec_config_dict_get(config, "child");
@@ -145,9 +144,9 @@ static int ec_node_once_set_config(struct ec_node *gen_node,
                goto fail;
        }
 
-       if (node->child != NULL)
-               ec_node_free(node->child);
-       node->child = ec_node_clone(child->node);
+       if (priv->child != NULL)
+               ec_node_free(priv->child);
+       priv->child = ec_node_clone(child->node);
 
        return 0;
 
@@ -170,16 +169,16 @@ static struct ec_node_type ec_node_once_type = {
 EC_NODE_TYPE_REGISTER(ec_node_once_type);
 
 int
-ec_node_once_set_child(struct ec_node *gen_node, struct ec_node *child)
+ec_node_once_set_child(struct ec_node *node, struct ec_node *child)
 {
        const struct ec_config *cur_config = NULL;
        struct ec_config *config = NULL;
        int ret;
 
-       if (ec_node_check_type(gen_node, &ec_node_once_type) < 0)
+       if (ec_node_check_type(node, &ec_node_once_type) < 0)
                goto fail;
 
-       cur_config = ec_node_get_config(gen_node);
+       cur_config = ec_node_get_config(node);
        if (cur_config == NULL)
                config = ec_config_dict();
        else
@@ -193,7 +192,7 @@ ec_node_once_set_child(struct ec_node *gen_node, struct ec_node *child)
        }
        child = NULL; /* freed */
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL; /* freed */
        if (ret < 0)
                goto fail;
@@ -208,19 +207,19 @@ fail:
 
 struct ec_node *ec_node_once(const char *id, struct ec_node *child)
 {
-       struct ec_node *gen_node = NULL;
+       struct ec_node *node = NULL;
 
        if (child == NULL)
                return NULL;
 
-       gen_node = ec_node_from_type(&ec_node_once_type, id);
-       if (gen_node == NULL)
+       node = ec_node_from_type(&ec_node_once_type, id);
+       if (node == NULL)
                goto fail;
 
-       ec_node_once_set_child(gen_node, child);
+       ec_node_once_set_child(node, child);
        child = NULL;
 
-       return gen_node;
+       return node;
 
 fail:
        ec_node_free(child);
index 4b26001..f2f8977 100644 (file)
 EC_LOG_TYPE_REGISTER(node_option);
 
 struct ec_node_option {
-       struct ec_node gen;
        struct ec_node *child;
 };
 
 static int
-ec_node_option_parse(const struct ec_node *gen_node,
+ec_node_option_parse(const struct ec_node *node,
                struct ec_parse *state,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_option *node = (struct ec_node_option *)gen_node;
+       struct ec_node_option *priv = ec_node_priv(node);
        int ret;
 
-       ret = ec_node_parse_child(node->child, state, strvec);
+       ret = ec_node_parse_child(priv->child, state, strvec);
        if (ret < 0)
                return ret;
 
@@ -46,42 +45,42 @@ ec_node_option_parse(const struct ec_node *gen_node,
 }
 
 static int
-ec_node_option_complete(const struct ec_node *gen_node,
+ec_node_option_complete(const struct ec_node *node,
                        struct ec_comp *comp,
                        const struct ec_strvec *strvec)
 {
-       struct ec_node_option *node = (struct ec_node_option *)gen_node;
+       struct ec_node_option *priv = ec_node_priv(node);
 
-       return ec_node_complete_child(node->child, comp, strvec);
+       return ec_node_complete_child(priv->child, comp, strvec);
 }
 
-static void ec_node_option_free_priv(struct ec_node *gen_node)
+static void ec_node_option_free_priv(struct ec_node *node)
 {
-       struct ec_node_option *node = (struct ec_node_option *)gen_node;
+       struct ec_node_option *priv = ec_node_priv(node);
 
-       ec_node_free(node->child);
+       ec_node_free(priv->child);
 }
 
 static size_t
-ec_node_option_get_children_count(const struct ec_node *gen_node)
+ec_node_option_get_children_count(const struct ec_node *node)
 {
-       struct ec_node_option *node = (struct ec_node_option *)gen_node;
+       struct ec_node_option *priv = ec_node_priv(node);
 
-       if (node->child)
+       if (priv->child)
                return 1;
        return 0;
 }
 
 static int
-ec_node_option_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_option_get_child(const struct ec_node *node, size_t i,
        struct ec_node **child, unsigned int *refs)
 {
-       struct ec_node_option *node = (struct ec_node_option *)gen_node;
+       struct ec_node_option *priv = ec_node_priv(node);
 
        if (i >= 1)
                return -1;
 
-       *child = node->child;
+       *child = priv->child;
        *refs = 2;
        return 0;
 }
@@ -97,10 +96,10 @@ static const struct ec_config_schema ec_node_option_schema[] = {
        },
 };
 
-static int ec_node_option_set_config(struct ec_node *gen_node,
+static int ec_node_option_set_config(struct ec_node *node,
                                const struct ec_config *config)
 {
-       struct ec_node_option *node = (struct ec_node_option *)gen_node;
+       struct ec_node_option *priv = ec_node_priv(node);
        const struct ec_config *child;
 
        child = ec_config_dict_get(config, "child");
@@ -111,9 +110,9 @@ static int ec_node_option_set_config(struct ec_node *gen_node,
                goto fail;
        }
 
-       if (node->child != NULL)
-               ec_node_free(node->child);
-       node->child = ec_node_clone(child->node);
+       if (priv->child != NULL)
+               ec_node_free(priv->child);
+       priv->child = ec_node_clone(child->node);
 
        return 0;
 
@@ -136,16 +135,16 @@ static struct ec_node_type ec_node_option_type = {
 EC_NODE_TYPE_REGISTER(ec_node_option_type);
 
 int
-ec_node_option_set_child(struct ec_node *gen_node, struct ec_node *child)
+ec_node_option_set_child(struct ec_node *node, struct ec_node *child)
 {
        const struct ec_config *cur_config = NULL;
        struct ec_config *config = NULL;
        int ret;
 
-       if (ec_node_check_type(gen_node, &ec_node_option_type) < 0)
+       if (ec_node_check_type(node, &ec_node_option_type) < 0)
                goto fail;
 
-       cur_config = ec_node_get_config(gen_node);
+       cur_config = ec_node_get_config(node);
        if (cur_config == NULL)
                config = ec_config_dict();
        else
@@ -159,7 +158,7 @@ ec_node_option_set_child(struct ec_node *gen_node, struct ec_node *child)
        }
        child = NULL; /* freed */
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL; /* freed */
        if (ret < 0)
                goto fail;
@@ -174,19 +173,19 @@ fail:
 
 struct ec_node *ec_node_option(const char *id, struct ec_node *child)
 {
-       struct ec_node *gen_node = NULL;
+       struct ec_node *node = NULL;
 
        if (child == NULL)
                goto fail;
 
-       gen_node = ec_node_from_type(&ec_node_option_type, id);
-       if (gen_node == NULL)
+       node = ec_node_from_type(&ec_node_option_type, id);
+       if (node == NULL)
                goto fail;
 
-       ec_node_option_set_child(gen_node, child);
+       ec_node_option_set_child(node, child);
        child = NULL;
 
-       return gen_node;
+       return node;
 
 fail:
        ec_node_free(child);
index 2bf8fc7..125b70b 100644 (file)
 EC_LOG_TYPE_REGISTER(node_or);
 
 struct ec_node_or {
-       struct ec_node gen;
        struct ec_node **table;
        size_t len;
 };
 
 static int
-ec_node_or_parse(const struct ec_node *gen_node,
+ec_node_or_parse(const struct ec_node *node,
                struct ec_parse *state,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_or *node = (struct ec_node_or *)gen_node;
+       struct ec_node_or *priv = ec_node_priv(node);
        unsigned int i;
        int ret;
 
-       for (i = 0; i < node->len; i++) {
-               ret = ec_node_parse_child(node->table[i], state, strvec);
+       for (i = 0; i < priv->len; i++) {
+               ret = ec_node_parse_child(priv->table[i], state, strvec);
                if (ret == EC_PARSE_NOMATCH)
                        continue;
                return ret;
@@ -50,16 +49,16 @@ ec_node_or_parse(const struct ec_node *gen_node,
 }
 
 static int
-ec_node_or_complete(const struct ec_node *gen_node,
+ec_node_or_complete(const struct ec_node *node,
                struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_or *node = (struct ec_node_or *)gen_node;
+       struct ec_node_or *priv = ec_node_priv(node);
        int ret;
        size_t n;
 
-       for (n = 0; n < node->len; n++) {
-               ret = ec_node_complete_child(node->table[n],
+       for (n = 0; n < priv->len; n++) {
+               ret = ec_node_complete_child(priv->table[n],
                                        comp, strvec);
                if (ret < 0)
                        return ret;
@@ -68,16 +67,16 @@ ec_node_or_complete(const struct ec_node *gen_node,
        return 0;
 }
 
-static void ec_node_or_free_priv(struct ec_node *gen_node)
+static void ec_node_or_free_priv(struct ec_node *node)
 {
-       struct ec_node_or *node = (struct ec_node_or *)gen_node;
+       struct ec_node_or *priv = ec_node_priv(node);
        size_t i;
 
-       for (i = 0; i < node->len; i++)
-               ec_node_free(node->table[i]);
-       ec_free(node->table);
-       node->table = NULL;
-       node->len = 0;
+       for (i = 0; i < priv->len; i++)
+               ec_node_free(priv->table[i]);
+       ec_free(priv->table);
+       priv->table = NULL;
+       priv->len = 0;
 }
 
 static const struct ec_config_schema ec_node_or_subschema[] = {
@@ -103,10 +102,10 @@ static const struct ec_config_schema ec_node_or_schema[] = {
        },
 };
 
-static int ec_node_or_set_config(struct ec_node *gen_node,
+static int ec_node_or_set_config(struct ec_node *node,
                                const struct ec_config *config)
 {
-       struct ec_node_or *node = (struct ec_node_or *)gen_node;
+       struct ec_node_or *priv = ec_node_priv(node);
        struct ec_node **table = NULL;
        size_t i, len = 0;
 
@@ -115,11 +114,11 @@ static int ec_node_or_set_config(struct ec_node *gen_node,
        if (table == NULL)
                goto fail;
 
-       for (i = 0; i < node->len; i++)
-               ec_node_free(node->table[i]);
-       ec_free(node->table);
-       node->table = table;
-       node->len = len;
+       for (i = 0; i < priv->len; i++)
+               ec_node_free(priv->table[i]);
+       ec_free(priv->table);
+       priv->table = table;
+       priv->len = len;
 
        return 0;
 
@@ -131,24 +130,24 @@ fail:
 }
 
 static size_t
-ec_node_or_get_children_count(const struct ec_node *gen_node)
+ec_node_or_get_children_count(const struct ec_node *node)
 {
-       struct ec_node_or *node = (struct ec_node_or *)gen_node;
-       return node->len;
+       struct ec_node_or *priv = ec_node_priv(node);
+       return priv->len;
 }
 
 static int
-ec_node_or_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_or_get_child(const struct ec_node *node, size_t i,
                struct ec_node **child, unsigned int *refs)
 {
-       struct ec_node_or *node = (struct ec_node_or *)gen_node;
+       struct ec_node_or *priv = ec_node_priv(node);
 
-       if (i >= node->len)
+       if (i >= priv->len)
                return -1;
 
-       *child = node->table[i];
+       *child = priv->table[i];
        /* each child node is referenced twice: once in the config and
-        * once in the node->table[] */
+        * once in the priv->table[] */
        *refs = 2;
        return 0;
 }
@@ -167,9 +166,8 @@ static struct ec_node_type ec_node_or_type = {
 
 EC_NODE_TYPE_REGISTER(ec_node_or_type);
 
-int ec_node_or_add(struct ec_node *gen_node, struct ec_node *child)
+int ec_node_or_add(struct ec_node *node, struct ec_node *child)
 {
-       struct ec_node_or *node = (struct ec_node_or *)gen_node;
        const struct ec_config *cur_config = NULL;
        struct ec_config *config = NULL, *children;
        int ret;
@@ -178,10 +176,10 @@ int ec_node_or_add(struct ec_node *gen_node, struct ec_node *child)
 
        /* XXX factorize this code in a helper */
 
-       if (ec_node_check_type(gen_node, &ec_node_or_type) < 0)
+       if (ec_node_check_type(node, &ec_node_or_type) < 0)
                goto fail;
 
-       cur_config = ec_node_get_config(gen_node);
+       cur_config = ec_node_get_config(node);
        if (cur_config == NULL)
                config = ec_config_dict();
        else
@@ -204,7 +202,7 @@ int ec_node_or_add(struct ec_node *gen_node, struct ec_node *child)
                goto fail;
        }
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL; /* freed */
        if (ret < 0)
                goto fail;
@@ -220,7 +218,7 @@ fail:
 struct ec_node *__ec_node_or(const char *id, ...)
 {
        struct ec_config *config = NULL, *children = NULL;
-       struct ec_node *gen_node = NULL;
+       struct ec_node *node = NULL;
        struct ec_node *child;
        va_list ap;
        int ret;
@@ -228,8 +226,8 @@ struct ec_node *__ec_node_or(const char *id, ...)
        va_start(ap, id);
        child = va_arg(ap, struct ec_node *);
 
-       gen_node = ec_node_from_type(&ec_node_or_type, id);
-       if (gen_node == NULL)
+       node = ec_node_from_type(&ec_node_or_type, id);
+       if (node == NULL)
                goto fail_free_children;
 
        config = ec_config_dict();
@@ -256,20 +254,20 @@ struct ec_node *__ec_node_or(const char *id, ...)
        }
        children = NULL;
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL; /* freed */
        if (ret < 0)
                goto fail;
 
        va_end(ap);
 
-       return gen_node;
+       return node;
 
 fail_free_children:
        for (; child != EC_NODE_ENDLIST; child = va_arg(ap, struct ec_node *))
                ec_node_free(child);
 fail:
-       ec_node_free(gen_node); /* will also free added children */
+       ec_node_free(node); /* will also free added children */
        ec_config_free(children);
        ec_config_free(config);
        va_end(ap);
index 69f352c..9e6678c 100644 (file)
 EC_LOG_TYPE_REGISTER(node_re);
 
 struct ec_node_re {
-       struct ec_node gen;
        char *re_str;
        regex_t re;
 };
 
 static int
-ec_node_re_parse(const struct ec_node *gen_node,
+ec_node_re_parse(const struct ec_node *node,
                struct ec_parse *state,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_re *node = (struct ec_node_re *)gen_node;
+       struct ec_node_re *priv = ec_node_priv(node);
        const char *str;
        regmatch_t pos;
 
@@ -41,7 +40,7 @@ ec_node_re_parse(const struct ec_node *gen_node,
                return EC_PARSE_NOMATCH;
 
        str = ec_strvec_val(strvec, 0);
-       if (regexec(&node->re, str, 1, &pos, 0) != 0)
+       if (regexec(&priv->re, str, 1, &pos, 0) != 0)
                return EC_PARSE_NOMATCH;
        if (pos.rm_so != 0 || pos.rm_eo != (int)strlen(str))
                return EC_PARSE_NOMATCH;
@@ -49,13 +48,13 @@ ec_node_re_parse(const struct ec_node *gen_node,
        return 1;
 }
 
-static void ec_node_re_free_priv(struct ec_node *gen_node)
+static void ec_node_re_free_priv(struct ec_node *node)
 {
-       struct ec_node_re *node = (struct ec_node_re *)gen_node;
+       struct ec_node_re *priv = ec_node_priv(node);
 
-       if (node->re_str != NULL) {
-               ec_free(node->re_str);
-               regfree(&node->re);
+       if (priv->re_str != NULL) {
+               ec_free(priv->re_str);
+               regfree(&priv->re);
        }
 }
 
@@ -70,10 +69,10 @@ static const struct ec_config_schema ec_node_re_schema[] = {
        },
 };
 
-static int ec_node_re_set_config(struct ec_node *gen_node,
+static int ec_node_re_set_config(struct ec_node *node,
                                const struct ec_config *config)
 {
-       struct ec_node_re *node = (struct ec_node_re *)gen_node;
+       struct ec_node_re *priv = ec_node_priv(node);
        const struct ec_config *value = NULL;
        char *s = NULL;
        regex_t re;
@@ -98,12 +97,12 @@ static int ec_node_re_set_config(struct ec_node *gen_node,
                goto fail;
        }
 
-       if (node->re_str != NULL) {
-               ec_free(node->re_str);
-               regfree(&node->re);
+       if (priv->re_str != NULL) {
+               ec_free(priv->re_str);
+               regfree(&priv->re);
        }
-       node->re_str = s;
-       node->re = re;
+       priv->re_str = s;
+       priv->re = re;
 
        return 0;
 
@@ -124,14 +123,14 @@ static struct ec_node_type ec_node_re_type = {
 
 EC_NODE_TYPE_REGISTER(ec_node_re_type);
 
-int ec_node_re_set_regexp(struct ec_node *gen_node, const char *str)
+int ec_node_re_set_regexp(struct ec_node *node, const char *str)
 {
        struct ec_config *config = NULL;
        int ret;
 
        EC_CHECK_ARG(str != NULL, -1, EINVAL);
 
-       if (ec_node_check_type(gen_node, &ec_node_re_type) < 0)
+       if (ec_node_check_type(node, &ec_node_re_type) < 0)
                goto fail;
 
        config = ec_config_dict();
@@ -142,7 +141,7 @@ int ec_node_re_set_regexp(struct ec_node *gen_node, const char *str)
        if (ret < 0)
                goto fail;
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL;
        if (ret < 0)
                goto fail;
@@ -156,19 +155,19 @@ fail:
 
 struct ec_node *ec_node_re(const char *id, const char *re_str)
 {
-       struct ec_node *gen_node = NULL;
+       struct ec_node *node = NULL;
 
-       gen_node = ec_node_from_type(&ec_node_re_type, id);
-       if (gen_node == NULL)
+       node = ec_node_from_type(&ec_node_re_type, id);
+       if (node == NULL)
                goto fail;
 
-       if (ec_node_re_set_regexp(gen_node, re_str) < 0)
+       if (ec_node_re_set_regexp(node, re_str) < 0)
                goto fail;
 
-       return gen_node;
+       return node;
 
 fail:
-       ec_node_free(gen_node);
+       ec_node_free(node);
        return NULL;
 }
 
index a007aba..cff1c8c 100644 (file)
@@ -34,7 +34,6 @@ struct regexp_pattern {
 };
 
 struct ec_node_re_lex {
-       struct ec_node gen;
        struct ec_node *child;
        struct regexp_pattern *table;
        size_t len;
@@ -116,17 +115,17 @@ fail:
 }
 
 static int
-ec_node_re_lex_parse(const struct ec_node *gen_node,
+ec_node_re_lex_parse(const struct ec_node *node,
                struct ec_parse *state,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_re_lex *node = (struct ec_node_re_lex *)gen_node;
+       struct ec_node_re_lex *priv = ec_node_priv(node);
        struct ec_strvec *new_vec = NULL;
        struct ec_parse *child_parse;
        const char *str;
        int ret;
 
-       if (node->child == NULL) {
+       if (priv->child == NULL) {
                errno = EINVAL;
                goto fail;
        }
@@ -135,12 +134,12 @@ ec_node_re_lex_parse(const struct ec_node *gen_node,
                new_vec = ec_strvec();
        } else {
                str = ec_strvec_val(strvec, 0);
-               new_vec = tokenize(node->table, node->len, str);
+               new_vec = tokenize(priv->table, priv->len, str);
        }
        if (new_vec == NULL)
                goto fail;
 
-       ret = ec_node_parse_child(node->child, state, new_vec);
+       ret = ec_node_parse_child(priv->child, state, new_vec);
        if (ret < 0)
                goto fail;
 
@@ -163,41 +162,41 @@ ec_node_re_lex_parse(const struct ec_node *gen_node,
        return -1;
 }
 
-static void ec_node_re_lex_free_priv(struct ec_node *gen_node)
+static void ec_node_re_lex_free_priv(struct ec_node *node)
 {
-       struct ec_node_re_lex *node = (struct ec_node_re_lex *)gen_node;
+       struct ec_node_re_lex *priv = ec_node_priv(node);
        unsigned int i;
 
-       ec_node_free(node->child);
-       for (i = 0; i < node->len; i++) {
-               ec_free(node->table[i].pattern);
-               ec_free(node->table[i].attr_name);
-               regfree(&node->table[i].r);
+       ec_node_free(priv->child);
+       for (i = 0; i < priv->len; i++) {
+               ec_free(priv->table[i].pattern);
+               ec_free(priv->table[i].attr_name);
+               regfree(&priv->table[i].r);
        }
 
-       ec_free(node->table);
+       ec_free(priv->table);
 }
 
 static size_t
-ec_node_re_lex_get_children_count(const struct ec_node *gen_node)
+ec_node_re_lex_get_children_count(const struct ec_node *node)
 {
-       struct ec_node_re_lex *node = (struct ec_node_re_lex *)gen_node;
+       struct ec_node_re_lex *priv = ec_node_priv(node);
 
-       if (node->child)
+       if (priv->child)
                return 1;
        return 0;
 }
 
 static int
-ec_node_re_lex_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_re_lex_get_child(const struct ec_node *node, size_t i,
                        struct ec_node **child, unsigned int *refs)
 {
-       struct ec_node_re_lex *node = (struct ec_node_re_lex *)gen_node;
+       struct ec_node_re_lex *priv = ec_node_priv(node);
 
        if (i >= 1)
                return -1;
 
-       *child = node->child;
+       *child = priv->child;
        *refs = 2;
        return 0;
 }
@@ -252,10 +251,10 @@ static const struct ec_config_schema ec_node_re_lex_schema[] = {
        },
 };
 
-static int ec_node_re_lex_set_config(struct ec_node *gen_node,
+static int ec_node_re_lex_set_config(struct ec_node *node,
                                const struct ec_config *config)
 {
-       struct ec_node_re_lex *node = (struct ec_node_re_lex *)gen_node;
+       struct ec_node_re_lex *priv = ec_node_priv(node);
        struct regexp_pattern *table = NULL;
        const struct ec_config *patterns, *child, *elt, *pattern, *keep, *attr;
        char *pattern_str = NULL, *attr_name = NULL;
@@ -340,17 +339,17 @@ static int ec_node_re_lex_set_config(struct ec_node *gen_node,
                }
        }
 
-       if (node->child != NULL)
-               ec_node_free(node->child);
-       node->child = ec_node_clone(child->node);
-       for (i = 0; i < (ssize_t)node->len; i++) {
-               ec_free(node->table[i].pattern);
-               ec_free(node->table[i].attr_name);
-               regfree(&node->table[i].r);
+       if (priv->child != NULL)
+               ec_node_free(priv->child);
+       priv->child = ec_node_clone(child->node);
+       for (i = 0; i < (ssize_t)priv->len; i++) {
+               ec_free(priv->table[i].pattern);
+               ec_free(priv->table[i].attr_name);
+               regfree(&priv->table[i].r);
        }
-       ec_free(node->table);
-       node->table = table;
-       node->len = n;
+       ec_free(priv->table);
+       priv->table = table;
+       priv->len = n;
 
        return 0;
 
@@ -382,14 +381,14 @@ static struct ec_node_type ec_node_re_lex_type = {
 
 EC_NODE_TYPE_REGISTER(ec_node_re_lex_type);
 
-int ec_node_re_lex_add(struct ec_node *gen_node, const char *pattern, int keep,
+int ec_node_re_lex_add(struct ec_node *node, const char *pattern, int keep,
        const char *attr_name)
 {
        const struct ec_config *cur_config = NULL;
        struct ec_config *config = NULL, *patterns = NULL, *elt = NULL;
        int ret;
 
-       if (ec_node_check_type(gen_node, &ec_node_re_lex_type) < 0)
+       if (ec_node_check_type(node, &ec_node_re_lex_type) < 0)
                goto fail;
 
        elt = ec_config_dict();
@@ -405,7 +404,7 @@ int ec_node_re_lex_add(struct ec_node *gen_node, const char *pattern, int keep,
                        goto fail;
        }
 
-       cur_config = ec_node_get_config(gen_node);
+       cur_config = ec_node_get_config(node);
        if (cur_config == NULL)
                config = ec_config_dict();
        else
@@ -429,7 +428,7 @@ int ec_node_re_lex_add(struct ec_node *gen_node, const char *pattern, int keep,
        }
        elt = NULL;
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL; /* freed */
        if (ret < 0)
                goto fail;
@@ -443,16 +442,16 @@ fail:
 }
 
 static int
-ec_node_re_lex_set_child(struct ec_node *gen_node, struct ec_node *child)
+ec_node_re_lex_set_child(struct ec_node *node, struct ec_node *child)
 {
        const struct ec_config *cur_config = NULL;
        struct ec_config *config = NULL;
        int ret;
 
-       if (ec_node_check_type(gen_node, &ec_node_re_lex_type) < 0)
+       if (ec_node_check_type(node, &ec_node_re_lex_type) < 0)
                goto fail;
 
-       cur_config = ec_node_get_config(gen_node);
+       cur_config = ec_node_get_config(node);
        if (cur_config == NULL)
                config = ec_config_dict();
        else
@@ -466,7 +465,7 @@ ec_node_re_lex_set_child(struct ec_node *gen_node, struct ec_node *child)
        }
        child = NULL; /* freed */
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL; /* freed */
        if (ret < 0)
                goto fail;
@@ -481,24 +480,24 @@ fail:
 
 struct ec_node *ec_node_re_lex(const char *id, struct ec_node *child)
 {
-       struct ec_node *gen_node = NULL;
+       struct ec_node *node = NULL;
 
        if (child == NULL)
                return NULL;
 
-       gen_node = ec_node_from_type(&ec_node_re_lex_type, id);
-       if (gen_node == NULL)
+       node = ec_node_from_type(&ec_node_re_lex_type, id);
+       if (node == NULL)
                goto fail;
 
-       if (ec_node_re_lex_set_child(gen_node, child) < 0) {
+       if (ec_node_re_lex_set_child(node, child) < 0) {
                child = NULL; /* freed */
                goto fail;
        }
 
-       return gen_node;
+       return node;
 
 fail:
-       ec_node_free(gen_node);
+       ec_node_free(node);
        ec_node_free(child);
        return NULL;
 }
index ff0c5de..6b1a2cd 100644 (file)
 EC_LOG_TYPE_REGISTER(node_seq);
 
 struct ec_node_seq {
-       struct ec_node gen;
        struct ec_node **table;
        size_t len;
 };
 
 static int
-ec_node_seq_parse(const struct ec_node *gen_node,
+ec_node_seq_parse(const struct ec_node *node,
                struct ec_parse *state,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_seq *node = (struct ec_node_seq *)gen_node;
+       struct ec_node_seq *priv = ec_node_priv(node);
        struct ec_strvec *childvec = NULL;
        size_t len = 0;
        unsigned int i;
        int ret;
 
-       for (i = 0; i < node->len; i++) {
+       for (i = 0; i < priv->len; i++) {
                childvec = ec_strvec_ndup(strvec, len,
                        ec_strvec_len(strvec) - len);
                if (childvec == NULL)
                        goto fail;
 
-               ret = ec_node_parse_child(node->table[i], state, childvec);
+               ret = ec_node_parse_child(priv->table[i], state, childvec);
                if (ret < 0)
                        goto fail;
 
@@ -146,26 +145,26 @@ fail:
 }
 
 static int
-ec_node_seq_complete(const struct ec_node *gen_node,
+ec_node_seq_complete(const struct ec_node *node,
                struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_seq *node = (struct ec_node_seq *)gen_node;
+       struct ec_node_seq *priv = ec_node_priv(node);
 
-       return __ec_node_seq_complete(node->table, node->len, comp,
+       return __ec_node_seq_complete(priv->table, priv->len, comp,
                                strvec);
 }
 
-static void ec_node_seq_free_priv(struct ec_node *gen_node)
+static void ec_node_seq_free_priv(struct ec_node *node)
 {
-       struct ec_node_seq *node = (struct ec_node_seq *)gen_node;
+       struct ec_node_seq *priv = ec_node_priv(node);
        size_t i;
 
-       for (i = 0; i < node->len; i++)
-               ec_node_free(node->table[i]);
-       ec_free(node->table);
-       node->table = NULL;
-       node->len = 0;
+       for (i = 0; i < priv->len; i++)
+               ec_node_free(priv->table[i]);
+       ec_free(priv->table);
+       priv->table = NULL;
+       priv->len = 0;
 }
 
 static const struct ec_config_schema ec_node_seq_subschema[] = {
@@ -190,10 +189,10 @@ static const struct ec_config_schema ec_node_seq_schema[] = {
        },
 };
 
-static int ec_node_seq_set_config(struct ec_node *gen_node,
+static int ec_node_seq_set_config(struct ec_node *node,
                                const struct ec_config *config)
 {
-       struct ec_node_seq *node = (struct ec_node_seq *)gen_node;
+       struct ec_node_seq *priv = ec_node_priv(node);
        struct ec_node **table = NULL;
        size_t i, len = 0;
 
@@ -202,11 +201,11 @@ static int ec_node_seq_set_config(struct ec_node *gen_node,
        if (table == NULL)
                goto fail;
 
-       for (i = 0; i < node->len; i++)
-               ec_node_free(node->table[i]);
-       ec_free(node->table);
-       node->table = table;
-       node->len = len;
+       for (i = 0; i < priv->len; i++)
+               ec_node_free(priv->table[i]);
+       ec_free(priv->table);
+       priv->table = table;
+       priv->len = len;
 
        return 0;
 
@@ -218,24 +217,24 @@ fail:
 }
 
 static size_t
-ec_node_seq_get_children_count(const struct ec_node *gen_node)
+ec_node_seq_get_children_count(const struct ec_node *node)
 {
-       struct ec_node_seq *node = (struct ec_node_seq *)gen_node;
-       return node->len;
+       struct ec_node_seq *priv = ec_node_priv(node);
+       return priv->len;
 }
 
 static int
-ec_node_seq_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_seq_get_child(const struct ec_node *node, size_t i,
                struct ec_node **child, unsigned int *refs)
 {
-       struct ec_node_seq *node = (struct ec_node_seq *)gen_node;
+       struct ec_node_seq *priv = ec_node_priv(node);
 
-       if (i >= node->len)
+       if (i >= priv->len)
                return -1;
 
-       *child = node->table[i];
+       *child = priv->table[i];
        /* each child node is referenced twice: once in the config and
-        * once in the node->table[] */
+        * once in the priv->table[] */
        *refs = 2;
        return 0;
 }
@@ -254,9 +253,8 @@ static struct ec_node_type ec_node_seq_type = {
 
 EC_NODE_TYPE_REGISTER(ec_node_seq_type);
 
-int ec_node_seq_add(struct ec_node *gen_node, struct ec_node *child)
+int ec_node_seq_add(struct ec_node *node, struct ec_node *child)
 {
-       struct ec_node_seq *node = (struct ec_node_seq *)gen_node;
        const struct ec_config *cur_config = NULL;
        struct ec_config *config = NULL, *children;
        int ret;
@@ -265,10 +263,10 @@ int ec_node_seq_add(struct ec_node *gen_node, struct ec_node *child)
 
        /* XXX factorize this code in a helper */
 
-       if (ec_node_check_type(gen_node, &ec_node_seq_type) < 0)
+       if (ec_node_check_type(node, &ec_node_seq_type) < 0)
                goto fail;
 
-       cur_config = ec_node_get_config(gen_node);
+       cur_config = ec_node_get_config(node);
        if (cur_config == NULL)
                config = ec_config_dict();
        else
@@ -291,7 +289,7 @@ int ec_node_seq_add(struct ec_node *gen_node, struct ec_node *child)
                goto fail;
        }
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL; /* freed */
        if (ret < 0)
                goto fail;
@@ -307,7 +305,7 @@ fail:
 struct ec_node *__ec_node_seq(const char *id, ...)
 {
        struct ec_config *config = NULL, *children = NULL;
-       struct ec_node *gen_node = NULL;
+       struct ec_node *node = NULL;
        struct ec_node *child;
        va_list ap;
        int ret;
@@ -315,8 +313,8 @@ struct ec_node *__ec_node_seq(const char *id, ...)
        va_start(ap, id);
        child = va_arg(ap, struct ec_node *);
 
-       gen_node = ec_node_from_type(&ec_node_seq_type, id);
-       if (gen_node == NULL)
+       node = ec_node_from_type(&ec_node_seq_type, id);
+       if (node == NULL)
                goto fail_free_children;
 
        config = ec_config_dict();
@@ -343,20 +341,20 @@ struct ec_node *__ec_node_seq(const char *id, ...)
        }
        children = NULL;
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL; /* freed */
        if (ret < 0)
                goto fail;
 
        va_end(ap);
 
-       return gen_node;
+       return node;
 
 fail_free_children:
        for (; child != EC_NODE_ENDLIST; child = va_arg(ap, struct ec_node *))
                ec_node_free(child);
 fail:
-       ec_node_free(gen_node); /* will also free added children */
+       ec_node_free(node); /* will also free added children */
        ec_config_free(children);
        ec_config_free(config);
        va_end(ap);
index e27f21b..9bd06ce 100644 (file)
@@ -26,7 +26,6 @@
 EC_LOG_TYPE_REGISTER(node_sh_lex);
 
 struct ec_node_sh_lex {
-       struct ec_node gen;
        struct ec_node *child;
 };
 
@@ -213,11 +212,11 @@ static struct ec_strvec *tokenize(const char *str, int completion,
 }
 
 static int
-ec_node_sh_lex_parse(const struct ec_node *gen_node,
+ec_node_sh_lex_parse(const struct ec_node *node,
                struct ec_parse *state,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_sh_lex *node = (struct ec_node_sh_lex *)gen_node;
+       struct ec_node_sh_lex *priv = ec_node_priv(node);
        struct ec_strvec *new_vec = NULL;
        struct ec_parse *child_parse;
        const char *str;
@@ -234,7 +233,7 @@ ec_node_sh_lex_parse(const struct ec_node *gen_node,
        if (new_vec == NULL)
                goto fail;
 
-       ret = ec_node_parse_child(node->child, state, new_vec);
+       ret = ec_node_parse_child(priv->child, state, new_vec);
        if (ret < 0)
                goto fail;
 
@@ -258,11 +257,11 @@ ec_node_sh_lex_parse(const struct ec_node *gen_node,
 }
 
 static int
-ec_node_sh_lex_complete(const struct ec_node *gen_node,
+ec_node_sh_lex_complete(const struct ec_node *node,
                        struct ec_comp *comp,
                        const struct ec_strvec *strvec)
 {
-       struct ec_node_sh_lex *node = (struct ec_node_sh_lex *)gen_node;
+       struct ec_node_sh_lex *priv = ec_node_priv(node);
        struct ec_comp *tmp_comp = NULL;
        struct ec_strvec *new_vec = NULL;
        struct ec_comp_iter *iter = NULL;
@@ -286,7 +285,7 @@ ec_node_sh_lex_complete(const struct ec_node *gen_node,
        if (tmp_comp == NULL)
                goto fail;
 
-       ret = ec_node_complete_child(node->child, tmp_comp, new_vec);
+       ret = ec_node_complete_child(priv->child, tmp_comp, new_vec);
        if (ret < 0)
                goto fail;
 
@@ -336,34 +335,34 @@ ec_node_sh_lex_complete(const struct ec_node *gen_node,
        return -1;
 }
 
-static void ec_node_sh_lex_free_priv(struct ec_node *gen_node)
+static void ec_node_sh_lex_free_priv(struct ec_node *node)
 {
-       struct ec_node_sh_lex *node = (struct ec_node_sh_lex *)gen_node;
+       struct ec_node_sh_lex *priv = ec_node_priv(node);
 
-       ec_node_free(node->child);
+       ec_node_free(priv->child);
 }
 
 static size_t
-ec_node_sh_lex_get_children_count(const struct ec_node *gen_node)
+ec_node_sh_lex_get_children_count(const struct ec_node *node)
 {
-       struct ec_node_sh_lex *node = (struct ec_node_sh_lex *)gen_node;
+       struct ec_node_sh_lex *priv = ec_node_priv(node);
 
-       if (node->child)
+       if (priv->child)
                return 1;
        return 0;
 }
 
 static int
-ec_node_sh_lex_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_sh_lex_get_child(const struct ec_node *node, size_t i,
        struct ec_node **child, unsigned int *refs)
 {
-       struct ec_node_sh_lex *node = (struct ec_node_sh_lex *)gen_node;
+       struct ec_node_sh_lex *priv = ec_node_priv(node);
 
        if (i >= 1)
                return -1;
 
        *refs = 1;
-       *child = node->child;
+       *child = priv->child;
        return 0;
 }
 
@@ -381,20 +380,22 @@ EC_NODE_TYPE_REGISTER(ec_node_sh_lex_type);
 
 struct ec_node *ec_node_sh_lex(const char *id, struct ec_node *child)
 {
-       struct ec_node_sh_lex *node = NULL;
+       struct ec_node *node = NULL;
+       struct ec_node_sh_lex *priv;
 
        if (child == NULL)
                return NULL;
 
-       node = (struct ec_node_sh_lex *)ec_node_from_type(&ec_node_sh_lex_type, id);
+       node = ec_node_from_type(&ec_node_sh_lex_type, id);
        if (node == NULL) {
                ec_node_free(child);
                return NULL;
        }
 
-       node->child = child;
+       priv = ec_node_priv(node);
+       priv->child = child;
 
-       return &node->gen;
+       return node;
 }
 
 /* LCOV_EXCL_START */
index 761ed76..c7afed6 100644 (file)
 EC_LOG_TYPE_REGISTER(node_space);
 
 struct ec_node_space {
-       struct ec_node gen;
 };
 
 static int
-ec_node_space_parse(const struct ec_node *gen_node,
+ec_node_space_parse(const struct ec_node *node,
                struct ec_parse *state,
                const struct ec_strvec *strvec)
 {
@@ -31,7 +30,7 @@ ec_node_space_parse(const struct ec_node *gen_node,
        size_t len = 0;
 
        (void)state;
-       (void)gen_node;
+       (void)node;
 
        if (ec_strvec_len(strvec) == 0)
                return EC_PARSE_NOMATCH;
index d53ea39..face6d5 100644 (file)
 EC_LOG_TYPE_REGISTER(node_str);
 
 struct ec_node_str {
-       struct ec_node gen;
        char *string;
        unsigned len;
 };
 
 static int
-ec_node_str_parse(const struct ec_node *gen_node,
+ec_node_str_parse(const struct ec_node *node,
                struct ec_parse *state,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_str *node = (struct ec_node_str *)gen_node;
+       struct ec_node_str *priv = ec_node_priv(node);
        const char *str;
 
        (void)state;
 
-       if (node->string == NULL) {
+       if (priv->string == NULL) {
                errno = EINVAL;
                return -1;
        }
@@ -44,18 +43,18 @@ ec_node_str_parse(const struct ec_node *gen_node,
                return EC_PARSE_NOMATCH;
 
        str = ec_strvec_val(strvec, 0);
-       if (strcmp(str, node->string) != 0)
+       if (strcmp(str, priv->string) != 0)
                return EC_PARSE_NOMATCH;
 
        return 1;
 }
 
 static int
-ec_node_str_complete(const struct ec_node *gen_node,
+ec_node_str_complete(const struct ec_node *node,
                struct ec_comp *comp,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_str *node = (struct ec_node_str *)gen_node;
+       struct ec_node_str *priv = ec_node_priv(node);
        const char *str;
        size_t n = 0;
 
@@ -63,8 +62,8 @@ ec_node_str_complete(const struct ec_node *gen_node,
                return 0;
 
        str = ec_strvec_val(strvec, 0);
-       for (n = 0; n < node->len; n++) {
-               if (str[n] != node->string[n])
+       for (n = 0; n < priv->len; n++) {
+               if (str[n] != priv->string[n])
                        break;
        }
 
@@ -72,25 +71,25 @@ ec_node_str_complete(const struct ec_node *gen_node,
        if (str[n] != '\0')
                return EC_PARSE_NOMATCH;
 
-       if (ec_comp_add_item(comp, gen_node, NULL, EC_COMP_FULL,
-                                       str, node->string) < 0)
+       if (ec_comp_add_item(comp, node, NULL, EC_COMP_FULL,
+                                       str, priv->string) < 0)
                return -1;
 
        return 0;
 }
 
-static const char *ec_node_str_desc(const struct ec_node *gen_node)
+static const char *ec_node_str_desc(const struct ec_node *node)
 {
-       struct ec_node_str *node = (struct ec_node_str *)gen_node;
+       struct ec_node_str *priv = ec_node_priv(node);
 
-       return node->string;
+       return priv->string;
 }
 
-static void ec_node_str_free_priv(struct ec_node *gen_node)
+static void ec_node_str_free_priv(struct ec_node *node)
 {
-       struct ec_node_str *node = (struct ec_node_str *)gen_node;
+       struct ec_node_str *priv = ec_node_priv(node);
 
-       ec_free(node->string);
+       ec_free(priv->string);
 }
 
 static const struct ec_config_schema ec_node_str_schema[] = {
@@ -104,10 +103,10 @@ static const struct ec_config_schema ec_node_str_schema[] = {
        },
 };
 
-static int ec_node_str_set_config(struct ec_node *gen_node,
+static int ec_node_str_set_config(struct ec_node *node,
                                const struct ec_config *config)
 {
-       struct ec_node_str *node = (struct ec_node_str *)gen_node;
+       struct ec_node_str *priv = ec_node_priv(node);
        const struct ec_config *value = NULL;
        char *s = NULL;
 
@@ -121,9 +120,9 @@ static int ec_node_str_set_config(struct ec_node *gen_node,
        if (s == NULL)
                goto fail;
 
-       ec_free(node->string);
-       node->string = s;
-       node->len = strlen(node->string);
+       ec_free(priv->string);
+       priv->string = s;
+       priv->len = strlen(priv->string);
 
        return 0;
 
@@ -145,12 +144,12 @@ static struct ec_node_type ec_node_str_type = {
 
 EC_NODE_TYPE_REGISTER(ec_node_str_type);
 
-int ec_node_str_set_str(struct ec_node *gen_node, const char *str)
+int ec_node_str_set_str(struct ec_node *node, const char *str)
 {
        struct ec_config *config = NULL;
        int ret;
 
-       if (ec_node_check_type(gen_node, &ec_node_str_type) < 0)
+       if (ec_node_check_type(node, &ec_node_str_type) < 0)
                goto fail;
 
        if (str == NULL) {
@@ -166,7 +165,7 @@ int ec_node_str_set_str(struct ec_node *gen_node, const char *str)
        if (ret < 0)
                goto fail;
 
-       ret = ec_node_set_config(gen_node, config);
+       ret = ec_node_set_config(node, config);
        config = NULL;
        if (ret < 0)
                goto fail;
@@ -180,19 +179,19 @@ fail:
 
 struct ec_node *ec_node_str(const char *id, const char *str)
 {
-       struct ec_node *gen_node = NULL;
+       struct ec_node *node = NULL;
 
-       gen_node = ec_node_from_type(&ec_node_str_type, id);
-       if (gen_node == NULL)
+       node = ec_node_from_type(&ec_node_str_type, id);
+       if (node == NULL)
                goto fail;
 
-       if (ec_node_str_set_str(gen_node, str) < 0)
+       if (ec_node_str_set_str(node, str) < 0)
                goto fail;
 
-       return gen_node;
+       return node;
 
 fail:
-       ec_node_free(gen_node);
+       ec_node_free(node);
        return NULL;
 }
 
index e3184ef..2f2fae7 100644 (file)
@@ -24,7 +24,6 @@
 EC_LOG_TYPE_REGISTER(node_subset);
 
 struct ec_node_subset {
-       struct ec_node gen;
        struct ec_node **table;
        unsigned int len;
 };
@@ -122,19 +121,19 @@ __ec_node_subset_parse(struct parse_result *out, struct ec_node **table,
 }
 
 static int
-ec_node_subset_parse(const struct ec_node *gen_node,
+ec_node_subset_parse(const struct ec_node *node,
                struct ec_parse *state,
                const struct ec_strvec *strvec)
 {
-       struct ec_node_subset *node = (struct ec_node_subset *)gen_node;
+       struct ec_node_subset *priv = ec_node_priv(node);
        struct ec_parse *parse = NULL;
        struct parse_result result;
        int ret;
 
        memset(&result, 0, sizeof(result));
 
-       ret = __ec_node_subset_parse(&result, node->table,
-                               node->len, state, strvec);
+       ret = __ec_node_subset_parse(&result, priv->table,
+                               priv->len, state, strvec);
        if (ret < 0)
                goto fail;
 
@@ -221,43 +220,43 @@ fail:
 }
 
 static int
-ec_node_subset_complete(const struct ec_node *gen_node,
+ec_node_subset_complete(const struct ec_node *node,
                        struct ec_comp *comp,
                        const struct ec_strvec *strvec)
 {
-       struct ec_node_subset *node = (struct ec_node_subset *)gen_node;
+       struct ec_node_subset *priv = ec_node_priv(node);
 
-       return __ec_node_subset_complete(node->table, node->len, comp,
+       return __ec_node_subset_complete(priv->table, priv->len, comp,
                                        strvec);
 }
 
-static void ec_node_subset_free_priv(struct ec_node *gen_node)
+static void ec_node_subset_free_priv(struct ec_node *node)
 {
-       struct ec_node_subset *node = (struct ec_node_subset *)gen_node;
+       struct ec_node_subset *priv = ec_node_priv(node);
        size_t i;
 
-       for (i = 0; i < node->len; i++)
-               ec_node_free(node->table[i]);
-       ec_free(node->table);
+       for (i = 0; i < priv->len; i++)
+               ec_node_free(priv->table[i]);
+       ec_free(priv->table);
 }
 
 static size_t
-ec_node_subset_get_children_count(const struct ec_node *gen_node)
+ec_node_subset_get_children_count(const struct ec_node *node)
 {
-       struct ec_node_subset *node = (struct ec_node_subset *)gen_node;
-       return node->len;
+       struct ec_node_subset *priv = ec_node_priv(node);
+       return priv->len;
 }
 
 static int
-ec_node_subset_get_child(const struct ec_node *gen_node, size_t i,
+ec_node_subset_get_child(const struct ec_node *node, size_t i,
                        struct ec_node **child, unsigned int *refs)
 {
-       struct ec_node_subset *node = (struct ec_node_subset *)gen_node;
+       struct ec_node_subset *priv = ec_node_priv(node);
 
-       if (i >= node->len)
+       if (i >= priv->len)
                return -1;
 
-       *child = node->table[i];
+       *child = priv->table[i];
        *refs = 1;
        return 0;
 }
@@ -274,9 +273,9 @@ static struct ec_node_type ec_node_subset_type = {
 
 EC_NODE_TYPE_REGISTER(ec_node_subset_type);
 
-int ec_node_subset_add(struct ec_node *gen_node, struct ec_node *child)
+int ec_node_subset_add(struct ec_node *node, struct ec_node *child)
 {
-       struct ec_node_subset *node = (struct ec_node_subset *)gen_node;
+       struct ec_node_subset *priv = ec_node_priv(node);
        struct ec_node **table;
 
        assert(node != NULL); // XXX specific assert for it, like in libyang
@@ -286,18 +285,18 @@ int ec_node_subset_add(struct ec_node *gen_node, struct ec_node *child)
                goto fail;
        }
 
-       if (ec_node_check_type(gen_node, &ec_node_subset_type) < 0)
+       if (ec_node_check_type(node, &ec_node_subset_type) < 0)
                goto fail;
 
-       table = ec_realloc(node->table, (node->len + 1) * sizeof(*node->table));
+       table = ec_realloc(priv->table, (priv->len + 1) * sizeof(*priv->table));
        if (table == NULL) {
                ec_node_free(child);
                return -1;
        }
 
-       node->table = table;
-       table[node->len] = child;
-       node->len++;
+       priv->table = table;
+       table[priv->len] = child;
+       priv->len++;
 
        return 0;
 
@@ -308,16 +307,14 @@ fail:
 
 struct ec_node *__ec_node_subset(const char *id, ...)
 {
-       struct ec_node *gen_node = NULL;
-       struct ec_node_subset *node = NULL;
+       struct ec_node *node = NULL;
        struct ec_node *child;
        va_list ap;
        int fail = 0;
 
        va_start(ap, id);
 
-       gen_node = ec_node_from_type(&ec_node_subset_type, id);
-       node = (struct ec_node_subset *)gen_node;
+       node = ec_node_from_type(&ec_node_subset_type, id);
        if (node == NULL)
                fail = 1;;
 
@@ -327,7 +324,7 @@ struct ec_node *__ec_node_subset(const char *id, ...)
 
                /* on error, don't quit the loop to avoid leaks */
                if (fail == 1 || child == NULL ||
-                               ec_node_subset_add(gen_node, child) < 0) {
+                               ec_node_subset_add(node, child) < 0) {
                        fail = 1;
                        ec_node_free(child);
                }
@@ -337,10 +334,10 @@ struct ec_node *__ec_node_subset(const char *id, ...)
                goto fail;
 
        va_end(ap);
-       return gen_node;
+       return node;
 
 fail:
-       ec_node_free(gen_node); /* will also free children */
+       ec_node_free(node); /* will also free children */
        va_end(ap);
        return NULL;
 }
index e01ff0a..b32dafb 100644 (file)
@@ -259,7 +259,7 @@ static void __ec_parse_dump(FILE *out,
 
        /* node can be null when parsing is incomplete */
        if (parse->node != NULL) {
-               id = parse->node->id;
+               id = ec_node_id(parse->node);
                typename = ec_node_type(parse->node)->name;
        }
 
@@ -402,8 +402,7 @@ ec_parse_find_next(struct ec_parse *root, struct ec_parse *start,
        for (iter = start; iter != NULL;
             iter = EC_PARSE_ITER_NEXT(root, iter, 1)) {
                if (iter->node != NULL &&
-                               iter->node->id != NULL &&
-                               !strcmp(iter->node->id, id))
+                               !strcmp(ec_node_id(iter->node), id))
                        return iter;
        }