mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
api.value.type: diagnose guaranteed failure with --yacc
Instead of generating invalid C code, generate an error when --yacc and '%define api.value.type union' are used together. * data/bison.m4: Issue an error in this case. * tests/types.at (%yacc vs. %define api.value.type union): New, check this error. * doc/bison.texi (Type Generation): Document it. * tests/output.at: Check that '-o y.tab.c' and '-y' behave equally wrt generated file names. * NEWS (Use of YACC='bison -y'): New. Promote the use of 'bison -o y.tab.c'.
This commit is contained in:
23
NEWS
23
NEWS
@@ -23,6 +23,26 @@ GNU Bison NEWS
|
||||
Missing semicolons at the end of actions are no longer added (as announced
|
||||
in the release 2.5).
|
||||
|
||||
*** Use of YACC='bison -y'
|
||||
|
||||
TL;DR: With Autoconf <= 2.69, pass -Wno-yacc to (AM_)YFLAGS if you use
|
||||
Bison extensions.
|
||||
|
||||
Traditional Yacc generates 'y.tab.c' whatever the name of the input file.
|
||||
Therefore Makefiles written for Yacc expect 'y.tab.c' (and possibly
|
||||
'y.tab.h' and 'y.outout') to be generated from 'foo.y'.
|
||||
|
||||
To this end, for ages, AC_PROG_YACC, Autoconf's macro to look for an
|
||||
implementation of Yacc, was using Bison as 'bison -y'. While it does
|
||||
ensure compatible output file names, it also enables warnings for
|
||||
incompatibilities with POSIX Yacc. In other words, 'bison -y' triggers
|
||||
warnings for Bison extensions.
|
||||
|
||||
Autoconf 2.70+ fixes this incompatibility by using YACC='bison -o y.tab.c'
|
||||
(which also generates 'y.tab.h' and 'y.output' when needed).
|
||||
Alternatively, disable Yacc warnings by passing '-Wno-yacc' to your Yacc
|
||||
flags (YFLAGS, or AM_YFLAGS with Automake).
|
||||
|
||||
** Bug fixes
|
||||
|
||||
*** The epilogue is no longer affected by internal #defines (glr.c)
|
||||
@@ -276,7 +296,8 @@ GNU Bison NEWS
|
||||
|
||||
The %define variable api.value.type supports several special values. The
|
||||
value "union" means that the user provides genuine types, not union member
|
||||
names such as "ival" and "sval" above.
|
||||
names such as "ival" and "sval" above (WARNING: will fail if
|
||||
-y/--yacc/%yacc is enabled).
|
||||
|
||||
%define api.value.type "union"
|
||||
%token <int> INT "integer"
|
||||
|
||||
@@ -960,7 +960,12 @@ m4_define_default([b4_parse_param], [])
|
||||
m4_define_default([b4_location_initial_column], [1])
|
||||
m4_define_default([b4_location_initial_line], [1])
|
||||
|
||||
# Sanity checks.
|
||||
|
||||
## --------------- ##
|
||||
## Sanity checks. ##
|
||||
## --------------- ##
|
||||
|
||||
# api.prefix >< %name-prefix.
|
||||
b4_percent_define_ifdef([api.prefix],
|
||||
[m4_ifdef([b4_prefix],
|
||||
[b4_complain_at(b4_percent_define_get_loc([api.prefix]),
|
||||
@@ -968,9 +973,19 @@ b4_percent_define_ifdef([api.prefix],
|
||||
[%name-prefix],
|
||||
[%define api.prefix])])])
|
||||
|
||||
# api.value.type >< %union.
|
||||
b4_percent_define_ifdef([api.value.type],
|
||||
[m4_ifdef([b4_union_members],
|
||||
[b4_complain_at(b4_percent_define_get_loc([api.value.type]),
|
||||
[['%s' and '%s' cannot be used together]],
|
||||
[%union],
|
||||
[%define api.value.type])])])
|
||||
|
||||
# api.value.type=union >< %yacc.
|
||||
b4_percent_define_ifdef([api.value.type],
|
||||
[m4_if(b4_percent_define_get([api.value.type]), [union],
|
||||
[b4_yacc_if(dnl
|
||||
[b4_complain_at(b4_percent_define_get_loc([api.value.type]),
|
||||
[['%s' and '%s' cannot be used together]],
|
||||
[%yacc],
|
||||
[%define api.value.type "union"])])])])
|
||||
|
||||
@@ -3795,6 +3795,11 @@ yylval.TOK_INT = 42;
|
||||
return TOK_INT;
|
||||
@end example
|
||||
|
||||
This Bison extension cannot work if @code{%yacc} (or
|
||||
@option{-y}/@option{--yacc}) is enabled, as POSIX mandates that Yacc
|
||||
generate tokens as macros (e.g., @samp{#define INT 258}, or @samp{#define
|
||||
TOK_INT 258}).
|
||||
|
||||
This feature is new, and user feedback would be most welcome.
|
||||
|
||||
A similar feature is provided for C++ that in addition overcomes C++
|
||||
|
||||
@@ -62,8 +62,13 @@ AT_CHECK_OUTPUT([foo.y], [], [-dv -o foo.c],
|
||||
[foo.c foo.h foo.output])
|
||||
AT_CHECK_OUTPUT([foo.y], [], [-dv -o foo.tab.c],
|
||||
[foo.output foo.tab.c foo.tab.h])
|
||||
AT_CHECK_OUTPUT([foo.y], [], [-dv -y],
|
||||
[y.output y.tab.c y.tab.h])
|
||||
|
||||
AT_CHECK_OUTPUT([foo.y], [], [-dv -g --xml -y],
|
||||
[y.dot y.output y.tab.c y.tab.h y.xml])
|
||||
# With '-o y.tab.c', we expect 'y.output' etc. (for compatility with Yacc).
|
||||
AT_CHECK_OUTPUT([foo.y], [], [-dv -g --xml -o y.tab.c],
|
||||
[y.dot y.output y.tab.c y.tab.h y.xml])
|
||||
|
||||
AT_CHECK_OUTPUT([foo.y], [], [-dv -b bar],
|
||||
[bar.output bar.tab.c bar.tab.h])
|
||||
AT_CHECK_OUTPUT([foo.y], [], [-dv -g -o foo.c],
|
||||
|
||||
@@ -37,6 +37,26 @@ AT_BISON_CHECK([[input.y]], [[1]], [[]],
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
## ---------------------------------------- ##
|
||||
## %yacc vs. %define api.value.type union. ##
|
||||
## ---------------------------------------- ##
|
||||
|
||||
AT_SETUP([[%yacc vs. %define api.value.type union]])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%yacc
|
||||
%define api.value.type "union"
|
||||
%%
|
||||
exp: %empty;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK([[input.y]], [[1]], [[]],
|
||||
[[input.y:2.9-22: error: '%yacc' and '%define api.value.type "union"' cannot be used together
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## ---------------- ##
|
||||
## api.value.type. ##
|
||||
## ---------------- ##
|
||||
|
||||
Reference in New Issue
Block a user