Fix abstract array handling
[babeltrace.git] / formats / ctf / metadata / ctf-visitor-semantic-validator.c
index c7473d67573f0177da03464c1f5903e6df2a607f..b89f7bd7660d0d363faf4dab4dd77d009bb57320 100644 (file)
@@ -24,6 +24,7 @@
 #include <glib.h>
 #include <inttypes.h>
 #include <errno.h>
+#include <babeltrace/babeltrace.h>
 #include <babeltrace/list.h>
 #include "ctf-scanner.h"
 #include "ctf-parser.h"
@@ -32,7 +33,7 @@
 #define _cds_list_first_entry(ptr, type, member)       \
        cds_list_entry((ptr)->next, type, member)
 
-#define printf_dbg(fmt, args...)       fprintf(fd, "%s: " fmt, __func__, ## args)
+#define fprintf_dbg(fd, fmt, args...)  fprintf(fd, "%s: " fmt, __func__, ## args)
 
 static
 int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node);
@@ -41,10 +42,11 @@ static
 int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node)
 {
        struct ctf_node *iter;
-       int is_ctf_exp_left = 0;
+       int is_ctf_exp = 0, is_ctf_exp_left = 0;
 
        switch (node->parent->type) {
        case NODE_CTF_EXPRESSION:
+               is_ctf_exp = 1;
                cds_list_for_each_entry(iter, &node->parent->u.ctf_expression.left,
                                        siblings) {
                        if (iter == node) {
@@ -53,8 +55,11 @@ int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node)
                                 * We are a left child of a ctf expression.
                                 * We are only allowed to be a string.
                                 */
-                               if (node->u.unary_expression.type != UNARY_STRING)
+                               if (node->u.unary_expression.type != UNARY_STRING) {
+                                       fprintf(fd, "[error]: semantic error (left child of a ctf expression is only allowed to be a string)\n");
+
                                        goto errperm;
+                               }
                                break;
                        }
                }
@@ -62,19 +67,33 @@ int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node)
                break;                  /* OK */
        case NODE_TYPE_DECLARATOR:
                /*
-                * We are the length of a type declarator. We can only be
-                * a numeric constant.
+                * We are the length of a type declarator.
                 */
                switch (node->u.unary_expression.type) {
-               case UNARY_SIGNED_CONSTANT:
                case UNARY_UNSIGNED_CONSTANT:
+               case UNARY_STRING:
                        break;
                default:
+                       fprintf(fd, "[error]: semantic error (children of type declarator and enum can only be unsigned numeric constants or references to fields (a.b.c))\n");
                        goto errperm;
                }
                break;                  /* OK */
+
+       case NODE_STRUCT:
+               /*
+                * We are the size of a struct align attribute.
+                */
+               switch (node->u.unary_expression.type) {
+               case UNARY_UNSIGNED_CONSTANT:
+                       break;
+               default:
+                       fprintf(fd, "[error]: semantic error (structure alignment attribute can only be unsigned numeric constants)\n");
+                       goto errperm;
+               }
+               break;
+
        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:
@@ -82,6 +101,7 @@ int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node)
                 * We disallow nested unary expressions and "sbrac" unary
                 * expressions.
                 */
+               fprintf(fd, "[error]: semantic error (nested unary expressions not allowed ( () and [] ))\n");
                goto errperm;
 
        case NODE_ROOT:
@@ -96,40 +116,64 @@ int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node)
        case NODE_POINTER:
        case NODE_FLOATING_POINT:
        case NODE_INTEGER:
-       case NODE_ENUM:
        case NODE_STRING:
+       case NODE_ENUM:
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
        case NODE_VARIANT:
