Add type_specifier list node
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 26 Apr 2011 01:33:13 +0000 (21:33 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 26 Apr 2011 01:33:13 +0000 (21:33 -0400)
Needed to correctly iterate on type_specifier_list and then iterate on
each type_specifier of the list.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/metadata/ctf-ast.h
formats/ctf/metadata/ctf-parser.y
formats/ctf/metadata/ctf-test/fail/typealias-no-array-alias.txt [new file with mode: 0644]
formats/ctf/metadata/ctf-test/succeed/ctf-test.txt
formats/ctf/metadata/ctf-visitor-generate-io-struct.c
formats/ctf/metadata/ctf-visitor-parent-links.c
formats/ctf/metadata/ctf-visitor-semantic-validator.c
formats/ctf/metadata/ctf-visitor-xml.c

index c12d09a97910dc43faf08237efee70bcd3a4f45a..bf6ddb42db41fdc0c51290d31c0b043744586604 100644 (file)
@@ -33,6 +33,7 @@ enum node_type {
        NODE_TYPEALIAS,
 
        NODE_TYPE_SPECIFIER,
+       NODE_TYPE_SPECIFIER_LIST,
        NODE_POINTER,
        NODE_TYPE_DECLARATOR,
 
@@ -62,9 +63,11 @@ struct ctf_node {
                struct {
                } unknown;
                struct {
-                       struct cds_list_head _typedef;
-                       struct cds_list_head typealias;
-                       struct cds_list_head declaration_specifier;
+                       /*
+                        * Children nodes are ctf_expression, typedef,
+                        * typealias and type_specifier_list.
+                        */
+                       struct cds_list_head declaration_list;
                        struct cds_list_head trace;
                        struct cds_list_head stream;
                        struct cds_list_head event;
@@ -72,21 +75,21 @@ struct ctf_node {
                struct {
                        /*
                         * Children nodes are ctf_expression, typedef,
-                        * typealias and declaration specifiers.
+                        * typealias and type_specifier_list.
                         */
                        struct cds_list_head declaration_list;
                } event;
                struct {
                        /*
                         * Children nodes are ctf_expression, typedef,
-                        * typealias and declaration specifiers.
+                        * typealias and type_specifier_list.
                         */
                        struct cds_list_head declaration_list;
                } stream;
                struct {
                        /*
                         * Children nodes are ctf_expression, typedef,
-                        * typealias and declaration specifiers.
+                        * typealias and type_specifier_list.
                         */
                        struct cds_list_head declaration_list;
                } trace;
@@ -122,16 +125,16 @@ struct ctf_node {
                        } link;
                } unary_expression;
                struct {
-                       struct cds_list_head declaration_specifier;
+                       struct ctf_node *type_specifier_list;
                        struct cds_list_head type_declarators;
                } _typedef;
                /* new type is "alias", existing type "target" */
                struct {
-                       struct cds_list_head declaration_specifier;
+                       struct ctf_node *type_specifier_list;
                        struct cds_list_head type_declarators;
                } typealias_target;
                struct {
-                       struct cds_list_head declaration_specifier;
+                       struct ctf_node *type_specifier_list;
                        struct cds_list_head type_declarators;
                } typealias_alias;
                struct {
@@ -155,9 +158,21 @@ struct ctf_node {
                                TYPESPEC_IMAGINARY,
                                TYPESPEC_CONST,
                                TYPESPEC_ID_TYPE,
+                               TYPESPEC_FLOATING_POINT,
+                               TYPESPEC_INTEGER,
+                               TYPESPEC_STRING,
+                               TYPESPEC_STRUCT,
+                               TYPESPEC_VARIANT,
+                               TYPESPEC_ENUM,
                        } type;
+                       /* For struct, variant and enum */
+                       struct ctf_node *node;
                        const char *id_type;
                } type_specifier;
+               struct {
+                       /* list of type_specifier */
+                       struct cds_list_head head;
+               } type_specifier_list;
                struct {
                        unsigned int const_qualifier;
                } pointer;
@@ -175,9 +190,9 @@ struct ctf_node {
                                        struct ctf_node *type_declarator;
                                        /*
                                         * unary expression (value) or
-                                        * declaration specifiers.
+                                        * type_specifier_list.
                                         */
-                                       struct cds_list_head length;
+                                       struct ctf_node *length;
                                        /* for abstract type declarator */
                                        unsigned int abstract_array;
                                } nested;
@@ -207,15 +222,15 @@ struct ctf_node {
                struct {
                        char *enum_id;
                        /*
-                        * Either empty, contains unary expression or
-                        * declaration specifiers.
+                        * Either NULL, or points to unary expression or
+                        * type_specifier_list.
                         */
-                       struct cds_list_head container_type;
+                       struct ctf_node *container_type;
                        struct cds_list_head enumerator_list;
                        int has_body;
                } _enum;
                struct {
-                       struct cds_list_head declaration_specifier;
+                       struct ctf_node *type_specifier_list;
                        struct cds_list_head type_declarators;
                } struct_or_variant_declaration;
                struct {
index 66e37923c9315dd482c577912f3f62a75fa5431a..fcc877ba7abacea65ef199f16b593a85bd119ec9 100644 (file)
@@ -76,6 +76,7 @@ static const char *node_type_to_str[] = {
        [ NODE_TYPEALIAS_ALIAS ] = "NODE_TYPEALIAS_ALIAS",
        [ NODE_TYPEALIAS ] = "NODE_TYPEALIAS",
        [ NODE_TYPE_SPECIFIER ] = "NODE_TYPE_SPECIFIER",
+       [ NODE_TYPE_SPECIFIER_LIST ] = "NODE_TYPE_SPECIFIER_LIST",
        [ NODE_POINTER ] = "NODE_POINTER",
        [ NODE_TYPE_DECLARATOR ] = "NODE_TYPE_DECLARATOR",
        [ NODE_FLOATING_POINT ] = "NODE_FLOATING_POINT",
@@ -257,15 +258,12 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
                break;
 
        case NODE_TYPEDEF:
-               CDS_INIT_LIST_HEAD(&node->u._typedef.declaration_specifier);
                CDS_INIT_LIST_HEAD(&node->u._typedef.type_declarators);
                break;
        case NODE_TYPEALIAS_TARGET:
-               CDS_INIT_LIST_HEAD(&node->u.typealias_target.declaration_specifier);
                CDS_INIT_LIST_HEAD(&node->u.typealias_target.type_declarators);
                break;
        case NODE_TYPEALIAS_ALIAS:
-               CDS_INIT_LIST_HEAD(&node->u.typealias_alias.declaration_specifier);
                CDS_INIT_LIST_HEAD(&node->u.typealias_alias.type_declarators);
                break;
        case NODE_TYPEALIAS:
@@ -273,6 +271,9 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
 
        case NODE_TYPE_SPECIFIER:
                break;
+       case NODE_TYPE_SPECIFIER_LIST:
+               CDS_INIT_LIST_HEAD(&node->u.type_specifier_list.head);
+               break;
        case NODE_POINTER:
                break;
        case NODE_TYPE_DECLARATOR:
@@ -292,11 +293,9 @@ static struct ctf_node *make_node(struct ctf_scanner *scanner,
                CDS_INIT_LIST_HEAD(&node->u.enumerator.values);
                break;
        case NODE_ENUM:
-               CDS_INIT_LIST_HEAD(&node->u._enum.container_type);
                CDS_INIT_LIST_HEAD(&node->u._enum.enumerator_list);
                break;
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
-               CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.declaration_specifier);
                CDS_INIT_LIST_HEAD(&node->u.struct_or_variant_declaration.type_declarators);
                break;
        case NODE_VARIANT:
@@ -346,6 +345,7 @@ static int reparent_ctf_expression(struct ctf_node *node,
        case NODE_TYPEALIAS_ALIAS:
        case NODE_TYPEALIAS:
        case NODE_TYPE_SPECIFIER:
+       case NODE_TYPE_SPECIFIER_LIST:
        case NODE_POINTER:
        case NODE_TYPE_DECLARATOR:
        case NODE_ENUMERATOR:
@@ -369,7 +369,7 @@ static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
 {
        switch (parent->type) {
        case NODE_ROOT:
-               _cds_list_splice_tail(&node->tmp_head, &parent->u.root._typedef);
+               _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
                break;
        case NODE_EVENT:
                _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
@@ -396,6 +396,7 @@ static int reparent_typedef(struct ctf_node *node, struct ctf_node *parent)
        case NODE_TYPEALIAS_ALIAS:
        case NODE_TYPEALIAS:
        case NODE_TYPE_SPECIFIER:
+       case NODE_TYPE_SPECIFIER_LIST:
        case NODE_POINTER:
        case NODE_TYPE_DECLARATOR:
        case NODE_ENUMERATOR:
@@ -417,7 +418,7 @@ static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
 {
        switch (parent->type) {
        case NODE_ROOT:
-               _cds_list_splice_tail(&node->tmp_head, &parent->u.root.typealias);
+               _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_list);
                break;
        case NODE_EVENT:
                _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
@@ -444,6 +445,7 @@ static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
        case NODE_TYPEALIAS_ALIAS:
        case NODE_TYPEALIAS:
        case NODE_TYPE_SPECIFIER:
+       case NODE_TYPE_SPECIFIER_LIST:
        case NODE_POINTER:
        case NODE_TYPE_DECLARATOR:
        case NODE_ENUMERATOR:
@@ -463,52 +465,90 @@ static int reparent_typealias(struct ctf_node *node, struct ctf_node *parent)
 
 static int reparent_type_specifier(struct ctf_node *node,
                                   struct ctf_node *parent)
+{
+       switch (parent->type) {
+       case NODE_TYPE_SPECIFIER_LIST:
+               _cds_list_splice_tail(&node->tmp_head, &parent->u.type_specifier_list.head);
+               break;
+
+       case NODE_TYPE_SPECIFIER:
+       case NODE_EVENT:
+       case NODE_STREAM:
+       case NODE_TRACE:
+       case NODE_VARIANT:
+       case NODE_STRUCT:
+       case NODE_TYPEDEF:
+       case NODE_TYPEALIAS_TARGET:
+       case NODE_TYPEALIAS_ALIAS:
+       case NODE_TYPE_DECLARATOR:
+       case NODE_ENUM:
+       case NODE_STRUCT_OR_VARIANT_DECLARATION:
+       case NODE_TYPEALIAS:
+       case NODE_FLOATING_POINT:
+       case NODE_INTEGER:
+       case NODE_STRING:
+       case NODE_CTF_EXPRESSION:
+       case NODE_POINTER:
+       case NODE_ENUMERATOR:
+       case NODE_UNARY_EXPRESSION:
+               return -EPERM;
+
+       case NODE_UNKNOWN:
+       default:
+               fprintf(stderr, "[error] %s: unknown node type %d\n", __func__,
+                       (int) parent->type);
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static int reparent_type_specifier_list(struct ctf_node *node,
+                                       struct ctf_node *parent)
 {
        switch (parent->type) {
        case NODE_ROOT:
-               _cds_list_splice_tail(&node->tmp_head, &parent->u.root.declaration_specifier);
+               cds_list_add_tail(&node->siblings, &parent->u.root.declaration_list);
                break;
        case NODE_EVENT:
-               _cds_list_splice_tail(&node->tmp_head, &parent->u.event.declaration_list);
+               cds_list_add_tail(&node->siblings, &parent->u.event.declaration_list);
                break;
        case NODE_STREAM:
-               _cds_list_splice_tail(&node->tmp_head, &parent->u.stream.declaration_list);
+               cds_list_add_tail(&node->siblings, &parent->u.stream.declaration_list);
                break;
        case NODE_TRACE:
-               _cds_list_splice_tail(&node->tmp_head, &parent->u.trace.declaration_list);
+               cds_list_add_tail(&node->siblings, &parent->u.trace.declaration_list);
                break;
        case NODE_VARIANT:
-               _cds_list_splice_tail(&node->tmp_head, &parent->u.variant.declaration_list);
+               cds_list_add_tail(&node->siblings, &parent->u.variant.declaration_list);
                break;
        case NODE_STRUCT:
-               _cds_list_splice_tail(&node->tmp_head, &parent->u._struct.declaration_list);
+               cds_list_add_tail(&node->siblings, &parent->u._struct.declaration_list);
                break;
        case NODE_TYPEDEF:
-               _cds_list_splice_tail(&node->tmp_head, &parent->u._typedef.declaration_specifier);
+               parent->u._typedef.type_specifier_list = node;
                break;
        case NODE_TYPEALIAS_TARGET:
-               _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_target.declaration_specifier);
+               parent->u.typealias_target.type_specifier_list = node;
                break;
        case NODE_TYPEALIAS_ALIAS:
-               _cds_list_splice_tail(&node->tmp_head, &parent->u.typealias_alias.declaration_specifier);
+               parent->u.typealias_alias.type_specifier_list = node;
                break;
        case NODE_TYPE_DECLARATOR:
                parent->u.type_declarator.type = TYPEDEC_NESTED;
-               CDS_INIT_LIST_HEAD(&parent->u.type_declarator.u.nested.length);
-               _cds_list_splice_tail(&node->tmp_head, &parent->u.type_declarator.u.nested.length);
+               parent->u.type_declarator.u.nested.length = node;
                break;
        case NODE_ENUM:
-               _cds_list_splice_tail(&node->tmp_head, &parent->u._enum.container_type);
+               parent->u._enum.container_type = node;
                break;
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
-               _cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.declaration_specifier);
+               parent->u.struct_or_variant_declaration.type_specifier_list = node;
                break;
+       case NODE_TYPE_SPECIFIER:
        case NODE_TYPEALIAS:
        case NODE_FLOATING_POINT:
        case NODE_INTEGER:
        case NODE_STRING:
        case NODE_CTF_EXPRESSION:
-       case NODE_TYPE_SPECIFIER:
        case NODE_POINTER:
        case NODE_ENUMERATOR:
        case NODE_UNARY_EXPRESSION:
@@ -557,6 +597,7 @@ static int reparent_type_declarator(struct ctf_node *node,
        case NODE_STRING:
        case NODE_CTF_EXPRESSION:
        case NODE_TYPE_SPECIFIER:
+       case NODE_TYPE_SPECIFIER_LIST:
        case NODE_POINTER:
        case NODE_ENUMERATOR:
        case NODE_UNARY_EXPRESSION:
@@ -594,20 +635,23 @@ static int set_parent_node(struct ctf_node *node,
        case NODE_EVENT:
                if (parent->type == NODE_ROOT) {
                        _cds_list_splice_tail(&node->tmp_head, &parent->u.root.event);
-               } else
+               } else {
                        return -EPERM;
+               }
                break;
        case NODE_STREAM:
                if (parent->type == NODE_ROOT) {
                        _cds_list_splice_tail(&node->tmp_head, &parent->u.root.stream);
-               } else
+               } else {
                        return -EPERM;
+               }
                break;
        case NODE_TRACE:
                if (parent->type == NODE_ROOT) {
                        _cds_list_splice_tail(&node->tmp_head, &parent->u.root.trace);
-               } else
+               } else {
                        return -EPERM;
+               }
                break;
 
        case NODE_CTF_EXPRESSION:
@@ -643,20 +687,26 @@ static int set_parent_node(struct ctf_node *node,
        case NODE_TYPE_DECLARATOR:
                return reparent_type_declarator(node, parent);
 
+       case NODE_TYPE_SPECIFIER_LIST:
+               return reparent_type_specifier_list(node, parent);
+
        case NODE_TYPE_SPECIFIER:
+               return reparent_type_specifier(node, parent);
+
        case NODE_FLOATING_POINT:
        case NODE_INTEGER:
        case NODE_STRING:
        case NODE_ENUM:
        case NODE_VARIANT:
        case NODE_STRUCT:
-               return reparent_type_specifier(node, parent);
+               return -EINVAL; /* Dealt with internally within grammar */
 
        case NODE_ENUMERATOR:
                if (parent->type == NODE_ENUM) {
                        _cds_list_splice_tail(&node->tmp_head, &parent->u._enum.enumerator_list);
-               } else
+               } else {
                        return -EPERM;
+               }
                break;
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
                switch (parent->type) {
@@ -715,9 +765,7 @@ static struct ctf_ast *ctf_ast_alloc(void)
        CDS_INIT_LIST_HEAD(&ast->allocated_nodes);
        ast->root.type = NODE_ROOT;
        CDS_INIT_LIST_HEAD(&ast->root.tmp_head);
-       CDS_INIT_LIST_HEAD(&ast->root.u.root._typedef);
-       CDS_INIT_LIST_HEAD(&ast->root.u.root.typealias);
-       CDS_INIT_LIST_HEAD(&ast->root.u.root.declaration_specifier);
+       CDS_INIT_LIST_HEAD(&ast->root.u.root.declaration_list);
        CDS_INIT_LIST_HEAD(&ast->root.u.root.trace);
        CDS_INIT_LIST_HEAD(&ast->root.u.root.stream);
        CDS_INIT_LIST_HEAD(&ast->root.u.root.event);
@@ -1101,31 +1149,51 @@ declaration:
                {       $$ = $1;        }
        |       declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
                {
+                       struct ctf_node *list;
+
                        $$ = make_node(scanner, NODE_TYPEDEF);
-                       _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
-                       _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.declaration_specifier);
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       $$->u._typedef.type_specifier_list = list;
+                       _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
+                       _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
                }
        |       TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
                {
+                       struct ctf_node *list;
+
                        $$ = make_node(scanner, NODE_TYPEDEF);
-                       _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._typedef.declaration_specifier);
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       $$->u._typedef.type_specifier_list = list;
+                       _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
                }
        |       declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
                {
+                       struct ctf_node *list;
+
                        $$ = make_node(scanner, NODE_TYPEDEF);
-                       _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       $$->u._typedef.type_specifier_list = list;
+                       _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
                }
        |       TYPEALIAS declaration_specifiers abstract_declarator_list COLON alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
                {
+                       struct ctf_node *list;
+
                        $$ = make_node(scanner, NODE_TYPEALIAS);
                        $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
                        $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
-                       _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
+
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
+                       _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
-                       _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
+
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
+                       _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
                }
        ;
@@ -1204,11 +1272,21 @@ trace_declaration_end:
 declaration_specifiers:
                CONST
                {
-                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
-                       $$->u.type_specifier.type = TYPESPEC_CONST;
+                       struct ctf_node *node;
+
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       node = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       node->u.type_specifier.type = TYPESPEC_CONST;
+                       cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
                }
        |       type_specifier
-               {       $$ = $1;        }
+               {
+                       struct ctf_node *node;
+
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       node = $1;
+                       cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
+               }
        |       declaration_specifiers CONST
                {
                        struct ctf_node *node;
@@ -1216,12 +1294,12 @@ declaration_specifiers:
                        $$ = $1;
                        node = make_node(scanner, NODE_TYPE_SPECIFIER);
                        node->u.type_specifier.type = TYPESPEC_CONST;
-                       cds_list_add_tail(&node->siblings, &($$)->tmp_head);
+                       cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
                }
        |       declaration_specifiers type_specifier
                {
                        $$ = $1;
-                       cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
+                       cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
                }
        ;
 
@@ -1304,40 +1382,66 @@ type_specifier:
                }
        |       FLOATING_POINT LBRAC RBRAC
                {
-                       $$ = make_node(scanner, NODE_FLOATING_POINT);
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
+                       $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
                }
        |       FLOATING_POINT LBRAC ctf_assignment_expression_list RBRAC
                {
-                       $$ = make_node(scanner, NODE_FLOATING_POINT);
-                       if (set_parent_node($3, $$))
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_FLOATING_POINT;
+                       $$->u.type_specifier.node = make_node(scanner, NODE_FLOATING_POINT);
+                       if (set_parent_node($3, $$->u.type_specifier.node))
                                reparent_error(scanner, "floating point reparent error");
                }
        |       INTEGER LBRAC RBRAC
                {
-                       $$ = make_node(scanner, NODE_INTEGER);
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_INTEGER;
+                       $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
                }
        |       INTEGER LBRAC ctf_assignment_expression_list RBRAC
                {
-                       $$ = make_node(scanner, NODE_INTEGER);
-                       if (set_parent_node($3, $$))
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_INTEGER;
+                       $$->u.type_specifier.node = make_node(scanner, NODE_INTEGER);
+                       if (set_parent_node($3, $$->u.type_specifier.node))
                                reparent_error(scanner, "integer reparent error");
                }
        |       STRING LBRAC RBRAC
                {
-                       $$ = make_node(scanner, NODE_STRING);
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_STRING;
+                       $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
                }
        |       STRING LBRAC ctf_assignment_expression_list RBRAC
                {
-                       $$ = make_node(scanner, NODE_STRING);
-                       if (set_parent_node($3, $$))
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_STRING;
+                       $$->u.type_specifier.node = make_node(scanner, NODE_STRING);
+                       if (set_parent_node($3, $$->u.type_specifier.node))
                                reparent_error(scanner, "string reparent error");
                }
        |       ENUM enum_type_specifier
-               {       $$ = $2;                }
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_ENUM;
+                       $$->u.type_specifier.node = $2;
+               }
        |       VARIANT variant_type_specifier
-               {       $$ = $2;                }
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_VARIANT;
+                       $$->u.type_specifier.node = $2;
+                       $$ = $2;
+               }
        |       STRUCT struct_type_specifier
-               {       $$ = $2;                }
+               {
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       $$->u.type_specifier.type = TYPESPEC_STRUCT;
+                       $$->u.type_specifier.node = $2;
+                       $$ = $2;
+               }
        ;
 
 struct_type_specifier:
@@ -1541,7 +1645,7 @@ enum_type_specifier:
                {
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 1;
-                       _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.container_type);
+                       ($$)->u._enum.container_type = $2;
                        _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
                }
        |       IDENTIFIER LBRAC enumerator_list RBRAC
@@ -1556,7 +1660,7 @@ enum_type_specifier:
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 1;
                        $$->u._enum.enum_id = $1->s;
-                       _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.container_type);
+                       ($$)->u._enum.container_type = $3;
                        _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
                }
        |       ID_TYPE LBRAC enumerator_list RBRAC
@@ -1571,7 +1675,7 @@ enum_type_specifier:
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 1;
                        $$->u._enum.enum_id = $1->s;
-                       _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.container_type);
+                       ($$)->u._enum.container_type = $3;
                        _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
                }
        |       LBRAC enumerator_list COMMA RBRAC
@@ -1584,7 +1688,7 @@ enum_type_specifier:
                {
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 1;
-                       _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.container_type);
+                       ($$)->u._enum.container_type = $2;
                        _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list);
                }
        |       IDENTIFIER LBRAC enumerator_list COMMA RBRAC
@@ -1599,7 +1703,7 @@ enum_type_specifier:
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 1;
                        $$->u._enum.enum_id = $1->s;
-                       _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.container_type);
+                       ($$)->u._enum.container_type = $3;
                        _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
                }
        |       IDENTIFIER
