%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

View File

@@ -3851,7 +3851,7 @@ example:
@noindent
specifies the union tag @code{value}, so the corresponding C type is
@code{union value}. If you do not specify a tag, it defaults to
@code{YYSTYPE}.
@code{YYSTYPE} (@pxref{%define Summary,,api.value.union.name}).
As another extension to POSIX, you may specify multiple @code{%union}
declarations; their contents are concatenated. However, only the first
@@ -6014,12 +6014,12 @@ Use this @var{type} as semantic value.
@item Default Value:
@itemize @minus
@item
@code{%union} if @code{%union} is used, otherwise @dots{}
@code{union-directive} if @code{%union} is used, otherwise @dots{}
@item
@code{int} if type tags are used (i.e., @samp{%token <@var{type}>@dots{}} or
@samp{%token <@var{type}>@dots{}} is used), otherwise @dots{}
@samp{%type <@var{type}>@dots{}} is used), otherwise @dots{}
@item
@code{""}
undefined.
@end itemize
@item History:
@@ -6030,6 +6030,30 @@ introduced in Bison 3.0. Was introduced for Java only in 2.3b as
@c api.value.type
@c ================================================== api.value.union.name
@deffn Directive {%define api.value.union.name} @var{name}
@itemize @bullet
@item Language(s):
C
@item Purpose:
The tag of the generated @code{union} (@emph{not} the name of the
@code{typedef}). This variable is set to @code{@var{id}} when @samp{%union
@var{id}} is used. There is no clear reason to give this union a name.
@item Accepted Values:
Any valid identifier.
@item Default Value:
@code{YYSTYPE}.
@item History:
Introduced in Bison 3.0.3.
@end itemize
@end deffn
@c api.value.type
@c ================================================== location_type
@deffn Directive {%define location_type}
Obsoleted by @code{api.location.type} since Bison 2.7.