From: Akim Demaille Date: Wed, 27 Mar 2013 08:18:32 +0000 (+0100) Subject: api.value.type: diagnose guaranteed failure with --yacc X-Git-Tag: v2.7.90~39 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/1fa19a769721658bb53177596531afbbea8b4e1c 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 3816fdd5..60a62e1d 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 "integer" diff --git a/data/bison.m4 b/data/bison.m4 index 8e105d0d..e536ceb3 100644 --- a/data/bison.m4 +++ b/data/bison.m4 @@ -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"])])])]) diff --git a/doc/bison.texi b/doc/bison.texi index 6f50658a..198403fe 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 5f7ff387..7dbc3db7 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 7cf0b23d..acd0e1c4 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. ## ## ---------------- ##