@@ -1613,7 +1717,7 @@ enum_type_specifier:
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 0;
                        $$->u._enum.enum_id = $1->s;
-                       _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.container_type);
+                       ($$)->u._enum.container_type = $3;
                }
        |       ID_TYPE LBRAC enumerator_list COMMA RBRAC
                {
@@ -1627,7 +1731,7 @@ enum_type_specifier:
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 1;
                        $$->u._enum.enum_id = $1->s;
-                       _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.container_type);
+                       ($$)->u._enum.container_type = $3;
                        _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list);
                }
        |       ID_TYPE
@@ -1641,7 +1745,7 @@ enum_type_specifier:
                        $$ = make_node(scanner, NODE_ENUM);
                        $$->u._enum.has_body = 0;
                        $$->u._enum.enum_id = $1->s;
-                       _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.container_type);
+                       ($$)->u._enum.container_type = $3;
                }
        ;
 
@@ -1663,37 +1767,61 @@ struct_or_variant_declaration_list:
 struct_or_variant_declaration:
                declaration_specifiers struct_or_variant_declarator_list SEMICOLON
                {
+                       struct ctf_node *list;
+
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION);
-                       _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.struct_or_variant_declaration.declaration_specifier);
+                       ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
                        _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators);
                }
        |       declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
                {
+                       struct ctf_node *list;
+
                        $$ = make_node(scanner, NODE_TYPEDEF);
-                       _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
-                       _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.declaration_specifier);
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       $$->u._typedef.type_specifier_list = list;
+                       _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
+                       _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
                }
        |       TYPEDEF declaration_specifiers type_declarator_list SEMICOLON
                {
+                       struct ctf_node *list;
+
                        $$ = make_node(scanner, NODE_TYPEDEF);
-                       _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._typedef.declaration_specifier);
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       $$->u._typedef.type_specifier_list = list;
+                       _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
                }
        |       declaration_specifiers TYPEDEF type_declarator_list SEMICOLON
                {
+                       struct ctf_node *list;
+
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        $$ = make_node(scanner, NODE_TYPEDEF);
-                       _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
+                       ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
                        _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
                }
        |       TYPEALIAS declaration_specifiers abstract_declarator_list COLON alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON
                {
+                       struct ctf_node *list;
+
                        $$ = make_node(scanner, NODE_TYPEALIAS);
                        $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
                        $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
-                       _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
+
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
+                       _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
-                       _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
+
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
+                       _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
                }
        ;
