enum, change enum name <container_type> to enum name : container_type
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 28 Apr 2011 23:28:19 +0000 (19:28 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 28 Apr 2011 23:28:19 +0000 (19:28 -0400)
This follows c++0x semantic (upcoming c++ standard).

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/metadata/Makefile.am
formats/ctf/metadata/ctf-parser.y
formats/ctf/metadata/ctf-test/succeed/ctf-test.txt

index 50b50430ff6b4dba58cc9df5586677059e74643e..ddd7d1e089d7bec8e2a815dfc8daf6d1feff1cbb 100644 (file)
@@ -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
 
index ad23ac64c8230e0ce88a639dd9081452c3963d1b..2e1846d91421a44acf461c0254234338d9d791ff 100644 (file)
@@ -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 <gs> IDENTIFIER ID_TYPE
@@ -860,10 +869,12 @@ void ctf_scanner_free(struct ctf_scanner *scanner)
 %type <n> event_declaration
 %type <n> stream_declaration
 %type <n> trace_declaration
+%type <n> integer_declaration_specifiers
 %type <n> declaration_specifiers
 %type <n> alias_declaration_specifiers
 
 %type <n> type_declarator_list
+%type <n> integer_type_specifier
 %type <n> type_specifier
 %type <n> struct_type_specifier
 %type <n> 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:
index c148a436964ea350a926c564e1096f6a2b294789..932db5c9844c3051d6631875540ca65f1c1e975a 100644 (file)
@@ -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 <int> {
+enum name1 : int {
   ZERO,
   ONE,
   TWO,
@@ -11,18 +11,18 @@ enum name1 <int> {
   ELEVEN,
 };
 
-enum name2 <long> { ONE, TWO };
+enum name2 : long { ONE, TWO };
 
-enum name3 <unsigned long> { ONE, TWO };
+enum name3 : unsigned long { ONE, TWO };
 
-enum name4 <unsigned long> {
+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 <long> { "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 <uint2_t> { 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 <choice> {
@@ -130,7 +130,7 @@ struct event_header_1 {
    * id: range: 0 - 30.
    * id 31 is reserved to indicate an extended header.
    */
-  enum <uint5_t> { compact = 0 ... 30, extended = 31 } id;
+  enum : uint5_t { compact = 0 ... 30, extended = 31 } id;
   variant <id> {
     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 <uint16_t> { compact = 0 ... 65534, extended = 65535 } id;
+  enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;
   variant <id> {
     struct {
       uint32_t timestamp;
This page took 0.0315839999999999 seconds and 4 git commands to generate.