From: Mathieu Desnoyers Date: Wed, 27 Apr 2011 02:07:51 +0000 (-0400) Subject: metadata: Support empty structures X-Git-Tag: v0.1~132 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=5039b4cc7e13ee486939c06381432ea35ed77bfa metadata: Support empty structures Signed-off-by: Mathieu Desnoyers --- diff --git a/formats/ctf/metadata/ctf-parser.y b/formats/ctf/metadata/ctf-parser.y index 437242bd..1f4aa9e4 100644 --- a/formats/ctf/metadata/ctf-parser.y +++ b/formats/ctf/metadata/ctf-parser.y @@ -1010,7 +1010,6 @@ postfix_expression: $$->u.unary_expression.type = UNARY_STRING; $$->u.unary_expression.u.string = yylval.gs->s; } - | DECIMAL_CONSTANT { $$ = make_node(scanner, NODE_UNARY_EXPRESSION); @@ -1447,7 +1446,7 @@ struct_type_specifier: { $$ = make_node(scanner, NODE_STRUCT); $$->u._struct.has_body = 1; - if (set_parent_node($2, $$)) + if ($2 && set_parent_node($2, $$)) reparent_error(scanner, "struct reparent error"); } | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end @@ -1455,7 +1454,7 @@ struct_type_specifier: $$ = make_node(scanner, NODE_STRUCT); $$->u._struct.has_body = 1; $$->u._struct.name = $1->s; - if (set_parent_node($3, $$)) + if ($3 && set_parent_node($3, $$)) reparent_error(scanner, "struct reparent error"); } | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end @@ -1463,7 +1462,7 @@ struct_type_specifier: $$ = make_node(scanner, NODE_STRUCT); $$->u._struct.has_body = 1; $$->u._struct.name = $1->s; - if (set_parent_node($3, $$)) + if ($3 && set_parent_node($3, $$)) reparent_error(scanner, "struct reparent error"); } | IDENTIFIER @@ -1495,7 +1494,7 @@ variant_type_specifier: { $$ = make_node(scanner, NODE_VARIANT); $$->u.variant.has_body = 1; - if (set_parent_node($2, $$)) + if ($2 && set_parent_node($2, $$)) reparent_error(scanner, "variant reparent error"); } | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end @@ -1503,7 +1502,7 @@ variant_type_specifier: $$ = make_node(scanner, NODE_VARIANT); $$->u.variant.has_body = 1; $$->u.variant.choice = $2->s; - if (set_parent_node($5, $$)) + if ($5 && set_parent_node($5, $$)) reparent_error(scanner, "variant reparent error"); } | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end @@ -1511,7 +1510,7 @@ variant_type_specifier: $$ = make_node(scanner, NODE_VARIANT); $$->u.variant.has_body = 1; $$->u.variant.choice = $2->s; - if (set_parent_node($5, $$)) + if ($5 && set_parent_node($5, $$)) reparent_error(scanner, "variant reparent error"); } | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end @@ -1519,7 +1518,7 @@ variant_type_specifier: $$ = make_node(scanner, NODE_VARIANT); $$->u.variant.has_body = 1; $$->u.variant.name = $1->s; - if (set_parent_node($3, $$)) + if ($3 && set_parent_node($3, $$)) reparent_error(scanner, "variant reparent error"); } | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end @@ -1528,7 +1527,7 @@ variant_type_specifier: $$->u.variant.has_body = 1; $$->u.variant.name = $1->s; $$->u.variant.choice = $3->s; - if (set_parent_node($6, $$)) + if ($6 && set_parent_node($6, $$)) reparent_error(scanner, "variant reparent error"); } | IDENTIFIER LT IDENTIFIER GT @@ -1544,7 +1543,7 @@ variant_type_specifier: $$->u.variant.has_body = 1; $$->u.variant.name = $1->s; $$->u.variant.choice = $3->s; - if (set_parent_node($6, $$)) + if ($6 && set_parent_node($6, $$)) reparent_error(scanner, "variant reparent error"); } | IDENTIFIER LT ID_TYPE GT @@ -1559,7 +1558,7 @@ variant_type_specifier: $$ = make_node(scanner, NODE_VARIANT); $$->u.variant.has_body = 1; $$->u.variant.name = $1->s; - if (set_parent_node($3, $$)) + if ($3 && set_parent_node($3, $$)) reparent_error(scanner, "variant reparent error"); } | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end @@ -1568,7 +1567,7 @@ variant_type_specifier: $$->u.variant.has_body = 1; $$->u.variant.name = $1->s; $$->u.variant.choice = $3->s; - if (set_parent_node($6, $$)) + if ($6 && set_parent_node($6, $$)) reparent_error(scanner, "variant reparent error"); } | ID_TYPE LT IDENTIFIER GT @@ -1584,7 +1583,7 @@ variant_type_specifier: $$->u.variant.has_body = 1; $$->u.variant.name = $1->s; $$->u.variant.choice = $3->s; - if (set_parent_node($6, $$)) + if ($6 && set_parent_node($6, $$)) reparent_error(scanner, "variant reparent error"); } | ID_TYPE LT ID_TYPE GT diff --git a/formats/ctf/metadata/ctf-test/succeed/ctf-test.txt b/formats/ctf/metadata/ctf-test/succeed/ctf-test.txt index 1ed2a014..034f8f52 100644 --- a/formats/ctf/metadata/ctf-test/succeed/ctf-test.txt +++ b/formats/ctf/metadata/ctf-test/succeed/ctf-test.txt @@ -1,5 +1,9 @@ -enum name { +typealias integer { size = 32; align = 32; signed = true; } : int; +typealias integer { size = 64; align = 64; signed = true; } : long; +typealias integer { size = 64; align = 64; } : unsigned long; + +enum name1 { ZERO, ONE, TWO, @@ -7,18 +11,18 @@ enum name { ELEVEN, }; -enum name { ONE, TWO }; +enum name2 { ONE, TWO }; -enum name { ONE, TWO }; +enum name3 { ONE, TWO }; -enum name { +enum name4 { string = 1 ... 2, "other string" = 3...4, yet_another_string, /* will be assigned to end_value2 + 1 */ "some other string" = 10, }; -enum name { "int" = 1, }; +enum name5 { "int" = 1, }; typealias floating_point { exp_dig = 8; /* sizeof(float) * CHAR_BIT - FLT_MANT_DIG */ @@ -29,9 +33,16 @@ typealias floating_point { typealias integer { size = 32; align = 32; - sign = false; + signed = false; } : struct page *; +trace { + major = 66; + minor = 2; + uuid = "1123fcea-706e-11e0-a38b-f3c28a683a3d"; + word_size = 64; +}; + stream { typealias integer { size = 64; align = 64; signed = false; } : uint64_t; typealias integer { size = 16; align = 16; signed = false; } : uint16_t; @@ -45,8 +56,9 @@ stream { }; struct example { - short a:12; - short b:5; + /* TODO gcc bitfields not supported yet. */ + /* short a:12; + short b:5; */ }; struct name { @@ -153,6 +165,14 @@ struct event_header_2 { typedef int rootscopetest; -event { a.b.c.d.e = f.g.h->i->j; }; +/* parser level only: event { a.b.c.d.e = f.g.h->i->j; }; */ + +event { + name = test_event; + id = 0; + stream_id = 5; + context := struct {}; + payload := struct {}; +}; typealias integer { size = 32; align = 32; signed = false; } : unsigned long long *; diff --git a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c index bdf7125d..28962abd 100644 --- a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c +++ b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c @@ -1177,7 +1177,7 @@ struct declaration *ctf_type_specifier_list_visit(FILE *fd, &node->u.integer.expressions, trace); case TYPESPEC_STRING: return ctf_declaration_string_visit(fd, depth, - &first->u.string.expressions, trace); + &node->u.string.expressions, trace); case TYPESPEC_STRUCT: return ctf_declaration_struct_visit(fd, depth, node->u._struct.name, @@ -1788,6 +1788,10 @@ int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node, return ret; } } + if (!trace->streams) { + fprintf(fd, "[error] %s: missing trace declaration\n", __func__); + return -EINVAL; + } cds_list_for_each_entry(iter, &node->u.root.stream, siblings) { ret = ctf_stream_visit(fd, depth + 1, iter, trace->root_declaration_scope, trace);