@@ -1701,17 +1829,31 @@ struct_or_variant_declaration:
 alias_declaration_specifiers:
                CONST
                {
-                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
-                       $$->u.type_specifier.type = TYPESPEC_CONST;
+                       struct ctf_node *node;
+
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       node = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       node->u.type_specifier.type = TYPESPEC_CONST;
+                       cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
                }
        |       type_specifier
-               {       $$ = $1;        }
+               {
+                       struct ctf_node *node;
+
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       node = $1;
+                       cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
+               }
        |       IDENTIFIER
                {
+                       struct ctf_node *node;
+
                        add_type(scanner, $1);
-                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER);
-                       ($$)->u.type_specifier.type = TYPESPEC_ID_TYPE;
-                       ($$)->u.type_specifier.id_type = yylval.gs->s;
+                       $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       node = make_node(scanner, NODE_TYPE_SPECIFIER);
+                       node->u.type_specifier.type = TYPESPEC_ID_TYPE;
+                       node->u.type_specifier.id_type = yylval.gs->s;
+                       cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
                }
        |       alias_declaration_specifiers CONST
                {
@@ -1720,12 +1862,12 @@ alias_declaration_specifiers:
                        $$ = $1;
                        node = make_node(scanner, NODE_TYPE_SPECIFIER);
                        node->u.type_specifier.type = TYPESPEC_CONST;
-                       cds_list_add_tail(&node->siblings, &($$)->tmp_head);
+                       cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
                }
        |       alias_declaration_specifiers type_specifier
                {
                        $$ = $1;
-                       cds_list_add_tail(&($2)->siblings, &($$)->tmp_head);
+                       cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head);
                }
        |       alias_declaration_specifiers IDENTIFIER
                {
@@ -1736,7 +1878,7 @@ alias_declaration_specifiers:
                        node = make_node(scanner, NODE_TYPE_SPECIFIER);
                        node->u.type_specifier.type = TYPESPEC_ID_TYPE;
                        node->u.type_specifier.id_type = yylval.gs->s;
-                       cds_list_add_tail(&node->siblings, &($$)->tmp_head);
+                       cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head);
                }
        ;
 
