From: Mathieu Desnoyers Date: Thu, 28 Apr 2011 23:28:19 +0000 (-0400) Subject: enum, change enum name to enum name : container_type X-Git-Tag: v0.1~130 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=0fbb34a5699c1dcb43d8e2b870390e7041465466 enum, change enum name to enum name : container_type This follows c++0x semantic (upcoming c++ standard). Signed-off-by: Mathieu Desnoyers --- diff --git a/formats/ctf/metadata/Makefile.am b/formats/ctf/metadata/Makefile.am index 50b50430..ddd7d1e0 100644 --- a/formats/ctf/metadata/Makefile.am +++ b/formats/ctf/metadata/Makefile.am @@ -1,6 +1,6 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include BUILT_SOURCES = ctf-parser.h -AM_YFLAGS = -t -d +AM_YFLAGS = -t -d -v noinst_LIBRARIES = libctf-parser.a libctf-ast.a diff --git a/formats/ctf/metadata/ctf-parser.y b/formats/ctf/metadata/ctf-parser.y index ad23ac64..2e1846d9 100644 --- a/formats/ctf/metadata/ctf-parser.y +++ b/formats/ctf/metadata/ctf-parser.y @@ -839,6 +839,15 @@ void ctf_scanner_free(struct ctf_scanner *scanner) /* %locations */ %parse-param {struct ctf_scanner *scanner} %lex-param {struct ctf_scanner *scanner} +/* + * Expect two shift-reduce conflicts. Caused by enum name-opt : type {} + * vs struct { int :value; } (unnamed bit-field). The default is to + * shift, so whenever we encounter an enumeration, we are doing the + * proper thing (shift). It is illegal to declare an enumeration + * "bit-field", so it is OK if this situation ends up in a parsing + * error. + */ +%expect 2 %start file %token CHARACTER_CONSTANT_START SQUOTE STRING_LITERAL_START DQUOTE ESCSEQ CHAR_STRING_TOKEN LSBRAC RSBRAC LPAREN RPAREN LBRAC RBRAC RARROW STAR PLUS MINUS LT GT TYPEASSIGN COLON SEMICOLON DOTDOTDOT DOT EQUAL COMMA CONST CHAR DOUBLE ENUM EVENT FLOATING_POINT FLOAT INTEGER INT LONG SHORT SIGNED STREAM STRING STRUCT TRACE TYPEALIAS TYPEDEF UNSIGNED VARIANT VOID _BOOL _COMPLEX _IMAGINARY DECIMAL_CONSTANT OCTAL_CONSTANT HEXADECIMAL_CONSTANT %token IDENTIFIER ID_TYPE @@ -860,10 +869,12 @@ void ctf_scanner_free(struct ctf_scanner *scanner) %type event_declaration %type stream_declaration %type trace_declaration +%type integer_declaration_specifiers %type declaration_specifiers %type alias_declaration_specifiers %type type_declarator_list +%type integer_type_specifier %type type_specifier %type struct_type_specifier %type variant_type_specifier @@ -1268,6 +1279,40 @@ trace_declaration_end: { pop_scope(scanner); } ; +integer_declaration_specifiers: + 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); + } + | integer_type_specifier + { + struct ctf_node *node; + + $$ = make_node(scanner, NODE_TYPE_SPECIFIER_LIST); + node = $1; + cds_list_add_tail(&node->siblings, &($$)->u.type_specifier_list.head); + } + | integer_declaration_specifiers CONST + { + struct ctf_node *node; + + $$ = $1; + 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); + } + | integer_declaration_specifiers integer_type_specifier + { + $$ = $1; + cds_list_add_tail(&($2)->siblings, &($$)->u.type_specifier_list.head); + } + ; + declaration_specifiers: CONST { @@ -1312,6 +1357,64 @@ type_declarator_list: } ; +integer_type_specifier: + CHAR + { + $$ = make_node(scanner, NODE_TYPE_SPECIFIER); + $$->u.type_specifier.type = TYPESPEC_CHAR; + } + | SHORT + { + $$ = make_node(scanner, NODE_TYPE_SPECIFIER); + $$->u.type_specifier.type = TYPESPEC_SHORT; + } + | INT + { + $$ = make_node(scanner, NODE_TYPE_SPECIFIER); + $$->u.type_specifier.type = TYPESPEC_INT; + } + | LONG + { + $$ = make_node(scanner, NODE_TYPE_SPECIFIER); + $$->u.type_specifier.type = TYPESPEC_LONG; + } + | SIGNED + { + $$ = make_node(scanner, NODE_TYPE_SPECIFIER); + $$->u.type_specifier.type = TYPESPEC_SIGNED; + } + | UNSIGNED + { + $$ = make_node(scanner, NODE_TYPE_SPECIFIER); + $$->u.type_specifier.type = TYPESPEC_UNSIGNED; + } + | _BOOL + { + $$ = make_node(scanner, NODE_TYPE_SPECIFIER); + $$->u.type_specifier.type = TYPESPEC_BOOL; + } + | ID_TYPE + { + $$ = make_node(scanner, NODE_TYPE_SPECIFIER); + $$->u.type_specifier.type = TYPESPEC_ID_TYPE; + $$->u.type_specifier.id_type = yylval.gs->s; + } + | INTEGER LBRAC RBRAC + { + $$ = 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_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"); + } + ; + type_specifier: VOID { @@ -1638,12 +1741,12 @@ enum_type_specifier: $$->u._enum.has_body = 1; _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list); } - | LT declaration_specifiers GT LBRAC enumerator_list RBRAC + | COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC { $$ = make_node(scanner, NODE_ENUM); $$->u._enum.has_body = 1; ($$)->u._enum.container_type = $2; - _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list); + _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list); } | IDENTIFIER LBRAC enumerator_list RBRAC { @@ -1652,13 +1755,13 @@ enum_type_specifier: $$->u._enum.enum_id = $1->s; _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list); } - | IDENTIFIER LT declaration_specifiers GT LBRAC enumerator_list RBRAC + | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC { $$ = make_node(scanner, NODE_ENUM); $$->u._enum.has_body = 1; $$->u._enum.enum_id = $1->s; ($$)->u._enum.container_type = $3; - _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list); + _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list); } | ID_TYPE LBRAC enumerator_list RBRAC { @@ -1667,13 +1770,13 @@ enum_type_specifier: $$->u._enum.enum_id = $1->s; _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list); } - | ID_TYPE LT declaration_specifiers GT LBRAC enumerator_list RBRAC + | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list RBRAC { $$ = make_node(scanner, NODE_ENUM); $$->u._enum.has_body = 1; $$->u._enum.enum_id = $1->s; ($$)->u._enum.container_type = $3; - _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list); + _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list); } | LBRAC enumerator_list COMMA RBRAC { @@ -1681,12 +1784,12 @@ enum_type_specifier: $$->u._enum.has_body = 1; _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list); } - | LT declaration_specifiers GT LBRAC enumerator_list COMMA RBRAC + | COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC { $$ = make_node(scanner, NODE_ENUM); $$->u._enum.has_body = 1; ($$)->u._enum.container_type = $2; - _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list); + _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._enum.enumerator_list); } | IDENTIFIER LBRAC enumerator_list COMMA RBRAC { @@ -1695,13 +1798,13 @@ enum_type_specifier: $$->u._enum.enum_id = $1->s; _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list); } - | IDENTIFIER LT declaration_specifiers GT LBRAC enumerator_list COMMA RBRAC + | IDENTIFIER COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC { $$ = make_node(scanner, NODE_ENUM); $$->u._enum.has_body = 1; $$->u._enum.enum_id = $1->s; ($$)->u._enum.container_type = $3; - _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list); + _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list); } | IDENTIFIER { @@ -1709,13 +1812,6 @@ enum_type_specifier: $$->u._enum.has_body = 0; $$->u._enum.enum_id = $1->s; } - | IDENTIFIER LT declaration_specifiers GT - { - $$ = make_node(scanner, NODE_ENUM); - $$->u._enum.has_body = 0; - $$->u._enum.enum_id = $1->s; - ($$)->u._enum.container_type = $3; - } | ID_TYPE LBRAC enumerator_list COMMA RBRAC { $$ = make_node(scanner, NODE_ENUM); @@ -1723,13 +1819,13 @@ enum_type_specifier: $$->u._enum.enum_id = $1->s; _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.enumerator_list); } - | ID_TYPE LT declaration_specifiers GT LBRAC enumerator_list COMMA RBRAC + | ID_TYPE COLON integer_declaration_specifiers LBRAC enumerator_list COMMA RBRAC { $$ = make_node(scanner, NODE_ENUM); $$->u._enum.has_body = 1; $$->u._enum.enum_id = $1->s; ($$)->u._enum.container_type = $3; - _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list); + _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list); } | ID_TYPE { @@ -1737,13 +1833,6 @@ enum_type_specifier: $$->u._enum.has_body = 0; $$->u._enum.enum_id = $1->s; } - | ID_TYPE LT declaration_specifiers GT - { - $$ = make_node(scanner, NODE_ENUM); - $$->u._enum.has_body = 0; - $$->u._enum.enum_id = $1->s; - ($$)->u._enum.container_type = $3; - } ; struct_or_variant_declaration_list: diff --git a/formats/ctf/metadata/ctf-test/succeed/ctf-test.txt b/formats/ctf/metadata/ctf-test/succeed/ctf-test.txt index c148a436..932db5c9 100644 --- a/formats/ctf/metadata/ctf-test/succeed/ctf-test.txt +++ b/formats/ctf/metadata/ctf-test/succeed/ctf-test.txt @@ -3,7 +3,7 @@ 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 { +enum name1 : int { ZERO, ONE, TWO, @@ -11,18 +11,18 @@ enum name1 { ELEVEN, }; -enum name2 { ONE, TWO }; +enum name2 : long { ONE, TWO }; -enum name3 { ONE, TWO }; +enum name3 : unsigned long { ONE, TWO }; -enum name4 { +enum name4 : unsigned long { string = 1 ... 2, "other string" = 3...4, yet_another_string, /* will be assigned to end_value2 + 1 */ "some other string" = 10, }; -enum name5 { "int" = 1, }; +enum name5 : long { "int" = 1, }; typealias floating_point { exp_dig = 8; /* sizeof(float) * CHAR_BIT - FLT_MANT_DIG */ @@ -69,7 +69,7 @@ struct name { typealias integer { size = 16; align = 16; signed = true; } := short; typealias uint32_t := unsigned int; - enum { a, b, c, d } choice; + enum : uint2_t { a, b, c, d } choice; /* Unrelated fields can be added between the variant and its tag */ int32_t somevalue; variant { @@ -130,7 +130,7 @@ struct event_header_1 { * id: range: 0 - 30. * id 31 is reserved to indicate an extended header. */ - enum { compact = 0 ... 30, extended = 31 } id; + enum : uint5_t { compact = 0 ... 30, extended = 31 } id; variant { struct { uint27_t timestamp; @@ -151,7 +151,7 @@ struct event_header_2 { * id: range: 0 - 65534. * id 65535 is reserved to indicate an extended header. */ - enum { compact = 0 ... 65534, extended = 65535 } id; + enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id; variant { struct { uint32_t timestamp;