-       case NODE_STRUCT:
        default:
                goto errinval;
        }
 
        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 (is_ctf_exp && _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) {
+                       fprintf(fd, "[error]: semantic error (empty link not allowed except on first node of unary expression (need to separate nodes with \".\" or \"->\")\n");
+                       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;
+               if (node->parent->type != NODE_CTF_EXPRESSION) {
+                       fprintf(fd, "[error]: semantic error (links \".\" and \"->\" are only allowed as children of ctf expression)\n");
+                       goto errperm;
+               }
+               /*
+                * Only strings can be separated linked by . or ->.
+                * This includes "", '' and non-quoted identifiers.
+                */
+               if (node->u.unary_expression.type != UNARY_STRING) {
+                       fprintf(fd, "[error]: semantic error (links \".\" and \"->\" are only allowed to separate strings and identifiers)\n");
+                       goto errperm;
+               }
                /* We don't allow link on the first node of the list */
-               if (_cds_list_first_entry(is_ctf_exp_left ?
+               if (is_ctf_exp && _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;
+                                         siblings) == node) {
+                       fprintf(fd, "[error]: semantic error (links \".\" and \"->\" are not allowed before first node of the unary expression list)\n");
+                       goto errperm;
+               }
                break;
        case UNARY_DOTDOTDOT:
                /* We only allow ... link between children of enumerator. */
-               if (node->parent->type != NODE_ENUMERATOR)
-                       return -EPERM;
+               if (node->parent->type != NODE_ENUMERATOR) {
+                       fprintf(fd, "[error]: semantic error (link \"...\" is only allowed within enumerator)\n");
+                       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,
-                                         siblings) == node)
-                       return -EPERM;
+                                         siblings) == node) {
+                       fprintf(fd, "[error]: semantic error (link \"...\" is not allowed on the first node of the unary expression list)\n");
+                       goto errperm;
+               }
                break;
        default:
                fprintf(fd, "[error] %s: unknown expression link type %d\n", __func__,
@@ -139,16 +183,18 @@ int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node)
        return 0;
 
 errinval:
-       fprintf(fd, "[error] %s: incoherent parent type %d for node type %d\n", __func__,
-               (int) node->parent->type, (int) node->type);
+       fprintf(fd, "[error] %s: incoherent parent type %s for node type %s\n", __func__,
+               node_type(node->parent), node_type(node));
        return -EINVAL;         /* Incoherent structure */
 
 errperm:
+       fprintf(fd, "[error] %s: semantic error (parent type %s for node type %s)\n", __func__,
+               node_type(node->parent), node_type(node));
        return -EPERM;          /* Structure not allowed */
 }
 
 static
-int ctf_visitor_type_specifier(FILE *fd, int depth, struct ctf_node *node)
+int ctf_visitor_type_specifier_list(FILE *fd, int depth, struct ctf_node *node)
 {
        switch (node->parent->type) {
        case NODE_CTF_EXPRESSION:
@@ -157,21 +203,60 @@ int ctf_visitor_type_specifier(FILE *fd, int depth, struct ctf_node *node)
        case NODE_TYPEALIAS_TARGET:
        case NODE_TYPEALIAS_ALIAS:
        case NODE_ENUM:
+       case NODE_STRUCT_OR_VARIANT_DECLARATION:
+       case NODE_ROOT:
                break;                  /* OK */
 
-       case NODE_ROOT:
        case NODE_EVENT:
        case NODE_STREAM:
        case NODE_TRACE:
        case NODE_UNARY_EXPRESSION:
        case NODE_TYPEALIAS:
        case NODE_TYPE_SPECIFIER:
+       case NODE_TYPE_SPECIFIER_LIST:
        case NODE_POINTER:
        case NODE_FLOATING_POINT:
        case NODE_INTEGER:
        case NODE_STRING:
        case NODE_ENUMERATOR:
+       case NODE_VARIANT:
+       case NODE_STRUCT:
+       default:
+               goto errinval;
+       }
+       return 0;
+errinval:
+       fprintf(fd, "[error] %s: incoherent parent type %s for node type %s\n", __func__,
+               node_type(node->parent), node_type(node));
+       return -EINVAL;         /* Incoherent structure */
+}
+
+static
+int ctf_visitor_type_specifier(FILE *fd, int depth, struct ctf_node *node)
+{
+       switch (node->parent->type) {
+       case NODE_TYPE_SPECIFIER_LIST:
+               break;                  /* OK */
+
+       case NODE_CTF_EXPRESSION:
+       case NODE_TYPE_DECLARATOR:
+       case NODE_TYPEDEF:
+       case NODE_TYPEALIAS_TARGET:
+       case NODE_TYPEALIAS_ALIAS:
+       case NODE_ENUM:
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
+       case NODE_ROOT:
+       case NODE_EVENT:
+       case NODE_STREAM:
+       case NODE_TRACE:
+       case NODE_UNARY_EXPRESSION:
+       case NODE_TYPEALIAS:
+       case NODE_TYPE_SPECIFIER:
+       case NODE_POINTER:
+       case NODE_FLOATING_POINT:
+       case NODE_INTEGER:
+       case NODE_STRING:
+       case NODE_ENUMERATOR:
        case NODE_VARIANT:
        case NODE_STRUCT:
        default:
@@ -179,8 +264,8 @@ int ctf_visitor_type_specifier(FILE *fd, int depth, struct ctf_node *node)
        }
        return 0;
 errinval:
-       fprintf(fd, "[error] %s: incoherent parent type %d for node type %d\n", __func__,
-               (int) node->parent->type, (int) node->type);
+       fprintf(fd, "[error] %s: incoherent parent type %s for node type %s\n", __func__,
+               node_type(node->parent), node_type(node));
        return -EINVAL;         /* Incoherent structure */
 }
 