@@ -1875,8 +2017,7 @@ direct_abstract_declarator:
                        $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
                        $$->u.type_declarator.type = TYPEDEC_NESTED;
                        $$->u.type_declarator.u.nested.type_declarator = $1;
-                       CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
-                       _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
+                       ($$)->u.type_declarator.u.nested.length = $3;
                }
        |       direct_abstract_declarator LSBRAC RSBRAC
                {
@@ -1925,8 +2066,7 @@ direct_alias_abstract_declarator:
                        $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
                        $$->u.type_declarator.type = TYPEDEC_NESTED;
                        $$->u.type_declarator.u.nested.type_declarator = $1;
-                       CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
-                       _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
+                       ($$)->u.type_declarator.u.nested.length = $3;
                }
        |       direct_alias_abstract_declarator LSBRAC RSBRAC
                {
@@ -1965,8 +2105,7 @@ direct_declarator:
                        $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
                        $$->u.type_declarator.type = TYPEDEC_NESTED;
                        $$->u.type_declarator.u.nested.type_declarator = $1;
-                       CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
-                       _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
+                       ($$)->u.type_declarator.u.nested.length = $3;
                }
        ;
 
@@ -1999,8 +2138,7 @@ direct_type_declarator:
                        $$ = make_node(scanner, NODE_TYPE_DECLARATOR);
                        $$->u.type_declarator.type = TYPEDEC_NESTED;
                        $$->u.type_declarator.u.nested.type_declarator = $1;
