X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Fmetadata%2Fctf-parser.y;h=66e37923c9315dd482c577912f3f62a75fa5431a;hp=8d8c29ce1e4826841f819c8438a5f8f78f5d1afa;hb=2b0a0f95394186acf18c453209e31b028312ecf3;hpb=05628561ca57ff5d269571a72a12cb86854c5f70 diff --git a/formats/ctf/metadata/ctf-parser.y b/formats/ctf/metadata/ctf-parser.y index 8d8c29ce..66e37923 100644 --- a/formats/ctf/metadata/ctf-parser.y +++ b/formats/ctf/metadata/ctf-parser.y @@ -292,6 +292,7 @@ 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: @@ -493,10 +494,11 @@ static int reparent_type_specifier(struct ctf_node *node, break; case NODE_TYPE_DECLARATOR: parent->u.type_declarator.type = TYPEDEC_NESTED; - parent->u.type_declarator.u.nested.length = node; + 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); break; case NODE_ENUM: - parent->u._enum.container_type = node; + _cds_list_splice_tail(&node->tmp_head, &parent->u._enum.container_type); break; case NODE_STRUCT_OR_VARIANT_DECLARATION: _cds_list_splice_tail(&node->tmp_head, &parent->u.struct_or_variant_declaration.declaration_specifier); @@ -811,17 +813,16 @@ void ctf_scanner_free(struct ctf_scanner *scanner) %type stream_declaration %type trace_declaration %type declaration_specifiers +%type alias_declaration_specifiers %type type_declarator_list -%type abstract_type_declarator_list %type type_specifier %type struct_type_specifier %type variant_type_specifier -%type type_specifier_or_integer_constant +%type declaration_specifiers_or_integer_constant %type enum_type_specifier %type struct_or_variant_declaration_list %type struct_or_variant_declaration -%type specifier_qualifier_list %type struct_or_variant_declarator_list %type struct_or_variant_declarator %type enumerator_list @@ -829,12 +830,13 @@ void ctf_scanner_free(struct ctf_scanner *scanner) %type abstract_declarator_list %type abstract_declarator %type direct_abstract_declarator +%type alias_abstract_declarator_list +%type alias_abstract_declarator +%type direct_alias_abstract_declarator %type declarator %type direct_declarator %type type_declarator %type direct_type_declarator -%type abstract_type_declarator -%type direct_abstract_type_declarator %type pointer %type ctf_assignment_expression_list %type ctf_assignment_expression @@ -877,6 +879,8 @@ keywords: { $$ = yylval.gs; } | _COMPLEX { $$ = yylval.gs; } + | _IMAGINARY + { $$ = yylval.gs; } | FLOATING_POINT { $$ = yylval.gs; } | INTEGER @@ -1114,7 +1118,7 @@ declaration: _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier); _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators); } - | TYPEALIAS declaration_specifiers abstract_declarator_list COLON declaration_specifiers abstract_type_declarator_list SEMICOLON + | TYPEALIAS declaration_specifiers abstract_declarator_list COLON alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON { $$ = make_node(scanner, NODE_TYPEALIAS); $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET); @@ -1124,15 +1128,6 @@ declaration: _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier); _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators); } - | TYPEALIAS declaration_specifiers abstract_declarator_list COLON type_declarator_list SEMICOLON - { - $$ = 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); - _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier); - _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators); - } ; event_declaration: @@ -1240,16 +1235,6 @@ type_declarator_list: } ; -abstract_type_declarator_list: - abstract_type_declarator - { $$ = $1; } - | abstract_type_declarator_list COMMA abstract_type_declarator - { - $$ = $1; - cds_list_add_tail(&($3)->siblings, &($$)->tmp_head); - } - ; - type_specifier: VOID { @@ -1306,6 +1291,11 @@ type_specifier: $$ = make_node(scanner, NODE_TYPE_SPECIFIER); $$->u.type_specifier.type = TYPESPEC_COMPLEX; } + | _IMAGINARY + { + $$ = make_node(scanner, NODE_TYPE_SPECIFIER); + $$->u.type_specifier.type = TYPESPEC_IMAGINARY; + } | ID_TYPE { $$ = make_node(scanner, NODE_TYPE_SPECIFIER); @@ -1354,12 +1344,14 @@ struct_type_specifier: struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end { $$ = make_node(scanner, NODE_STRUCT); + $$->u._struct.has_body = 1; if (set_parent_node($2, $$)) reparent_error(scanner, "struct reparent error"); } | IDENTIFIER struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end { $$ = make_node(scanner, NODE_STRUCT); + $$->u._struct.has_body = 1; $$->u._struct.name = $1->s; if (set_parent_node($3, $$)) reparent_error(scanner, "struct reparent error"); @@ -1367,6 +1359,7 @@ struct_type_specifier: | ID_TYPE struct_declaration_begin struct_or_variant_declaration_list struct_declaration_end { $$ = make_node(scanner, NODE_STRUCT); + $$->u._struct.has_body = 1; $$->u._struct.name = $1->s; if (set_parent_node($3, $$)) reparent_error(scanner, "struct reparent error"); @@ -1374,11 +1367,13 @@ struct_type_specifier: | IDENTIFIER { $$ = make_node(scanner, NODE_STRUCT); + $$->u._struct.has_body = 0; $$->u._struct.name = $1->s; } | ID_TYPE { $$ = make_node(scanner, NODE_STRUCT); + $$->u._struct.has_body = 0; $$->u._struct.name = $1->s; } ; @@ -1397,12 +1392,14 @@ variant_type_specifier: variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end { $$ = make_node(scanner, NODE_VARIANT); + $$->u.variant.has_body = 1; if (set_parent_node($2, $$)) reparent_error(scanner, "variant reparent error"); } | LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end { $$ = make_node(scanner, NODE_VARIANT); + $$->u.variant.has_body = 1; $$->u.variant.choice = $2->s; if (set_parent_node($5, $$)) reparent_error(scanner, "variant reparent error"); @@ -1410,6 +1407,7 @@ variant_type_specifier: | LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end { $$ = make_node(scanner, NODE_VARIANT); + $$->u.variant.has_body = 1; $$->u.variant.choice = $2->s; if (set_parent_node($5, $$)) reparent_error(scanner, "variant reparent error"); @@ -1417,6 +1415,7 @@ variant_type_specifier: | IDENTIFIER variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end { $$ = make_node(scanner, NODE_VARIANT); + $$->u.variant.has_body = 1; $$->u.variant.name = $1->s; if (set_parent_node($3, $$)) reparent_error(scanner, "variant reparent error"); @@ -1424,6 +1423,7 @@ variant_type_specifier: | IDENTIFIER LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end { $$ = make_node(scanner, NODE_VARIANT); + $$->u.variant.has_body = 1; $$->u.variant.name = $1->s; $$->u.variant.choice = $3->s; if (set_parent_node($6, $$)) @@ -1432,12 +1432,14 @@ variant_type_specifier: | IDENTIFIER LT IDENTIFIER GT { $$ = make_node(scanner, NODE_VARIANT); + $$->u.variant.has_body = 0; $$->u.variant.name = $1->s; $$->u.variant.choice = $3->s; } | IDENTIFIER LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end { $$ = make_node(scanner, NODE_VARIANT); + $$->u.variant.has_body = 1; $$->u.variant.name = $1->s; $$->u.variant.choice = $3->s; if (set_parent_node($6, $$)) @@ -1446,12 +1448,14 @@ variant_type_specifier: | IDENTIFIER LT ID_TYPE GT { $$ = make_node(scanner, NODE_VARIANT); + $$->u.variant.has_body = 0; $$->u.variant.name = $1->s; $$->u.variant.choice = $3->s; } | ID_TYPE variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end { $$ = make_node(scanner, NODE_VARIANT); + $$->u.variant.has_body = 1; $$->u.variant.name = $1->s; if (set_parent_node($3, $$)) reparent_error(scanner, "variant reparent error"); @@ -1459,6 +1463,7 @@ variant_type_specifier: | ID_TYPE LT IDENTIFIER GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end { $$ = make_node(scanner, NODE_VARIANT); + $$->u.variant.has_body = 1; $$->u.variant.name = $1->s; $$->u.variant.choice = $3->s; if (set_parent_node($6, $$)) @@ -1467,12 +1472,14 @@ variant_type_specifier: | ID_TYPE LT IDENTIFIER GT { $$ = make_node(scanner, NODE_VARIANT); + $$->u.variant.has_body = 0; $$->u.variant.name = $1->s; $$->u.variant.choice = $3->s; } | ID_TYPE LT ID_TYPE GT variant_declaration_begin struct_or_variant_declaration_list variant_declaration_end { $$ = make_node(scanner, NODE_VARIANT); + $$->u.variant.has_body = 1; $$->u.variant.name = $1->s; $$->u.variant.choice = $3->s; if (set_parent_node($6, $$)) @@ -1481,6 +1488,7 @@ variant_type_specifier: | ID_TYPE LT ID_TYPE GT { $$ = make_node(scanner, NODE_VARIANT); + $$->u.variant.has_body = 0; $$->u.variant.name = $1->s; $$->u.variant.choice = $3->s; } @@ -1496,7 +1504,7 @@ variant_declaration_end: { pop_scope(scanner); } ; -type_specifier_or_integer_constant: +declaration_specifiers_or_integer_constant: declaration_specifiers { $$ = $1; } | DECIMAL_CONSTANT @@ -1526,98 +1534,114 @@ enum_type_specifier: LBRAC enumerator_list RBRAC { $$ = make_node(scanner, NODE_ENUM); + $$->u._enum.has_body = 1; _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list); } - | LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC + | LT declaration_specifiers GT LBRAC enumerator_list RBRAC { $$ = make_node(scanner, NODE_ENUM); - $$->u._enum.container_type = $2; + $$->u._enum.has_body = 1; + _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.container_type); _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list); } | IDENTIFIER LBRAC enumerator_list RBRAC { $$ = 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.enumerator_list); } - | IDENTIFIER LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC + | IDENTIFIER LT declaration_specifiers GT 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(&($3)->tmp_head, &($$)->u._enum.container_type); _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list); } | ID_TYPE LBRAC enumerator_list RBRAC { $$ = 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.enumerator_list); } - | ID_TYPE LT type_specifier_or_integer_constant GT LBRAC enumerator_list RBRAC + | ID_TYPE LT declaration_specifiers GT 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(&($3)->tmp_head, &($$)->u._enum.container_type); _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list); } | LBRAC enumerator_list COMMA RBRAC { $$ = make_node(scanner, NODE_ENUM); + $$->u._enum.has_body = 1; _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.enumerator_list); } - | LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC + | LT declaration_specifiers GT LBRAC enumerator_list COMMA RBRAC { $$ = make_node(scanner, NODE_ENUM); - $$->u._enum.container_type = $2; + $$->u._enum.has_body = 1; + _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._enum.container_type); _cds_list_splice_tail(&($5)->tmp_head, &($$)->u._enum.enumerator_list); } | IDENTIFIER LBRAC enumerator_list COMMA RBRAC { $$ = 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.enumerator_list); } - | IDENTIFIER LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC + | IDENTIFIER LT declaration_specifiers GT 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(&($3)->tmp_head, &($$)->u._enum.container_type); _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list); } | IDENTIFIER { $$ = make_node(scanner, NODE_ENUM); + $$->u._enum.has_body = 0; $$->u._enum.enum_id = $1->s; } - | IDENTIFIER LT type_specifier_or_integer_constant GT + | 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; + _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.container_type); } | ID_TYPE LBRAC enumerator_list COMMA RBRAC { $$ = 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.enumerator_list); } - | ID_TYPE LT type_specifier_or_integer_constant GT LBRAC enumerator_list COMMA RBRAC + | ID_TYPE LT declaration_specifiers GT 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(&($3)->tmp_head, &($$)->u._enum.container_type); _cds_list_splice_tail(&($6)->tmp_head, &($$)->u._enum.enumerator_list); } | ID_TYPE { $$ = make_node(scanner, NODE_ENUM); + $$->u._enum.has_body = 0; $$->u._enum.enum_id = $1->s; } - | ID_TYPE LT type_specifier_or_integer_constant GT + | 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; + _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._enum.container_type); } ; @@ -1637,32 +1661,32 @@ struct_or_variant_declaration_list: ; struct_or_variant_declaration: - specifier_qualifier_list struct_or_variant_declarator_list SEMICOLON + declaration_specifiers struct_or_variant_declarator_list SEMICOLON { $$ = make_node(scanner, NODE_STRUCT_OR_VARIANT_DECLARATION); _cds_list_splice_tail(&($1)->tmp_head, &($$)->u.struct_or_variant_declaration.declaration_specifier); _cds_list_splice_tail(&($2)->tmp_head, &($$)->u.struct_or_variant_declaration.type_declarators); } - | specifier_qualifier_list TYPEDEF specifier_qualifier_list type_declarator_list SEMICOLON + | declaration_specifiers TYPEDEF declaration_specifiers type_declarator_list SEMICOLON { $$ = 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); _cds_list_splice_tail(&($4)->tmp_head, &($$)->u._typedef.type_declarators); } - | TYPEDEF specifier_qualifier_list type_declarator_list SEMICOLON + | TYPEDEF declaration_specifiers type_declarator_list SEMICOLON { $$ = make_node(scanner, NODE_TYPEDEF); _cds_list_splice_tail(&($2)->tmp_head, &($$)->u._typedef.declaration_specifier); _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators); } - | specifier_qualifier_list TYPEDEF type_declarator_list SEMICOLON + | declaration_specifiers TYPEDEF type_declarator_list SEMICOLON { $$ = 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.type_declarators); } - | TYPEALIAS specifier_qualifier_list abstract_declarator_list COLON specifier_qualifier_list abstract_type_declarator_list SEMICOLON + | TYPEALIAS declaration_specifiers abstract_declarator_list COLON alias_declaration_specifiers alias_abstract_declarator_list SEMICOLON { $$ = make_node(scanner, NODE_TYPEALIAS); $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET); @@ -1672,18 +1696,9 @@ struct_or_variant_declaration: _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier); _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators); } - | TYPEALIAS specifier_qualifier_list abstract_declarator_list COLON type_declarator_list SEMICOLON - { - $$ = 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); - _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier); - _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators); - } ; -specifier_qualifier_list: +alias_declaration_specifiers: CONST { $$ = make_node(scanner, NODE_TYPE_SPECIFIER); @@ -1691,7 +1706,14 @@ specifier_qualifier_list: } | type_specifier { $$ = $1; } - | specifier_qualifier_list CONST + | IDENTIFIER + { + 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; + } + | alias_declaration_specifiers CONST { struct ctf_node *node; @@ -1700,11 +1722,22 @@ specifier_qualifier_list: node->u.type_specifier.type = TYPESPEC_CONST; cds_list_add_tail(&node->siblings, &($$)->tmp_head); } - | specifier_qualifier_list type_specifier + | alias_declaration_specifiers type_specifier { $$ = $1; cds_list_add_tail(&($2)->siblings, &($$)->tmp_head); } + | alias_declaration_specifiers IDENTIFIER + { + struct ctf_node *node; + + add_type(scanner, $2); + $$ = $1; + 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); + } ; struct_or_variant_declarator_list: @@ -1837,12 +1870,13 @@ direct_abstract_declarator: $$->u.type_declarator.type = TYPEDEC_NESTED; $$->u.type_declarator.u.nested.type_declarator = $2; } - | direct_abstract_declarator LSBRAC type_specifier_or_integer_constant RSBRAC + | direct_abstract_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC { $$ = make_node(scanner, NODE_TYPE_DECLARATOR); $$->u.type_declarator.type = TYPEDEC_NESTED; $$->u.type_declarator.u.nested.type_declarator = $1; - $$->u.type_declarator.u.nested.length = $3; + CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length); + _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length); } | direct_abstract_declarator LSBRAC RSBRAC { @@ -1853,114 +1887,120 @@ direct_abstract_declarator: } ; -declarator: - direct_declarator +alias_abstract_declarator_list: + alias_abstract_declarator { $$ = $1; } - | pointer direct_declarator + | alias_abstract_declarator_list COMMA alias_abstract_declarator + { + $$ = $1; + cds_list_add_tail(&($3)->siblings, &($$)->tmp_head); + } + ; + +alias_abstract_declarator: + direct_alias_abstract_declarator + { $$ = $1; } + | pointer direct_alias_abstract_declarator { $$ = $2; cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers); } ; -direct_declarator: - IDENTIFIER +direct_alias_abstract_declarator: + /* empty */ { $$ = make_node(scanner, NODE_TYPE_DECLARATOR); - $$->u.type_declarator.type = TYPEDEC_ID; - $$->u.type_declarator.u.id = $1->s; + $$->u.type_declarator.type = TYPEDEC_ID; + /* id is NULL */ } - | LPAREN declarator RPAREN + | LPAREN alias_abstract_declarator RPAREN { $$ = make_node(scanner, NODE_TYPE_DECLARATOR); $$->u.type_declarator.type = TYPEDEC_NESTED; $$->u.type_declarator.u.nested.type_declarator = $2; } - | direct_declarator LSBRAC type_specifier_or_integer_constant RSBRAC + | direct_alias_abstract_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC { $$ = make_node(scanner, NODE_TYPE_DECLARATOR); $$->u.type_declarator.type = TYPEDEC_NESTED; $$->u.type_declarator.u.nested.type_declarator = $1; - $$->u.type_declarator.u.nested.length = $3; + CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length); + _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length); + } + | direct_alias_abstract_declarator LSBRAC RSBRAC + { + $$ = make_node(scanner, NODE_TYPE_DECLARATOR); + $$->u.type_declarator.type = TYPEDEC_NESTED; + $$->u.type_declarator.u.nested.type_declarator = $1; + $$->u.type_declarator.u.nested.abstract_array = 1; } ; -type_declarator: - direct_type_declarator +declarator: + direct_declarator { $$ = $1; } - | pointer direct_type_declarator + | pointer direct_declarator { $$ = $2; cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers); } ; -direct_type_declarator: +direct_declarator: IDENTIFIER { - add_type(scanner, $1); $$ = make_node(scanner, NODE_TYPE_DECLARATOR); $$->u.type_declarator.type = TYPEDEC_ID; $$->u.type_declarator.u.id = $1->s; } - | LPAREN type_declarator RPAREN + | LPAREN declarator RPAREN { $$ = make_node(scanner, NODE_TYPE_DECLARATOR); $$->u.type_declarator.type = TYPEDEC_NESTED; $$->u.type_declarator.u.nested.type_declarator = $2; } - | direct_type_declarator LSBRAC type_specifier_or_integer_constant RSBRAC + | direct_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC { $$ = make_node(scanner, NODE_TYPE_DECLARATOR); $$->u.type_declarator.type = TYPEDEC_NESTED; $$->u.type_declarator.u.nested.type_declarator = $1; - $$->u.type_declarator.u.nested.length = $3; + CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length); + _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length); } ; -abstract_type_declarator: - direct_abstract_type_declarator +type_declarator: + direct_type_declarator { $$ = $1; } - | pointer direct_abstract_type_declarator + | pointer direct_type_declarator { $$ = $2; cds_list_splice(&($1)->tmp_head, &($$)->u.type_declarator.pointers); } ; -direct_abstract_type_declarator: - /* empty */ - { - $$ = make_node(scanner, NODE_TYPE_DECLARATOR); - $$->u.type_declarator.type = TYPEDEC_ID; - /* id is NULL */ - } - | IDENTIFIER +direct_type_declarator: + IDENTIFIER { add_type(scanner, $1); $$ = make_node(scanner, NODE_TYPE_DECLARATOR); $$->u.type_declarator.type = TYPEDEC_ID; $$->u.type_declarator.u.id = $1->s; } - | LPAREN abstract_type_declarator RPAREN + | LPAREN type_declarator RPAREN { $$ = make_node(scanner, NODE_TYPE_DECLARATOR); $$->u.type_declarator.type = TYPEDEC_NESTED; $$->u.type_declarator.u.nested.type_declarator = $2; } - | direct_abstract_type_declarator LSBRAC type_specifier_or_integer_constant RSBRAC + | direct_type_declarator LSBRAC declaration_specifiers_or_integer_constant RSBRAC { $$ = make_node(scanner, NODE_TYPE_DECLARATOR); $$->u.type_declarator.type = TYPEDEC_NESTED; $$->u.type_declarator.u.nested.type_declarator = $1; - $$->u.type_declarator.u.nested.length = $3; - } - | direct_abstract_type_declarator LSBRAC RSBRAC - { - $$ = make_node(scanner, NODE_TYPE_DECLARATOR); - $$->u.type_declarator.type = TYPEDEC_NESTED; - $$->u.type_declarator.u.nested.type_declarator = $1; - $$->u.type_declarator.u.nested.abstract_array = 1; + CDS_INIT_LIST_HEAD(&($$)->u.type_declarator.u.nested.length); + _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.type_declarator.u.nested.length); } ; @@ -2045,7 +2085,7 @@ ctf_assignment_expression: _cds_list_splice_tail(&($1)->tmp_head, &($$)->u._typedef.declaration_specifier); _cds_list_splice_tail(&($3)->tmp_head, &($$)->u._typedef.type_declarators); } - | TYPEALIAS declaration_specifiers abstract_declarator_list COLON declaration_specifiers abstract_type_declarator_list + | TYPEALIAS declaration_specifiers abstract_declarator_list COLON alias_declaration_specifiers alias_abstract_declarator_list { $$ = make_node(scanner, NODE_TYPEALIAS); $$->u.typealias.target = make_node(scanner, NODE_TYPEALIAS_TARGET); @@ -2055,13 +2095,4 @@ ctf_assignment_expression: _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier); _cds_list_splice_tail(&($6)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators); } - | TYPEALIAS declaration_specifiers abstract_declarator_list COLON type_declarator_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); - _cds_list_splice_tail(&($3)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.declaration_specifier); - _cds_list_splice_tail(&($5)->tmp_head, &($$)->u.typealias.alias->u.typealias_alias.type_declarators); - } ;