@@ -199,10 +284,44 @@ int ctf_visitor_type_declarator(FILE *fd, int depth, struct ctf_node *node)
                 */
                if (!cds_list_empty(&node->u.type_declarator.pointers))
                        goto errperm;
-               /* Fall-through */
-       case NODE_TYPEDEF:
+               break;                  /* OK */
        case NODE_TYPEALIAS_TARGET:
+               break;                  /* OK */
        case NODE_TYPEALIAS_ALIAS:
+               /*
+                * Only accept alias name containing:
+                * - identifier
+                * - identifier *   (any number of pointers)
+                * NOT accepting alias names containing [] (would otherwise
+                * cause semantic clash for later declarations of
+                * arrays/sequences of elements, where elements could be
+                * arrays/sequences themselves (if allowed in typealias).
+                * NOT accepting alias with identifier. The declarator should
+                * be either empty or contain pointer(s).
+                */
+               if (node->u.type_declarator.type == TYPEDEC_NESTED)
+                       goto errperm;
+               cds_list_for_each_entry(iter, &node->parent->u.typealias_alias.type_specifier_list->u.type_specifier_list.head,
+                                       siblings) {
+                       switch (iter->u.type_specifier.type) {
+                       case TYPESPEC_FLOATING_POINT:
+                       case TYPESPEC_INTEGER:
+                       case TYPESPEC_STRING:
+                       case TYPESPEC_STRUCT:
+                       case TYPESPEC_VARIANT:
+                       case TYPESPEC_ENUM:
+                               if (cds_list_empty(&node->u.type_declarator.pointers))
+                                       goto errperm;
+                               break;
+                       default:
+                               break;
+                       }
+               }
+               if (node->u.type_declarator.type == TYPEDEC_ID &&
+                   node->u.type_declarator.u.id != NULL)
+                       goto errperm;
+               break;                  /* OK */
+       case NODE_TYPEDEF:
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
                break;                  /* OK */
 
@@ -226,30 +345,40 @@ int ctf_visitor_type_declarator(FILE *fd, int depth, struct ctf_node *node)
                goto errinval;
        }
 