-                       CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length);
-                       _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length);
+                       ($$)->u.type_declarator.u.nested.length = $3;
                }
        ;
 
@@ -2053,8 +2191,9 @@ ctf_assignment_expression:
                                reparent_error(scanner, "ctf_assignment_expression left expects string");
                        _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
                }
-       |       unary_expression TYPEASSIGN type_specifier
+       |       unary_expression TYPEASSIGN type_specifier      /* Only allow struct */
                {
+                       struct ctf_node *list;
                        /*
                         * Because we have left and right, cannot use
                         * set_parent_node.
@@ -2063,36 +2202,57 @@ ctf_assignment_expression:
                        _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.ctf_expression.left);
                        if ($1->u.unary_expression.type != UNARY_STRING)
                                reparent_error(scanner, "ctf_assignment_expression left expects string");
-                       cds_list_add(&($3)->siblings, &($3)->tmp_head);
-                       _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.ctf_expression.right);
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       cds_list_add_tail(&($3)->siblings, &list->u.type_specifier_list.head);
+                       cds_list_add_tail(&list->siblings, &($$)->u.ctf_expression.right);
                }
        |       declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list
                {
+                       struct ctf_node *list;
+
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
+                       _cds_list_splice_tail(&($3)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        $$ = make_node(scanner, NODE_TYPEDEF);
-                       _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.declaration_specifier);
-                       _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
+                       ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
                        _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators);
                }
        |       TYPEDEF declaration_specifiers type_declarator_list
                {
+                       struct ctf_node *list;
+
                        $$ = make_node(scanner, NODE_TYPEDEF);
-                       _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._typedef.declaration_specifier);
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       $$->u._typedef.type_specifier_list = list;
+                       _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
                }
        |       declaration_specifiers TYPEDEF type_declarator_list
                {
+                       struct ctf_node *list;
+
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       _cds_list_splice_tail(&($1)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        $$ = make_node(scanner, NODE_TYPEDEF);
-                       _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier);
+                       ($$)->u.struct_or_variant_declaration.type_specifier_list = list;
                        _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators);
                }
        |       TYPEALIAS declaration_specifiers abstract_declarator_list COLON alias_declaration_specifiers alias_abstract_declarator_list
                {
+                       struct ctf_node *list;
+
                        $$ = make_node(scanner, NODE_TYPEALIAS);
                        $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET);
                        $$->u.typealias.alias = make_node(scanner, NODE_TYPEALIAS_ALIAS);
-                       _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.typealias.target->u.typealias_target.declaration_specifier);
+
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       $$->u.typealias.target->u.typealias_target.type_specifier_list = list;
+                       _cds_list_splice_tail(&($2)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.target->u.typealias_target.type_declarators);
-                       _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier);
+
+                       list = make_node(scanner, NODE_TYPE_SPECIFIER_LIST);
+                       $$->u.typealias.alias->u.typealias_alias.type_specifier_list = list;
+                       _cds_list_splice_tail(&($5)->u.type_specifier_list.head, &list->u.type_specifier_list.head);
                        _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators);
                }
        ;
diff --git a/formats/ctf/metadata/ctf-test/fail/typealias-no-array-alias.txt b/formats/ctf/metadata/ctf-test/fail/typealias-no-array-alias.txt
new file mode 100644 (file)
index 0000000..35cea7a
--- /dev/null
@@ -0,0 +1 @@
+typealias integer { size = 32; align = 32; signed = false; } : unsigned const long [];
index 2b127cc412a5f7b2151998847c13ab253892fcd9..1ed2a014882efd8eb659e8aefba93162b896fb03 100644 (file)
@@ -156,4 +156,3 @@ typedef int rootscopetest;
 event { a.b.c.d.e = f.g.h->i->j; };
 
 typealias integer { size = 32; align = 32; signed = false; } : unsigned long long *;
-typealias integer { size = 32; align = 32; signed = false; } : unsigned const long [];
index d9b8d77481fd791b81186a8b486a2305b18d1675..4ddd9b784edb78df3949b5bde00a83f92c2a1dbd 100644 (file)
@@ -1652,30 +1652,36 @@ int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node,
 
        switch (node->type) {
        case NODE_ROOT:
-               cds_list_for_each_entry(iter, &node->u.root._typedef,
+               cds_list_for_each_entry(iter, &node->u.root.declaration_list,
                                        siblings) {
-                       ret = ctf_typedef_visit(fd, depth + 1,
+                       switch (iter->type) {
+                       case NODE_TYPEDEF:
+                               ret = ctf_typedef_visit(fd, depth + 1,
+                                                       trace->root_declaration_scope,
+                                                       &iter->u._typedef.declaration_specifier,
+                                                       &iter->u._typedef.type_declarators,
+                                                       trace);
+                               if (ret)
+                                       return ret;
+                               break;
+                       case NODE_TYPEALIAS:
+                               ret = ctf_typealias_visit(fd, depth + 1,
                                                trace->root_declaration_scope,
-                                               &iter->u._typedef.declaration_specifier,
-                                               &iter->u._typedef.type_declarators,
+                                               iter->u.typealias.target, iter->u.typealias.alias,
                                                trace);
-                       if (ret)
-                               return ret;
-               }
-               cds_list_for_each_entry(iter, &node->u.root.typealias,
-                                       siblings) {
-                       ret = ctf_typealias_visit(fd, depth + 1,
-                                       trace->root_declaration_scope,
-                                       iter->u.typealias.target, iter->u.typealias.alias,
-                                       trace);
-                       if (ret)
-                               return ret;
-               }
-               cds_list_for_each_entry(iter, &node->u.root.declaration_specifier, siblings) {
-                       ret = ctf_declaration_specifier_visit(fd, depth, iter,
-                                       trace->root_declaration_scope, trace);
-                       if (ret)
-                               return ret;
+                               if (ret)
+                                       return ret;
+                               break;
+                       case NODE_DECLARATION_SPECIFIER:
+                               ret = ctf_declaration_specifier_visit(fd, depth, iter,
+                                               trace->root_declaration_scope, trace);
+                               if (ret)
+                                       return ret;
+                               break;
+                       default:
+                               fprintf(stderr, "[error] %s: unexpected root child type %d\n", __func__,
+                                       (int) iter->type);
+                               return -EINVAL;
                }
                cds_list_for_each_entry(iter, &node->u.root.trace, siblings) {
                        ret = ctf_trace_visit(fd, depth + 1, iter, trace);
index 8c4b2124c73d3fd8a34dd42015b774a68439b625..9337dd49b832e9a053f568d6f3b96887ba04bd23 100644 (file)
@@ -80,6 +80,8 @@ int ctf_visitor_unary_expression(FILE *fd, int depth, struct ctf_node *node)
 static
 int ctf_visitor_type_specifier(FILE *fd, int depth, struct ctf_node *node)
 {
+       int ret;
+
        switch (node->u.type_specifier.type) {
        case TYPESPEC_VOID:
        case TYPESPEC_CHAR:
@@ -96,6 +98,17 @@ int ctf_visitor_type_specifier(FILE *fd, int depth, struct ctf_node *node)
        case TYPESPEC_CONST:
        case TYPESPEC_ID_TYPE:
                break;
+       case TYPESPEC_FLOATING_POINT:
+       case TYPESPEC_INTEGER:
+       case TYPESPEC_STRING:
+       case TYPESPEC_STRUCT:
+       case TYPESPEC_VARIANT:
+       case TYPESPEC_ENUM:
+               node->u.type_specifier.node->parent = node;
+               ret = ctf_visitor_parent_links(fd, depth + 1, node->u.type_specifier.node);
+               if (ret)
+                       return ret;
+               break;
 
        case TYPESPEC_UNKNOWN:
        default:
@@ -135,10 +148,9 @@ int ctf_visitor_type_declarator(FILE *fd, int depth, struct ctf_node *node)
                        if (ret)
                                return ret;
                }
-               cds_list_for_each_entry(iter, &node->u.type_declarator.u.nested.length,
-                                       siblings) {
-                       iter->parent = node;
-                       ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+               if (node->u.type_declarator.u.nested.length) {
+                       node->u.type_declarator.u.nested.length->parent = node;
+                       ret = ctf_visitor_parent_links(fd, depth + 1, node->u.type_declarator.u.nested.length);
                        if (ret)
                                return ret;
                }
@@ -167,21 +179,7 @@ int ctf_visitor_parent_links(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) {
-                       iter->parent = node;
-                       ret = ctf_visitor_parent_links(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
-               cds_list_for_each_entry(iter, &node->u.root.typealias,
-                                       siblings) {
-                       iter->parent = node;
-                       ret = ctf_visitor_parent_links(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) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
                        if (ret)
@@ -253,12 +251,10 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
 
        case NODE_TYPEDEF:
                depth++;
-               cds_list_for_each_entry(iter, &node->u._typedef.declaration_specifier, siblings) {
-                       iter->parent = node;
-                       ret = ctf_visitor_parent_links(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
+               node->u._typedef.type_specifier_list->parent = node;
+               ret = ctf_visitor_parent_links(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) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
@@ -269,12 +265,10 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                break;
        case NODE_TYPEALIAS_TARGET:
                depth++;
-               cds_list_for_each_entry(iter, &node->u.typealias_target.declaration_specifier, siblings) {
-                       iter->parent = node;
-                       ret = ctf_visitor_parent_links(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
+               node->u.typealias_target.type_specifier_list->parent = node;
+               ret = ctf_visitor_parent_links(fd, depth + 1, node->u.typealias_target.type_specifier_list);
+               if (ret)
+                       return ret;
                cds_list_for_each_entry(iter, &node->u.typealias_target.type_declarators, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
@@ -285,12 +279,10 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                break;
        case NODE_TYPEALIAS_ALIAS:
                depth++;
-               cds_list_for_each_entry(iter, &node->u.typealias_alias.declaration_specifier, siblings) {
-                       iter->parent = node;
-                       ret = ctf_visitor_parent_links(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
+               node->u.typealias_alias.type_specifier_list->parent = node;
+               ret = ctf_visitor_parent_links(fd, depth + 1, node->u.typealias_alias.type_specifier_list);
+               if (ret)
+                       return ret;
                cds_list_for_each_entry(iter, &node->u.typealias_alias.type_declarators, siblings) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
@@ -310,6 +302,15 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                        return ret;
                break;
 
+       case NODE_TYPE_SPECIFIER_LIST:
+               cds_list_for_each_entry(iter, &node->u.type_specifier_list.head, siblings) {
+                       iter->parent = node;
+                       ret = ctf_visitor_parent_links(fd, depth + 1, iter);
+                       if (ret)
+                               return ret;
+               }
+               break;
+
        case NODE_TYPE_SPECIFIER:
                ret = ctf_visitor_type_specifier(fd, depth, node);
                if (ret)
@@ -357,14 +358,9 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                break;
        case NODE_ENUM:
                depth++;
-
-               cds_list_for_each_entry(iter, &node->u._enum.container_type,
-                                       siblings) {
-                       iter->parent = node;
-                       ret = ctf_visitor_parent_links(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
+               ret = ctf_visitor_parent_links(fd, depth + 1, node->u._enum.container_type);
+               if (ret)
+                       return ret;
 
                cds_list_for_each_entry(iter, &node->u._enum.enumerator_list, siblings) {
                        iter->parent = node;
@@ -375,12 +371,11 @@ int ctf_visitor_parent_links(FILE *fd, int depth, struct ctf_node *node)
                depth--;
                break;
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
-               cds_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.declaration_specifier, siblings) {
-                       iter->parent = node;
-                       ret = ctf_visitor_parent_links(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
+               node->u.struct_or_variant_declaration.type_specifier_list->parent = node;
+               ret = ctf_visitor_parent_links(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) {
                        iter->parent = node;
                        ret = ctf_visitor_parent_links(fd, depth + 1, iter);
index 8decc19ef64a7fd5b6b6f808183766704c1d883d..6385b0bd3ffb2e76c61f3abe059083a8d53cd871 100644 (file)
@@ -180,7 +180,7 @@ errperm:
 }
 
 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:
@@ -190,8 +190,47 @@ int ctf_visitor_type_specifier(FILE *fd, int depth, struct ctf_node *node)
        case NODE_TYPEALIAS_ALIAS:
        case NODE_ENUM:
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
+       case NODE_ROOT:
+               break;                  /* OK */
+
+       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:
@@ -248,8 +287,19 @@ int ctf_visitor_type_declarator(FILE *fd, int depth, struct ctf_node *node)
                 */
                if (node->u.type_declarator.type == TYPEDEC_NESTED)
                        goto errperm;
-               if (cds_list_empty(&node->u.type_declarator.pointers))
-                       goto errperm;
+               switch (node->u.type_declarator.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;
@@ -292,25 +342,16 @@ int ctf_visitor_type_declarator(FILE *fd, int depth, struct ctf_node *node)
                break;
        case TYPEDEC_NESTED:
        {
-               int nr_nest_len;
-
                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;
                }
-               cds_list_for_each_entry(iter, &node->u.type_declarator.u.nested.length,
-                                       siblings) {
-                       ret = _ctf_visitor_semantic_check(fd, depth + 1,
-                               iter);
-                       if (ret)
-                               return ret;
-                       nr_nest_len++;
-                       if (iter->type == NODE_UNARY_EXPRESSION && nr_nest_len > 1) {
-                               goto errperm;
-                       }
-               }
+               ret = _ctf_visitor_semantic_check(fd, depth + 1,
+                       node->u.type_declarator.u.nested.length);
+               if (ret)
+                       return ret;
                if (node->u.type_declarator.bitfield_len) {
                        ret = _ctf_visitor_semantic_check(fd, depth + 1,
                                node->u.type_declarator.bitfield_len);
@@ -347,19 +388,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;
@@ -443,6 +472,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:
@@ -487,6 +517,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:
@@ -499,11 +530,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)
@@ -523,11 +553,10 @@ 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);
@@ -555,11 +584,10 @@ 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);
@@ -593,6 +621,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:
@@ -612,6 +641,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)
@@ -633,28 +667,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;
 
