Le 25 mars 2013 à 09:21, Akim Demaille <[email protected]> a écrit :
>> All this seems fine to me. How did you decide to address the yacc #define >> issue? I suppose it's OK to break with perfect yacc compatibility when >> using a non-yacc feature. > > Autoconf was modified to use YACC='bison -o y.tab.c' instead of > YACC='bison -y'. It has the same effect, but it does not enable > -Wyacc. So eventually, users won't even notice. Meanwhile I > will recommend, in NEWS, that users (of older Autoconfs) pass > -Wno-yacc to AM_YFLAGS. I have installed the following patch in the api.value.type branch. I still have to address your other message. Thanks again Joel! commit 279eff672a0c40cda9daeed0618e5ad9b2f298e0 Author: Akim Demaille <[email protected]> Date: Wed Mar 27 09:18:32 2013 +0100 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'. diff --git a/NEWS b/NEWS index 3816fdd..60a62e1 100644 --- a/NEWS +++ b/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" diff --git a/data/bison.m4 b/data/bison.m4 index 7cc0fa6..fd2deca 100644 --- a/data/bison.m4 +++ b/data/bison.m4 @@ -946,7 +946,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]), @@ -954,9 +959,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"])])])]) diff --git a/doc/bison.texi b/doc/bison.texi index 3066ffb..736947a 100644 --- a/doc/bison.texi +++ b/doc/bison.texi @@ -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++ diff --git a/tests/output.at b/tests/output.at index 5f7ff38..7dbc3db 100644 --- a/tests/output.at +++ b/tests/output.at @@ -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], diff --git a/tests/types.at b/tests/types.at index 7cf0b23..acd0e1c 100644 --- a/tests/types.at +++ b/tests/types.at @@ -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. ## ## ---------------- ##