-       if (!cds_list_empty(&node->u.type_declarator.pointers)) {
-               cds_list_for_each_entry(iter, &node->u.type_declarator.pointers,
-                                       siblings) {
-                       ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
+       cds_list_for_each_entry(iter, &node->u.type_declarator.pointers,
+                               siblings) {
+               ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
+               if (ret)
+                       return ret;
        }
 
        switch (node->u.type_declarator.type) {
        case TYPEDEC_ID:
                break;
        case TYPEDEC_NESTED:
+       {
                if (node->u.type_declarator.u.nested.type_declarator) {
                        ret = _ctf_visitor_semantic_check(fd, depth + 1,
                                node->u.type_declarator.u.nested.type_declarator);
                        if (ret)
                                return ret;
                }
-               if (node->u.type_declarator.u.nested.length) {
-                       ret = _ctf_visitor_semantic_check(fd, depth + 1,
-                               node->u.type_declarator.u.nested.length);
-                       if (ret)
-                               return ret;
+               if (!node->u.type_declarator.u.nested.abstract_array) {
+                       cds_list_for_each_entry(iter, &node->u.type_declarator.u.nested.length,
+                                               siblings) {
+                               if (iter->type != NODE_UNARY_EXPRESSION) {
+                                       fprintf(fd, "[error] %s: expecting unary expression as length\n", __func__);
+                                       return -EINVAL;
+                               }
+                               ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
+                               if (ret)
+                                       return ret;
+                       }
+               } else {
+                       if (node->parent->type == NODE_TYPEALIAS_TARGET) {
+                               fprintf(fd, "[error] %s: abstract array declarator not permitted as target of typealias\n", __func__);
+                               return -EINVAL;
+                       }
                }
                if (node->u.type_declarator.bitfield_len) {
                        ret = _ctf_visitor_semantic_check(fd, depth + 1,
@@ -258,6 +387,7 @@ int ctf_visitor_type_declarator(FILE *fd, int depth, struct ctf_node *node)
                                return ret;
                }
                break;
+       }
        case TYPEDEC_UNKNOWN:
        default:
                fprintf(fd, "[error] %s: unknown type declarator %d\n", __func__,
@@ -268,11 +398,13 @@ int ctf_visitor_type_declarator(FILE *fd, int depth, struct ctf_node *node)
        return 0;
 
 errinval:
-       fprintf(fd, "[error] %s: incoherent parent type %d for node type %d\n", __func__,
-               (int) node->parent->type, (int) node->type);
+       fprintf(fd, "[error] %s: incoherent parent type %s for node type %s\n", __func__,
+               node_type(node->parent), node_type(node));
        return -EINVAL;         /* Incoherent structure */
 
 errperm:
+       fprintf(fd, "[error] %s: semantic error (parent type %s for node type %s)\n", __func__,
+               node_type(node->parent), node_type(node));
        return -EPERM;          /* Structure not allowed */
 }
 
@@ -284,19 +416,7 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
 
        switch (node->type) {
        case NODE_ROOT:
-               cds_list_for_each_entry(iter, &node->u.root._typedef,
-                                       siblings) {
-                       ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
-               cds_list_for_each_entry(iter, &node->u.root.typealias,
-                                       siblings) {
-                       ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
-               cds_list_for_each_entry(iter, &node->u.root.declaration_specifier, siblings) {
+               cds_list_for_each_entry(iter, &node->u.root.declaration_list, siblings) {
                        ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
                        if (ret)
                                return ret;
@@ -380,6 +500,7 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                case NODE_STRUCT_OR_VARIANT_DECLARATION:
                case NODE_TYPEALIAS:
                case NODE_TYPE_SPECIFIER:
+               case NODE_TYPE_SPECIFIER_LIST:
                case NODE_POINTER:
                case NODE_TYPE_DECLARATOR:
                case NODE_ENUMERATOR:
@@ -424,6 +545,7 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                case NODE_TYPEALIAS:
                case NODE_STRUCT_OR_VARIANT_DECLARATION:
                case NODE_TYPE_SPECIFIER:
+               case NODE_TYPE_SPECIFIER_LIST:
                case NODE_POINTER:
                case NODE_TYPE_DECLARATOR:
                case NODE_FLOATING_POINT:
@@ -436,11 +558,10 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                }
 
                depth++;
-               cds_list_for_each_entry(iter, &node->u._typedef.declaration_specifier, siblings) {
-                       ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
+               ret = _ctf_visitor_semantic_check(fd, depth + 1,
+                       node->u._typedef.type_specifier_list);
+               if (ret)
+                       return ret;
                cds_list_for_each_entry(iter, &node->u._typedef.type_declarators, siblings) {
                        ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
                        if (ret)
@@ -449,6 +570,9 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                depth--;
                break;
        case NODE_TYPEALIAS_TARGET:
+       {
+               int nr_declarators;
+
                switch (node->parent->type) {
                case NODE_TYPEALIAS:
                        break;                  /* OK */
@@ -457,19 +581,29 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                }
 
                depth++;
-               cds_list_for_each_entry(iter, &node->u.typealias_target.declaration_specifier, siblings) {
-                       ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
+               ret = _ctf_visitor_semantic_check(fd, depth + 1,
+                       node->u.typealias_target.type_specifier_list);
+               if (ret)
+                       return ret;
+               nr_declarators = 0;
                cds_list_for_each_entry(iter, &node->u.typealias_target.type_declarators, siblings) {
                        ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
                        if (ret)
                                return ret;
+                       nr_declarators++;
+               }
+               if (nr_declarators > 1) {
+                       fprintf(fd, "[error] %s: Too many declarators in typealias alias (%d, max is 1)\n", __func__, nr_declarators);
+               
+                       return -EINVAL;
                }
                depth--;
                break;
+       }
        case NODE_TYPEALIAS_ALIAS:
+       {
+               int nr_declarators;
+
                switch (node->parent->type) {
                case NODE_TYPEALIAS:
                        break;                  /* OK */
@@ -478,18 +612,25 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                }
 
                depth++;
-               cds_list_for_each_entry(iter, &node->u.typealias_alias.declaration_specifier, siblings) {
-                       ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
+               ret = _ctf_visitor_semantic_check(fd, depth + 1,
+                       node->u.typealias_alias.type_specifier_list);
+               if (ret)
+                       return ret;
+               nr_declarators = 0;
                cds_list_for_each_entry(iter, &node->u.typealias_alias.type_declarators, siblings) {
                        ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
                        if (ret)
                                return ret;
+                       nr_declarators++;
+               }
+               if (nr_declarators > 1) {
+                       fprintf(fd, "[error] %s: Too many declarators in typealias alias (%d, max is 1)\n", __func__, nr_declarators);
+               
+                       return -EINVAL;
                }
                depth--;
                break;
+       }
        case NODE_TYPEALIAS:
                switch (node->parent->type) {
                case NODE_ROOT:
@@ -508,6 +649,7 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                case NODE_TYPEALIAS:
                case NODE_STRUCT_OR_VARIANT_DECLARATION:
                case NODE_TYPE_SPECIFIER:
+               case NODE_TYPE_SPECIFIER_LIST:
                case NODE_POINTER:
                case NODE_TYPE_DECLARATOR:
                case NODE_FLOATING_POINT:
@@ -527,6 +669,11 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                        return ret;
                break;
 
+       case NODE_TYPE_SPECIFIER_LIST:
+               ret = ctf_visitor_type_specifier_list(fd, depth, node);
+               if (ret)
+                       return ret;
+               break;
        case NODE_TYPE_SPECIFIER:
                ret = ctf_visitor_type_specifier(fd, depth, node);
                if (ret)
@@ -548,28 +695,8 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
 
        case NODE_FLOATING_POINT:
                switch (node->parent->type) {
-               case NODE_CTF_EXPRESSION:
-               case NODE_TYPEDEF:
-               case NODE_TYPEALIAS_TARGET:
-               case NODE_TYPEALIAS_ALIAS:
-               case NODE_STRUCT_OR_VARIANT_DECLARATION:
-                       break;                  /* OK */
-
-               case NODE_ROOT:
-               case NODE_EVENT:
-               case NODE_STREAM:
-               case NODE_TRACE:
-               case NODE_TYPEALIAS:
                case NODE_TYPE_SPECIFIER:
-               case NODE_POINTER:
-               case NODE_TYPE_DECLARATOR:
-               case NODE_FLOATING_POINT:
-               case NODE_INTEGER:
-               case NODE_STRING:
-               case NODE_ENUMERATOR:
-               case NODE_ENUM:
-               case NODE_VARIANT:
-               case NODE_STRUCT:
+                       break;                  /* OK */
                default:
                        goto errinval;
 
@@ -584,29 +711,8 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                break;
        case NODE_INTEGER:
                switch (node->parent->type) {
-               case NODE_CTF_EXPRESSION:
-               case NODE_UNARY_EXPRESSION:
-               case NODE_TYPEDEF:
-               case NODE_TYPEALIAS_TARGET:
-               case NODE_TYPEALIAS_ALIAS:
-               case NODE_TYPE_DECLARATOR:
-               case NODE_ENUM:
-               case NODE_STRUCT_OR_VARIANT_DECLARATION:
-                       break;                  /* OK */
-
-               case NODE_ROOT:
-               case NODE_EVENT:
-               case NODE_STREAM:
-               case NODE_TRACE:
-               case NODE_TYPEALIAS:
                case NODE_TYPE_SPECIFIER:
-               case NODE_POINTER:
-               case NODE_FLOATING_POINT:
-               case NODE_INTEGER:
-               case NODE_STRING:
-               case NODE_ENUMERATOR:
-               case NODE_VARIANT:
-               case NODE_STRUCT:
+                       break;                  /* OK */
                default:
                        goto errinval;
 
@@ -620,28 +726,8 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                break;
        case NODE_STRING:
                switch (node->parent->type) {
-               case NODE_CTF_EXPRESSION:
-               case NODE_TYPEDEF:
-               case NODE_TYPEALIAS_TARGET:
-               case NODE_TYPEALIAS_ALIAS:
-               case NODE_STRUCT_OR_VARIANT_DECLARATION:
-                       break;                  /* OK */
-
-               case NODE_ROOT:
-               case NODE_EVENT:
-               case NODE_STREAM:
-               case NODE_TRACE:
-               case NODE_TYPEALIAS:
                case NODE_TYPE_SPECIFIER:
-               case NODE_POINTER:
-               case NODE_TYPE_DECLARATOR:
-               case NODE_FLOATING_POINT:
-               case NODE_INTEGER:
-               case NODE_STRING:
-               case NODE_ENUMERATOR:
-               case NODE_ENUM:
-               case NODE_VARIANT:
-               case NODE_STRUCT:
+                       break;                  /* OK */
                default:
                        goto errinval;
 
@@ -670,20 +756,24 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                {
                        int count = 0;
 
-                       cds_list_for_each_entry(iter, &node->parent->u.enumerator.values,
+                       cds_list_for_each_entry(iter, &node->u.enumerator.values,
                                                siblings) {
                                switch (count++) {
                                case 0: if (iter->type != NODE_UNARY_EXPRESSION
                                            || (iter->u.unary_expression.type != UNARY_SIGNED_CONSTANT
                                                && iter->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
-                                           || iter->u.unary_expression.link != UNARY_LINK_UNKNOWN)
+                                           || iter->u.unary_expression.link != UNARY_LINK_UNKNOWN) {
+                                               fprintf(fd, "[error]: semantic error (first unary expression of enumerator is unexpected)\n");
                                                goto errperm;
+                                       }
                                        break;
                                case 1: if (iter->type != NODE_UNARY_EXPRESSION
                                            || (iter->u.unary_expression.type != UNARY_SIGNED_CONSTANT
                                                && iter->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
-                                           || iter->u.unary_expression.link != UNARY_DOTDOTDOT)
+                                           || iter->u.unary_expression.link != UNARY_DOTDOTDOT) {
+                                               fprintf(fd, "[error]: semantic error (second unary expression of enumerator is unexpected)\n");
                                                goto errperm;
+                                       }
                                        break;
                                default:
                                        goto errperm;
@@ -699,28 +789,8 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                break;
        case NODE_ENUM:
                switch (node->parent->type) {
-               case NODE_ROOT:
-               case NODE_EVENT:
-               case NODE_STREAM:
-               case NODE_TRACE:
-               case NODE_CTF_EXPRESSION:
-               case NODE_TYPEDEF:
-               case NODE_TYPEALIAS_TARGET:
-               case NODE_TYPEALIAS_ALIAS:
-               case NODE_TYPE_DECLARATOR:
-               case NODE_STRUCT_OR_VARIANT_DECLARATION:
-                       break;                  /* OK */
-
-               case NODE_TYPEALIAS:
                case NODE_TYPE_SPECIFIER:
-               case NODE_POINTER:
-               case NODE_FLOATING_POINT:
-               case NODE_INTEGER:
-               case NODE_STRING:
-               case NODE_ENUMERATOR:
-               case NODE_ENUM:
-               case NODE_VARIANT:
-               case NODE_STRUCT:
+                       break;                  /* OK */
                default:
                        goto errinval;
 
@@ -729,11 +799,9 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                }
 
                depth++;
-               if (node->u._enum.container_type) {
-                       ret = _ctf_visitor_semantic_check(fd, depth + 1, node->u._enum.container_type);
-                       if (ret)
-                               return ret;
-               }
+               ret = _ctf_visitor_semantic_check(fd, depth + 1, node->u._enum.container_type);
+               if (ret)
+                       return ret;
 
                cds_list_for_each_entry(iter, &node->u._enum.enumerator_list, siblings) {
                        ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
@@ -750,11 +818,10 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                default:
                        goto errinval;
                }
-               cds_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.declaration_specifier, siblings) {
-                       ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
+               ret = _ctf_visitor_semantic_check(fd, depth + 1,
+                       node->u.struct_or_variant_declaration.type_specifier_list);
+               if (ret)
+                       return ret;
                cds_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.type_declarators, siblings) {
                        ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
                        if (ret)
@@ -763,28 +830,8 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                break;
        case NODE_VARIANT:
                switch (node->parent->type) {
-               case NODE_ROOT:
-               case NODE_EVENT:
-               case NODE_STREAM:
-               case NODE_TRACE:
-               case NODE_CTF_EXPRESSION:
-               case NODE_TYPEDEF:
-               case NODE_TYPEALIAS_TARGET:
-               case NODE_TYPEALIAS_ALIAS:
-               case NODE_STRUCT_OR_VARIANT_DECLARATION:
-                       break;                  /* OK */
-
-               case NODE_TYPEALIAS:
                case NODE_TYPE_SPECIFIER:
-               case NODE_POINTER:
-               case NODE_TYPE_DECLARATOR:
-               case NODE_FLOATING_POINT:
-               case NODE_INTEGER:
-               case NODE_STRING:
-               case NODE_ENUMERATOR:
-               case NODE_ENUM:
-               case NODE_VARIANT:
-               case NODE_STRUCT:
+                       break;                  /* OK */
                default:
                        goto errinval;
 
@@ -800,28 +847,8 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
 
        case NODE_STRUCT:
                switch (node->parent->type) {
-               case NODE_ROOT:
-               case NODE_EVENT:
-               case NODE_STREAM:
-               case NODE_TRACE:
-               case NODE_CTF_EXPRESSION:
-               case NODE_TYPEDEF:
-               case NODE_TYPEALIAS_TARGET:
-               case NODE_TYPEALIAS_ALIAS:
-               case NODE_STRUCT_OR_VARIANT_DECLARATION:
-                       break;                  /* OK */
-
-               case NODE_TYPEALIAS:
                case NODE_TYPE_SPECIFIER:
-               case NODE_POINTER:
-               case NODE_TYPE_DECLARATOR:
-               case NODE_FLOATING_POINT:
-               case NODE_INTEGER:
-               case NODE_STRING:
-               case NODE_ENUMERATOR:
-               case NODE_ENUM:
-               case NODE_VARIANT:
-               case NODE_STRUCT:
+                       break;                  /* OK */
                default:
                        goto errinval;
 
@@ -844,11 +871,13 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
        return ret;
 
 errinval:
-       fprintf(fd, "[error] %s: incoherent parent type %d for node type %d\n", __func__,
-               (int) node->parent->type, (int) node->type);
+       fprintf(fd, "[error] %s: incoherent parent type %s for node type %s\n", __func__,
+               node_type(node->parent), node_type(node));
        return -EINVAL;         /* Incoherent structure */
 
 errperm:
+       fprintf(fd, "[error] %s: semantic error (parent type %s for node type %s)\n", __func__,
+               node_type(node->parent), node_type(node));
        return -EPERM;          /* Structure not allowed */
 }
 
@@ -861,8 +890,15 @@ int ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
         * take the safe route and recreate them at each validation, just in
         * case the structure has changed.
         */
+       printf_verbose("CTF visitor: parent links creation... ");
        ret = ctf_visitor_parent_links(fd, depth, node);
        if (ret)
                return ret;
-       return _ctf_visitor_semantic_check(fd, depth, node);
+       printf_verbose("done.\n");
+       printf_verbose("CTF visitor: semantic check... ");
+       ret = _ctf_visitor_semantic_check(fd, depth, node);
+       if (ret)
+               return ret;
+       printf_verbose("done.\n");
+       return ret;
 }
This page took 0.032989 seconds and 4 git commands to generate.