@@ -669,29 +683,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;
 
@@ -705,28 +698,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;
 
@@ -788,28 +761,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;
 
@@ -818,12 +771,9 @@ int _ctf_visitor_semantic_check(FILE *fd, int depth, struct ctf_node *node)
                }
 
                depth++;
-               cds_list_for_each_entry(iter, &node->u._enum.container_type,
-                                       siblings) {
-                       ret = _ctf_visitor_semantic_check(fd, depth + 1, iter);
-                       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);
@@ -840,11 +790,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)
@@ -853,28 +802,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;
 
@@ -890,28 +819,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;
 
index 7f08031a1e08a579b68af62ebcee97a34f645f5e..d1c0751c51e3c8c548144c087cd1834c05d6fa52 100644 (file)
@@ -115,11 +115,61 @@ int ctf_visitor_print_unary_expression(FILE *fd, int depth, struct ctf_node *nod
        return 0;
 }
 
+static
+int ctf_visitor_print_type_specifier_list(FILE *fd, int depth, struct ctf_node *node)
+{
+       struct ctf_node *iter;
+       int ret;
+
+       print_tabs(fd, depth);
+       fprintf(fd, "<type_specifier_list>\n");
+       cds_list_for_each_entry(iter, &node->u.type_specifier_list.head, siblings) {
+               ret = ctf_visitor_print_xml(fd, depth + 1, iter);
+               if (ret)
+                       return ret;
+       }
+       print_tabs(fd, depth);
+       fprintf(fd, "</type_specifier_list>\n");
+       return 0;
+}
+
 static
 int ctf_visitor_print_type_specifier(FILE *fd, int depth, struct ctf_node *node)
 {
        print_tabs(fd, depth);
-       fprintf(fd, "<type_specifier \"");
+
+       switch (node->u.type_specifier.type) {
+       case TYPESPEC_VOID:
+       case TYPESPEC_CHAR:
+       case TYPESPEC_SHORT:
+       case TYPESPEC_INT:
+       case TYPESPEC_LONG:
+       case TYPESPEC_FLOAT:
+       case TYPESPEC_DOUBLE:
+       case TYPESPEC_SIGNED:
+       case TYPESPEC_UNSIGNED:
+       case TYPESPEC_BOOL:
+       case TYPESPEC_COMPLEX:
+       case TYPESPEC_IMAGINARY:
+       case TYPESPEC_CONST:
+       case TYPESPEC_ID_TYPE:
+               fprintf(fd, "<type_specifier \"");
+               break;
+       case TYPESPEC_FLOATING_POINT:
+       case TYPESPEC_INTEGER:
+       case TYPESPEC_STRING:
+       case TYPESPEC_STRUCT:
+       case TYPESPEC_VARIANT:
+       case TYPESPEC_ENUM:
+               fprintf(fd, "<type_specifier>\n");
+               depth++;
+               break;
+       case TYPESPEC_UNKNOWN:
+       default:
+               fprintf(stderr, "[error] %s: unknown type specifier %d\n", __func__,
+                       (int) node->u.type_specifier.type);
+               return -EINVAL;
+       }
 
        switch (node->u.type_specifier.type) {
        case TYPESPEC_VOID:
@@ -164,14 +214,54 @@ int ctf_visitor_print_type_specifier(FILE *fd, int depth, struct ctf_node *node)
        case TYPESPEC_ID_TYPE:
                fprintf(fd, "%s", node->u.type_specifier.id_type);
                break;
+       case TYPESPEC_FLOATING_POINT:
+       case TYPESPEC_INTEGER:
+       case TYPESPEC_STRING:
+       case TYPESPEC_STRUCT:
+       case TYPESPEC_VARIANT:
+       case TYPESPEC_ENUM:
+               return ctf_visitor_print_xml(fd, depth, node->u.type_specifier.node);
+       case TYPESPEC_UNKNOWN:
+       default:
+               fprintf(stderr, "[error] %s: unknown type specifier %d\n", __func__,
+                       (int) node->u.type_specifier.type);
+               return -EINVAL;
+       }
 
+       switch (node->u.type_specifier.type) {
+       case TYPESPEC_VOID:
+       case TYPESPEC_CHAR:
+       case TYPESPEC_SHORT:
+       case TYPESPEC_INT:
+       case TYPESPEC_LONG:
+       case TYPESPEC_FLOAT:
+       case TYPESPEC_DOUBLE:
+       case TYPESPEC_SIGNED:
+       case TYPESPEC_UNSIGNED:
+       case TYPESPEC_BOOL:
+       case TYPESPEC_COMPLEX:
+       case TYPESPEC_IMAGINARY:
+       case TYPESPEC_CONST:
+       case TYPESPEC_ID_TYPE:
+               fprintf(fd, "\"/>\n");
+               break;
+       case TYPESPEC_FLOATING_POINT:
+       case TYPESPEC_INTEGER:
+       case TYPESPEC_STRING:
+       case TYPESPEC_STRUCT:
+       case TYPESPEC_VARIANT:
+       case TYPESPEC_ENUM:
+               print_tabs(fd, depth);
+               fprintf(fd, "</type_specifier>\n");
+               depth--;
+               break;
        case TYPESPEC_UNKNOWN:
        default:
                fprintf(stderr, "[error] %s: unknown type specifier %d\n", __func__,
                        (int) node->u.type_specifier.type);
                return -EINVAL;
        }
-       fprintf(fd, "\"/>\n");
+
        return 0;
 }
 
