%union: fix the support for named %union

Bison supports a union tag, for obscure reasons.  But it does a poor
job at it, especially since Bison 3.0.
Reported by Stephen Cameron and Tobias Frost.

It did not ensure that the name was not given several times.  An easy
way to do this is to make the %union tag be handled as a %define
variable, as they cannot be defined several times.

Since Bison 3.0, the synclines were wrongly placed, resulting in
invalid code.  Addressing this issue, because of the way the union tag
was stored (as a code muscle), would have been tedious.  Unless we
rather define the %union tag as a %percent variable, whose synclines
are easier to manipulate.

So replace the b4_union_name muscle by the api.value.union.name
%define variable, document, and check.

* data/bison.m4: Make sure that api.value.union.name has a keyword value.
* data/c++.m4: Make sure that api.value.union.name is not defined.
* data/c.m4 (b4_union_name): No longer use it, use api.value.union.name.
* doc/bison.texi (%define Summary): Document it.
* src/parse-gram.y (union_name): No longer define b4_uion_name, but
api.value.union.name.
* tests/input.at (Redefined %union name): New.
* tests/synclines.at (%union name syncline): New.
* tests/types.at: Check named %unions.
This commit is contained in:
Akim Demaille
2015-01-04 14:16:23 +01:00
parent 3209eb1c4c
commit 827bc59ca1
12 changed files with 363 additions and 212 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -61,7 +61,7 @@ extern int gram_debug;
param_parse = 1 << 1,
param_both = param_lex | param_parse
} param_type;
#line 645 "src/parse-gram.y" /* yacc.c:1909 */
#line 647 "src/parse-gram.y" /* yacc.c:1909 */
#include "muscle-tab.h"
#line 68 "src/parse-gram.h" /* yacc.c:1909 */
@@ -132,7 +132,7 @@ extern int gram_debug;
/* Value type. */
#if ! defined GRAM_STYPE && ! defined GRAM_STYPE_IS_DECLARED
typedef union GRAM_STYPE GRAM_STYPE;
union GRAM_STYPE
{
#line 182 "src/parse-gram.y" /* yacc.c:1909 */
@@ -155,7 +155,7 @@ named_ref *named_ref;
param_type param;
#line 409 "src/parse-gram.y" /* yacc.c:1909 */
code_props_type code_type;
#line 647 "src/parse-gram.y" /* yacc.c:1909 */
#line 649 "src/parse-gram.y" /* yacc.c:1909 */
struct
{
@@ -165,6 +165,8 @@ code_props_type code_type;
#line 167 "src/parse-gram.h" /* yacc.c:1909 */
};
typedef union GRAM_STYPE GRAM_STYPE;
# define GRAM_STYPE_IS_TRIVIAL 1
# define GRAM_STYPE_IS_DECLARED 1
#endif

View File

@@ -421,7 +421,9 @@ code_props_type:
union_name:
%empty {}
| ID { muscle_code_grow ("union_name", $1, @1); }
| ID { muscle_percent_define_insert ("api.value.union.name",
@1, muscle_keyword, $1,
MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE); }
;
grammar_declaration: