AST semantic validation: add unary exp tests
[babeltrace.git] / formats / ctf / metadata / ctf-visitor-semantic-validator.c
index c7473d67573f0177da03464c1f5903e6df2a607f..6c9f45f04aba8bd9c22464c97e3913ee94e3d513 100644 (file)
@@ -74,7 +74,7 @@ int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node)
                }
                break;                  /* OK */
        case NODE_ENUMERATOR:
-               /* The enumerator parent has validated our validity already. */
+               /* The enumerator's parent has validated its validity already. */
                break;                  /* OK */
 
        case NODE_UNARY_EXPRESSION:
@@ -107,24 +107,37 @@ int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node)
 
        switch (node->u.unary_expression.link) {
        case UNARY_LINK_UNKNOWN:
-               break;
+               /* We don't allow empty link except on the first node of the list */
+               if (_cds_list_first_entry(is_ctf_exp_left ?
+                                         &node->parent->u.ctf_expression.left :
+                                         &node->parent->u.ctf_expression.right,
+                                         struct ctf_node,
+                                         siblings) != node)
+                       goto errperm;
+               break;                  /* OK */
        case UNARY_DOTLINK:
        case UNARY_ARROWLINK:
                /* We only allow -> and . links between children of ctf_expression. */
                if (node->parent->type != NODE_CTF_EXPRESSION)
-                       return -EPERM;
+                       goto errperm;
                /* We don't allow link on the first node of the list */
                if (_cds_list_first_entry(is_ctf_exp_left ?
                                          &node->parent->u.ctf_expression.left :
                                          &node->parent->u.ctf_expression.right,
                                          struct ctf_node,
                                          siblings) == node)
-                       return -EPERM;
+                       goto errperm;
+               /*
+                * Only strings can be separated linked by . or ->.
+                * This includes "", '' and non-quoted identifiers.
+                */
+               if (node->u.unary_expression.type != UNARY_STRING)
+                       goto errperm;
                break;
        case UNARY_DOTDOTDOT:
                /* We only allow ... link between children of enumerator. */
                if (node->parent->type != NODE_ENUMERATOR)
-                       return -EPERM;
+                       goto errperm;
                /* We don't allow link on the first node of the list */
                if (_cds_list_first_entry(&node->parent->u.enumerator.values,
                                          struct ctf_node,
This page took 0.023667 seconds and 4 git commands to generate.