@@ -218,17 +308,12 @@ int ctf_visitor_print_type_declarator(FILE *fd, int depth, struct ctf_node *node
                        print_tabs(fd, depth);
                        fprintf(fd, "</type_declarator>\n");
                }
-               if (!cds_list_empty(&node->u.type_declarator.u.nested.length)) {
+               if (node->u.type_declarator.u.nested.length) {
                        print_tabs(fd, depth);
                        fprintf(fd, "<length>\n");
-               }
-               cds_list_for_each_entry(iter, &node->u.type_declarator.u.nested.length,
-                                       siblings) {
-                       ret = ctf_visitor_print_xml(fd, depth + 1, iter);
+                       ret = ctf_visitor_print_xml(fd, depth + 1, node->u.type_declarator.u.nested.length);
                        if (ret)
                                return ret;
-               }
-               if (!cds_list_empty(&node->u.type_declarator.u.nested.length)) {
                        print_tabs(fd, depth);
                        fprintf(fd, "</length>\n");
                }
@@ -271,23 +356,12 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
        case NODE_ROOT:
                print_tabs(fd, depth);
                fprintf(fd, "<root>\n");
-               cds_list_for_each_entry(iter, &node->u.root._typedef,
+               cds_list_for_each_entry(iter, &node->u.root.declaration_list,
                                        siblings) {
                        ret = ctf_visitor_print_xml(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
-               cds_list_for_each_entry(iter, &node->u.root.typealias,
-                                       siblings) {
-                       ret = ctf_visitor_print_xml(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
-               cds_list_for_each_entry(iter, &node->u.root.declaration_specifier, siblings) {
-                       ret = ctf_visitor_print_xml(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
                cds_list_for_each_entry(iter, &node->u.root.trace, siblings) {
                        ret = ctf_visitor_print_xml(fd, depth + 1, iter);
                        if (ret)
@@ -376,25 +450,19 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
                print_tabs(fd, depth);
                fprintf(fd, "<typedef>\n");
                depth++;
-               print_tabs(fd, depth);
-               fprintf(fd, "<declaration_specifier>\n");
-               cds_list_for_each_entry(iter, &node->u._typedef.declaration_specifier, siblings) {
-                       ret = ctf_visitor_print_xml(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
-               print_tabs(fd, depth);
-               fprintf(fd, "</declaration_specifier>\n");
+               ret = ctf_visitor_print_xml(fd, depth + 1, node->u._typedef.type_specifier_list);
+               if (ret)
+                       return ret;
 
                print_tabs(fd, depth);
-               fprintf(fd, "<type_declarators>\n");
+               fprintf(fd, "<type_declarator_list>\n");
                cds_list_for_each_entry(iter, &node->u._typedef.type_declarators, siblings) {
                        ret = ctf_visitor_print_xml(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
                print_tabs(fd, depth);
-               fprintf(fd, "</type_declarators>\n");
+               fprintf(fd, "</type_declarator_list>\n");
                depth--;
                print_tabs(fd, depth);
                fprintf(fd, "</typedef>\n");
@@ -404,25 +472,19 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
                fprintf(fd, "<target>\n");
                depth++;
 
-               print_tabs(fd, depth);
-               fprintf(fd, "<declaration_specifier>\n");
-               cds_list_for_each_entry(iter, &node->u.typealias_target.declaration_specifier, siblings) {
-                       ret = ctf_visitor_print_xml(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
-               print_tabs(fd, depth);
-               fprintf(fd, "</declaration_specifier>\n");
+               ret = ctf_visitor_print_xml(fd, depth, node->u.typealias_target.type_specifier_list);
+               if (ret)
+                       return ret;
 
                print_tabs(fd, depth);
-               fprintf(fd, "<type_declarators>\n");
+               fprintf(fd, "<type_declarator_list>\n");
                cds_list_for_each_entry(iter, &node->u.typealias_target.type_declarators, siblings) {
                        ret = ctf_visitor_print_xml(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
                print_tabs(fd, depth);
-               fprintf(fd, "</type_declarators>\n");
+               fprintf(fd, "</type_declarator_list>\n");
 
                depth--;
                print_tabs(fd, depth);
@@ -433,25 +495,19 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
                fprintf(fd, "<alias>\n");
                depth++;
 
-               print_tabs(fd, depth);
-               fprintf(fd, "<declaration_specifier>\n");
-               cds_list_for_each_entry(iter, &node->u.typealias_alias.declaration_specifier, siblings) {
-                       ret = ctf_visitor_print_xml(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
-               print_tabs(fd, depth);
-               fprintf(fd, "</declaration_specifier>\n");
+               ret = ctf_visitor_print_xml(fd, depth, node->u.typealias_alias.type_specifier_list);
+               if (ret)
+                       return ret;
 
                print_tabs(fd, depth);
-               fprintf(fd, "<type_declarators>\n");
+               fprintf(fd, "<type_declarator_list>\n");
                cds_list_for_each_entry(iter, &node->u.typealias_alias.type_declarators, siblings) {
                        ret = ctf_visitor_print_xml(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
                print_tabs(fd, depth);
-               fprintf(fd, "</type_declarators>\n");
+               fprintf(fd, "</type_declarator_list>\n");
 
                depth--;
                print_tabs(fd, depth);
@@ -470,6 +526,12 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
                fprintf(fd, "</typealias>\n");
                break;
 
+       case NODE_TYPE_SPECIFIER_LIST:
+               ret = ctf_visitor_print_type_specifier_list(fd, depth, node);
+               if (ret)
+                       return ret;
+               break;
+
        case NODE_TYPE_SPECIFIER:
                ret = ctf_visitor_print_type_specifier(fd, depth, node);
                if (ret)
@@ -544,18 +606,15 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
                        fprintf(fd, "<enum >\n");
                depth++;
 
-               if (!cds_list_empty(&node->u._enum.container_type)) {
+               if (node->u._enum.container_type) {
                        print_tabs(fd, depth);
                        fprintf(fd, "<container_type>\n");
                }
 
-               cds_list_for_each_entry(iter, &node->u._enum.container_type,
-                                       siblings) {
-                       ret = ctf_visitor_print_xml(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
-               if (!cds_list_empty(&node->u._enum.container_type)) {
+               ret = ctf_visitor_print_xml(fd, depth + 1, node->u._enum.container_type);
+               if (ret)
+                       return ret;
+               if (node->u._enum.container_type) {
                        print_tabs(fd, depth);
                        fprintf(fd, "</container_type>\n");
                }
@@ -575,25 +634,20 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node)
                fprintf(fd, "</enum>\n");
                break;
        case NODE_STRUCT_OR_VARIANT_DECLARATION:
-               print_tabs(fd, depth);
-               fprintf(fd, "<declaration_specifier>\n");
-               cds_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.declaration_specifier, siblings) {
-                       ret = ctf_visitor_print_xml(fd, depth + 1, iter);
-                       if (ret)
-                               return ret;
-               }
-               print_tabs(fd, depth);
-               fprintf(fd, "</declaration_specifier>\n");
+               ret = ctf_visitor_print_xml(fd, depth,
+                       node->u.struct_or_variant_declaration.type_specifier_list);
+               if (ret)
+                       return ret;
 
                print_tabs(fd, depth);
-               fprintf(fd, "<type_declarators>\n");
+               fprintf(fd, "<type_declarator_list>\n");
                cds_list_for_each_entry(iter, &node->u.struct_or_variant_declaration.type_declarators, siblings) {
                        ret = ctf_visitor_print_xml(fd, depth + 1, iter);
                        if (ret)
                                return ret;
                }
                print_tabs(fd, depth);
-               fprintf(fd, "</type_declarators>\n");
+               fprintf(fd, "</type_declarator_list>\n");
                break;
        case NODE_VARIANT:
                print_tabs(fd, depth);
This page took 0.049589 seconds and 4 git commands to generate.