Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to translate conditional enum names if possible #139

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions models/test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@
<NODE name="*" mode="rw" help="List of houses"/>
</NODE>
</NODE>
<NODE name="cages" when="../type = 'big'">
<NODE name="cage" help="This is a leaf list of pet houses">
<NODE name="*" mode="rw" help="List of houses"/>
</NODE>
</NODE>
<NODE name="claws" when="../../wombat" mode="rw" help="claws per paw"/>
<NODE name="friend" must="../../cat" mode="rw" help="animal friend"/>
<NODE name="n-type" when="derived-from-or-self(./type, 'a-types:type')" mode="rw" help="animal n-type"/>
Expand Down
22 changes: 20 additions & 2 deletions sch_conditions.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef struct _cond_result
char *path;
char *value;
char *step_value; /* actual value of step if step_exists has been called */
sch_instance *instance;
} cond_result;

typedef enum
Expand Down Expand Up @@ -125,6 +126,12 @@ sch_step_exists_traverse_nodes (GNode *node, gpointer data)
if (APTERYX_HAS_VALUE (node))
{
exists->value = g_strdup (APTERYX_VALUE (node));
sch_node *s_node = sch_lookup (exists->instance, path);
if (s_node)
{
/* We now have the schema node for the value, see if any translation is needed */
exists->value = sch_translate_from (s_node, exists->value);
}
}

/* Returning true stops the tree traverse */
Expand All @@ -136,11 +143,12 @@ sch_step_exists_traverse_nodes (GNode *node, gpointer data)
}

static void
sch_step_exists (GNode *root, char *path, cond_result *presult)
sch_step_exists (sch_instance *instance, GNode *root, char *path, cond_result *presult)
{
cond_result exists = { };

exists.path = path;
exists.instance = instance;
g_node_traverse (root, G_IN_ORDER, G_TRAVERSE_ALL, -1,
sch_step_exists_traverse_nodes, &exists);
presult->result = exists.result;
Expand Down Expand Up @@ -211,6 +219,16 @@ sch_process_operator (sch_instance *instance, GNode *root, char *path,
else if (xnode->left->type == XPATH_TYPE_STEP)
{
/* We already looked up step value and saved it. */
if (rresult.result && rresult.value)
{
/* The left node retains the path to the node with the value */
sch_node *s_node = sch_lookup (instance, lresult.value);
if (s_node)
{
/* We now have the schema node for the value, see if any translation is needed */
rresult.value = sch_translate_from (s_node, rresult.value);
}
}
g_free (lresult.value);
lresult.value = lresult.step_value;
lresult.step_value = NULL;
Expand Down Expand Up @@ -704,7 +722,7 @@ sch_process_xnode (sch_instance *instance, GNode *root, char *path, char *step_p
if (presult->result)
{
/* This tests if a path exists, and gets its value */
sch_step_exists (root, presult->value, &result);
sch_step_exists (instance, root, presult->value, &result);
presult->result = result.result;
g_free (presult->step_value);
presult->step_value = result.value;
Expand Down
Loading