From 3e11b713fa76482be45bff5b067cfab5ab6e9be1 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 25 Apr 2011 21:33:13 -0400 Subject: [PATCH] Add type_specifier list node Needed to correctly iterate on type_specifier_list and then iterate on each type_specifier of the list. Signed-off-by: Mathieu Desnoyers --- formats/ctf/metadata/ctf-ast.h | 45 ++- formats/ctf/metadata/ctf-parser.y | 346 +++++++++++++----- .../fail/typealias-no-array-alias.txt | 1 + .../metadata/ctf-test/succeed/ctf-test.txt | 1 - .../metadata/ctf-visitor-generate-io-struct.c | 48 +-- .../ctf/metadata/ctf-visitor-parent-links.c | 97 +++-- .../metadata/ctf-visitor-semantic-validator.c | 273 +++++--------- formats/ctf/metadata/ctf-visitor-xml.c | 200 ++++++---- 8 files changed, 575 insertions(+), 436 deletions(-) create mode 100644 formats/ctf/metadata/ctf-test/fail/typealias-no-array-alias.txt diff --git a/formats/ctf/metadata/ctf-ast.h b/formats/ctf/metadata/ctf-ast.h index c12d09a9..bf6ddb42 100644 --- a/formats/ctf/metadata/ctf-ast.h +++ b/formats/ctf/metadata/ctf-ast.h @@ -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 { diff --git a/formats/ctf/metadata/ctf-parser.y b/formats/ctf/metadata/ctf-parser.y index 66e37923..fcc877ba 100644 --- a/formats/ctf/metadata/ctf-parser.y +++ b/formats/ctf/metadata/ctf-parser.y @@ -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 index 00000000..35cea7a6 --- /dev/null +++ b/formats/ctf/metadata/ctf-test/fail/typealias-no-array-alias.txt @@ -0,0 +1 @@ +typealias integer { size = 32; align = 32; signed = false; } : unsigned const long []; diff --git a/formats/ctf/metadata/ctf-test/succeed/ctf-test.txt b/formats/ctf/metadata/ctf-test/succeed/ctf-test.txt index 2b127cc4..1ed2a014 100644 --- a/formats/ctf/metadata/ctf-test/succeed/ctf-test.txt +++ b/formats/ctf/metadata/ctf-test/succeed/ctf-test.txt @@ -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 []; diff --git a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c index d9b8d774..4ddd9b78 100644 --- a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c +++ b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c @@ -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); diff --git a/formats/ctf/metadata/ctf-visitor-parent-links.c b/formats/ctf/metadata/ctf-visitor-parent-links.c index 8c4b2124..9337dd49 100644 --- a/formats/ctf/metadata/ctf-visitor-parent-links.c +++ b/formats/ctf/metadata/ctf-visitor-parent-links.c @@ -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); diff --git a/formats/ctf/metadata/ctf-visitor-semantic-validator.c b/formats/ctf/metadata/ctf-visitor-semantic-validator.c index 8decc19e..6385b0bd 100644 --- a/formats/ctf/metadata/ctf-visitor-semantic-validator.c +++ b/formats/ctf/metadata/ctf-visitor-semantic-validator.c @@ -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; diff --git a/formats/ctf/metadata/ctf-visitor-xml.c b/formats/ctf/metadata/ctf-visitor-xml.c index 7f08031a..d1c0751c 100644 --- a/formats/ctf/metadata/ctf-visitor-xml.c +++ b/formats/ctf/metadata/ctf-visitor-xml.c @@ -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, "\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, "\n"); + return 0; +} + static int ctf_visitor_print_type_specifier(FILE *fd, int depth, struct ctf_node *node) { print_tabs(fd, depth); - fprintf(fd, "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"); + 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, "\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, "\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, "\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, "\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, "\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, "\n"); depth++; - print_tabs(fd, depth); - fprintf(fd, "\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, "\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, "\n"); + fprintf(fd, "\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, "\n"); + fprintf(fd, "\n"); depth--; print_tabs(fd, depth); fprintf(fd, "\n"); @@ -404,25 +472,19 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node) fprintf(fd, "\n"); depth++; - print_tabs(fd, depth); - fprintf(fd, "\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, "\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, "\n"); + fprintf(fd, "\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, "\n"); + fprintf(fd, "\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, "\n"); depth++; - print_tabs(fd, depth); - fprintf(fd, "\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, "\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, "\n"); + fprintf(fd, "\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, "\n"); + fprintf(fd, "\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, "\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, "\n"); depth++; - if (!cds_list_empty(&node->u._enum.container_type)) { + if (node->u._enum.container_type) { print_tabs(fd, depth); fprintf(fd, "\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, "\n"); } @@ -575,25 +634,20 @@ int ctf_visitor_print_xml(FILE *fd, int depth, struct ctf_node *node) fprintf(fd, "\n"); break; case NODE_STRUCT_OR_VARIANT_DECLARATION: - print_tabs(fd, depth); - fprintf(fd, "\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, "\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, "\n"); + fprintf(fd, "\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, "\n"); + fprintf(fd, "\n"); break; case NODE_VARIANT: print_tabs(fd, depth); -- 2.34.1